From 558578b7ef8ec7d5574481e86d9e86aeb033e457 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Tue, 6 Jun 2023 20:39:03 +0530 Subject: [PATCH 01/14] Update legacy theme styles to add responsiveness to featured images --- templates/style.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/templates/style.php b/templates/style.php index 7ebf9f21314..0b2f110e26c 100644 --- a/templates/style.php +++ b/templates/style.php @@ -279,6 +279,11 @@ .amp-wp-article-featured-image { margin: 0 0 1em; } +.amp-wp-article-featured-image img { + max-width: 100%; + height: auto; + margin: 0 auto; +} .amp-wp-article-featured-image amp-img { margin: 0 auto; } From 2b2b9c337a34f34c289085612faea91960d7ed43 Mon Sep 17 00:00:00 2001 From: Lovekesh Kumar Date: Thu, 6 Jul 2023 21:03:34 +0530 Subject: [PATCH 02/14] Update legacy theme featured image style Co-authored-by: Weston Ruter --- templates/style.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/style.php b/templates/style.php index 0b2f110e26c..abfb293eea8 100644 --- a/templates/style.php +++ b/templates/style.php @@ -279,7 +279,7 @@ .amp-wp-article-featured-image { margin: 0 0 1em; } -.amp-wp-article-featured-image img { +.amp-wp-article-featured-image img:not(amp-img) { max-width: 100%; height: auto; margin: 0 auto; From d62b5c28d2815b53d8bc6795479235c1fc6babc8 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 6 Jul 2023 21:13:40 +0530 Subject: [PATCH 03/14] Fix maridb container init in GH workflows --- .github/workflows/build-test-measure.yml | 18 ++++++++++-------- bin/ci/install-wp-tests.sh | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-test-measure.yml b/.github/workflows/build-test-measure.yml index c4d49a96ac8..aa4ea18f75f 100644 --- a/.github/workflows/build-test-measure.yml +++ b/.github/workflows/build-test-measure.yml @@ -362,12 +362,13 @@ jobs: mysql: image: mariadb:latest env: - MYSQL_ALLOW_EMPTY_PASSWORD: true - MYSQL_ROOT_PASSWORD: - MYSQL_DATABASE: wordpress_test + MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true + MARIADB_DATABASE: wordpress_test + MARIADB_MYSQL_LOCALHOST_USER: 1 + MARIADB_MYSQL_LOCALHOST_GRANTS: USAGE ports: - 3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + options: --health-cmd="healthcheck.sh --su-mysql --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3 continue-on-error: ${{ matrix.experimental == true }} strategy: fail-fast: false @@ -606,12 +607,13 @@ jobs: mysql: image: mariadb:latest env: - MYSQL_ALLOW_EMPTY_PASSWORD: true - MYSQL_ROOT_PASSWORD: - MYSQL_DATABASE: wordpress_test + MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true + MARIADB_DATABASE: wordpress_test + MARIADB_MYSQL_LOCALHOST_USER: 1 + MARIADB_MYSQL_LOCALHOST_GRANTS: USAGE ports: - 3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + options: --health-cmd="healthcheck.sh --su-mysql --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3 continue-on-error: ${{ matrix.experimental == true }} strategy: fail-fast: false diff --git a/bin/ci/install-wp-tests.sh b/bin/ci/install-wp-tests.sh index eb1ef5c6584..08a4c234c98 100755 --- a/bin/ci/install-wp-tests.sh +++ b/bin/ci/install-wp-tests.sh @@ -135,7 +135,8 @@ install_db() { fi # create database - mysqladmin create "$DB_NAME" --user="$DB_USER" --password="$DB_PASS""$EXTRA" + mariadb-admin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA || \ + mysqladmin create "$DB_NAME" --user="$DB_USER" --password="$DB_PASS"$EXTRA } install_wp From 2b21baa19b6b5f1905a5091f765dec6b2e79275c Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 6 Jul 2023 21:32:27 +0530 Subject: [PATCH 04/14] Decouple composer normalize from phpcs job --- .github/workflows/build-test-measure.yml | 39 ++++++++++++++++++------ 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-test-measure.yml b/.github/workflows/build-test-measure.yml index aa4ea18f75f..b3c8cd69068 100644 --- a/.github/workflows/build-test-measure.yml +++ b/.github/workflows/build-test-measure.yml @@ -156,6 +156,36 @@ jobs: repo-token: '${{ secrets.GITHUB_TOKEN }}' report-json: 'lint-js-report.json' +#----------------------------------------------------------------------------------------------------------------------- + + normalize-composer: + name: 'Normalize composer.json' + needs: pre-run + if: needs.pre-run.outputs.changed-php-count > 0 || needs.pre-run.outputs.changed-gha-workflow-count > 0 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' + coverage: none + + - name: Get composer-normalize.phar + run: | + wget https://github.com/ergebnis/composer-normalize/releases/latest/download/composer-normalize.phar + chmod +x composer-normalize.phar + + - name: Validate composer.json + run: composer --no-interaction validate --no-check-all + + - name: Normalize composer.json + run: | + composer config --no-interaction --no-plugins allow-plugins.ergebnis/composer-normalize true + ./composer-normalize.phar --dry-run + #----------------------------------------------------------------------------------------------------------------------- lint-php: @@ -189,18 +219,9 @@ jobs: - name: Install Composer dependencies run: composer install --prefer-dist --optimize-autoloader --no-progress --no-interaction - - name: Validate composer.json - run: composer --no-interaction validate --no-check-all - - name: Detect coding standard violations (PHPCS) run: vendor/bin/phpcs -q --report=checkstyle --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 | cs2pr --graceful-warnings - - name: Normalize composer.json - run: | - composer config --no-interaction --no-plugins allow-plugins.ergebnis/composer-normalize true - composer require --no-interaction --dev ergebnis/composer-normalize --ignore-platform-reqs - composer --no-interaction normalize --dry-run - #----------------------------------------------------------------------------------------------------------------------- static-analysis-php: From 843fd5580ff25069cfa4c17377a753ba0a0c524f Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 6 Jul 2023 22:03:55 +0530 Subject: [PATCH 05/14] Fix phpstan errors --- includes/embeds/class-amp-core-block-handler.php | 2 ++ includes/embeds/class-amp-tumblr-embed-handler.php | 2 ++ includes/sanitizers/class-amp-style-sanitizer.php | 1 + 3 files changed, 5 insertions(+) diff --git a/includes/embeds/class-amp-core-block-handler.php b/includes/embeds/class-amp-core-block-handler.php index e80b9d9eb8d..6466e660232 100644 --- a/includes/embeds/class-amp-core-block-handler.php +++ b/includes/embeds/class-amp-core-block-handler.php @@ -569,6 +569,7 @@ private function process_text_widgets( Document $dom ) { foreach ( $dom->xpath->query( '//div[ @class = "textwidget" ]' ) as $text_widget ) { // Restore the width/height attributes which were preserved in preserve_widget_text_element_dimensions. foreach ( $dom->xpath->query( sprintf( './/*[ @%s or @%s ]', self::AMP_PRESERVED_WIDTH_ATTRIBUTE_NAME, self::AMP_PRESERVED_HEIGHT_ATTRIBUTE_NAME ), $text_widget ) as $element ) { + /** @var DOMElement $element */ if ( $element->hasAttribute( self::AMP_PRESERVED_WIDTH_ATTRIBUTE_NAME ) ) { $element->setAttribute( Attribute::WIDTH, $element->getAttribute( self::AMP_PRESERVED_WIDTH_ATTRIBUTE_NAME ) ); $element->removeAttribute( self::AMP_PRESERVED_WIDTH_ATTRIBUTE_NAME ); @@ -586,6 +587,7 @@ private function process_text_widgets( Document $dom ) { * responsive so this is built-in. Note also the style rule for .wp-video in amp-default.css. */ foreach ( $dom->xpath->query( './/div[ @class = "wp-video" and @style ]', $text_widget ) as $element ) { + /** @var DOMElement $element */ $element->removeAttribute( 'style' ); } } diff --git a/includes/embeds/class-amp-tumblr-embed-handler.php b/includes/embeds/class-amp-tumblr-embed-handler.php index 73acba07989..4c5ff7ef4a9 100644 --- a/includes/embeds/class-amp-tumblr-embed-handler.php +++ b/includes/embeds/class-amp-tumblr-embed-handler.php @@ -86,6 +86,8 @@ public function sanitize_raw_embeds( Document $dom ) { ); $overflow_element->textContent = __( 'See more', 'amp' ); $amp_element->appendChild( $overflow_element ); + + /** @var DOMElement $placeholder */ $placeholder->setAttribute( Attribute::PLACEHOLDER, '' ); $amp_element->appendChild( $placeholder ); diff --git a/includes/sanitizers/class-amp-style-sanitizer.php b/includes/sanitizers/class-amp-style-sanitizer.php index 01da0d613b0..2f5f0850cab 100644 --- a/includes/sanitizers/class-amp-style-sanitizer.php +++ b/includes/sanitizers/class-amp-style-sanitizer.php @@ -1017,6 +1017,7 @@ public function sanitize() { } } else { foreach ( $styled_elements as $element ) { + /** @var DOMElement $element */ $attr = $element->getAttributeNode( Attribute::STYLE ); if ( $attr && preg_match( '/!\s*important/i', $attr->value ) ) { ValidationExemption::mark_node_as_px_verified( $attr ); From 5b2cf503c1ec9f3d7d14b19fc489ce5c295c5b6f Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 6 Jul 2023 22:34:07 +0530 Subject: [PATCH 06/14] Remove fetchpriority from test markup --- tests/php/test-amp-gallery-embed-handler.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/php/test-amp-gallery-embed-handler.php b/tests/php/test-amp-gallery-embed-handler.php index 1990c24ff87..526a2efdec9 100644 --- a/tests/php/test-amp-gallery-embed-handler.php +++ b/tests/php/test-amp-gallery-embed-handler.php @@ -282,6 +282,9 @@ public function test__conversion( $source, $expected, $use_legacy_mode = false ) // Remove lazy loading attribute. $content = preg_replace( '/\s+loading="lazy"/', '', $content ); + // Remove fetchpriority attribute. + $content = preg_replace( '/\s+fetchpriority="high"/', '', $content ); + $this->assertEquals( $this->normalize( $expected ), $this->normalize( $content ) From 8f619045cf18935510d5c19c045003b66b59becc Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 6 Jul 2023 22:59:37 +0530 Subject: [PATCH 07/14] Update deprecated ` WP_Scripts::print_inline_script` with `WP_Scripts::get_inline_script_tag()` --- tests/php/src/Admin/PolyfillsTest.php | 23 +++++++++++++++++++--- tests/php/src/Editor/EditorSupportTest.php | 13 ++++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/tests/php/src/Admin/PolyfillsTest.php b/tests/php/src/Admin/PolyfillsTest.php index 4035352a51f..e8e5c8fc869 100644 --- a/tests/php/src/Admin/PolyfillsTest.php +++ b/tests/php/src/Admin/PolyfillsTest.php @@ -85,11 +85,11 @@ public function test_registration() { // These should pass in WP < 5.6. $this->assertTrue( wp_script_is( 'lodash', 'registered' ) ); - $this->assertStringContainsString( '_.noConflict();', wp_scripts()->print_inline_script( 'lodash', 'after', false ) ); + $this->assertStringContainsString( '_.noConflict();', self::get_inline_script( 'lodash', 'after' ) ); $this->assertTrue( wp_script_is( 'wp-api-fetch', 'registered' ) ); - $this->assertStringContainsString( 'createRootURLMiddleware', wp_scripts()->print_inline_script( 'wp-api-fetch', 'after', false ) ); - $this->assertStringContainsString( 'createNonceMiddleware', wp_scripts()->print_inline_script( 'wp-api-fetch', 'after', false ) ); + $this->assertStringContainsString( 'createRootURLMiddleware', self::get_inline_script( 'wp-api-fetch', 'after' ) ); + $this->assertStringContainsString( 'createNonceMiddleware', self::get_inline_script( 'wp-api-fetch', 'after' ) ); $this->assertTrue( wp_script_is( 'wp-hooks', 'registered' ) ); $this->assertTrue( wp_script_is( 'wp-i18n', 'registered' ) ); @@ -99,4 +99,21 @@ public function test_registration() { $this->assertTrue( wp_style_is( 'wp-components', 'registered' ) ); } + + /** + * Get inline script. + * + * @param string $handle Script handle. + * @param string $position Script position. + * @param bool $display Whether to display the script. + * + * @return string + */ + public static function get_inline_script( $handle, $position = 'after', $display = false ) { + if ( method_exists( wp_scripts(), 'get_inline_script_tag' ) ) { + return wp_scripts()->get_inline_script_tag( $handle, $position ); + } else { + return wp_scripts()->print_inline_script( $handle, $position, $display ); + } + } } diff --git a/tests/php/src/Editor/EditorSupportTest.php b/tests/php/src/Editor/EditorSupportTest.php index 07a490b5d9b..fcac464d504 100644 --- a/tests/php/src/Editor/EditorSupportTest.php +++ b/tests/php/src/Editor/EditorSupportTest.php @@ -8,6 +8,7 @@ use AmpProject\AmpWP\Infrastructure\Service; use AmpProject\AmpWP\Tests\Helpers\WithBlockEditorSupport; use AmpProject\AmpWP\Tests\TestCase; +use AmpProject\AmpWP\Tests\Admin\PolyfillsTest; /** @coversDefaultClass \AmpProject\AmpWP\Editor\EditorSupport */ final class EditorSupportTest extends TestCase { @@ -71,7 +72,7 @@ public function test_supports_current_screen( $post_type_uses_block_editor, $pos /** @covers ::maybe_show_notice() */ public function test_dont_show_notice_if_no_screen_defined() { $this->instance->maybe_show_notice(); - $this->assertFalse( wp_scripts()->print_inline_script( 'wp-edit-post', 'after', false ) ); + $this->assertFalse( PolyfillsTest::get_inline_script( 'wp-edit-post', 'after' ) ); } /** @covers ::maybe_show_notice() */ @@ -79,7 +80,7 @@ public function test_dont_show_notice_for_unsupported_post_type() { $this->setup_environment( true, false ); $this->instance->maybe_show_notice(); - $this->assertFalse( wp_scripts()->print_inline_script( 'wp-edit-post', 'after', false ) ); + $this->assertFalse( PolyfillsTest::get_inline_script( 'wp-edit-post', 'after' ) ); } /** @covers ::maybe_show_notice() */ @@ -92,11 +93,11 @@ public function test_show_notice_for_supported_post_type() { $this->instance->maybe_show_notice(); if ( $this->instance->is_current_screen_block_editor_for_amp_enabled_post_type() ) { - $this->assertFalse( wp_scripts()->print_inline_script( 'wp-edit-post', 'after', false ) ); + $this->assertFalse( PolyfillsTest::get_inline_script( 'wp-edit-post', 'after' ) ); } else { $this->assertStringContainsString( 'AMP functionality is not available', - wp_scripts()->print_inline_script( 'wp-edit-post', 'after', false ) + PolyfillsTest::get_inline_script( 'wp-edit-post', 'after' ) ); } } @@ -108,7 +109,7 @@ public function test_maybe_show_notice_for_unsupported_user() { $this->instance->maybe_show_notice(); - $this->assertFalse( wp_scripts()->print_inline_script( 'wp-edit-post', 'after', false ) ); + $this->assertFalse( PolyfillsTest::get_inline_script( 'wp-edit-post', 'after' ) ); } /** @covers ::maybe_show_notice() */ @@ -125,7 +126,7 @@ public function test_maybe_show_notice_for_gutenberg_4_9() { wp_set_current_user( self::factory()->user->create( [ 'role' => 'administrator' ] ) ); $this->instance->maybe_show_notice(); - $inline_script = wp_scripts()->print_inline_script( 'wp-edit-post', 'after', false ); + $inline_script = PolyfillsTest::get_inline_script( 'wp-edit-post', 'after' ); $this->assertStringContainsString( 'AMP functionality is not available', $inline_script ); } } From 14e58fb9242db5e6e856ee024629d3e81a1e174a Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 6 Jul 2023 23:12:41 +0530 Subject: [PATCH 08/14] Update `PolyfillsTest::get_inline_script()` --- tests/php/src/Admin/PolyfillsTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/php/src/Admin/PolyfillsTest.php b/tests/php/src/Admin/PolyfillsTest.php index e8e5c8fc869..8fdb9035ba7 100644 --- a/tests/php/src/Admin/PolyfillsTest.php +++ b/tests/php/src/Admin/PolyfillsTest.php @@ -111,7 +111,13 @@ public function test_registration() { */ public static function get_inline_script( $handle, $position = 'after', $display = false ) { if ( method_exists( wp_scripts(), 'get_inline_script_tag' ) ) { - return wp_scripts()->get_inline_script_tag( $handle, $position ); + $script = wp_scripts()->get_inline_script_tag( $handle, $position ); + + if ( ! $script ) { + return false; + } + + return $script; } else { return wp_scripts()->print_inline_script( $handle, $position, $display ); } From d00a23987d813476682bc47ba26cd7094e408237 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Fri, 7 Jul 2023 21:49:08 +0530 Subject: [PATCH 09/14] Remove clamp values from tests as they can be dynamic after new WP releases --- tests/php/src/ReaderThemeSupportFeaturesTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/php/src/ReaderThemeSupportFeaturesTest.php b/tests/php/src/ReaderThemeSupportFeaturesTest.php index cf40846c159..b467cb4cc28 100644 --- a/tests/php/src/ReaderThemeSupportFeaturesTest.php +++ b/tests/php/src/ReaderThemeSupportFeaturesTest.php @@ -483,16 +483,15 @@ public function test_print_theme_support_styles_reader( $is_legacy ) { $this->assertStringContainsString( '', $output ); } From 403af64b63ceca4281b67233ee0b2a02245cc892 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Fri, 7 Jul 2023 21:58:02 +0530 Subject: [PATCH 10/14] Add WP_DEVELOPMENT_MODE to theme in phpunit bootstrap file --- tests/php/bootstrap.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/php/bootstrap.php b/tests/php/bootstrap.php index c3307a4bdda..6544797f06a 100644 --- a/tests/php/bootstrap.php +++ b/tests/php/bootstrap.php @@ -5,6 +5,7 @@ use Yoast\WPTestUtils\WPIntegration; +define( 'WP_DEVELOPMENT_MODE', 'theme' ); define( 'TESTS_PLUGIN_DIR', dirname( dirname( __DIR__ ) ) ); // When run in wp-env context, set the test config file path. From 5247813eaf1efc1c167fdaab1ebe1f5f34f429c7 Mon Sep 17 00:00:00 2001 From: Lovekesh Kumar Date: Fri, 7 Jul 2023 22:23:02 +0530 Subject: [PATCH 11/14] Remove `$display` param from `::get_inline_script()` function Co-authored-by: Weston Ruter --- tests/php/src/Admin/PolyfillsTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/php/src/Admin/PolyfillsTest.php b/tests/php/src/Admin/PolyfillsTest.php index 8fdb9035ba7..d3587ff8f36 100644 --- a/tests/php/src/Admin/PolyfillsTest.php +++ b/tests/php/src/Admin/PolyfillsTest.php @@ -105,11 +105,10 @@ public function test_registration() { * * @param string $handle Script handle. * @param string $position Script position. - * @param bool $display Whether to display the script. * * @return string */ - public static function get_inline_script( $handle, $position = 'after', $display = false ) { + public static function get_inline_script( $handle, $position = 'after' ) { if ( method_exists( wp_scripts(), 'get_inline_script_tag' ) ) { $script = wp_scripts()->get_inline_script_tag( $handle, $position ); @@ -119,7 +118,7 @@ public static function get_inline_script( $handle, $position = 'after', $display return $script; } else { - return wp_scripts()->print_inline_script( $handle, $position, $display ); + return wp_scripts()->print_inline_script( $handle, $position, false ); } } } From e65ef3685c3a73726da500282ceb4d6fd67b283b Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Fri, 7 Jul 2023 22:55:24 +0530 Subject: [PATCH 12/14] Revert "Add WP_DEVELOPMENT_MODE to theme in phpunit bootstrap file" This reverts commit 403af64. --- tests/php/bootstrap.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/php/bootstrap.php b/tests/php/bootstrap.php index 6544797f06a..c3307a4bdda 100644 --- a/tests/php/bootstrap.php +++ b/tests/php/bootstrap.php @@ -5,7 +5,6 @@ use Yoast\WPTestUtils\WPIntegration; -define( 'WP_DEVELOPMENT_MODE', 'theme' ); define( 'TESTS_PLUGIN_DIR', dirname( dirname( __DIR__ ) ) ); // When run in wp-env context, set the test config file path. From be8c3fba2110e333b3cd93fb3646c2aa68cdca29 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Fri, 7 Jul 2023 22:59:27 +0530 Subject: [PATCH 13/14] Remove dependency from `wp_theme_has_theme_json()` to check if theme has theme.json file --- src/ReaderThemeSupportFeatures.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ReaderThemeSupportFeatures.php b/src/ReaderThemeSupportFeatures.php index 5f98b1bc3e2..560e7dcdf50 100644 --- a/src/ReaderThemeSupportFeatures.php +++ b/src/ReaderThemeSupportFeatures.php @@ -579,9 +579,10 @@ public function get_relative_luminance_from_hex( $hex ) { * @return bool False if `wp_get_global_settings()` not exists or theme.json not found, true otherwise. */ private function theme_has_theme_json() { - if ( function_exists( 'wp_theme_has_theme_json' ) ) { - return wp_theme_has_theme_json(); - } + // @TODO: Uncomment this once `wp_theme_has_theme_json()` caching is fixed. + // if ( function_exists( 'wp_theme_has_theme_json' ) ) { + // return wp_theme_has_theme_json(); + // } static $theme_has_support = null; @@ -605,14 +606,21 @@ private function theme_has_theme_json() { return $theme_has_support; } - // Does the theme have its own theme.json? - $theme_has_support = is_readable( get_stylesheet_directory() . '/theme.json' ); + $stylesheet_directory = get_stylesheet_directory(); + $template_directory = get_template_directory(); - // Look up the parent if the child does not have a theme.json. - if ( ! $theme_has_support ) { - $theme_has_support = is_readable( get_template_directory() . '/theme.json' ); + // This is the same as get_theme_file_path(), which isn't available in load-styles.php context. + if ( $stylesheet_directory !== $template_directory && file_exists( $stylesheet_directory . '/theme.json' ) ) { + $path = $stylesheet_directory . '/theme.json'; + } else { + $path = $template_directory . '/theme.json'; } + /** This filter is documented in wp-includes/link-template.php */ + $path = apply_filters( 'theme_file_path', $path, 'theme.json' ); + + $theme_has_support = file_exists( $path ); + return $theme_has_support; } From 892fa935cf99e8fabeb197a1edfb75b13e1fb30f Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 7 Jul 2023 12:38:27 -0700 Subject: [PATCH 14/14] Update theme_has_theme_json to match core-patched version --- src/ReaderThemeSupportFeatures.php | 37 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/ReaderThemeSupportFeatures.php b/src/ReaderThemeSupportFeatures.php index 560e7dcdf50..ca004360e3e 100644 --- a/src/ReaderThemeSupportFeatures.php +++ b/src/ReaderThemeSupportFeatures.php @@ -584,31 +584,32 @@ private function theme_has_theme_json() { // return wp_theme_has_theme_json(); // } - static $theme_has_support = null; + static $theme_has_support = null; + static $prev_stylesheet_directory = null; + static $prev_template_directory = null; + + $stylesheet_directory = get_stylesheet_directory(); + $template_directory = get_template_directory(); + + // Make sure that the cached $theme_has_support value is reset when the theme changes. + if ( null !== $theme_has_support && ( + $stylesheet_directory !== $prev_stylesheet_directory || + $template_directory !== $prev_template_directory + ) ) { + $theme_has_support = null; + } + $prev_stylesheet_directory = $stylesheet_directory; + $prev_template_directory = $template_directory; if ( null !== $theme_has_support && - - /* - * Ignore static cache when `WP_DEBUG` is enabled. Why? To avoid interfering with - * the theme developer's workflow. - * - * @todo Replace `WP_DEBUG` once an "in development mode" check is available in Core. - */ - ! ( defined( 'WP_DEBUG' ) && WP_DEBUG ) && - - /* - * Ignore cache when automated test suites are running. Why? To ensure - * the static cache is reset between each test. - */ - ! ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) + // Ignore static cache when the development mode is set to 'theme', to avoid interfering with + // the theme developer's workflow. + ( function_exists( 'wp_get_development_mode' ) && wp_get_development_mode() !== 'theme' ) ) { return $theme_has_support; } - $stylesheet_directory = get_stylesheet_directory(); - $template_directory = get_template_directory(); - // This is the same as get_theme_file_path(), which isn't available in load-styles.php context. if ( $stylesheet_directory !== $template_directory && file_exists( $stylesheet_directory . '/theme.json' ) ) { $path = $stylesheet_directory . '/theme.json';