PluginProbe
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts / trunk
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts vtrunk
2.8.14 2.8.13 2.8.12 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.10 2.8.11 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 trunk 1.0.1 1.0.2 1.1.0 1.1.1 All 147 releases
← All changes | includes/patterns.php +44 -15 2.7.6trunk View file →
@@ -88,9 +88,9 @@
88 88 // Handle save post.
89 89 add_action( 'save_post_' . $this->post_type, [ $this, 'save_post' ], 10, 2 );
90 90
91 91 // Clear the transient cache on upgraded.
92 - add_action( 'cbb_version_upgraded', [ $this, 'clear_transient_cache' ] );
92 + add_action( 'cbb/version_upgraded', [ $this, 'clear_transient_cache' ] );
93 93
94 94 // Force to remove custom fields.
95 95 add_action( 'add_meta_boxes', [ $this, 'remove_meta_boxes' ] );
96 96 }
@@ -106,8 +106,15 @@
106 106 $this->post_type,
107 107 [
108 108 'rest_base' => 'boldblocks-patterns',
109 109 'show_in_menu' => 'edit.php?post_type=boldblocks_block',
110 + 'capabilities' => [
111 + 'read_post' => 'manage_options',
112 + 'edit_post' => 'manage_options',
113 + 'delete_post' => 'manage_options',
114 + 'edit_posts' => 'manage_options',
115 + 'delete_posts' => 'manage_options',
116 + ],
110 117 ],
111 118 [
112 119 'name' => _x( 'Patterns', 'post type general name', 'content-blocks-builder' ),
113 120 'singular_name' => _x( 'Pattern', 'post type singular name', 'content-blocks-builder' ),
@@ -210,20 +217,22 @@
210 217
211 218 $this->register_meta(
212 219 'boldblocks_pattern_disabled_inserter',
213 220 [
214 - 'type' => 'boolean',
215 - 'default' => false,
221 + 'type' => 'boolean',
222 + 'sanitize_callback' => 'rest_sanitize_boolean',
223 + 'default' => false,
216 224 ]
217 225 );
218 226
219 227 // Setting fields.
228 + // phpcs:disable PluginCheck.CodeAnalysis.SettingSanitization.register_settingDynamic
220 229 register_setting(
221 - 'boldblocks',
222 - 'boldblocks_pattern_categories',
230 + 'cbb',
231 + 'cbb_pattern_categories',
223 232 [
224 - 'type' => 'array',
225 - 'show_in_rest' => array(
233 + 'type' => 'array',
234 + 'show_in_rest' => array(
226 235 'schema' => array(
227 236 'items' => array(
228 237 'type' => 'object',
229 238 'properties' => array(
@@ -236,15 +245,34 @@
236 245 ),
237 246 ),
238 247 ),
239 248 ),
240 - 'default' => [],
249 + 'sanitize_callback' => function( $value ) {
250 + if ( ! is_array( $value ) ) {
251 + return [];
252 + }
253 +
254 + $categories = [];
255 + foreach ( $value as $category ) {
256 + if ( ! is_array( $category ) ) {
257 + continue;
258 + }
259 +
260 + $categories[] = [
261 + 'name' => sanitize_text_field( $category['name'] ?? '' ),
262 + 'label' => sanitize_text_field( $category['label'] ?? '' ),
263 + ];
264 + }
265 +
266 + return $categories;
267 + },
268 + 'default' => [],
241 269 ]
242 270 );
243 271
244 272 register_setting(
245 - 'boldblocks',
246 - 'boldblocks_pattern_categories_all_label',
273 + 'cbb',
274 + 'cbb_pattern_categories_all_label',
247 275 [
248 276 'type' => 'string',
249 277 'show_in_rest' => true,
250 278 'default' => __( 'All patterns by CBB', 'content-blocks-builder' ),
@@ -249,8 +277,9 @@
249 277 'show_in_rest' => true,
250 278 'default' => __( 'All patterns by CBB', 'content-blocks-builder' ),
251 279 ]
252 280 );
281 + // phpcs:enable PluginCheck.CodeAnalysis.SettingSanitization.register_settingDynamic
253 282 }
254 283
255 284 /**
256 285 * Register meta field
@@ -303,9 +332,9 @@
303 332 * @return void
304 333 */
305 334 public function register_patterns() {
306 335 // Register custom categories.
307 - $pattern_categories = get_option( 'boldblocks_pattern_categories', [] );
336 + $pattern_categories = get_option( 'cbb_pattern_categories', [] );
308 337 if ( is_array( $pattern_categories ) ) {
309 338 foreach ( $pattern_categories as $category ) {
310 339 if ( ! empty( $category['name'] ) && ! empty( $category['label'] ) ) {
311 340 if ( ! \WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( $category['name'] ) ) {
@@ -314,10 +343,10 @@
314 343 }
315 344 }
316 345 }
317 346
318 - // Register a custom category for patterns made by BoldBlocks.
319 - register_block_pattern_category( 'boldblocks', [ 'label' => get_option( 'boldblocks_pattern_categories_all_label', _x( 'All patterns by CBB', 'Block pattern category', 'content-blocks-builder' ) ) ] );
347 + // Register a custom category for patterns made by CBB.
348 + register_block_pattern_category( 'cbb', [ 'label' => get_option( 'cbb_pattern_categories_all_label', _x( 'All patterns by CBB', 'CBB block pattern category', 'content-blocks-builder' ) ) ] );
320 349
321 350 if ( apply_filters( 'boldblocks_load_patterns', true ) ) {
322 351 // Query all patterns.
323 352 $pattern_posts = $this->get_all_custom_patterns();
@@ -407,9 +436,9 @@
407 436 },
408 437 $categories
409 438 );
410 439 }
411 - $categories[] = 'boldblocks';
440 + $categories[] = 'cbb';
412 441
413 442 $pattern_settings = [
414 443 'title' => wp_strip_all_tags( $pattern_post->post_title ),
415 444 'content' => $pattern_post->post_content,
@@ -505,9 +534,9 @@
505 534 */
506 535 public function manage_pattern_columns( $column, $post_id ) {
507 536 switch ( $column ) {
508 537 case 'pattern_name':
509 - echo esc_html( sprintf( _x( 'boldblocks/%s', 'Pattern name' ), sanitize_key( get_post_field( 'post_name', $post_id ) ) ) );
538 + echo esc_html( 'boldblocks/' . sanitize_key( get_post_field( 'post_name', $post_id ) ) );
510 539 break;
511 540
512 541 // Just break out of the switch statement for everything else.
513 542 default: