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/variations.php +25 -19 2.7.5trunk View file →
@@ -97,9 +97,9 @@
97 97 // Handle save post.
98 98 add_action( 'save_post_' . $this->post_type, [ $this, 'save_post' ], 10, 2 );
99 99
100 100 // Clear the transient cache on upgraded.
101 - add_action( 'cbb_version_upgraded', [ $this, 'clear_transient_cache' ] );
101 + add_action( 'cbb/version_upgraded', [ $this, 'clear_transient_cache' ] );
102 102
103 103 // Enqueue styles for the iframe editor.
104 104 add_filter( 'block_editor_settings_all', [ $this, 'enqueue_style_for_the_editor' ] );
105 105
@@ -123,9 +123,12 @@
123 123 'rest_base' => 'boldblocks-variations',
124 124 'show_in_menu' => 'edit.php?post_type=boldblocks_block',
125 125 'show_in_admin_bar' => false,
126 126 'capabilities' => array(
127 - 'create_posts' => 'do_not_allow',
127 + 'create_posts' => 'do_not_allow',
128 + 'edit_posts' => 'manage_options',
129 + 'edit_others_posts' => 'manage_options',
130 + 'delete_posts' => 'manage_options',
128 131 ),
129 132 'map_meta_cap' => true,
130 133 ],
131 134 [
@@ -238,8 +241,9 @@
238 241 $variation_handle = false;
239 242 $custom_style = $block_variation['custom_style'] ?? false;
240 243 if ( $custom_style ) {
241 244 $variation_handle = $block_variation['variationClass'];
245 + // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
242 246 wp_register_style( $variation_handle, '' );
243 247 wp_add_inline_style( $variation_handle, $custom_style );
244 248
245 249 wp_enqueue_block_style( $block_variation['blockName'], [ 'handle' => $variation_handle ] );
@@ -301,22 +305,16 @@
301 305 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
302 306 $post_id = absint( $_GET['post'] );
303 307 $current_post = get_post( $post_id );
304 308
305 - if ( ! $current_post || ! $current_post instanceof \WP_Post ) {
309 + if ( ! $current_post instanceof \WP_Post || $this->post_type !== $current_post->post_type ) {
306 310 return;
307 311 }
308 312
309 - if ( $this->post_type !== $current_post->post_type ) {
310 - return;
311 - }
312 -
313 313 $block_name = get_post_meta( $post_id, 'boldblocks_variation_block_name', true );
314 314 if ( $block_name ) {
315 315 $post_type_object = get_post_type_object( $this->post_type );
316 - $post_type_object->template = array(
317 - array( $block_name ),
318 - );
316 + $post_type_object->template = [ [ $block_name ] ];
319 317 }
320 318 }
321 319 }
322 320
@@ -379,9 +377,9 @@
379 377
380 378 $custom_style_handler = $this->the_plugin_instance->get_component( CustomStyle::class );
381 379
382 380 $variation_posts = array_map(
383 - function( $item ) use ( $custom_style_handler ) {
381 + function ( $item ) use ( $custom_style_handler ) {
384 382 $variation_name = get_post_meta( $item->ID, 'boldblocks_variation_name', true );
385 383 $variation_class = 'is-style-' . str_replace( '/', '-', $variation_name );
386 384
387 385 $custom_style = get_post_meta( $item->ID, 'boldblocks_variation_custom_style', true );
@@ -396,16 +394,16 @@
396 394 'title' => $item->post_title,
397 395 'postContent' => $item->post_content,
398 396 'description' => get_post_meta( $item->ID, 'boldblocks_variation_description', true ),
399 397 'blockIcon' => get_post_meta( $item->ID, 'boldblocks_variation_icon', true ),
400 - 'isDefault' => ! ! get_post_meta( $item->ID, 'boldblocks_variation_is_default', true ),
401 - 'isTransformable' => ! ! get_post_meta( $item->ID, 'boldblocks_variation_is_transformable', true ),
402 - 'hideFromInserter' => ! ! get_post_meta( $item->ID, 'boldblocks_variation_hide_from_inserter', true ),
398 + 'isDefault' => (bool) get_post_meta( $item->ID, 'boldblocks_variation_is_default', true ),
399 + 'isTransformable' => (bool) get_post_meta( $item->ID, 'boldblocks_variation_is_transformable', true ),
400 + 'hideFromInserter' => (bool) get_post_meta( $item->ID, 'boldblocks_variation_hide_from_inserter', true ),
403 401 'variationData' => get_post_meta( $item->ID, 'boldblocks_variation_data', true ),
404 402 'dependentBlocks' => get_post_meta( $item->ID, 'boldblocks_variation_dependent_blocks', true ),
405 403 'variationClass' => $variation_class,
406 404 'custom_style' => $custom_style,
407 - 'enable_block_style' => ! ! get_post_meta( $item->ID, 'boldblocks_variation_enable_style', true ),
405 + 'enable_block_style' => (bool) get_post_meta( $item->ID, 'boldblocks_variation_enable_style', true ),
408 406 ];
409 407 },
410 408 $raw_posts
411 409 );
@@ -455,9 +453,9 @@
455 453 array(
456 454 'methods' => 'POST',
457 455 'callback' => [ $this, 'create_variation' ],
458 456 'permission_callback' => function () {
459 - return current_user_can( 'publish_posts' );
457 + return current_user_can( 'manage_options' );
460 458 },
461 459 )
462 460 );
463 461 }
@@ -474,8 +472,13 @@
474 472 if ( empty( $args['title'] ) || empty( $args['content'] ) || empty( $args['meta'] ) ) {
475 473 wp_send_json_error( __( 'Invalid request!', 'content-blocks-builder' ), 400 );
476 474 }
477 475
476 + // Verify nonce.
477 + if ( ! isset( $args['cbb_variation_nonce'] ) || ! wp_verify_nonce( $args['cbb_variation_nonce'], 'cbb_variation_nonce' ) ) {
478 + wp_send_json_error( __( 'Nonce verification failed!', 'content-blocks-builder' ), 403 );
479 + }
480 +
478 481 // Using Posts controller to create a custom variation.
479 482 $controller = new \WP_REST_Posts_Controller( $this->post_type );
480 483 $response = $controller->create_item( $request );
481 484
@@ -485,9 +488,9 @@
485 488 if ( is_wp_error( $response ) ) {
486 489 wp_send_json_error( $response );
487 490 }
488 491
489 - if ( $response->status === 201 ) {
492 + if ( 201 === $response->get_status() ) {
490 493 wp_send_json(
491 494 [
492 495 'data' => __( 'The new variation has been created!', 'content-blocks-builder' ),
493 496 'success' => true,
@@ -494,8 +497,11 @@
494 497 'post' => $response->data,
495 498 ]
496 499 );
497 500 }
501 +
502 + // Default fallback if something goes wrong.
503 + wp_send_json_error( __( 'An error occurred while creating the variation.', 'content-blocks-builder' ), 500 );
498 504 }
499 505
500 506 /**
501 507 * Add custom columns to custom post type
@@ -593,9 +599,8 @@
593 599 default:
594 600 break;
595 601 }
596 602 }
597 -
598 603 }
599 604
600 605 /**
601 606 * Add filters for custom variation columns
@@ -736,8 +741,9 @@
736 741 $custom_style = $custom_style_handler->refine_custom_value( $custom_style, [ 'selector' => $block_class ], 'CSS' );
737 742 $custom_style .= '.is-selected,.has-child-selected,.has-child-selected * {animation:none!important;}';
738 743
739 744 $variation_handle = 'edit-variation-style';
745 + // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
740 746 wp_register_style( $variation_handle, '' );
741 747 wp_add_inline_style( $variation_handle, $custom_style );
742 748 wp_enqueue_style( $variation_handle );
743 749 }
@@ -757,9 +763,9 @@
757 763 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
758 764 $post_id = absint( $_GET['post'] );
759 765 $current_post = get_post( $post_id );
760 766
761 - if ( ! $current_post || ! $current_post instanceof \WP_Post || $this->post_type !== $current_post->post_type ) {
767 + if ( ! $current_post instanceof \WP_Post || $this->post_type !== $current_post->post_type ) {
762 768 return;
763 769 }
764 770
765 771 return get_post_meta( $post_id, 'boldblocks_variation_block_name', true );