Skip to content

Commit

Permalink
Plugin: Call deprecated hooks only when new filters not present
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Apr 21, 2021
1 parent 1fd4a92 commit 7894f89
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
6 changes: 4 additions & 2 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,10 @@ function gutenberg_register_theme_block_category( $categories ) {
);
return $categories;
}

add_filter( 'block_categories', 'gutenberg_register_theme_block_category' );
// This can be removed when plugin support requires WordPress 5.8.0+.
if ( ! function_exists( 'get_default_block_categories' ) ) {
add_filter( 'block_categories', 'gutenberg_register_theme_block_category' );
}

/**
* Checks whether the current block type supports the feature requested.
Expand Down
18 changes: 16 additions & 2 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ function gutenberg_register_vendor_script( $scripts, $handle, $src, $deps = arra
/**
* Extends block editor settings to remove the Gutenberg's `editor-styles.css`;
*
* This can be removed when plugin support requires WordPress 5.8.0+.
*
* @param array $settings Default editor settings.
*
* @return array Filtered editor settings.
Expand Down Expand Up @@ -671,11 +673,18 @@ function gutenberg_extend_block_editor_styles( $settings ) {

return $settings;
}
add_filter( 'block_editor_settings', 'gutenberg_extend_block_editor_styles' );
// This can be removed when plugin support requires WordPress 5.8.0+.
if ( function_exists( 'get_block_editor_settings' ) ) {
add_filter( 'block_editor_settings_all', 'gutenberg_extend_block_editor_styles' );
} else {
add_filter( 'block_editor_settings', 'gutenberg_extend_block_editor_styles' );
}

/**
* Adds a flag to the editor settings to know whether we're in FSE theme or not.
*
* This can be removed when plugin support requires WordPress 5.8.0+.
*
* @param array $settings Default editor settings.
*
* @return array Filtered editor settings.
Expand All @@ -688,7 +697,12 @@ function gutenberg_extend_block_editor_settings_with_fse_theme_flag( $settings )

return $settings;
}
add_filter( 'block_editor_settings', 'gutenberg_extend_block_editor_settings_with_fse_theme_flag' );
// This can be removed when plugin support requires WordPress 5.8.0+.
if ( function_exists( 'get_block_editor_settings' ) ) {
add_filter( 'block_editor_settings_all', 'gutenberg_extend_block_editor_settings_with_fse_theme_flag' );
} else {
add_filter( 'block_editor_settings', 'gutenberg_extend_block_editor_settings_with_fse_theme_flag' );
}

/**
* Sets the editor styles to be consumed by JS.
Expand Down
7 changes: 6 additions & 1 deletion lib/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ function gutenberg_extend_post_editor_settings( $settings ) {

return $settings;
}
add_filter( 'block_editor_settings', 'gutenberg_extend_post_editor_settings' );
// This can be removed when plugin support requires WordPress 5.8.0+.
if ( function_exists( 'get_block_editor_settings' ) ) {
add_filter( 'block_editor_settings_all', 'gutenberg_extend_post_editor_settings' );
} else {
add_filter( 'block_editor_settings', 'gutenberg_extend_post_editor_settings' );
}

/**
* Initialize a block-based editor.
Expand Down
10 changes: 9 additions & 1 deletion lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ function gutenberg_experimental_global_styles_enqueue_assets() {
/**
* Adds the necessary data for the Global Styles client UI to the block settings.
*
* This can be removed when plugin support requires WordPress 5.8.0+.
*
* @param array $settings Existing block editor settings.
* @return array New block editor settings
*/
Expand Down Expand Up @@ -168,7 +170,13 @@ function gutenberg_experimental_global_styles_register_user_cpt() {
}

add_action( 'init', 'gutenberg_experimental_global_styles_register_user_cpt' );
add_filter( 'block_editor_settings', 'gutenberg_experimental_global_styles_settings', PHP_INT_MAX );
// This can be removed when plugin support requires WordPress 5.8.0+.
if ( function_exists( 'get_block_editor_settings' ) ) {
add_filter( 'block_editor_settings_all', 'gutenberg_experimental_global_styles_settings', PHP_INT_MAX );
} else {
add_filter( 'block_editor_settings', 'gutenberg_experimental_global_styles_settings', PHP_INT_MAX );

}
add_action( 'wp_enqueue_scripts', 'gutenberg_experimental_global_styles_enqueue_assets' );


Expand Down
9 changes: 8 additions & 1 deletion lib/widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,21 @@ function gutenberg_get_legacy_widget_settings() {
/**
* Extends default editor settings with values supporting legacy widgets.
*
* This can be removed when plugin support requires WordPress 5.8.0+.
*
* @param array $settings Default editor settings.
*
* @return array Filtered editor settings.
*/
function gutenberg_legacy_widget_settings( $settings ) {
return array_merge( $settings, gutenberg_get_legacy_widget_settings() );
}
add_filter( 'block_editor_settings', 'gutenberg_legacy_widget_settings' );
// This can be removed when plugin support requires WordPress 5.8.0+.
if ( function_exists( 'get_block_editor_settings' ) ) {
add_filter( 'block_editor_settings_all', 'gutenberg_legacy_widget_settings' );
} else {
add_filter( 'block_editor_settings', 'gutenberg_legacy_widget_settings' );
}

/**
* Function to enqueue admin-widgets as part of the block editor assets.
Expand Down
1 change: 0 additions & 1 deletion phpunit/block-editor-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ function filter_block_editor_settings_my_editor( $editor_settings ) {

/**
* @ticket 52920
* @expectedDeprecated block_categories
* @expectedDeprecated block_editor_settings
*/
function test_get_block_editor_settings_deprecated_filter_post_editor() {
Expand Down

0 comments on commit 7894f89

Please sign in to comment.