Add PHP version check for plugin.#149
Conversation
|
@peterwilsoncc looking for review here, thanks! |
peterwilsoncc
left a comment
There was a problem hiding this comment.
The version check works as expected but I've included a couple of notes inline, the main issue is avoiding the potential for syntax errors triggering fatals.
| echo wp_kses_post( | ||
| sprintf( | ||
| /* translators: %s: Minimum required PHP version */ | ||
| __( 'Ads.txt requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'ads-txt' ), | ||
| esc_html( adstxt_minimum_php_requirement() ) | ||
| ) | ||
| ); |
There was a problem hiding this comment.
As the translation doesn't include HTML, the kses call can be avoided by escaping the string.
| echo wp_kses_post( | |
| sprintf( | |
| /* translators: %s: Minimum required PHP version */ | |
| __( 'Ads.txt requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'ads-txt' ), | |
| esc_html( adstxt_minimum_php_requirement() ) | |
| ) | |
| ); | |
| printf( | |
| /* translators: %s: Minimum required PHP version */ | |
| esc_html__( 'Ads.txt requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'ads-txt' ), | |
| esc_html( adstxt_minimum_php_requirement() ) | |
| ); |
|
|
||
| require_once __DIR__ . '/inc/post-type.php'; | ||
| require_once __DIR__ . '/inc/admin.php'; | ||
| require_once __DIR__ . '/inc/save.php'; |
There was a problem hiding this comment.
To avoid an issue similar to 10up/simple-page-ordering#163, the lines below this will need to be moved to a new file and moved to a file within the inc folder.
This will allow for the code to be updated to use modern PHP syntax without throwing a fatal error in older versions of PHP due to a syntax error.
|
@peterwilsoncc Your previous feedback items on this PR have been addressed! Note: Some E2E related jobs were not successful as per https://github.com/10up/ads-txt/actions/runs/7477337138 - do we typically ignore these? CC: @jeffpaul |
| * | ||
| * @return void | ||
| */ | ||
| function tenup_display_ads_txt() { |
There was a problem hiding this comment.
Now that these functions have been moved to a file with a namespace, I'd suggest we remove any namespacing from the function names. This includes any of the tenup_ prefixes and could also remove some of the adstxt ones.
I'd suggest something like the following:
tenup_display_ads_txt->display_ads_txtadd_adstxt_capabilities->add_capabilitiesremove_adstxt_capabilities->remove_capabilitiestenup_ads_txt_add_query_vars->add_query_vars
I have fixed these |

Description of the Change
Add minimum version check for the plugin before loading it. This will ensure plugin update doesn't break the site that don't match our minimum PHP version.
Closes #148
How to test the Change
Changelog Entry
Credits
Props @dkotter, @rahulsprajapati
Checklist: