Skip to content

Commit

Permalink
Gutenpack: Revert deprecating jetpack_register_block (#11328)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
enejb authored and jeherve committed Feb 15, 2019
1 parent e5fca6d commit 376b6d8
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 60 deletions.
42 changes: 13 additions & 29 deletions class.jetpack-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 );
}

/**
Expand All @@ -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'] );
Expand Down Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion extensions/blocks/business-hours/business-hours.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @package Jetpack
*/

jetpack_register_block_type(
jetpack_register_block(
'jetpack/business-hours',
array( 'render_callback' => 'jetpack_business_hours_render' )
);
Expand Down
8 changes: 4 additions & 4 deletions extensions/blocks/contact-info/contact-info.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) )
);
Expand Down
2 changes: 1 addition & 1 deletion extensions/blocks/gif/gif.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @package Jetpack
*/

jetpack_register_block_type(
jetpack_register_block(
'jetpack/gif',
array(
'render_callback' => 'jetpack_gif_block_render',
Expand Down
2 changes: 1 addition & 1 deletion extensions/blocks/mailchimp/mailchimp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion extensions/blocks/map/map.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @package Jetpack
*/

jetpack_register_block_type(
jetpack_register_block(
'jetpack/map',
array(
'render_callback' => 'jetpack_map_block_load_assets',
Expand Down
2 changes: 1 addition & 1 deletion extensions/blocks/markdown/markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}

2 changes: 1 addition & 1 deletion extensions/blocks/slideshow/slideshow.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @package Jetpack
*/

jetpack_register_block_type(
jetpack_register_block(
'jetpack/slideshow',
array(
'render_callback' => 'jetpack_slideshow_block_load_assets',
Expand Down
2 changes: 1 addition & 1 deletion extensions/blocks/tiled-gallery/tiled-gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion extensions/blocks/vr/vr.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* @package Jetpack
*/

jetpack_register_block_type( 'jetpack/vr' );
jetpack_register_block( 'jetpack/vr' );
24 changes: 12 additions & 12 deletions modules/contact-form/grunion-contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
) );
Expand Down
2 changes: 1 addition & 1 deletion modules/related-posts/jetpack-related-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down
2 changes: 1 addition & 1 deletion modules/simple-payments/simple-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}
Expand Down
2 changes: 1 addition & 1 deletion modules/subscriptions/views.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/videopress/class.videopress-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down
2 changes: 1 addition & 1 deletion tests/php/sync/test_class.jetpack-sync-callables.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions tests/php/test_class.jetpack-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] );
}
Expand All @@ -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"' );
Expand Down

0 comments on commit 376b6d8

Please sign in to comment.