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 +140 -41 2.8.4trunk 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
@@ -150,9 +152,9 @@
150 152 // Handle save post.
151 153 add_action( 'save_post_' . $this->post_type, [ $this, 'save_post' ], 10, 2 );
152 154
153 155 // Clear the transient cache on upgraded.
154 - add_action( 'cbb_version_upgraded', [ $this, 'clear_transient_cache' ] );
156 + add_action( 'cbb/version_upgraded', [ $this, 'clear_transient_cache' ] );
155 157
156 158 // Enqueue frontend scripts for non-cbb blocks.
157 159 add_filter( 'render_block', [ $this, 'enqueue_frontend_block_scripts' ], 10, 3 );
158 160
@@ -546,9 +548,9 @@
546 548 'type' => 'string',
547 549 ),
548 550 ),
549 551 'additionalProperties' => array(
550 - 'type' => [ 'string', 'boolean', 'object', 'array' ],
552 + 'type' => [ 'integer', 'number', 'boolean', 'string', 'object', 'array' ], // The order of data type matters.
551 553 ),
552 554 ),
553 555 ),
554 556 ),
@@ -572,9 +574,9 @@
572 574 'type' => 'string',
573 575 ),
574 576 ),
575 577 'additionalProperties' => array(
576 - 'type' => [ 'string', 'boolean', 'object', 'array' ],
578 + 'type' => [ 'integer', 'number', 'boolean', 'string', 'object', 'array' ],
577 579 ),
578 580 ),
579 581 ),
580 582 ),
@@ -749,8 +751,9 @@
749 751 'supports' => [
750 752 'cbb' => true,
751 753 'layout' => true,
752 754 'migrateClass' => ! empty( $args['migrateClass'] ) ? ( isset( $args['id'] ) ? 'wp-block-boldblocks-custom' : 'wp-block-boldblocks-custom-parent' ) : '',
755 + 'CSSClasses' => $args['className'] ?? '',
753 756 ],
754 757 'uses_context' => [ 'postId', 'postType', 'cbb/block-overrides' ],
755 758 ];
756 759
@@ -917,47 +920,103 @@
917 920 }
918 921 }
919 922 }
920 923
921 - if ( ! $is_backend && ! empty( $args['custom_scripts'] ) ) {
924 + if ( ! empty( $args['custom_scripts'] ) && ! $is_backend ) {
922 925 $custom_scripts = $args['custom_scripts'];
923 926
924 - foreach ( $custom_scripts as $script ) {
925 - if ( ! $script || ! is_array( $script ) || empty( $script['value'] ) ) {
926 - 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'];
927 968 }
969 + );
928 970
929 - $script_type = $script['script_type'] ?? '';
930 - // Legacy support for script_type.
931 - if ( ! $script_type ) {
932 - if ( $script['is_module'] ?? false ) {
933 - $script_type = 'module';
934 - } elseif ( ! empty( $script['handle'] ) ) {
935 - $script_type = 'custom';
936 - } else {
937 - $script_type = 'default';
938 - }
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 + }
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 ] );
939 1000 }
940 - $is_module = 'module' === $script_type;
941 - $handle = $is_module ? $block_module_inline_handle : $block_inline_handle;
942 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 +
943 1013 // Determine if a custom handle should be used.
944 - if ( 'custom' === $script_type && ! empty( $script['handle'] ) ) {
1014 + if ( 'custom' === $script_type ) {
945 1015 $handle = $this->refine_script_handle( $script['handle'], $is_backend );
946 1016 } else {
947 - // Get dep handles.
948 - $dep_handles = $script['deps'] ?? 'CBB_BLOCK_API';
949 - if ( false === strpos( $dep_handles, 'CBB_BLOCK_API' ) ) {
950 - if ( ! $dep_handles ) {
951 - $dep_handles = 'CBB_BLOCK_API';
952 - } else {
953 - $dep_handles = 'CBB_BLOCK_API,' . $dep_handles;
954 - }
955 - }
1017 + $handle = 'module' === $script_type ? $block_module_inline_handle : $block_inline_handle;
956 1018
957 - // Register the default handle for module and inline scripts.
958 - wp_register_script( $handle, '', explode( ',', $this->refine_script_handle( $dep_handles, $is_backend ) ), BOLDBLOCKS_CBB_VERSION, [ 'in_footer' => true ] );
959 -
960 1019 // Add handle to view scripts and editor scripts if backend.
961 1020 if ( ! in_array( $handle, $handles['view_script_handles'], true ) ) {
962 1021 $handles['view_script_handles'][] = $handle;
963 1022 }
@@ -1113,8 +1172,9 @@
1113 1172 $screen = get_current_screen();
1114 1173 if ( $screen && $screen->is_block_editor ) {
1115 1174 wp_enqueue_code_editor( array( 'type' => 'text/css' ) );
1116 1175 wp_enqueue_code_editor( array( 'type' => 'javascript' ) );
1176 + wp_enqueue_code_editor( array( 'type' => 'application/json' ) );
1117 1177 }
1118 1178 }
1119 1179
1120 1180 /**
@@ -1173,8 +1233,10 @@
1173 1233 $blocks_scripts = [
1174 1234 'blocks' => $all_custom_blocks,
1175 1235 'variations' => $this->the_plugin_instance->get_component( Variations::class )->get_all_variations(),
1176 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(),
1177 1239 ];
1178 1240
1179 1241 // Get block name for current variation.
1180 1242 $block_name = $this->the_plugin_instance->get_component( Variations::class )->get_block_name();
@@ -1342,9 +1404,9 @@
1342 1404 }
1343 1405
1344 1406 $block_name = sprintf( 'boldblocks/%s', $this->sanitize_block_name( $item->post_name ) );
1345 1407 $block_version = get_post_meta( $item->ID, 'boldblocks_block_version', true );
1346 - $migrateClass = version_compare( $block_version, '2.7.14', '<=' );
1408 + $migrate_class = version_compare( $block_version, '2.7.14', '<=' );
1347 1409
1348 1410 $block_args = [
1349 1411 'id' => $item->ID,
1350 1412 'name' => $block_name,
@@ -1361,9 +1423,9 @@
1361 1423 'enableCustomAttributes' => (bool) get_post_meta( $item->ID, 'boldblocks_enable_custom_attributes', true ),
1362 1424 ],
1363 1425 'enableVariationPicker' => (bool) get_post_meta( $item->ID, 'boldblocks_enable_variation_picker', true ),
1364 1426 'blockVersion' => $block_version,
1365 - 'migrateClass' => $migrateClass,
1427 + 'migrateClass' => $migrate_class,
1366 1428 'dependentBlocks' => get_post_meta( $item->ID, 'boldblocks_block_dependent_blocks', true ),
1367 1429 'hideOnFrontend' => $hide_on_frontend,
1368 1430 'isTransformable' => $is_transformable,
1369 1431 'isHidden' => $is_hidden,
@@ -1407,9 +1469,9 @@
1407 1469 'custom_styles' => $this->refine_custom_scripts( $block_custom_styles, 'CSS', $parent_block_name, $block_name ),
1408 1470 'hideOnFrontend' => $hide_on_frontend,
1409 1471 'blockParent' => $block_parent,
1410 1472 'blockAncestor' => $block_ancestor,
1411 - 'migrateClass' => $migrateClass,
1473 + 'migrateClass' => $migrate_class,
1412 1474
1413 1475 ];
1414 1476
1415 1477 if ( $keywords ) {
@@ -1784,9 +1846,9 @@
1784 1846 }
1785 1847
1786 1848 if ( $block_instance->block_type->supports['cbb'] ?? false ) {
1787 1849 $GLOBALS['boldblocks_frontend_loaded'] = true;
1788 - } 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 ) ) {
1789 1851 wp_enqueue_script( $this->custom_blocks_frontend_handle );
1790 1852 wp_enqueue_style( $this->custom_blocks_handle );
1791 1853
1792 1854 $GLOBALS['boldblocks_frontend_loaded'] = true;
@@ -1795,15 +1857,14 @@
1795 1857 return $block_content;
1796 1858 }
1797 1859
1798 1860 /**
1799 - * Whether to load the frontend scripts for non-cbb blocks.
1861 + * Whether to load the frontend scripts for non-cbb sticky blocks.
1800 1862 *
1801 - * @param array $block
1802 - * @param WP_Block $block_instance
1863 + * @param array $block
1803 1864 * @return boolean
1804 1865 */
1805 - private function is_enqueue_frontend_script_for_non_cbb_blocks( $block, $block_instance ) {
1866 + private function is_enqueue_frontend_script_for_sticky_blocks( $block ) {
1806 1867 $block_names = $this->the_plugin_instance->get_component( CustomStyle::class )->non_cbb_blocks;
1807 1868 if ( ! in_array( $block['blockName'] ?? '', $block_names, true ) ) {
1808 1869 return false;
1809 1870 }
@@ -1816,8 +1877,18 @@
1816 1877 return false;
1817 1878 }
1818 1879
1819 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 + /**
1820 1891 * Enqueue frontend scripts for carousel layout in the query loop block
1821 1892 *
1822 1893 * @param string $block_content
1823 1894 * @param array $block
@@ -1936,9 +2007,9 @@
1936 2007 return $block_content;
1937 2008 }
1938 2009
1939 2010 if ( $block_instance->block_type->supports['hideOnFrontend'] ?? false ) {
1940 - return null;
2011 + return '<!-- ' . esc_html( $block_instance->name ) . ' -->';
1941 2012 }
1942 2013
1943 2014 return $block_content;
1944 2015 }
@@ -2617,8 +2688,36 @@
2617 2688 $post_id = 'post.php' === $pagenow && isset( $_GET['post'] ) ? absint( $_GET['post'] ) : 0;
2618 2689 $post = $post_id ? get_post( $post_id ) : false;
2619 2690
2620 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 + );
2621 2720 }
2622 2721
2623 2722 /**
2624 2723 * Get max items