PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.1.2
GenerateBlocks v1.1.2
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / includes / general.php
generateblocks / includes Last commit date
class-do-css.php 6 years ago class-enqueue-css.php 6 years ago class-plugin-update.php 6 years ago class-settings.php 6 years ago dashboard.php 6 years ago defaults.php 6 years ago functions.php 6 years ago general.php 6 years ago generate-css.php 6 years ago
general.php
200 lines
1 <?php
2 /**
3 * General actions and filters.
4 *
5 * @package GenerateBlocks
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 add_action( 'enqueue_block_editor_assets', 'generateblocks_do_block_editor_assets' );
13 /**
14 * Enqueue Gutenberg block assets for backend editor.
15 *
16 * @uses {wp-blocks} for block type registration & related functions.
17 * @uses {wp-element} for WP Element abstraction — structure of blocks.
18 * @uses {wp-i18n} to internationalize the block's text.
19 * @uses {wp-editor} for WP editor styles.
20 * @since 0.1
21 */
22 function generateblocks_do_block_editor_assets() {
23 wp_enqueue_script(
24 'generateblocks',
25 GENERATEBLOCKS_DIR_URL . 'dist/blocks.build.js',
26 array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor', 'wp-compose', 'wp-data' ),
27 filemtime( GENERATEBLOCKS_DIR . 'dist/blocks.build.js' ),
28 true
29 );
30
31 if ( function_exists( 'wp_set_script_translations' ) ) {
32 wp_set_script_translations( 'generateblocks', 'generateblocks' );
33 }
34
35 wp_enqueue_script(
36 'generateblocks-dompurify',
37 GENERATEBLOCKS_DIR_URL . 'assets/js/purify.min.js',
38 array( 'generateblocks' ),
39 filemtime( GENERATEBLOCKS_DIR . 'assets/js/purify.min.js' ),
40 true
41 );
42
43 wp_enqueue_style(
44 'generateblocks',
45 GENERATEBLOCKS_DIR_URL . 'dist/blocks.editor.build.css',
46 array( 'wp-edit-blocks' ),
47 filemtime( GENERATEBLOCKS_DIR . 'dist/blocks.editor.build.css' )
48 );
49
50 wp_localize_script(
51 'generateblocks',
52 'generateBlocksInfo',
53 array(
54 'isGeneratePress' => defined( 'GENERATE_VERSION' ),
55 'hasCustomFields' => post_type_supports( get_post_type(), 'custom-fields' ),
56 'hasWideAlignSupport' => current_theme_supports( 'align-wide' ),
57 'colorComponentDiplay' => generateblocks_get_option( 'color_component_display' ),
58 )
59 );
60
61 if ( function_exists( 'generate_get_color_defaults' ) ) {
62 $color_settings = wp_parse_args(
63 get_option( 'generate_settings', array() ),
64 generate_get_color_defaults()
65 );
66
67 $generatepressDefaultStyling = apply_filters(
68 'generateblocks_gp_default_styling',
69 array(
70 'buttonBackground' => $color_settings['form_button_background_color'],
71 'buttonBackgroundHover' => $color_settings['form_button_background_color_hover'],
72 'buttonText' => $color_settings['form_button_text_color'],
73 'buttonTextHover' => $color_settings['form_button_text_color_hover'],
74 'buttonPaddingTop' => '10px',
75 'buttonPaddingRight' => '20px',
76 'buttonPaddingBottom' => '10px',
77 'buttonPaddingLeft' => '20px',
78 )
79 );
80
81 $css = sprintf(
82 '.gb-button.button {
83 background-color: %1$s;
84 color: %2$s;
85 padding-top: %3$s;
86 padding-right: %4$s;
87 padding-bottom: %5$s;
88 padding-left: %6$s;
89 }',
90 $generatepressDefaultStyling['buttonBackground'],
91 $generatepressDefaultStyling['buttonText'],
92 $generatepressDefaultStyling['buttonPaddingTop'],
93 $generatepressDefaultStyling['buttonPaddingRight'],
94 $generatepressDefaultStyling['buttonPaddingBottom'],
95 $generatepressDefaultStyling['buttonPaddingLeft']
96 );
97
98 $css .= sprintf(
99 '.gb-button.button:active, .gb-button.button:hover, .gb-button.button:focus {
100 background-color: %1$s;
101 color: %2$s;
102 }',
103 $generatepressDefaultStyling['buttonBackgroundHover'],
104 $generatepressDefaultStyling['buttonTextHover']
105 );
106
107 wp_add_inline_style( 'generateblocks', $css );
108 }
109
110 $defaults = generateblocks_get_block_defaults();
111
112 wp_localize_script(
113 'generateblocks',
114 'generateBlocksDefaults',
115 $defaults
116 );
117
118 wp_localize_script(
119 'generateblocks',
120 'generateBlocksStyling',
121 generateblocks_get_default_styles()
122 );
123 }
124
125 add_filter( 'block_categories', 'generateblocks_do_category' );
126 /**
127 * Add GeneratePress category to Gutenberg.
128 *
129 * @param array $categories Existing categories.
130 * @since 0.1
131 */
132 function generateblocks_do_category( $categories ) {
133 return array_merge(
134 array(
135 array(
136 'slug' => 'generateblocks',
137 'title' => __( 'GenerateBlocks', 'generateblocks' ),
138 ),
139 ),
140 $categories
141 );
142 }
143
144 add_action( 'wp_enqueue_scripts', 'generateblocks_do_google_fonts' );
145 add_action( 'enqueue_block_editor_assets', 'generateblocks_do_google_fonts' );
146 /**
147 * Do Google Fonts.
148 *
149 * @since 0.1
150 */
151 function generateblocks_do_google_fonts() {
152 $fonts_url = generateblocks_get_google_fonts_uri();
153
154 if ( $fonts_url ) {
155 wp_enqueue_style( 'generateblocks-google-fonts', $fonts_url, array(), null, 'all' ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
156 }
157 }
158
159 add_action( 'init', 'generateblocks_register_meta' );
160 /**
161 * Register our post meta.
162 *
163 * @since 0.1
164 */
165 function generateblocks_register_meta() {
166 register_meta(
167 'post',
168 '_generate-full-width-content',
169 array(
170 'show_in_rest' => true,
171 'auth_callback' => '__return_true',
172 'single' => true,
173 )
174 );
175 }
176
177 add_filter( 'generateblocks_css_print_method', 'generateblocks_set_css_print_method' );
178 /**
179 * Set our CSS print method.
180 *
181 * @param string $method Existing method.
182 */
183 function generateblocks_set_css_print_method( $method ) {
184 return generateblocks_get_option( 'css_print_method' );
185 }
186
187 add_filter( 'excerpt_allowed_blocks', 'generateblocks_set_excerpt_allowed_blocks' );
188 /**
189 * Add blocks that can be displayed in post excerpts.
190 *
191 * @param array $allowed Existing allowed blocks.
192 * @since 1.0
193 */
194 function generateblocks_set_excerpt_allowed_blocks( $allowed ) {
195 $allowed[] = 'generateblocks/headline';
196 $allowed[] = 'generateblocks/container';
197
198 return $allowed;
199 }
200