WordPress / plugin-check

A repository for the new Plugin Check plugin from the WordPress Performance and Plugins Team.
https://wordpress.org/plugins/plugin-check/
GNU General Public License v2.0
195 stars 39 forks source link

Run checks in the context of the minimum WP version supported by a plugin #384

Closed dd32 closed 5 months ago

dd32 commented 5 months ago

Some PHPCS rules are WordPress version dependent, only being triggered for older (or newer) versions of WordPress.

One such rule is this, which is triggered unless the minimum wp is set to 6.2:

LINE  84: ERROR Unsupported placeholder used in $wpdb->prepare(). Found: "%i".
                (WordPress.DB.PreparedSQLPlaceholders.UnsupportedPlaceholder)
>>  84:  ········$count·=·$wpdb->get_var($wpdb->prepare("SELECT·COUNT(*)·FROM·%i",·$table_name));

WPCS allows setting the minimum required WP version, which this PR implements https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#setting-minimum-supported-wp-version-from-the-command-line-wordpresscs-0140

I've not added a unit test for this, as I wasn't immediately able to figure out how to do so, but this PR works in my initial testing.

joemcgill commented 5 months ago

Thanks @dd32. This does seem like something the Plugin Check plugin should account for. It would be great to get some tests added for this functionality if you have time.

Additionally, it seems this issue currently effects the current version of the plugin published to the .org repo, which is currently in the legacy-plugin branch of the repo, so applying a similar change there may be needed until https://github.com/WordPress/plugin-check/issues/283 is resolved and version 1.0.0 can be released.

dd32 commented 5 months ago

It would be great to get some tests added for this functionality if you have time.

Feel free to add them, as I said, I couldn't figure out how to in the overcomplicated abstractions.

Additionally, it seems this issue currently effects the current version of the plugin published to the .org repo, which is currently in the legacy-plugin branch of the repo, so applying a similar change there may be needed until https://github.com/WordPress/plugin-check/issues/283 is resolved and version 1.0.0 can be released.

Probably, but I don't think that's a priority, since AFAIK the legacy version should be abandoned in its entirety based on how things have been moving