Themes: Make sure the current_theme_supports-{$feature} filter is consistently applied.

Previously, the filter was not applied if there are no arguments passed to `current_theme_supports()`.

Follow-up to [12350], [19682].

Props helgatheviking, azouamauriac, pavanpatil1, SergeyBiryukov.
Fixes #55219.

git-svn-id: https://develop.svn.wordpress.org/trunk@52812 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2022-03-01 16:05:14 +00:00
parent 44122bf7df
commit f0dfa682a5
2 changed files with 14 additions and 2 deletions

View File

@ -3037,9 +3037,10 @@ function current_theme_supports( $feature, ...$args ) {
return false;
}
// If no args passed then no extra checks need be performed.
// If no args passed then no extra checks need to be performed.
if ( ! $args ) {
return true;
/** This filter is documented in wp-includes/theme.php */
return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[ $feature ] ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
}
switch ( $feature ) {

View File

@ -167,6 +167,17 @@ class Tests_Theme_Support extends WP_UnitTestCase {
$this->assertFalse( current_theme_supports( 'foobar', 'bar' ) );
}
/**
* @ticket 55219
*/
public function test_plugin_hook_with_no_args() {
add_theme_support( 'foobar' );
add_filter( 'current_theme_supports-foobar', '__return_false' );
$this->assertFalse( current_theme_supports( 'foobar' ) );
}
/**
* @ticket 26900
*/