#59758 closed defect (bug) (fixed)
Update Theme via CLI ignores Requires PHP Constraint
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.5 | Priority: | normal |
Severity: | normal | Version: | 6.4 |
Component: | Upgrade/Install | Keywords: | has-patch add-to-field-guide |
Focuses: | Cc: |
Description
As described in the Theme Handbook Main Stylesheet (style.css) Explanations the Requires PHP
line defines
The oldest PHP version supported, in X.X format, only the number
In the WordPress Web UI (/wp-admin
), you are prevented from updating to a newer version of the theme if your server does not meet this requirement (in the Themes page, Update is unavailable and in the general Updates page, the update fails).
However, updating the theme via WP CLI does allow updating a theme to a version even if the theme requires a version of PHP that exceeds the requirement.
Reproduction Steps
To test this we will use the Rider Theme from the wordpress.org Themes Repository.
Rider Version | Requires PHP |
---|---|
2.1.0 | 5.6 |
3.0.0 | 8.1 |
- Run WordPress on a server with PHP version
8.0
- e.g. if you are using the WordPress development repo, change the
LOCAL_PHP
value in.env
fromlatest
to8.0-fpm
and restart - you can confirm your PHP version with the WP CLI task
wp --info
and checking thePHP version
in the output, this task can be run on the WordPress development repository withnpm run env:cli -- wp --info
- e.g. if you are using the WordPress development repo, change the
- Install and activate version
2.1.0
of the Rider theme (which Requires PHP5.6
)wp theme install rider --version=2.1.0 --activate
- this task can be run on the WordPress development repo with
npm run env:cli -- wp theme install rider --version=2.1.0 --activate
- this task can be run on the WordPress development repo with
- Update the Rider theme to the latest version (
3.0.0
), which Requires PHP8.1
wp theme update rider
- this task can be run on the WordPress development repo with
npm run env:cli -- wp theme update rider
- this task can be run on the WordPress development repo with
Expected Behavior
The Rider theme is NOT updated because the "Requires PHP" version exceeds the version on the server.
Actual Behavior
The Rider theme is updated to the latest version (3.0.0
), which has a Requires PHP value that exceeds our server.
Related Trac Ticket for Plugins
In #59198 a similar problem with Plugins was addressed.
Does this Fix Belong in WordPress Core?
Since I've only been able to recreate this issue via WP CLI, one might argue the fix for this belongs in WP CLI however since we are checking the "Requires PHP" value in Plugins here in WordPress core (see #59198), I'd argue we should be doing the same for Themes.
Props @afragen for calling out this need in this comment on 59198
Props @h4l9k for helping write up this issue
Attachments (2)
Change History (13)
@
16 months ago
Rider theme version 3.0.0 on server with PHP 8.0 after this update was performed via WP CLI
This ticket was mentioned in PR #5583 on WordPress/wordpress-develop by salcode.
16 months ago
#2
- Keywords has-patch added; needs-patch removed
Add PHP version and WordPress version checks on bulk theme update.
Trac ticket: #59758
This ticket was mentioned in Slack in #core by marybaum. View the logs.
15 months ago
@lakshmananphp commented on PR #5583:
15 months ago
#5
I have tested the patch on PHP 7.4
It works as expected; thanks @salcode
Here are the screenshots of my CLI log.
This is my first time to test a patch, so correct me if I'm wrong.
Without patch
With path
CLI info:
OS: Linux 5.10.47-linuxkit #1 SMP PREEMPT Sat Jul 3 21:50:16 UTC 2021 x86_64 Shell: /bin/bash PHP binary: /usr/local/bin/php PHP version: 7.4.30 php.ini used: MySQL binary: /usr/bin/mysql MySQL version: /usr/bin/mysql Ver 15.1 Distrib 10.5.15-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper SQL modes: WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli WP-CLI vendor dir: phar://wp-cli.phar/vendor WP_CLI phar path: /var/www WP-CLI packages dir: WP-CLI global config: WP-CLI project config: /var/www/wp-cli.yml WP-CLI version: 2.6.0
#6
@
15 months ago
Test Report
Env / Setup:
Theme: TT4
WordPress: 6.4
OS: macOS Sonoma
Localhost: docker wordpress-develop container
Browser: Chrome
Note: I used the Rider theme for testing, mainly checking WP CLI logs.
Setup Steps:
npm run env:cli -- wp theme install rider --version=2.1.0 --activate
Steps to test
Update the rider theme via WP CLI
Apply the patch
Remove the rider theme
Install v2.1.0 again
Update the theme via CLI
Results
Without the patch:
The rider theme got updated to the 3.0 version, which requires PHP 8.1
With the patch:
I got the error "The PHP version on your server is 7.4.30. However, the new theme requires 8.1", and the theme did not get updated.
I've added screenshots on the PR (https://github.com/WordPress/wordpress-develop/pull/5583#issuecomment-1823567981).
Conclusion:
The patch works as expected
This ticket was mentioned in Slack in #core by lakshmananphp. View the logs.
15 months ago
#9
@
14 months ago
- Owner set to jorbin
- Resolution set to fixed
- Status changed from new to closed
In 57252:
14 months ago
#10
Merged in https://core.trac.wordpress.org/changeset/57252
Thanks!
Rider theme version 2.1.0 on server with PHP 8.0