[wp-trac] [WordPress Trac] #59591: Missing checks for pattern files trigger (invisible) PHP warnings

WordPress Trac noreply at wordpress.org
Wed Oct 11 10:06:40 UTC 2023


#59591: Missing checks for pattern files trigger (invisible) PHP warnings
--------------------------+-----------------------------
 Reporter:  afercia       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  6.4
Component:  Themes        |    Version:  trunk
 Severity:  normal        |   Keywords:  has-screenshots
  Focuses:                |
--------------------------+-----------------------------
 This morning I pulled latest changes onto my local WordPress trunk
 environment.
 Suddenly, all the admin pages showed an unexpected spacing at the top of
 the page. That's because the CSS class `php-error` was added to the body
 element but no actual error or warning is printed out on the page. See
 attached screenshot.

 Turned out
 [https://github.com/WordPress/twentytwentyfour/pull/576/commits/b88e2e23e0706cb85c3780293a75e9242d299ad1
 this commit on Twenty Twenty-Four] which has been included in core renamed
 the pattern file `cta.php` to `text-centered-cta-subscribe.php`

 After manually dumping `$error_get_last` in the `src/wp-admin/admin-
 header.php` I was finally able to see what the PHP warning is about:


 {{{
 array(4) {
   ["type"]=>
   int(2)
   ["message"]=>
   string(144) "include(): Failed opening '/var/www/src/wp-
 content/themes/twentytwentyfour/patterns/cta.php' for inclusion
 (include_path='.:/usr/local/lib/php')"
   ["file"]=>
   string(43) "/var/www/src/wp-includes/block-patterns.php"
   ["line"]=>
   int(355)
 }
 }}}

 Content of the `debug.log` file:


 {{{
 [11-Oct-2023 09:52:22 UTC] PHP Warning:  include(/var/www/src/wp-
 content/themes/twentytwentyfour/patterns/cta.php): failed to open stream:
 No such file or directory in /var/www/src/wp-includes/block-patterns.php
 on line 355
 [11-Oct-2023 09:52:22 UTC] PHP Warning:  include(): Failed opening
 '/var/www/src/wp-content/themes/twentytwentyfour/patterns/cta.php' for
 inclusion (include_path='.:/usr/local/lib/php') in /var/www/src/wp-
 includes/block-patterns.php on line 355
 }}}

 I'm not familiar with this part of the code but it turns out it has to do
 with the pattern files caching mechanism.

 From a quick look, it seems the cache gets cleared when updating a theme
 from the admin UI. However, it seems it does _not_ get cleared when a
 theme gets updated via a different flow. For example:

 - Users can download a new version of the theme in use from the WordPress
 thems directory.
 - The can just unzip the file and uploaded the new theme files via FTP.
 - This is a legitimate scenario and it has been supported since ages.
 - If the theme new version renamed some pattern files, the PHP warning
 will be triggered.
 - If the theme new version _added_ new pattern files, I have no idea what
 would happen. I'm not sure there is something in place to actually read
 the `patterns` directory and check for new files.
 - If the theme new version _deleted_ some pattern files, I have no idea
 what would happen.

 I'm not sure these scenarios have been considered and actually _tested_
 when the caching mechanism has been implemented.

 There could be more scenarios where the theme pattern files get renamed /
 added / deleted that haven't been taken into consideration.

 Since the new release is very close, I'd think it's important to double
 check all possible, legitimate, scenarios and prevent any PHP warning and
 the like

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59591>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list