| @@ -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 | |
| @@ -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 | |
| @@ -1231,8 +1234,9 @@ | ||
| 1231 | 1234 | 'blocks' => $all_custom_blocks, |
| 1232 | 1235 | 'variations' => $this->the_plugin_instance->get_component( Variations::class )->get_all_variations(), |
| 1233 | 1236 | 'variationNonce' => wp_create_nonce( 'cbb_variation_nonce' ), |
| 1234 | 1237 | 'animations' => $this->get_animated_blocks(), |
| 1238 | + 'canEditCSS' => $this->the_plugin_instance->get_component( CustomStyle::class )->user_can_edit_css(), | |
| 1235 | 1239 | ]; |
| 1236 | 1240 | |
| 1237 | 1241 | // Get block name for current variation. |
| 1238 | 1242 | $block_name = $this->the_plugin_instance->get_component( Variations::class )->get_block_name(); |
| @@ -1400,9 +1404,9 @@ | ||
| 1400 | 1404 | } |
| 1401 | 1405 | |
| 1402 | 1406 | $block_name = sprintf( 'boldblocks/%s', $this->sanitize_block_name( $item->post_name ) ); |
| 1403 | 1407 | $block_version = get_post_meta( $item->ID, 'boldblocks_block_version', true ); |
| 1404 | - $migrateClass = version_compare( $block_version, '2.7.14', '<=' ); | |
| 1408 | + $migrate_class = version_compare( $block_version, '2.7.14', '<=' ); | |
| 1405 | 1409 | |
| 1406 | 1410 | $block_args = [ |
| 1407 | 1411 | 'id' => $item->ID, |
| 1408 | 1412 | 'name' => $block_name, |
| @@ -1419,9 +1423,9 @@ | ||
| 1419 | 1423 | 'enableCustomAttributes' => (bool) get_post_meta( $item->ID, 'boldblocks_enable_custom_attributes', true ), |
| 1420 | 1424 | ], |
| 1421 | 1425 | 'enableVariationPicker' => (bool) get_post_meta( $item->ID, 'boldblocks_enable_variation_picker', true ), |
| 1422 | 1426 | 'blockVersion' => $block_version, |
| 1423 | - 'migrateClass' => $migrateClass, | |
| 1427 | + 'migrateClass' => $migrate_class, | |
| 1424 | 1428 | 'dependentBlocks' => get_post_meta( $item->ID, 'boldblocks_block_dependent_blocks', true ), |
| 1425 | 1429 | 'hideOnFrontend' => $hide_on_frontend, |
| 1426 | 1430 | 'isTransformable' => $is_transformable, |
| 1427 | 1431 | 'isHidden' => $is_hidden, |
| @@ -1465,9 +1469,9 @@ | ||
| 1465 | 1469 | 'custom_styles' => $this->refine_custom_scripts( $block_custom_styles, 'CSS', $parent_block_name, $block_name ), |
| 1466 | 1470 | 'hideOnFrontend' => $hide_on_frontend, |
| 1467 | 1471 | 'blockParent' => $block_parent, |
| 1468 | 1472 | 'blockAncestor' => $block_ancestor, |
| 1469 | - 'migrateClass' => $migrateClass, | |
| 1473 | + 'migrateClass' => $migrate_class, | |
| 1470 | 1474 | |
| 1471 | 1475 | ]; |
| 1472 | 1476 | |
| 1473 | 1477 | if ( $keywords ) { |
| @@ -1842,9 +1846,9 @@ | ||
| 1842 | 1846 | } |
| 1843 | 1847 | |
| 1844 | 1848 | if ( $block_instance->block_type->supports['cbb'] ?? false ) { |
| 1845 | 1849 | $GLOBALS['boldblocks_frontend_loaded'] = true; |
| 1846 | - } 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 ) ) { | |
| 1847 | 1851 | wp_enqueue_script( $this->custom_blocks_frontend_handle ); |
| 1848 | 1852 | wp_enqueue_style( $this->custom_blocks_handle ); |
| 1849 | 1853 | |
| 1850 | 1854 | $GLOBALS['boldblocks_frontend_loaded'] = true; |
| @@ -1853,15 +1857,14 @@ | ||
| 1853 | 1857 | return $block_content; |
| 1854 | 1858 | } |
| 1855 | 1859 | |
| 1856 | 1860 | /** |
| 1857 | - * Whether to load the frontend scripts for non-cbb blocks. | |
| 1861 | + * Whether to load the frontend scripts for non-cbb sticky blocks. | |
| 1858 | 1862 | * |
| 1859 | - * @param array $block | |
| 1860 | - * @param WP_Block $block_instance | |
| 1863 | + * @param array $block | |
| 1861 | 1864 | * @return boolean |
| 1862 | 1865 | */ |
| 1863 | - private function is_enqueue_frontend_script_for_non_cbb_blocks( $block, $block_instance ) { | |
| 1866 | + private function is_enqueue_frontend_script_for_sticky_blocks( $block ) { | |
| 1864 | 1867 | $block_names = $this->the_plugin_instance->get_component( CustomStyle::class )->non_cbb_blocks; |
| 1865 | 1868 | if ( ! in_array( $block['blockName'] ?? '', $block_names, true ) ) { |
| 1866 | 1869 | return false; |
| 1867 | 1870 | } |
| @@ -1871,8 +1874,18 @@ | ||
| 1871 | 1874 | return true; |
| 1872 | 1875 | } |
| 1873 | 1876 | |
| 1874 | 1877 | return false; |
| 1878 | + } | |
| 1879 | + | |
| 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 ); | |
| 1875 | 1888 | } |
| 1876 | 1889 | |
| 1877 | 1890 | /** |
| 1878 | 1891 | * Enqueue frontend scripts for carousel layout in the query loop block |