Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a check to ensure we have a valid PHP version before loading plugin functionality and output an admin notice f needed #135

Merged
merged 5 commits into from
Sep 19, 2023

Conversation

kmgalanakis
Copy link
Contributor

Description of the Change

In this PR, I'm adding a check for the minimum required PHP version before attempting to load the plugin files. If the condition is not met an admin notice is displayed and the plugin files are not loaded.

Closes #129

How to test the Change

  • To see the admin notice and have the plugin functionality not loaded, try to load the plugin on a site with PHP version lower that 7.4.

Changelog Entry

Added - Check for minimum required PHP version before loading the plugin

Credits

Props @kmgalanakis

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@kmgalanakis kmgalanakis requested a review from a team as a code owner August 14, 2023 07:03
@kmgalanakis kmgalanakis self-assigned this Aug 14, 2023
@kmgalanakis kmgalanakis requested review from peterwilsoncc and removed request for a team August 14, 2023 07:03
@kmgalanakis kmgalanakis mentioned this pull request Aug 14, 2023
@kmgalanakis kmgalanakis force-pushed the feature/add-php-checks branch 3 times, most recently from bb38784 to 5ea47da Compare August 14, 2023 07:54
@jeffpaul jeffpaul added this to the 1.2.0 milestone Aug 14, 2023
…in functionality and output an admin notice if needed
Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of notes about keeping the main file compatible with PHP 5.6 as the plugin supports WP 5.7 and later.

In the linting workflow it would be good to add some compatibility checks:

  • for the entire plugin, check that it's compatible with PHP 7.4 and later
  • for the main file only, check that it's compatible with PHP 5.6 and later

<?php
echo wp_kses_post(
sprintf(
/* translators: %s: Minimum required PHP version */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alignment nit: one extra tab to align with line below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*
* @return string Minimum version required.
*/
function minimum_php_requirement(): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function minimum_php_requirement(): string {
function minimum_php_requirement() {

This is to keep the file compatible with PHP 5.6 (as it supports versions of WP prior to 6.3)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(sorry, wrong profile)

*
* @return bool True if meets minimum requirements, false otherwise.
*/
function site_meets_php_requirements(): bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function site_meets_php_requirements(): bool {
function site_meets_php_requirements() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(sorry, wrong profile)

@dkotter
Copy link
Collaborator

dkotter commented Sep 11, 2023

A couple of notes about keeping the main file compatible with PHP 5.6 as the plugin supports WP 5.7 and later.

@peterwilsoncc Curious on your reasoning for this? I get that we support WordPress 5.7+ which itself supports PHP 5.6+ but we're also saying we only support PHP 7.4+. While I can see this may be looked at as a conflict (how can we truly claim to support WP 5.7 if we don't support PHP 5.6) I'm personally fine with us pushing users to new PHP versions even if they're running older WP versions.

Is there worry that someone may be running PHP 5.6 and also be running this plugin, even though the plugin only supports PHP 7.4+? I guess to me feels like extra work to try and ensure the main plugin file always stays PHP 5.6 compatible for what is hopefully an edge case (someone running PHP 5.6 that happens to be able to bypass WordPress' update/install requirements and ends up with this plugin installed)

@peterwilsoncc
Copy link
Contributor

@dkotter There are two main reasons:

  1. If the main file isn't compatible with the older versions of PHP, then the site may fatal before it's shown, in which case including the check seems a little pointless.
  2. There's a bug in WP in which the bulk updates screen doesn't check the PHP Compatibility header in the plugin, see WordPress#59198 so it's possible someone running an older version of WP can upgrade the plugin even though they shouldn't be.

I agree it's an edge case but as it's relatively trivial to protect against I think it's a good idea to do so.

@github-actions github-actions bot added the needs:code-review This requires code review. label Sep 15, 2023
@kmgalanakis-sage
Copy link

Good point @dkotter, thank you for your feedback

@jeffpaul
Copy link
Member

@peterwilsoncc back to you for review/testing

@jeffpaul jeffpaul removed their request for review September 18, 2023 13:17
Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGM and passed manual testing on different versions of PHP

@peterwilsoncc peterwilsoncc merged commit 45d06c3 into develop Sep 19, 2023
10 checks passed
@peterwilsoncc peterwilsoncc deleted the feature/add-php-checks branch September 19, 2023 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs:code-review This requires code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add PHP checks
5 participants