PluginProbe
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts / 2.8.15
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts v2.8.15
2.8.15 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 All 148 releases
← All changes | includes/custom-blocks.php +231 -48 2.7.9 → 2.8.15 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 ),
@@ -534,9 +548,9 @@
534 548 'type' => 'string',
535 549 ),
536 550 ),
537 551 'additionalProperties' => array(
538 - 'type' => [ 'string', 'boolean', 'object', 'array' ],
552 + 'type' => [ 'integer', 'number', 'boolean', 'string', 'object', 'array' ], // The order of data type matters.
539 553 ),
540 554 ),
541 555 ),
542 556 ),
@@ -560,9 +574,9 @@
560 574 'type' => 'string',
561 575 ),
562 576 ),
563 577 'additionalProperties' => array(
564 - 'type' => [ 'string', 'boolean', 'object', 'array' ],
578 + 'type' => [ 'integer', 'number', 'boolean', 'string', 'object', 'array' ],
565 579 ),
566 580 ),
567 581 ),
568 582 ),
@@ -711,12 +725,9 @@
711 725 // Make name as the key.
712 726 $this->repeater_blocks = array_column( $this->repeater_blocks, null, 'name' );
713 727
714 728 // Get current post.
715 - global $pagenow;
716 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended
717 - $post_id = 'post.php' === $pagenow && isset( $_GET['post'] ) ? absint( $_GET['post'] ) : 0;
718 - $post = $post_id ? get_post( $post_id ) : false;
729 + $post = $this->get_current_post();
719 730 $block_name = '';
720 731 $repeater_block_name = '';
721 732
722 733 if ( $post && $this->post_type === $post->post_type ) {
@@ -737,10 +748,12 @@
737 748 // Build block attributes.
738 749 $block_atts = [
739 750 'api_version' => 3,
740 751 'supports' => [
741 - 'cbb' => true,
742 - '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'] ?? '',
743 756 ],
744 757 'uses_context' => [ 'postId', 'postType', 'cbb/block-overrides' ],
745 758 ];
746 759
@@ -856,10 +869,11 @@
856 869 }
857 870
858 871 // Scripts & styles.
859 872 $is_backend = is_admin();
860 - $block_inline_handle = 'cbb-' . str_replace( '/', '-', $name );
861 - $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;
862 876
863 877 if ( ! empty( $args['external_scripts'] ) ) {
864 878 $external_scripts = array_filter(
865 879 $args['external_scripts'],
@@ -906,25 +920,102 @@
906 920 }
907 921 }
908 922 }
909 923
910 - if ( ! $is_backend && ! empty( $args['custom_scripts'] ) ) {
924 + if ( ! empty( $args['custom_scripts'] ) && ! $is_backend ) {
911 925 $custom_scripts = $args['custom_scripts'];
912 926
913 - foreach ( $custom_scripts as $script ) {
914 - if ( ! $script || ! is_array( $script ) || empty( $script['value'] ) ) {
915 - 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'];
916 968 }
969 + );
917 970
918 - $is_module = $script['is_module'] ?? false;
919 - $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 + }
920 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 +
921 1013 // Determine if a custom handle should be used.
922 - if ( ! empty( $script['handle'] ) && ! $is_module ) {
1014 + if ( 'custom' === $script_type ) {
923 1015 $handle = $this->refine_script_handle( $script['handle'], $is_backend );
924 1016 } else {
925 - // Register the default handle for module and inline scripts.
926 - 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;
927 1018
928 1019 // Add handle to view scripts and editor scripts if backend.
929 1020 if ( ! in_array( $handle, $handles['view_script_handles'], true ) ) {
930 1021 $handles['view_script_handles'][] = $handle;
@@ -1047,8 +1138,9 @@
1047 1138 * @return string
1048 1139 */
1049 1140 private function refine_script_handle( $handle, $is_backend = false ) {
1050 1141 if ( $handle ) {
1142 + $handle = str_replace( ' ', '', $handle );
1051 1143 $handle = str_replace( 'CBB_BLOCK_API', $is_backend ? $this->custom_blocks_handle : $this->custom_blocks_frontend_handle, $handle );
1052 1144 $handle = str_replace( 'CBB_CAROUSEL_API', $is_backend ? $this->custom_blocks_handle : $this->carousel_blocks_frontend_handle, $handle );
1053 1145 }
1054 1146
@@ -1080,12 +1172,28 @@
1080 1172 $screen = get_current_screen();
1081 1173 if ( $screen && $screen->is_block_editor ) {
1082 1174 wp_enqueue_code_editor( array( 'type' => 'text/css' ) );
1083 1175 wp_enqueue_code_editor( array( 'type' => 'javascript' ) );
1176 + wp_enqueue_code_editor( array( 'type' => 'application/json' ) );
1084 1177 }
1085 1178 }
1086 1179
1087 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 = $this->the_plugin_instance->get_file_uri( 'includes/assets/esprima-next/esprima.js' );
1190 + }
1191 +
1192 + return $src;
1193 + }
1194 +
1195 + /**
1088 1196 * Register scripts
1089 1197 *
1090 1198 * @return void
1091 1199 */
@@ -1104,13 +1212,31 @@
1104 1212
1105 1213 // Add translation.
1106 1214 wp_set_script_translations( $this->custom_blocks_handle, 'content-blocks-builder' );
1107 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 +
1108 1232 // Define data.
1109 1233 $blocks_scripts = [
1110 - 'blocks' => $this->get_all_custom_blocks(),
1234 + 'blocks' => $all_custom_blocks,
1111 1235 'variations' => $this->the_plugin_instance->get_component( Variations::class )->get_all_variations(),
1112 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(),
1113 1239 ];
1114 1240
1115 1241 // Get block name for current variation.
1116 1242 $block_name = $this->the_plugin_instance->get_component( Variations::class )->get_block_name();
@@ -1236,9 +1362,9 @@
1236 1362
1237 1363 $raw_posts = get_posts( $post_args );
1238 1364
1239 1365 $block_posts = array_map(
1240 - function( $item ) {
1366 + function ( $item ) {
1241 1367 // Template lock.
1242 1368 $template_lock = get_post_meta( $item->ID, 'boldblocks_template_lock', true );
1243 1369
1244 1370 // Convert boolean string to boolean.
@@ -1250,18 +1376,18 @@
1250 1376 $block_external_styles = get_post_meta( $item->ID, 'boldblocks_block_external_styles', true );
1251 1377 $block_custom_styles = get_post_meta( $item->ID, 'boldblocks_block_custom_styles', true );
1252 1378
1253 1379 // Hide on frontend.
1254 - $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 );
1255 1381
1256 1382 // Is a readonly block.
1257 - $is_readonly = ! ! get_post_meta( $item->ID, 'boldblocks_is_readonly', true );
1383 + $is_readonly = (bool) get_post_meta( $item->ID, 'boldblocks_is_readonly', true );
1258 1384
1259 1385 // Is block transformable.
1260 - $is_transformable = ! ! get_post_meta( $item->ID, 'boldblocks_is_transformable', true );
1386 + $is_transformable = (bool) get_post_meta( $item->ID, 'boldblocks_is_transformable', true );
1261 1387
1262 1388 // Is block hidden.
1263 - $is_hidden = ! ! get_post_meta( $item->ID, 'boldblocks_is_hidden', true );
1389 + $is_hidden = (bool) get_post_meta( $item->ID, 'boldblocks_is_hidden', true );
1264 1390
1265 1391 // Parent & ancestor.
1266 1392 $block_parent = get_post_meta( $item->ID, 'boldblocks_block_parent', true );
1267 1393 $block_parent = $block_parent ? array_filter( explode( ',', $block_parent ) ) : [];
@@ -1276,9 +1402,11 @@
1276 1402 } else {
1277 1403 $keywords = false;
1278 1404 }
1279 1405
1280 - $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', '<=' );
1281 1409
1282 1410 $block_args = [
1283 1411 'id' => $item->ID,
1284 1412 'name' => $block_name,
@@ -1291,12 +1419,13 @@
1291 1419 'blockIcon' => get_post_meta( $item->ID, 'boldblocks_block_icon', true ),
1292 1420 'blockSupports' => get_post_meta( $item->ID, 'boldblocks_block_supports', true ),
1293 1421 'blockAttributes' => [
1294 1422 'attributes' => get_post_meta( $item->ID, 'boldblocks_block_attributes', true ),
1295 - 'enableCustomAttributes' => ! ! get_post_meta( $item->ID, 'boldblocks_enable_custom_attributes', true ),
1423 + 'enableCustomAttributes' => (bool) get_post_meta( $item->ID, 'boldblocks_enable_custom_attributes', true ),
1296 1424 ],
1297 - 'enableVariationPicker' => ! ! get_post_meta( $item->ID, 'boldblocks_enable_variation_picker', true ),
1298 - '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,
1299 1428 'dependentBlocks' => get_post_meta( $item->ID, 'boldblocks_block_dependent_blocks', true ),
1300 1429 'hideOnFrontend' => $hide_on_frontend,
1301 1430 'isTransformable' => $is_transformable,
1302 1431 'isHidden' => $is_hidden,
@@ -1330,11 +1459,11 @@
1330 1459 'blockIcon' => get_post_meta( $item->ID, 'boldblocks_parent_block_icon', true ),
1331 1460 'blockSupports' => get_post_meta( $item->ID, 'boldblocks_parent_block_supports', true ),
1332 1461 'blockAttributes' => [
1333 1462 'attributes' => get_post_meta( $item->ID, 'boldblocks_parent_block_attributes', true ),
1334 - '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 ),
1335 1464 ],
1336 - '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 ),
1337 1466 'external_scripts' => $block_external_scripts,
1338 1467 'custom_scripts' => $this->refine_custom_scripts( $block_custom_scripts, 'JS', $parent_block_name, $block_name ),
1339 1468 'external_styles' => $block_external_styles,
1340 1469 'custom_styles' => $this->refine_custom_scripts( $block_custom_styles, 'CSS', $parent_block_name, $block_name ),
@@ -1340,8 +1469,10 @@
1340 1469 'custom_styles' => $this->refine_custom_scripts( $block_custom_styles, 'CSS', $parent_block_name, $block_name ),
1341 1470 'hideOnFrontend' => $hide_on_frontend,
1342 1471 'blockParent' => $block_parent,
1343 1472 'blockAncestor' => $block_ancestor,
1473 + 'migrateClass' => $migrate_class,
1474 +
1344 1475 ];
1345 1476
1346 1477 if ( $keywords ) {
1347 1478 $parent_args['keywords'] = $keywords;
@@ -1499,9 +1630,9 @@
1499 1630 'parent_block_icon' => esc_html__( 'Parent icon', 'content-blocks-builder' ),
1500 1631 'parent_block_name' => esc_html__( 'Parent block name', 'content-blocks-builder' ),
1501 1632 );
1502 1633
1503 - if ( $this->the_plugin_instance->is_debug_mode() ) {
1634 + if ( apply_filters( 'cbb_display_block_version', $this->the_plugin_instance->is_debug_mode() ) ) {
1504 1635 $custom_columns['block_version'] = esc_html__( 'Block version', 'content-blocks-builder' );
1505 1636 }
1506 1637
1507 1638 // Add after title column.
@@ -1715,9 +1846,9 @@
1715 1846 }
1716 1847
1717 1848 if ( $block_instance->block_type->supports['cbb'] ?? false ) {
1718 1849 $GLOBALS['boldblocks_frontend_loaded'] = true;
1719 - } 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 ) ) {
1720 1851 wp_enqueue_script( $this->custom_blocks_frontend_handle );
1721 1852 wp_enqueue_style( $this->custom_blocks_handle );
1722 1853
1723 1854 $GLOBALS['boldblocks_frontend_loaded'] = true;
@@ -1726,15 +1857,14 @@
1726 1857 return $block_content;
1727 1858 }
1728 1859
1729 1860 /**
1730 - * Whether to load the frontend scripts for non-cbb blocks.
1861 + * Whether to load the frontend scripts for non-cbb sticky blocks.
1731 1862 *
1732 - * @param array $block
1733 - * @param WP_Block $block_instance
1863 + * @param array $block
1734 1864 * @return boolean
1735 1865 */
1736 - private function is_enqueue_frontend_script_for_non_cbb_blocks( $block, $block_instance ) {
1866 + private function is_enqueue_frontend_script_for_sticky_blocks( $block ) {
1737 1867 $block_names = $this->the_plugin_instance->get_component( CustomStyle::class )->non_cbb_blocks;
1738 1868 if ( ! in_array( $block['blockName'] ?? '', $block_names, true ) ) {
1739 1869 return false;
1740 1870 }
@@ -1747,8 +1877,18 @@
1747 1877 return false;
1748 1878 }
1749 1879
1750 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 + /**
1751 1891 * Enqueue frontend scripts for carousel layout in the query loop block
1752 1892 *
1753 1893 * @param string $block_content
1754 1894 * @param array $block
@@ -1821,14 +1961,14 @@
1821 1961 register_rest_field(
1822 1962 $this->post_type,
1823 1963 'keywords',
1824 1964 array(
1825 - 'get_callback' => function( $params ) {
1965 + 'get_callback' => function ( $params ) {
1826 1966 $keywords = wp_list_pluck( wp_get_object_terms( $params['id'], 'boldblocks_block_keywords' ), 'name' );
1827 1967
1828 1968 return \implode( ',', $keywords );
1829 1969 },
1830 - 'update_callback' => function( $value, $post ) {
1970 + 'update_callback' => function ( $value, $post ) {
1831 1971 wp_set_post_terms( $post->ID, $value, 'boldblocks_block_keywords' );
1832 1972 },
1833 1973 'schema' => array(
1834 1974 'type' => 'string',
@@ -1867,9 +2007,9 @@
1867 2007 return $block_content;
1868 2008 }
1869 2009
1870 2010 if ( $block_instance->block_type->supports['hideOnFrontend'] ?? false ) {
1871 - return null;
2011 + return '<!-- ' . esc_html( $block_instance->name ) . ' -->';
1872 2012 }
1873 2013
1874 2014 return $block_content;
1875 2015 }
@@ -2139,8 +2279,9 @@
2139 2279 }
2140 2280 }
2141 2281 }
2142 2282
2283 + // ignoreStickyPosts is depreated since WP 6.8.
2143 2284 // Ignore sticky posts not exlude them.
2144 2285 if ( ( $cbb_params['ignoreStickyPosts'] ?? false ) && ( 'exclude' === $query_context['sticky'] ?? '' ) ) {
2145 2286 $cbb_args['ignore_sticky_posts'] = true;
2146 2287 $sticky = get_option( 'sticky_posts' );
@@ -2165,9 +2306,9 @@
2165 2306 }
2166 2307
2167 2308 $orderby = array_filter(
2168 2309 array_map(
2169 - function( $item ) {
2310 + function ( $item ) {
2170 2311 return $item ? sanitize_text_field( $item ) : false;
2171 2312 },
2172 2313 $orderby
2173 2314 )
@@ -2533,8 +2674,50 @@
2533 2674 }
2534 2675 }
2535 2676
2536 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 + );
2537 2720 }
2538 2721
2539 2722 /**
2540 2723 * Get max items