From 814424b5fd00b1e28e873ea3efd118478dd795a0 Mon Sep 17 00:00:00 2001 From: Igor Rozum Date: Thu, 6 Aug 2026 20:51:10 -0400 Subject: [PATCH 1/2] Tests: Add coverage for a future is_post_format_archive() conditional tag --- tests/phpunit/includes/abstract-testcase.php | 1 + tests/phpunit/tests/query/conditionals.php | 29 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 98b3456935716..25932ed1cb1eb 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -1186,6 +1186,7 @@ public function assertQueryTrue( ...$prop ) { 'is_month', 'is_page', 'is_paged', + 'is_post_format_archive', 'is_post_type_archive', 'is_posts_page', 'is_preview', diff --git a/tests/phpunit/tests/query/conditionals.php b/tests/phpunit/tests/query/conditionals.php index 4b473178897ae..af5d1be477b92 100644 --- a/tests/phpunit/tests/query/conditionals.php +++ b/tests/phpunit/tests/query/conditionals.php @@ -1598,6 +1598,35 @@ public function test_is_single_should_not_match_numeric_id_to_post_name_beginnin $this->assertFalse( is_single( $p1 ) ); } + /** + * @ticket 23749 + */ + public function test_is_post_format_archive() { + $post_id = self::factory()->post->create(); + set_post_format( $post_id, 'aside' ); + + $this->go_to( '/?post_format=aside' ); + + $this->assertQueryTrue( 'is_archive', 'is_tax', 'is_post_format_archive' ); + $this->assertTrue( is_post_format_archive() ); + $this->assertTrue( is_post_format_archive( 'aside' ) ); + $this->assertTrue( is_post_format_archive( array( 'gallery', 'aside' ) ) ); + $this->assertFalse( is_post_format_archive( 'gallery' ) ); + } + + /** + * @ticket 23749 + */ + public function test_is_post_format_archive_false_outside_a_post_format_archive() { + $post_id = self::factory()->post->create(); + set_post_format( $post_id, 'aside' ); + + $this->go_to( get_permalink( $post_id ) ); + + $this->assertFalse( is_post_format_archive() ); + $this->assertFalse( is_post_format_archive( 'aside' ) ); + } + /** * @ticket 44005 * @group privacy From 4be34b9b707e993c3cec6afa3c8fb4ee70754cc0 Mon Sep 17 00:00:00 2001 From: Igor Rozum Date: Thu, 6 Aug 2026 20:51:10 -0400 Subject: [PATCH 2/2] Query: Add is_post_format_archive() conditional tag --- src/wp-includes/class-wp-query.php | 21 +++++++++++++++++++++ src/wp-includes/query.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index 228691d26d12b..64387e277da0d 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -4408,6 +4408,27 @@ public function is_tax( $taxonomy = '', $term = '' ) { ); } + /** + * Is the query for an existing post format archive page? + * + * @since 7.2.0 + * + * @param string|string[] $post_formats Optional. Post format or array of post formats + * to check against. Default empty. + * @return bool Whether the query is for an existing post format archive page. + */ + public function is_post_format_archive( $post_formats = '' ) { + $prefixed_formats = array(); + + if ( $post_formats ) { + foreach ( (array) $post_formats as $post_format ) { + $prefixed_formats[] = 'post-format-' . sanitize_key( $post_format ); + } + } + + return $this->is_tax( 'post_format', $prefixed_formats ); + } + /** * Determines whether the current URL is within the comments popup window. * diff --git a/src/wp-includes/query.php b/src/wp-includes/query.php index 60571c01cb880..43c2badddb71b 100644 --- a/src/wp-includes/query.php +++ b/src/wp-includes/query.php @@ -345,6 +345,35 @@ function is_tax( $taxonomy = '', $term = '' ) { return $wp_query->is_tax( $taxonomy, $term ); } +/** + * Determines whether the query is for an existing post format archive page. + * + * If the $post_formats parameter is specified, this function will additionally + * check if the query is for one of the post formats specified. + * + * For more information on this and similar theme functions, check out + * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ + * Conditional Tags} article in the Theme Developer Handbook. + * + * @since 7.2.0 + * + * @global WP_Query $wp_query WordPress Query object. + * + * @param string|string[] $post_formats Optional. Post format or array of post formats + * to check against. Default empty. + * @return bool Whether the query is for an existing post format archive page. + */ +function is_post_format_archive( $post_formats = '' ) { + global $wp_query; + + if ( ! isset( $wp_query ) ) { + _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); + return false; + } + + return $wp_query->is_post_format_archive( $post_formats ); +} + /** * Determines whether the query is for an existing date archive. *