Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use static method / properties in Duotone class. #4860

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/wp-includes/block-supports/duotone.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,30 @@
* @since 5.8.0
*/

$duotone = new WP_Duotone();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no new global added here, just a local variable.

This is a global variable.

Any code that runs after this file has been included in wp-settings.php will have access to the global $duotone variable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. WordPress does this in lots of places. I don't see the problem with it....

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does WordPress with static methods. In practice, a global variable is similar to a class with static methods... I'm no core committer, but as a member of the release squad, I'm only in favor of last-minute style changes right before RC1 if there are objective reasons.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajlende @priethor I am going to invert this question, why is static being used in the first place. It is never uncommon in WordPress space to do this? I have heard something about keeping state, but that can be done with a global as well.


// Register the block support.
WP_Block_Supports::get_instance()->register(
'duotone',
array(
'register_attribute' => array( 'WP_Duotone', 'register_duotone_support' ),
'register_attribute' => array( $duotone, 'register_duotone_support' ),
)
);

// Add classnames to blocks using duotone support.
add_filter( 'render_block', array( 'WP_Duotone', 'render_duotone_support' ), 10, 3 );
add_filter( 'render_block', array( $duotone, 'render_duotone_support' ), 10, 3 );

// Enqueue styles.
// Block styles (core-block-supports-inline-css) before the style engine (wp_enqueue_stored_styles).
// Global styles (global-styles-inline-css) after the other global styles (wp_enqueue_global_styles).
add_action( 'wp_enqueue_scripts', array( 'WP_Duotone', 'output_block_styles' ), 9 );
add_action( 'wp_enqueue_scripts', array( 'WP_Duotone', 'output_global_styles' ), 11 );
add_action( 'wp_enqueue_scripts', array( $duotone, 'output_block_styles' ), 9 );
add_action( 'wp_enqueue_scripts', array( $duotone, 'output_global_styles' ), 11 );

// Add SVG filters to the footer. Also, for classic themes, output block styles (core-block-supports-inline-css).
add_action( 'wp_footer', array( 'WP_Duotone', 'output_footer_assets' ), 10 );
add_action( 'wp_footer', array( $duotone, 'output_footer_assets' ), 10 );

// Add styles and SVGs for use in the editor via the EditorStyles component.
add_filter( 'block_editor_settings_all', array( 'WP_Duotone', 'add_editor_settings' ), 10 );
add_filter( 'block_editor_settings_all', array( $duotone, 'add_editor_settings' ), 10 );

// Migrate the old experimental duotone support flag.
add_filter( 'block_type_metadata_settings', array( 'WP_Duotone', 'migrate_experimental_duotone_support_flag' ), 10, 2 );
add_filter( 'block_type_metadata_settings', array( $duotone, 'migrate_experimental_duotone_support_flag' ), 10, 2 );
Loading
Loading