From 0795e0ce097264a30e42857a9cd6bd56511d144e Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 21 Jan 2021 00:00:39 -0800 Subject: [PATCH] Use wp_robots() instead of noindex() in WP 5.7 (#5793) --- includes/amp-post-template-functions.php | 6 +++++- tests/php/test-amp-post-template-functions.php | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/includes/amp-post-template-functions.php b/includes/amp-post-template-functions.php index a60c9775dac..bd714001dc4 100644 --- a/includes/amp-post-template-functions.php +++ b/includes/amp-post-template-functions.php @@ -11,7 +11,11 @@ * @internal */ function amp_post_template_init_hooks() { - add_action( 'amp_post_template_head', 'noindex' ); + if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '5.7', '>=' ) ) { + add_action( 'amp_post_template_head', 'wp_robots' ); + } else { + add_action( 'amp_post_template_head', 'noindex' ); + } add_action( 'amp_post_template_head', 'amp_post_template_add_title' ); add_action( 'amp_post_template_head', 'amp_post_template_add_canonical' ); add_action( 'amp_post_template_head', 'amp_post_template_add_fonts' ); diff --git a/tests/php/test-amp-post-template-functions.php b/tests/php/test-amp-post-template-functions.php index 3643d4f775f..f167d035661 100644 --- a/tests/php/test-amp-post-template-functions.php +++ b/tests/php/test-amp-post-template-functions.php @@ -22,7 +22,11 @@ public function setUp() { /** @covers ::amp_post_template_init_hooks() */ public function test_amp_post_template_init_hooks() { amp_post_template_init_hooks(); - $this->assertSame( 10, has_action( 'amp_post_template_head', 'noindex' ) ); + if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '5.7', '>=' ) ) { + $this->assertSame( 10, has_action( 'amp_post_template_head', 'wp_robots' ) ); + } else { + $this->assertSame( 10, has_action( 'amp_post_template_head', 'noindex' ) ); + } $this->assertSame( 10, has_action( 'amp_post_template_head', 'amp_post_template_add_title' ) ); $this->assertSame( 10, has_action( 'amp_post_template_head', 'amp_post_template_add_canonical' ) ); $this->assertSame( 10, has_action( 'amp_post_template_head', 'amp_post_template_add_fonts' ) );