Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 2 |
CRAP | n/a |
0 / 0 |
|
| wpcomsh_coblocks_plugins_loaded | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 | |||
| wpcomsh_coblocks_there_can_be_only_one_opentable_block | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Customizations for CoBlocks |
| 4 | * |
| 5 | * CoBlocks is automatically installed as part of the WordPress.com on Atomic migration process. |
| 6 | * We need to adjust some CoBlocks behaviors to provide tailored WordPress.com experience. |
| 7 | * |
| 8 | * @package coblocks |
| 9 | */ |
| 10 | |
| 11 | /** |
| 12 | * Makes coblock modifications once all plugins have been loaded. |
| 13 | */ |
| 14 | function wpcomsh_coblocks_plugins_loaded() { |
| 15 | // Disable CoBlocks block-patterns. |
| 16 | // See https://github.com/godaddy-wordpress/coblocks/pull/1659 |
| 17 | if ( |
| 18 | class_exists( 'CoBlocks_Block_Patterns' ) |
| 19 | && defined( 'CoBlocks_Block_Patterns::POST_TYPE' ) |
| 20 | ) { |
| 21 | $instance = CoBlocks_Block_Patterns::register(); |
| 22 | |
| 23 | remove_action( 'admin_enqueue_scripts', array( $instance, 'conditional_load_patterns' ) ); |
| 24 | |
| 25 | if ( is_wp_version_compatible( '5.5' ) ) { |
| 26 | remove_action( 'init', array( $instance, 'register_post_type' ) ); |
| 27 | remove_action( 'init', array( $instance, 'register_type_taxonomy' ) ); |
| 28 | remove_action( 'init', array( $instance, 'register_category_taxonomy' ) ); |
| 29 | remove_action( 'init', array( $instance, 'load_block_patterns' ) ); |
| 30 | remove_action( 'rest_insert_' . CoBlocks_Block_Patterns::POST_TYPE, array( $instance, 'add_taxonomies_on_insert_post' ), 10 ); |
| 31 | |
| 32 | remove_filter( 'coblocks_layout_selector_categories', array( $instance, 'load_categories' ) ); |
| 33 | remove_filter( 'coblocks_layout_selector_layouts', array( $instance, 'load_layouts' ) ); |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | add_action( 'plugins_loaded', 'wpcomsh_coblocks_plugins_loaded' ); |
| 38 | |
| 39 | /** |
| 40 | * Disable Coblocks' OpenTable block |
| 41 | * Jetpack already ships with a similar block. |
| 42 | */ |
| 43 | function wpcomsh_coblocks_there_can_be_only_one_opentable_block() { |
| 44 | wp_add_inline_script( |
| 45 | 'coblocks-editor', |
| 46 | <<<'SCRIPT' |
| 47 | document.addEventListener( 'DOMContentLoaded', function() { |
| 48 | if ( wp.blocks.getBlockType( 'jetpack/opentable' ) && wp.blocks.getBlockType( 'coblocks/opentable' ) ) { |
| 49 | wp.blocks.unregisterBlockType( 'coblocks/opentable' ); |
| 50 | } |
| 51 | } ); |
| 52 | SCRIPT |
| 53 | ); |
| 54 | } |
| 55 | // Use later priority to give coblocks plenty of time to enqueue its scripts. |
| 56 | add_action( 'enqueue_block_editor_assets', 'wpcomsh_coblocks_there_can_be_only_one_opentable_block', 99 ); |