From 376b6d8e92e21dcd7a40efa0186be451a64c41ff Mon Sep 17 00:00:00 2001 From: Enej Bajgoric Date: Fri, 15 Feb 2019 15:32:53 -0800 Subject: [PATCH] Gutenpack: Revert deprecating jetpack_register_block (#11328) We introduced `jetpack_register_block_type` in #11310. But since we already have a wrapper function that we also deprecated. We end up with 2 functions `jetpack_register_block_type` and `jetpack_register_block` that do the same thing. This PR removed the new wrapper function in favour of the old one and ads a check that we don't call jetpack_register_block_type without `jetpack/` which is what we expect. #### Changes proposed in this Pull Request: * remove the newly added jetpack_register_block_type in favour of the old jetpack_register_block_type. #### Testing instructions: * Do the tests still pass? * Do the blocks still load in the editor? * Do you notice any php errors/notices? #### Proposed changelog entry I don't think this needs a changelog entry --- class.jetpack-gutenberg.php | 42 ++++++------------- .../blocks/business-hours/business-hours.php | 2 +- .../blocks/contact-info/contact-info.php | 8 ++-- extensions/blocks/gif/gif.php | 2 +- extensions/blocks/mailchimp/mailchimp.php | 2 +- extensions/blocks/map/map.php | 2 +- extensions/blocks/markdown/markdown.php | 2 +- extensions/blocks/slideshow/slideshow.php | 2 +- .../blocks/tiled-gallery/tiled-gallery.php | 2 +- extensions/blocks/vr/vr.php | 2 +- modules/contact-form/grunion-contact-form.php | 24 +++++------ .../related-posts/jetpack-related-posts.php | 2 +- modules/simple-payments/simple-payments.php | 2 +- modules/subscriptions/views.php | 2 +- .../videopress/class.videopress-gutenberg.php | 2 +- .../test_class.jetpack-sync-callables.php | 2 +- tests/php/test_class.jetpack-gutenberg.php | 4 +- 17 files changed, 44 insertions(+), 60 deletions(-) diff --git a/class.jetpack-gutenberg.php b/class.jetpack-gutenberg.php index 5e60e32df821b..a464c1e712d60 100644 --- a/class.jetpack-gutenberg.php +++ b/class.jetpack-gutenberg.php @@ -7,44 +7,28 @@ */ /** - * Wrapper function to safely register a Jetpack Gutenberg block + * Wrapper function to safely register a gutenberg block type * * @param string $slug Slug of the block. * @param array $args Arguments that are passed into register_block_type. * * @see register_block_type * - * @since 7.1.0 + * @since 6.7.0 * * @return WP_Block_Type|false The registered block type on success, or false on failure. */ -function jetpack_register_block_type( $slug, $args = array() ) { +function jetpack_register_block( $slug, $args = array() ) { if ( ! function_exists( 'register_block_type' ) ) { return false; } + if ( 0 !== strpos( $slug, 'jetpack/' ) && ! strpos( $slug, '/' ) ) { + _doing_it_wrong( 'jetpack_register_block', 'Prefix the block with jetpack/ ', '7.1.0' ); + $slug = 'jetpack/' . $slug; + } return register_block_type( $slug, $args ); } -/** - * Helper function to register a Jetpack Gutenberg block - * - * @deprecated 7.1.0 Use jetpack_register_block_type() instead - * - * @param string $slug Slug of the block. - * @param array $args Arguments that are passed into register_block_type. - * - * @see register_block_type - * - * @since 6.7.0 - * - * @return void - */ -function jetpack_register_block( $slug, $args = array() ) { - _deprecated_function( __FUNCTION__, '7.1', 'jetpack_register_block_type' ); - - Jetpack_Gutenberg::register_block( $slug, $args ); -} - /** * Helper function to register a Jetpack Gutenberg plugin * @@ -139,15 +123,15 @@ protected static function share_items( $a, $b ) { /** * Register a block * - * @deprecated 7.1.0 Use jetpack_register_block_type() instead + * @deprecated 7.1.0 Use jetpack_register_block() instead * * @param string $slug Slug of the block. * @param array $args Arguments that are passed into register_block_type(). */ public static function register_block( $slug, $args ) { - _deprecated_function( __METHOD__, '7.1', 'jetpack_register_block_type' ); + _deprecated_function( __METHOD__, '7.1', 'jetpack_register_block' ); - jetpack_register_block_type( 'jetpack/' . $slug, $args ); + jetpack_register_block( 'jetpack/' . $slug, $args ); } /** @@ -166,14 +150,14 @@ public static function register_plugin( $slug ) { /** * Register a block * - * @deprecated 7.0.0 Use jetpack_register_block_type() instead + * @deprecated 7.0.0 Use jetpack_register_block() instead * * @param string $slug Slug of the block. * @param array $args Arguments that are passed into the register_block_type. * @param array $availability array containing if a block is available and the reason when it is not. */ public static function register( $slug, $args, $availability ) { - _deprecated_function( __METHOD__, '7.0', 'jetpack_register_block_type' ); + _deprecated_function( __METHOD__, '7.0', 'jetpack_register_block' ); if ( isset( $availability['available'] ) && ! $availability['available'] ) { self::set_extension_unavailability_reason( $slug, $availability['unavailable_reason'] ); @@ -353,7 +337,7 @@ public static function get_availability() { /** * Fires before Gutenberg extensions availability is computed. * - * In the function call you supply, use `jetpack_register_block_type()` to set a block as available. + * In the function call you supply, use `jetpack_register_block()` to set a block as available. * Alternatively, use `Jetpack_Gutenberg::set_extension_available()` (for a non-block plugin), and * `Jetpack_Gutenberg::set_extension_unavailable()` (if the block or plugin should not be registered * but marked as unavailable). diff --git a/extensions/blocks/business-hours/business-hours.php b/extensions/blocks/business-hours/business-hours.php index c69105ea4058d..a8a6b57fffdfb 100644 --- a/extensions/blocks/business-hours/business-hours.php +++ b/extensions/blocks/business-hours/business-hours.php @@ -7,7 +7,7 @@ * @package Jetpack */ -jetpack_register_block_type( +jetpack_register_block( 'jetpack/business-hours', array( 'render_callback' => 'jetpack_business_hours_render' ) ); diff --git a/extensions/blocks/contact-info/contact-info.php b/extensions/blocks/contact-info/contact-info.php index e57d1e5713708..62ca86edf3555 100644 --- a/extensions/blocks/contact-info/contact-info.php +++ b/extensions/blocks/contact-info/contact-info.php @@ -7,21 +7,21 @@ * @package Jetpack */ -jetpack_register_block_type( +jetpack_register_block( 'jetpack/contact-info', array( 'render_callback' => 'jetpack_contact_info_block_load_assets', ) ); -jetpack_register_block_type( +jetpack_register_block( 'jetpack/email', array( 'parent' => array( 'jetpack/contact-info' ) ) ); -jetpack_register_block_type( +jetpack_register_block( 'jetpack/address', array( 'parent' => array( 'jetpack/contact-info' ) ) ); -jetpack_register_block_type( +jetpack_register_block( 'jetpack/phone', array( 'parent' => array( 'jetpack/contact-info' ) ) ); diff --git a/extensions/blocks/gif/gif.php b/extensions/blocks/gif/gif.php index 6729b299b106a..cb35f3dac0a1c 100644 --- a/extensions/blocks/gif/gif.php +++ b/extensions/blocks/gif/gif.php @@ -7,7 +7,7 @@ * @package Jetpack */ -jetpack_register_block_type( +jetpack_register_block( 'jetpack/gif', array( 'render_callback' => 'jetpack_gif_block_render', diff --git a/extensions/blocks/mailchimp/mailchimp.php b/extensions/blocks/mailchimp/mailchimp.php index cc83ac3d2abee..72e6fea76a0de 100644 --- a/extensions/blocks/mailchimp/mailchimp.php +++ b/extensions/blocks/mailchimp/mailchimp.php @@ -8,7 +8,7 @@ */ if ( ( defined( 'IS_WPCOM' ) && IS_WPCOM ) || Jetpack::is_active() ) { - jetpack_register_block_type( + jetpack_register_block( 'jetpack/mailchimp', array( 'render_callback' => 'jetpack_mailchimp_block_load_assets', diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index 8e3f2340bef85..6e8c9d2a2ac78 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -7,7 +7,7 @@ * @package Jetpack */ -jetpack_register_block_type( +jetpack_register_block( 'jetpack/map', array( 'render_callback' => 'jetpack_map_block_load_assets', diff --git a/extensions/blocks/markdown/markdown.php b/extensions/blocks/markdown/markdown.php index 59bc70bd9d16c..7490b9d28d090 100644 --- a/extensions/blocks/markdown/markdown.php +++ b/extensions/blocks/markdown/markdown.php @@ -15,6 +15,6 @@ ( defined( 'IS_WPCOM' ) && IS_WPCOM ) || ( method_exists( 'Jetpack', 'is_module_active' ) && Jetpack::is_module_active( 'markdown' ) ) ) { - jetpack_register_block_type( 'jetpack/markdown' ); + jetpack_register_block( 'jetpack/markdown' ); } diff --git a/extensions/blocks/slideshow/slideshow.php b/extensions/blocks/slideshow/slideshow.php index c0b1867049799..4fdc1392c075e 100644 --- a/extensions/blocks/slideshow/slideshow.php +++ b/extensions/blocks/slideshow/slideshow.php @@ -7,7 +7,7 @@ * @package Jetpack */ -jetpack_register_block_type( +jetpack_register_block( 'jetpack/slideshow', array( 'render_callback' => 'jetpack_slideshow_block_load_assets', diff --git a/extensions/blocks/tiled-gallery/tiled-gallery.php b/extensions/blocks/tiled-gallery/tiled-gallery.php index fd0da16c3e38f..836139e25e3c0 100644 --- a/extensions/blocks/tiled-gallery/tiled-gallery.php +++ b/extensions/blocks/tiled-gallery/tiled-gallery.php @@ -11,7 +11,7 @@ ( defined( 'IS_WPCOM' ) && IS_WPCOM ) || class_exists( 'Jetpack_Photon' ) && Jetpack::is_module_active( 'photon' ) ) { - jetpack_register_block_type( + jetpack_register_block( 'jetpack/tiled-gallery', array( 'render_callback' => 'jetpack_tiled_gallery_load_block_assets', diff --git a/extensions/blocks/vr/vr.php b/extensions/blocks/vr/vr.php index ec650cc4f886d..f6ef70a67b3e8 100644 --- a/extensions/blocks/vr/vr.php +++ b/extensions/blocks/vr/vr.php @@ -7,4 +7,4 @@ * @package Jetpack */ -jetpack_register_block_type( 'jetpack/vr' ); +jetpack_register_block( 'jetpack/vr' ); diff --git a/modules/contact-form/grunion-contact-form.php b/modules/contact-form/grunion-contact-form.php index 29b9146eaf708..d23d648a709c2 100644 --- a/modules/contact-form/grunion-contact-form.php +++ b/modules/contact-form/grunion-contact-form.php @@ -245,52 +245,52 @@ protected function __construct() { } private static function register_contact_form_blocks() { - jetpack_register_block_type( 'jetpack/contact-form', array( + jetpack_register_block( 'jetpack/contact-form', array( 'render_callback' => array( __CLASS__, 'gutenblock_render_form' ), ) ); // Field render methods. - jetpack_register_block_type( 'jetpack/field-text', array( + jetpack_register_block( 'jetpack/field-text', array( 'parent' => array( 'jetpack/contact-form' ), 'render_callback' => array( __CLASS__, 'gutenblock_render_field_text' ), ) ); - jetpack_register_block_type( 'jetpack/field-name', array( + jetpack_register_block( 'jetpack/field-name', array( 'parent' => array( 'jetpack/contact-form' ), 'render_callback' => array( __CLASS__, 'gutenblock_render_field_name' ), ) ); - jetpack_register_block_type( 'jetpack/field-email', array( + jetpack_register_block( 'jetpack/field-email', array( 'parent' => array( 'jetpack/contact-form' ), 'render_callback' => array( __CLASS__, 'gutenblock_render_field_email' ), ) ); - jetpack_register_block_type( 'jetpack/field-url', array( + jetpack_register_block( 'jetpack/field-url', array( 'parent' => array( 'jetpack/contact-form' ), 'render_callback' => array( __CLASS__, 'gutenblock_render_field_url' ), ) ); - jetpack_register_block_type( 'jetpack/field-date', array( + jetpack_register_block( 'jetpack/field-date', array( 'parent' => array( 'jetpack/contact-form' ), 'render_callback' => array( __CLASS__, 'gutenblock_render_field_date' ), ) ); - jetpack_register_block_type( 'jetpack/field-telephone', array( + jetpack_register_block( 'jetpack/field-telephone', array( 'parent' => array( 'jetpack/contact-form' ), 'render_callback' => array( __CLASS__, 'gutenblock_render_field_telephone' ), ) ); - jetpack_register_block_type( 'jetpack/field-textarea', array( + jetpack_register_block( 'jetpack/field-textarea', array( 'parent' => array( 'jetpack/contact-form' ), 'render_callback' => array( __CLASS__, 'gutenblock_render_field_textarea' ), ) ); - jetpack_register_block_type( 'jetpack/field-checkbox', array( + jetpack_register_block( 'jetpack/field-checkbox', array( 'parent' => array( 'jetpack/contact-form' ), 'render_callback' => array( __CLASS__, 'gutenblock_render_field_checkbox' ), ) ); - jetpack_register_block_type( 'jetpack/field-checkbox-multiple', array( + jetpack_register_block( 'jetpack/field-checkbox-multiple', array( 'parent' => array( 'jetpack/contact-form' ), 'render_callback' => array( __CLASS__, 'gutenblock_render_field_checkbox_multiple' ), ) ); - jetpack_register_block_type( 'jetpack/field-radio', array( + jetpack_register_block( 'jetpack/field-radio', array( 'parent' => array( 'jetpack/contact-form' ), 'render_callback' => array( __CLASS__, 'gutenblock_render_field_radio' ), ) ); - jetpack_register_block_type( 'jetpack/field-select', array( + jetpack_register_block( 'jetpack/field-select', array( 'parent' => array( 'jetpack/contact-form' ), 'render_callback' => array( __CLASS__, 'gutenblock_render_field_select' ), ) ); diff --git a/modules/related-posts/jetpack-related-posts.php b/modules/related-posts/jetpack-related-posts.php index a4fc115400246..3e45a3bda03ee 100644 --- a/modules/related-posts/jetpack-related-posts.php +++ b/modules/related-posts/jetpack-related-posts.php @@ -69,7 +69,7 @@ public function __construct() { add_action( 'rest_api_init', array( $this, 'rest_register_related_posts' ) ); } - jetpack_register_block_type( + jetpack_register_block( 'jetpack/related-posts', array( 'render_callback' => array( $this, 'render_block' ), diff --git a/modules/simple-payments/simple-payments.php b/modules/simple-payments/simple-payments.php index 4cf4364c906fc..d7155766effeb 100644 --- a/modules/simple-payments/simple-payments.php +++ b/modules/simple-payments/simple-payments.php @@ -62,7 +62,7 @@ public function init_hook_action() { function register_gutenberg_block() { if ( $this->is_enabled_jetpack_simple_payments() ) { - jetpack_register_block_type( 'jetpack/simple-payments' ); + jetpack_register_block( 'jetpack/simple-payments' ); } else { Jetpack_Gutenberg::set_extension_unavailable( 'jetpack/simple-payments', 'missing_plan' ); } diff --git a/modules/subscriptions/views.php b/modules/subscriptions/views.php index e0ca7e923d830..2885419acb084 100644 --- a/modules/subscriptions/views.php +++ b/modules/subscriptions/views.php @@ -745,7 +745,7 @@ function jetpack_blog_subscriptions_init() { function jetpack_register_subscriptions_block() { if ( class_exists( 'WP_Block_Type_Registry' ) && ! WP_Block_Type_Registry::get_instance()->is_registered( 'jetpack/subscriptions' ) ) { - jetpack_register_block_type( 'jetpack/subscriptions' ); + jetpack_register_block( 'jetpack/subscriptions' ); } } diff --git a/modules/videopress/class.videopress-gutenberg.php b/modules/videopress/class.videopress-gutenberg.php index a9940b17eb712..ab29368cd27bc 100644 --- a/modules/videopress/class.videopress-gutenberg.php +++ b/modules/videopress/class.videopress-gutenberg.php @@ -105,7 +105,7 @@ public function set_extension_availability() { * It defines a server-side rendering that adds VideoPress support to the core video block. */ public function register_video_block_with_videopress() { - jetpack_register_block_type( + jetpack_register_block( 'core/video', array( 'render_callback' => array( $this, 'render_video_block_with_videopress' ), diff --git a/tests/php/sync/test_class.jetpack-sync-callables.php b/tests/php/sync/test_class.jetpack-sync-callables.php index ea7ece9a12f0a..9d4b6aaaeffb7 100644 --- a/tests/php/sync/test_class.jetpack-sync-callables.php +++ b/tests/php/sync/test_class.jetpack-sync-callables.php @@ -54,7 +54,7 @@ public function test_sync_callable_whitelist() { add_filter( 'jetpack_set_available_extensions', array( $this, 'add_test_block' ) ); Jetpack_Gutenberg::init(); - jetpack_register_block_type( 'jetpack/test' ); + jetpack_register_block( 'jetpack/test' ); $callables = array( 'wp_max_upload_size' => wp_max_upload_size(), diff --git a/tests/php/test_class.jetpack-gutenberg.php b/tests/php/test_class.jetpack-gutenberg.php index 2bfb766df19d1..ee633e8a4fd63 100644 --- a/tests/php/test_class.jetpack-gutenberg.php +++ b/tests/php/test_class.jetpack-gutenberg.php @@ -61,7 +61,7 @@ public static function get_extensions_whitelist() { } function test_registered_block_is_available() { - jetpack_register_block_type( 'jetpack/apple' ); + jetpack_register_block( 'jetpack/apple' ); $availability = Jetpack_Gutenberg::get_availability(); $this->assertTrue( $availability['apple']['available'] ); } @@ -74,7 +74,7 @@ function test_registered_block_is_not_available() { } function test_registered_block_is_not_available_when_not_defined_in_whitelist() { - jetpack_register_block_type( 'jetpack/durian' ); + jetpack_register_block( 'jetpack/durian' ); $availability = Jetpack_Gutenberg::get_availability(); $this->assertFalse( $availability['durian']['available'], 'durian is available!' ); $this->assertEquals( $availability['durian']['unavailable_reason'], 'not_whitelisted', 'unavailable_reason is not "not_whitelisted"' );