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/custom-blocks.php +241 -50 2.7.8trunk View file →
@@ -95,8 +95,10 @@
95 95 private $html_editor_style = '';
96 96
97 97 /**
98 98 * Constructor
99 + *
100 + * @param ContentBlocksBuilder $the_plugin_instance
99 101 */
100 102 public function __construct( $the_plugin_instance ) {
101 103 parent::__construct( $the_plugin_instance );
102 104
@@ -143,13 +145,16 @@
143 145
144 146 // Register codemirror.
145 147 add_action( 'admin_enqueue_scripts', [ $this, 'register_code_editor_scripts' ] );
146 148
149 + // Change the script src to use new version of esprima.
150 + add_filter( 'script_loader_src', [ $this, 'adjust_esprima_script' ], 10, 2 );
151 +
147 152 // Handle save post.
148 153 add_action( 'save_post_' . $this->post_type, [ $this, 'save_post' ], 10, 2 );
149 154
150 155 // Clear the transient cache on upgraded.
151 - add_action( 'cbb_version_upgraded', [ $this, 'clear_transient_cache' ] );
156 + add_action( 'cbb/version_upgraded', [ $this, 'clear_transient_cache' ] );
152 157
153 158 // Enqueue frontend scripts for non-cbb blocks.
154 159 add_filter( 'render_block', [ $this, 'enqueue_frontend_block_scripts' ], 10, 3 );
155 160
@@ -432,18 +437,27 @@
432 437 'schema' => array(
433 438 'items' => array(
434 439 'type' => 'object',
435 440 'properties' => array(
436 - 'is_module' => array(
441 + 'value' => array(
442 + 'type' => 'string',
443 + ),
444 + 'script_type' => array(
445 + 'type' => 'string',
446 + 'default' => '', // 'module', 'custom', 'default'.
447 + ),
448 + 'handle' => array(
449 + 'type' => 'string',
450 + ),
451 + // is_module is deprecated. it will be removed in the future.
452 + 'is_module' => array(
437 453 'type' => 'boolean',
438 454 'default' => false,
439 455 ),
440 - 'handle' => array(
441 - 'type' => 'string',
456 + 'deps' => array(
457 + 'type' => 'string',
458 + 'default' => '',
442 459 ),
443 - 'value' => array(
444 - 'type' => 'string',
445 - ),
446 460 ),
447 461 ),
448 462 ),
449 463 ),
@@ -503,8 +517,11 @@
503 517 'properties' => array(
504 518 'handle' => array(
505 519 'type' => 'string',
506 520 ),
521 + 'type' => array(
522 + 'type' => 'string',
523 + ),
507 524 'value' => array(
508 525 'type' => 'string',
509 526 ),
510 527 ),
@@ -531,9 +548,9 @@
531 548 'type' => 'string',
532 549 ),
533 550 ),
534 551 'additionalProperties' => array(
535 - 'type' => [ 'string', 'boolean', 'object', 'array' ],
552 + 'type' => [ 'integer', 'number', 'boolean', 'string', 'object', 'array' ], // The order of data type matters.
536 553 ),
537 554 ),
538 555 ),
539 556 ),
@@ -557,9 +574,9 @@
557 574 'type' => 'string',
558 575 ),
559 576 ),
560 577 'additionalProperties' => array(
561 - 'type' => [ 'string', 'boolean', 'object', 'array' ],
578 + 'type' => [ 'integer', 'number', 'boolean', 'string', 'object', 'array' ],
562 579 ),
563 580 ),
564 581 ),
565 582 ),
@@ -708,12 +725,9 @@
708 725 // Make name as the key.
709 726 $this->repeater_blocks = array_column( $this->repeater_blocks, null, 'name' );
710 727
711 728 // Get current post.
712 - global $pagenow;
713 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended
714 - $post_id = 'post.php' === $pagenow && isset( $_GET['post'] ) ? absint( $_GET['post'] ) : 0;
715 - $post = $post_id ? get_post( $post_id ) : false;
729 + $post = $this->get_current_post();
716 730 $block_name = '';
717 731 $repeater_block_name = '';
718 732
719 733 if ( $post && $this->post_type === $post->post_type ) {
@@ -734,10 +748,12 @@
734 748 // Build block attributes.
735 749 $block_atts = [
736 750 'api_version' => 3,
737 751 'supports' => [
738 - 'cbb' => true,
739 - 'layout' => true,
752 + 'cbb' => true,
753 + 'layout' => true,
754 + 'migrateClass' => ! empty( $args['migrateClass'] ) ? ( isset( $args['id'] ) ? 'wp-block-boldblocks-custom' : 'wp-block-boldblocks-custom-parent' ) : '',
755 + 'CSSClasses' => $args['className'] ?? '',
740 756 ],
741 757 'uses_context' => [ 'postId', 'postType', 'cbb/block-overrides' ],
742 758 ];
743 759
@@ -853,10 +869,11 @@
853 869 }
854 870
855 871 // Scripts & styles.
856 872 $is_backend = is_admin();
857 - $block_inline_handle = 'cbb-' . str_replace( '/', '-', $name );
858 - $block_module_inline_handle = 'cbb-script-module-' . str_replace( '/', '-', $name );
873 + $name_handle = str_replace( '/', '-', $name );
874 + $block_inline_handle = 'cbb-' . $name_handle;
875 + $block_module_inline_handle = 'cbb-script-module-' . $name_handle;
859 876
860 877 if ( ! empty( $args['external_scripts'] ) ) {
861 878 $external_scripts = array_filter(
862 879 $args['external_scripts'],
@@ -903,25 +920,102 @@
903 920 }
904 921 }
905 922 }
906 923
907 - if ( ! $is_backend && ! empty( $args['custom_scripts'] ) ) {
924 + if ( ! empty( $args['custom_scripts'] ) && ! $is_backend ) {
908 925 $custom_scripts = $args['custom_scripts'];
909 926
910 - foreach ( $custom_scripts as $script ) {
911 - if ( ! $script || ! is_array( $script ) || empty( $script['value'] ) ) {
912 - continue;
927 + // Refine custom scripts.
928 + $custom_scripts = array_reduce(
929 + $custom_scripts,
930 + function ( $carry, $script ) {
931 + // Skip if script is empty.
932 + if ( ! $script || ! is_array( $script ) || empty( $script['value'] ) ) {
933 + return $carry;
934 + }
935 +
936 + // Refine script type.
937 + $script_type = $script['script_type'] ?? '';
938 +
939 + // Legacy support for script_type.
940 + if ( ! $script_type ) {
941 + if ( $script['is_module'] ?? false ) {
942 + $script_type = 'module';
943 + } elseif ( ! empty( $script['handle'] ) ) {
944 + $script_type = 'custom';
945 + } else {
946 + $script_type = 'default';
947 + }
948 +
949 + $script['script_type'] = $script_type;
950 + }
951 +
952 + // If custom type but no handle, change to default.
953 + if ( 'custom' === $script_type && empty( $script['handle'] ) ) {
954 + $script['script_type'] = 'default';
955 + }
956 +
957 + $carry[] = $script;
958 +
959 + return $carry;
960 + },
961 + []
962 + );
963 +
964 + $default_handle_scripts = array_filter(
965 + $custom_scripts,
966 + function ( $script ) {
967 + return 'custom' !== $script['script_type'];
913 968 }
969 + );
914 970
915 - $is_module = $script['is_module'] ?? false;
916 - $handle = $is_module ? $block_module_inline_handle : $block_inline_handle;
971 + if ( $default_handle_scripts ) {
972 + $dep_handles = array_reduce(
973 + $default_handle_scripts,
974 + function ( $carry, $script ) {
975 + if ( 'module' === $script['script_type'] ) {
976 + $carry['has_module'] = true;
977 + } elseif ( ! empty( $script['deps'] ) ) {
978 + $deps = explode( ',', $script['deps'] );
979 + foreach ( $deps as $dep ) {
980 + $dep = trim( $dep );
981 + if ( ! $dep || in_array( $dep, $carry['deps'], true ) ) {
982 + continue;
983 + }
917 984
985 + $carry['deps'][] = $dep;
986 + }
987 + }
988 +
989 + return $carry;
990 + },
991 + [
992 + 'has_module' => false,
993 + 'deps' => [],
994 + ]
995 + );
996 +
997 + if ( $dep_handles['has_module'] ) {
998 + // Register the default handle for module scripts.
999 + wp_register_script( $block_module_inline_handle, '', [], BOLDBLOCKS_CBB_VERSION, [ 'in_footer' => true ] );
1000 + }
1001 +
1002 + if ( ! in_array( 'CBB_BLOCK_API', $dep_handles['deps'], true ) ) {
1003 + array_unshift( $dep_handles['deps'], 'CBB_BLOCK_API' );
1004 + }
1005 +
1006 + // Register the default handle for inline scripts.
1007 + wp_register_script( $block_inline_handle, '', explode( ',', $this->refine_script_handle( implode( ',', $dep_handles['deps'] ), $is_backend ) ), BOLDBLOCKS_CBB_VERSION, [ 'in_footer' => true ] );
1008 + }
1009 +
1010 + foreach ( $custom_scripts as $script ) {
1011 + $script_type = $script['script_type'];
1012 +
918 1013 // Determine if a custom handle should be used.
919 - if ( ! empty( $script['handle'] ) && ! $is_module ) {
1014 + if ( 'custom' === $script_type ) {
920 1015 $handle = $this->refine_script_handle( $script['handle'], $is_backend );
921 1016 } else {
922 - // Register the default handle for module and inline scripts.
923 - wp_register_script( $handle, '', [ $this->refine_script_handle( 'CBB_BLOCK_API', $is_backend ) ], BOLDBLOCKS_CBB_VERSION, [ 'in_footer' => true ] );
1017 + $handle = 'module' === $script_type ? $block_module_inline_handle : $block_inline_handle;
924 1018
925 1019 // Add handle to view scripts and editor scripts if backend.
926 1020 if ( ! in_array( $handle, $handles['view_script_handles'], true ) ) {
927 1021 $handles['view_script_handles'][] = $handle;
@@ -978,8 +1072,13 @@
978 1072 $is_preview = ! empty( $args['dependentBlocks'] ) && is_array( $args['dependentBlocks'] ) && count( $args['dependentBlocks'] ) === 1 && 'core/html' === ( $args['dependentBlocks'][0] ?? '' );
979 1073
980 1074 foreach ( $custom_styles as $style ) {
981 1075 if ( $style && is_array( $style ) && $style['value'] ) {
1076 + $snippet_type = $style['type'] ?? 'all';
1077 + if ( ( 'view' === $snippet_type && $is_backend ) || ( 'editor' === $snippet_type && ! $is_backend ) ) {
1078 + continue;
1079 + }
1080 +
982 1081 $value = $style['value'];
983 1082 if ( $is_preview ) {
984 1083 $this->html_editor_style .= $value;
985 1084 }
@@ -1039,8 +1138,9 @@
1039 1138 * @return string
1040 1139 */
1041 1140 private function refine_script_handle( $handle, $is_backend = false ) {
1042 1141 if ( $handle ) {
1142 + $handle = str_replace( ' ', '', $handle );
1043 1143 $handle = str_replace( 'CBB_BLOCK_API', $is_backend ? $this->custom_blocks_handle : $this->custom_blocks_frontend_handle, $handle );
1044 1144 $handle = str_replace( 'CBB_CAROUSEL_API', $is_backend ? $this->custom_blocks_handle : $this->carousel_blocks_frontend_handle, $handle );
1045 1145 }
1046 1146
@@ -1072,12 +1172,28 @@
1072 1172 $screen = get_current_screen();
1073 1173 if ( $screen && $screen->is_block_editor ) {
1074 1174 wp_enqueue_code_editor( array( 'type' => 'text/css' ) );
1075 1175 wp_enqueue_code_editor( array( 'type' => 'javascript' ) );
1176 + wp_enqueue_code_editor( array( 'type' => 'application/json' ) );
1076 1177 }
1077 1178 }
1078 1179
1079 1180 /**
1181 + * Adjust the src of the esprima script.
1182 + *
1183 + * @param string $src The source URL of the script.
1184 + * @param string $handle The handle of the script.
1185 + * @return string The adjusted source URL of the script.
1186 + */
1187 + public function adjust_esprima_script( $src, $handle ) {
1188 + if ( 'esprima' === $handle ) {
1189 + $src = 'https://cdn.jsdelivr.net/npm/esprima-next@5.8.4/dist/esprima.js';
1190 + }
1191 +
1192 + return $src;
1193 + }
1194 +
1195 + /**
1080 1196 * Register scripts
1081 1197 *
1082 1198 * @return void
1083 1199 */
@@ -1096,13 +1212,31 @@
1096 1212
1097 1213 // Add translation.
1098 1214 wp_set_script_translations( $this->custom_blocks_handle, 'content-blocks-builder' );
1099 1215
1216 + // Get all blocks.
1217 + $all_custom_blocks = $this->get_all_custom_blocks();
1218 + $current_post = $this->get_current_post();
1219 + if ( $current_post && $this->post_type === $current_post->post_type ) {
1220 + // Hide the current block.
1221 + $all_custom_blocks = array_map(
1222 + function ( $block ) use ( $current_post ) {
1223 + if ( $block['id'] === $current_post->ID ) {
1224 + $block['isHidden'] = true;
1225 + }
1226 + return $block;
1227 + },
1228 + $all_custom_blocks
1229 + );
1230 + }
1231 +
1100 1232 // Define data.
1101 1233 $blocks_scripts = [
1102 - 'blocks' => $this->get_all_custom_blocks(),
1234 + 'blocks' => $all_custom_blocks,
1103 1235 'variations' => $this->the_plugin_instance->get_component( Variations::class )->get_all_variations(),
1104 1236 'variationNonce' => wp_create_nonce( 'cbb_variation_nonce' ),
1237 + 'animations' => $this->get_animated_blocks(),
1238 + 'canEditCSS' => $this->the_plugin_instance->get_component( CustomStyle::class )->user_can_edit_css(),
1105 1239 ];
1106 1240
1107 1241 // Get block name for current variation.
1108 1242 $block_name = $this->the_plugin_instance->get_component( Variations::class )->get_block_name();
@@ -1228,9 +1362,9 @@
1228 1362
1229 1363 $raw_posts = get_posts( $post_args );
1230 1364
1231 1365 $block_posts = array_map(
1232 - function( $item ) {
1366 + function ( $item ) {
1233 1367 // Template lock.
1234 1368 $template_lock = get_post_meta( $item->ID, 'boldblocks_template_lock', true );
1235 1369
1236 1370 // Convert boolean string to boolean.
@@ -1242,18 +1376,18 @@
1242 1376 $block_external_styles = get_post_meta( $item->ID, 'boldblocks_block_external_styles', true );
1243 1377 $block_custom_styles = get_post_meta( $item->ID, 'boldblocks_block_custom_styles', true );
1244 1378
1245 1379 // Hide on frontend.
1246 - $hide_on_frontend = ! ! get_post_meta( $item->ID, 'boldblocks_hide_on_frontend', true );
1380 + $hide_on_frontend = (bool) get_post_meta( $item->ID, 'boldblocks_hide_on_frontend', true );
1247 1381
1248 1382 // Is a readonly block.
1249 - $is_readonly = ! ! get_post_meta( $item->ID, 'boldblocks_is_readonly', true );
1383 + $is_readonly = (bool) get_post_meta( $item->ID, 'boldblocks_is_readonly', true );
1250 1384
1251 1385 // Is block transformable.
1252 - $is_transformable = ! ! get_post_meta( $item->ID, 'boldblocks_is_transformable', true );
1386 + $is_transformable = (bool) get_post_meta( $item->ID, 'boldblocks_is_transformable', true );
1253 1387
1254 1388 // Is block hidden.
1255 - $is_hidden = ! ! get_post_meta( $item->ID, 'boldblocks_is_hidden', true );
1389 + $is_hidden = (bool) get_post_meta( $item->ID, 'boldblocks_is_hidden', true );
1256 1390
1257 1391 // Parent & ancestor.
1258 1392 $block_parent = get_post_meta( $item->ID, 'boldblocks_block_parent', true );
1259 1393 $block_parent = $block_parent ? array_filter( explode( ',', $block_parent ) ) : [];
@@ -1268,9 +1402,11 @@
1268 1402 } else {
1269 1403 $keywords = false;
1270 1404 }
1271 1405
1272 - $block_name = sprintf( 'boldblocks/%s', $this->sanitize_block_name( $item->post_name ) );
1406 + $block_name = sprintf( 'boldblocks/%s', $this->sanitize_block_name( $item->post_name ) );
1407 + $block_version = get_post_meta( $item->ID, 'boldblocks_block_version', true );
1408 + $migrate_class = version_compare( $block_version, '2.7.14', '<=' );
1273 1409
1274 1410 $block_args = [
1275 1411 'id' => $item->ID,
1276 1412 'name' => $block_name,
@@ -1283,12 +1419,13 @@
1283 1419 'blockIcon' => get_post_meta( $item->ID, 'boldblocks_block_icon', true ),
1284 1420 'blockSupports' => get_post_meta( $item->ID, 'boldblocks_block_supports', true ),
1285 1421 'blockAttributes' => [
1286 1422 'attributes' => get_post_meta( $item->ID, 'boldblocks_block_attributes', true ),
1287 - 'enableCustomAttributes' => ! ! get_post_meta( $item->ID, 'boldblocks_enable_custom_attributes', true ),
1423 + 'enableCustomAttributes' => (bool) get_post_meta( $item->ID, 'boldblocks_enable_custom_attributes', true ),
1288 1424 ],
1289 - 'enableVariationPicker' => ! ! get_post_meta( $item->ID, 'boldblocks_enable_variation_picker', true ),
1290 - 'blockVersion' => get_post_meta( $item->ID, 'boldblocks_block_version', true ),
1425 + 'enableVariationPicker' => (bool) get_post_meta( $item->ID, 'boldblocks_enable_variation_picker', true ),
1426 + 'blockVersion' => $block_version,
1427 + 'migrateClass' => $migrate_class,
1291 1428 'dependentBlocks' => get_post_meta( $item->ID, 'boldblocks_block_dependent_blocks', true ),
1292 1429 'hideOnFrontend' => $hide_on_frontend,
1293 1430 'isTransformable' => $is_transformable,
1294 1431 'isHidden' => $is_hidden,
@@ -1322,11 +1459,11 @@
1322 1459 'blockIcon' => get_post_meta( $item->ID, 'boldblocks_parent_block_icon', true ),
1323 1460 'blockSupports' => get_post_meta( $item->ID, 'boldblocks_parent_block_supports', true ),
1324 1461 'blockAttributes' => [
1325 1462 'attributes' => get_post_meta( $item->ID, 'boldblocks_parent_block_attributes', true ),
1326 - 'enableCustomAttributes' => ! ! get_post_meta( $item->ID, 'boldblocks_parent_enable_custom_attributes', true ),
1463 + 'enableCustomAttributes' => (bool) get_post_meta( $item->ID, 'boldblocks_parent_enable_custom_attributes', true ),
1327 1464 ],
1328 - 'enableVariationPicker' => ! ! get_post_meta( $item->ID, 'boldblocks_parent_enable_variation_picker', true ),
1465 + 'enableVariationPicker' => (bool) get_post_meta( $item->ID, 'boldblocks_parent_enable_variation_picker', true ),
1329 1466 'external_scripts' => $block_external_scripts,
1330 1467 'custom_scripts' => $this->refine_custom_scripts( $block_custom_scripts, 'JS', $parent_block_name, $block_name ),
1331 1468 'external_styles' => $block_external_styles,
1332 1469 'custom_styles' => $this->refine_custom_scripts( $block_custom_styles, 'CSS', $parent_block_name, $block_name ),
@@ -1332,8 +1469,10 @@
1332 1469 'custom_styles' => $this->refine_custom_scripts( $block_custom_styles, 'CSS', $parent_block_name, $block_name ),
1333 1470 'hideOnFrontend' => $hide_on_frontend,
1334 1471 'blockParent' => $block_parent,
1335 1472 'blockAncestor' => $block_ancestor,
1473 + 'migrateClass' => $migrate_class,
1474 +
1336 1475 ];
1337 1476
1338 1477 if ( $keywords ) {
1339 1478 $parent_args['keywords'] = $keywords;
@@ -1491,9 +1630,9 @@
1491 1630 'parent_block_icon' => esc_html__( 'Parent icon', 'content-blocks-builder' ),
1492 1631 'parent_block_name' => esc_html__( 'Parent block name', 'content-blocks-builder' ),
1493 1632 );
1494 1633
1495 - if ( $this->the_plugin_instance->is_debug_mode() ) {
1634 + if ( apply_filters( 'cbb_display_block_version', $this->the_plugin_instance->is_debug_mode() ) ) {
1496 1635 $custom_columns['block_version'] = esc_html__( 'Block version', 'content-blocks-builder' );
1497 1636 }
1498 1637
1499 1638 // Add after title column.
@@ -1547,9 +1686,9 @@
1547 1686 $block_version = get_post_meta( $post_id, 'boldblocks_block_version', true );
1548 1687 if ( $block_version ) {
1549 1688 echo esc_html( $block_version );
1550 1689 } else {
1551 - esc_html_e( '1.x', 'content-blocks-builder' );
1690 + echo esc_html( '1.x' );
1552 1691 }
1553 1692 break;
1554 1693
1555 1694 // Just break out of the switch statement for everything else.
@@ -1707,9 +1846,9 @@
1707 1846 }
1708 1847
1709 1848 if ( $block_instance->block_type->supports['cbb'] ?? false ) {
1710 1849 $GLOBALS['boldblocks_frontend_loaded'] = true;
1711 - } elseif ( $this->is_enqueue_frontend_script_for_non_cbb_blocks( $block, $block_instance ) ) {
1850 + } elseif ( $this->is_enqueue_frontend_script_for_animations( $block ) || $this->is_enqueue_frontend_script_for_sticky_blocks( $block ) ) {
1712 1851 wp_enqueue_script( $this->custom_blocks_frontend_handle );
1713 1852 wp_enqueue_style( $this->custom_blocks_handle );
1714 1853
1715 1854 $GLOBALS['boldblocks_frontend_loaded'] = true;
@@ -1718,15 +1857,14 @@
1718 1857 return $block_content;
1719 1858 }
1720 1859
1721 1860 /**
1722 - * Whether to load the frontend scripts for non-cbb blocks.
1861 + * Whether to load the frontend scripts for non-cbb sticky blocks.
1723 1862 *
1724 - * @param array $block
1725 - * @param WP_Block $block_instance
1863 + * @param array $block
1726 1864 * @return boolean
1727 1865 */
1728 - private function is_enqueue_frontend_script_for_non_cbb_blocks( $block, $block_instance ) {
1866 + private function is_enqueue_frontend_script_for_sticky_blocks( $block ) {
1729 1867 $block_names = $this->the_plugin_instance->get_component( CustomStyle::class )->non_cbb_blocks;
1730 1868 if ( ! in_array( $block['blockName'] ?? '', $block_names, true ) ) {
1731 1869 return false;
1732 1870 }
@@ -1739,8 +1877,18 @@
1739 1877 return false;
1740 1878 }
1741 1879
1742 1880 /**
1881 + * Whether to load the frontend scripts for non-cbb animation blocks.
1882 + *
1883 + * @param array $block
1884 + * @return boolean
1885 + */
1886 + private function is_enqueue_frontend_script_for_animations( $block ) {
1887 + return ! empty( $block['attrs']['boldblocks']['animations'] ) && in_array( $block['blockName'] ?? '', $this->get_animated_blocks(), true );
1888 + }
1889 +
1890 + /**
1743 1891 * Enqueue frontend scripts for carousel layout in the query loop block
1744 1892 *
1745 1893 * @param string $block_content
1746 1894 * @param array $block
@@ -1813,14 +1961,14 @@
1813 1961 register_rest_field(
1814 1962 $this->post_type,
1815 1963 'keywords',
1816 1964 array(
1817 - 'get_callback' => function( $params ) {
1965 + 'get_callback' => function ( $params ) {
1818 1966 $keywords = wp_list_pluck( wp_get_object_terms( $params['id'], 'boldblocks_block_keywords' ), 'name' );
1819 1967
1820 1968 return \implode( ',', $keywords );
1821 1969 },
1822 - 'update_callback' => function( $value, $post ) {
1970 + 'update_callback' => function ( $value, $post ) {
1823 1971 wp_set_post_terms( $post->ID, $value, 'boldblocks_block_keywords' );
1824 1972 },
1825 1973 'schema' => array(
1826 1974 'type' => 'string',
@@ -1859,9 +2007,9 @@
1859 2007 return $block_content;
1860 2008 }
1861 2009
1862 2010 if ( $block_instance->block_type->supports['hideOnFrontend'] ?? false ) {
1863 - return null;
2011 + return '<!-- ' . esc_html( $block_instance->name ) . ' -->';
1864 2012 }
1865 2013
1866 2014 return $block_content;
1867 2015 }
@@ -1917,9 +2065,9 @@
1917 2065 if ( ! empty( $custom_styles ) ) {
1918 2066 $custom_styles = array_filter(
1919 2067 $custom_styles,
1920 2068 function ( $style ) {
1921 - return ! empty( $style['value'] );
2069 + return ! empty( $style['value'] ) && 'view' !== ( $style['type'] ?? '' );
1922 2070 }
1923 2071 );
1924 2072
1925 2073 $dynamic_style = '';
@@ -2131,8 +2279,9 @@
2131 2279 }
2132 2280 }
2133 2281 }
2134 2282
2283 + // ignoreStickyPosts is depreated since WP 6.8.
2135 2284 // Ignore sticky posts not exlude them.
2136 2285 if ( ( $cbb_params['ignoreStickyPosts'] ?? false ) && ( 'exclude' === $query_context['sticky'] ?? '' ) ) {
2137 2286 $cbb_args['ignore_sticky_posts'] = true;
2138 2287 $sticky = get_option( 'sticky_posts' );
@@ -2157,9 +2306,9 @@
2157 2306 }
2158 2307
2159 2308 $orderby = array_filter(
2160 2309 array_map(
2161 - function( $item ) {
2310 + function ( $item ) {
2162 2311 return $item ? sanitize_text_field( $item ) : false;
2163 2312 },
2164 2313 $orderby
2165 2314 )
@@ -2525,8 +2674,50 @@
2525 2674 }
2526 2675 }
2527 2676
2528 2677 return $posts;
2678 + }
2679 +
2680 + /**
2681 + * Get the current post
2682 + *
2683 + * @return string
2684 + */
2685 + public function get_current_post() {
2686 + global $pagenow;
2687 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
2688 + $post_id = 'post.php' === $pagenow && isset( $_GET['post'] ) ? absint( $_GET['post'] ) : 0;
2689 + $post = $post_id ? get_post( $post_id ) : false;
2690 +
2691 + return $post instanceof \WP_Post ? $post : false;
2692 + }
2693 +
2694 + /**
2695 + * Get animated blocks
2696 + */
2697 + public function get_animated_blocks() {
2698 + return apply_filters(
2699 + 'cbb_get_animated_blocks',
2700 + [
2701 + 'core/heading',
2702 + 'core/paragraph',
2703 + 'core/image',
2704 + 'core/button',
2705 + 'core/buttons',
2706 + 'core/list-item',
2707 + 'core/list',
2708 + 'core/group',
2709 + 'core/columns',
2710 + 'core/column',
2711 + 'core/cover',
2712 + 'core/media-text',
2713 + 'core/post-title',
2714 + 'core/post-excerpt',
2715 + 'core/post-terms',
2716 + 'core/readmore',
2717 + 'boldblocks/svg-block',
2718 + ]
2719 + );
2529 2720 }
2530 2721
2531 2722 /**
2532 2723 * Get max items