-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
118 lines (89 loc) · 3.01 KB
/
plugin.php
File metadata and controls
118 lines (89 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* Plugin Name: LDC2020 Blocks
* Description: Gutenberg Blocks for LDC2020 Theme.
* Author: Simplicity Partners
* Text Domain: michel-blocks
*/
if (!defined('ABSPATH')) {
exit;
}
function ldc_register_dynamic_block($block, $options = array())
{
register_block_type(
'ldc/' . $block,
array_merge(
array(
'editor_script' => 'michel-blocks-editor-script',
'editor_style' => 'michel-blocks-editor-style',
// 'style' => 'michel-blocks-style'
),
$options
)
);
}
function ldc2020_blocks_register()
{
wp_register_script(
'michel-blocks-editor-script',
plugins_url('dist/js/editor.blocks.js', __FILE__),
array('wp-blocks', 'wp-element', 'wp-editor', 'wp-components'),
false,
true
);
wp_register_style(
'michel-blocks-editor-style',
plugins_url('dist/css/blocks.editor.css', __FILE__),
array("michel-blocks-style")
);
/* I'm deferring this style to optimize the pageload
wp_register_style(
'michel-blocks-style',
plugins_url('dist/css/blocks.style.css', __FILE__),
array()
);
*/
require_once plugin_dir_path(__FILE__) . '/inc/register-blocks.php';
}
add_action('init', 'ldc2020_blocks_register');
// register and enqueue loadCSS
function ldc2020_blocks_load_scripts_and_styles() {
// register loadCSS
wp_register_script( 'michel-blocks-load-css-async', plugins_url('src/js/loadCSS.js', __FILE__), array(), '', false );
// enqueue loadCSS
wp_enqueue_script( 'michel-blocks-load-css-async' );
// send vars from php to js
$translation_array = array( 'plugin_path' => plugins_url() . "/michel-blocks" );
wp_localize_script( 'michel-blocks-load-css-async', 'plugin_vars', $translation_array );
}
add_action('wp_enqueue_scripts', 'ldc2020_blocks_load_scripts_and_styles', 999);
function ldc2020_blocks_assets_frontend()
{
if ( !is_admin() ) {
// Enqueue Frontend blocks JS
wp_enqueue_script(
'michel-blocks-frontend-js',
plugins_url('dist/js/frontend.blocks.js', __FILE__),
['wp-blocks', 'wp-element', 'wp-editor', 'wp-components', 'wp-api'],
filemtime( plugin_dir_path(__FILE__) . 'dist/js/frontend.blocks.js' ),
true
);
}
}
add_action('enqueue_block_assets', 'ldc2020_blocks_assets_frontend');
function prefix_disable_gutenberg($current_status, $post_type)
{
if ($post_type === 'location') return false;
return $current_status;
}
add_filter('use_block_editor_for_post_type', 'prefix_disable_gutenberg', 10, 2);
add_filter( 'block_editor_settings' , 'remove_guten_wrapper_styles' );
function remove_guten_wrapper_styles( $settings ) {
unset($settings['styles'][0]);
return $settings;
}
function ldc_acf_add_google_map_api_key( $api ){
$api['key'] = 'GOOGLE_API_HERE';
return $api;
}
add_filter('acf/fields/google_map/api', 'ldc_acf_add_google_map_api_key');