PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.3.4
GenerateBlocks v1.3.4
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 5 years ago class-enqueue-css.php 4 years ago class-plugin-update.php 5 years ago class-render-blocks.php 5 years ago class-rest.php 5 years ago class-settings.php 5 years ago dashboard.php 5 years ago defaults.php 5 years ago functions.php 4 years ago general.php 4 years ago generate-css.php 5 years ago
general.php
270 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.js',
26 array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor', 'wp-compose', 'wp-data' ),
27 filemtime( GENERATEBLOCKS_DIR . 'dist/blocks.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_style(
36 'generateblocks',
37 GENERATEBLOCKS_DIR_URL . 'dist/blocks.css',
38 array( 'wp-edit-blocks' ),
39 filemtime( GENERATEBLOCKS_DIR . 'dist/blocks.css' )
40 );
41
42 $image_sizes = get_intermediate_image_sizes();
43 $image_sizes = array_diff( $image_sizes, array( '1536x1536', '2048x2048' ) );
44 $image_sizes[] = 'full';
45
46 wp_localize_script(
47 'generateblocks',
48 'generateBlocksInfo',
49 array(
50 'isGeneratePress' => defined( 'GENERATE_VERSION' ),
51 'hasCustomFields' => post_type_supports( get_post_type(), 'custom-fields' ),
52 'hasWideAlignSupport' => current_theme_supports( 'align-wide' ),
53 'imageSizes' => $image_sizes,
54 'svgShapes' => generateblocks_get_svg_shapes(),
55 'syncResponsivePreviews' => generateblocks_get_option( 'sync_responsive_previews' ),
56 )
57 );
58
59 if ( function_exists( 'generate_get_color_defaults' ) ) {
60 $color_settings = wp_parse_args(
61 get_option( 'generate_settings', array() ),
62 generate_get_color_defaults()
63 );
64
65 $generatepressDefaultStyling = apply_filters(
66 'generateblocks_gp_default_styling',
67 array(
68 'buttonBackground' => $color_settings['form_button_background_color'],
69 'buttonBackgroundHover' => $color_settings['form_button_background_color_hover'],
70 'buttonText' => $color_settings['form_button_text_color'],
71 'buttonTextHover' => $color_settings['form_button_text_color_hover'],
72 'buttonPaddingTop' => '10px',
73 'buttonPaddingRight' => '20px',
74 'buttonPaddingBottom' => '10px',
75 'buttonPaddingLeft' => '20px',
76 )
77 );
78
79 $css = sprintf(
80 '.gb-button.button {
81 background-color: %1$s;
82 color: %2$s;
83 padding-top: %3$s;
84 padding-right: %4$s;
85 padding-bottom: %5$s;
86 padding-left: %6$s;
87 }',
88 $generatepressDefaultStyling['buttonBackground'],
89 $generatepressDefaultStyling['buttonText'],
90 $generatepressDefaultStyling['buttonPaddingTop'],
91 $generatepressDefaultStyling['buttonPaddingRight'],
92 $generatepressDefaultStyling['buttonPaddingBottom'],
93 $generatepressDefaultStyling['buttonPaddingLeft']
94 );
95
96 $css .= sprintf(
97 '.gb-button.button:active, .gb-button.button:hover, .gb-button.button:focus {
98 background-color: %1$s;
99 color: %2$s;
100 }',
101 $generatepressDefaultStyling['buttonBackgroundHover'],
102 $generatepressDefaultStyling['buttonTextHover']
103 );
104
105 wp_add_inline_style( 'generateblocks', $css );
106 }
107
108 $defaults = generateblocks_get_block_defaults();
109
110 wp_localize_script(
111 'generateblocks',
112 'generateBlocksDefaults',
113 $defaults
114 );
115
116 wp_localize_script(
117 'generateblocks',
118 'generateBlocksStyling',
119 generateblocks_get_default_styles()
120 );
121 }
122
123 if ( version_compare( $GLOBALS['wp_version'], '5.8-alpha-1', '<' ) ) {
124 add_filter( 'block_categories', 'generateblocks_do_category' );
125 } else {
126 add_filter( 'block_categories_all', 'generateblocks_do_category' );
127 }
128 /**
129 * Add GeneratePress category to Gutenberg.
130 *
131 * @param array $categories Existing categories.
132 * @since 0.1
133 */
134 function generateblocks_do_category( $categories ) {
135 return array_merge(
136 array(
137 array(
138 'slug' => 'generateblocks',
139 'title' => __( 'GenerateBlocks', 'generateblocks' ),
140 ),
141 ),
142 $categories
143 );
144 }
145
146 add_action( 'wp_enqueue_scripts', 'generateblocks_do_google_fonts' );
147 add_action( 'enqueue_block_editor_assets', 'generateblocks_do_google_fonts' );
148 /**
149 * Do Google Fonts.
150 *
151 * @since 0.1
152 */
153 function generateblocks_do_google_fonts() {
154 $fonts_url = generateblocks_get_google_fonts_uri();
155
156 if ( $fonts_url ) {
157 wp_enqueue_style( 'generateblocks-google-fonts', $fonts_url, array(), null, 'all' ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
158 }
159 }
160
161 add_action( 'init', 'generateblocks_register_meta' );
162 /**
163 * Register our post meta.
164 *
165 * @since 0.1
166 */
167 function generateblocks_register_meta() {
168 register_meta(
169 'post',
170 '_generate-full-width-content',
171 array(
172 'show_in_rest' => true,
173 'auth_callback' => '__return_true',
174 'single' => true,
175 )
176 );
177 }
178
179 add_filter( 'generateblocks_css_print_method', 'generateblocks_set_css_print_method' );
180 /**
181 * Set our CSS print method.
182 *
183 * @param string $method Existing method.
184 */
185 function generateblocks_set_css_print_method( $method ) {
186 return generateblocks_get_option( 'css_print_method' );
187 }
188
189 add_filter( 'excerpt_allowed_blocks', 'generateblocks_set_excerpt_allowed_blocks' );
190 /**
191 * Add blocks that can be displayed in post excerpts.
192 *
193 * @param array $allowed Existing allowed blocks.
194 * @since 1.0
195 */
196 function generateblocks_set_excerpt_allowed_blocks( $allowed ) {
197 $allowed[] = 'generateblocks/headline';
198 $allowed[] = 'generateblocks/container';
199
200 return $allowed;
201 }
202
203 add_filter( 'generateblocks_before_container_close', 'generateblocks_do_shape_divider', 10, 2 );
204 /**
205 * Add shape divider to Container.
206 *
207 * @since 1.2.0
208 * @param string $output The current block output.
209 * @param array $attributes The current block attributes.
210 */
211 function generateblocks_do_shape_divider( $output, $attributes ) {
212 $defaults = generateblocks_get_block_defaults();
213
214 $settings = wp_parse_args(
215 $attributes,
216 $defaults['container']
217 );
218
219 if ( ! empty( $settings['shapeDividers'] ) ) {
220 $shapes = generateblocks_get_svg_shapes();
221 $shape_values = array();
222
223 foreach ( $shapes as $group => $data ) {
224 if ( ! empty( $data['svgs'] ) && is_array( $data['svgs'] ) ) {
225 foreach ( $data['svgs'] as $key => $shape ) {
226 $shape_values[ $key ] = $shape['icon'];
227 }
228 }
229 }
230
231 $output .= '<div class="gb-shapes">';
232
233 foreach ( (array) $settings['shapeDividers'] as $index => $option ) {
234 if ( ! empty( $option['shape'] ) ) {
235 if ( isset( $shape_values[ $option['shape'] ] ) ) {
236 $shapeNumber = $index + 1;
237
238 $output .= sprintf(
239 '<div class="gb-shape gb-shape-' . $shapeNumber . '">%s</div>',
240 $shape_values[ $option['shape'] ]
241 );
242 }
243 }
244 }
245
246 $output .= '</div>';
247 }
248
249 return $output;
250 }
251
252 add_filter( 'generateblocks_do_content', 'generateblocks_do_widget_styling' );
253 /**
254 * Process all widget content for potential styling.
255 *
256 * @since 1.3.4
257 * @param string $content The existing content to process.
258 */
259 function generateblocks_do_widget_styling( $content ) {
260 $widget_blocks = get_option( 'widget_block' );
261
262 foreach ( (array) $widget_blocks as $block ) {
263 if ( isset( $block['content'] ) ) {
264 $content .= $block['content'];
265 }
266 }
267
268 return $content;
269 }
270