Skip to content

Commit

Permalink
Add existance check for core versions of actions/filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Lende committed Apr 19, 2023
1 parent 55113c0 commit 664558e
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions lib/block-supports/duotone.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package gutenberg
*/

// Register duotone block supports.
// Register the block support. (overrides core one)
WP_Block_Supports::get_instance()->register(
'duotone',
array(
Expand All @@ -14,26 +14,49 @@
);

// Set up metadata prior to rendering any blocks.
if ( class_exists( 'WP_Duotone' ) ) {
remove_action( 'wp_loaded', array( 'WP_Duotone', 'set_global_styles_presets' ) );
remove_action( 'wp_loaded', array( 'WP_Duotone', 'set_global_style_block_names' ) );
}
add_action( 'wp_loaded', array( 'WP_Duotone_Gutenberg', 'set_global_styles_presets' ), 10 );
add_action( 'wp_loaded', array( 'WP_Duotone_Gutenberg', 'set_global_style_block_names' ), 10 );

// Remove WordPress core filter to avoid rendering duplicate support elements.
remove_filter( 'render_block', 'wp_render_duotone_support', 10, 2 );
// Add classnames to blocks using duotone support.
if ( function_exists( 'wp_render_duotone_support' ) ) {
// Deprecated render function.
remove_filter( 'render_block', 'wp_render_duotone_support' );
}
if ( class_exists( 'WP_Duotone' ) ) {
remove_filter( 'render_block', array( 'WP_Duotone', 'render_duotone_support' ) );
}
add_filter( 'render_block', array( 'WP_Duotone_Gutenberg', 'render_duotone_support' ), 10, 2 );

// Enqueue styles.
// Block styles (core-block-supports-inline-css) before the style engine (gutenberg_enqueue_stored_styles).
// Global styles (global-styles-inline-css) after the other global styles (gutenberg_enqueue_global_styles).
if ( class_exists( 'WP_Duotone' ) ) {
remove_action( 'wp_enqueue_scripts', array( 'WP_Duotone', 'output_block_styles' ) );
remove_action( 'wp_enqueue_scripts', array( 'WP_Duotone', 'output_global_styles' ) );
}
add_action( 'wp_enqueue_scripts', array( 'WP_Duotone_Gutenberg', 'output_block_styles' ), 9 );
add_action( 'wp_enqueue_scripts', array( 'WP_Duotone_Gutenberg', 'output_global_styles' ), 11 );

// Add SVG filters to the footer. Also, for classic themes, output block styles (core-block-supports-inline-css).
if ( class_exists( 'WP_Duotone' ) ) {
remove_action( 'wp_footer', array( 'WP_Duotone', 'output_footer_assets' ) );
}
add_action( 'wp_footer', array( 'WP_Duotone_Gutenberg', 'output_footer_assets' ), 10 );

// Add styles and SVGs for use in the editor via the EditorStyles component.
if ( class_exists( 'WP_Duotone' ) ) {
remove_filter( 'block_editor_settings_all', array( 'WP_Duotone', 'add_editor_settings' ) );
}
add_filter( 'block_editor_settings_all', array( 'WP_Duotone_Gutenberg', 'add_editor_settings' ), 10 );

// Migrate the old experimental duotone support flag.
if ( class_exists( 'WP_Duotone' ) ) {
remove_filter( 'block_type_metadata_settings', array( 'WP_Duotone', 'migrate_experimental_duotone_support_flag' ) );
}
add_filter( 'block_type_metadata_settings', array( 'WP_Duotone_Gutenberg', 'migrate_experimental_duotone_support_flag' ), 10, 2 );

/*
Expand Down

0 comments on commit 664558e

Please sign in to comment.