Automattic / VIP-Coding-Standards

PHP_CodeSniffer ruleset to enforce WordPress VIP coding standards.
https://wpvip.com/documentation/how-to-install-php-code-sniffer-for-wordpress-com-vip/
Other
237 stars 40 forks source link

End restricting usage of `term_exists()` #720

Closed Chouby closed 9 months ago

Chouby commented 2 years ago

What problem would the enhancement address for VIP?

Since WP 6.0.0, term_exists() uses get_terms() internally`. See https://core.trac.wordpress.org/ticket/36949. This means that reporting this function as not being cached is not true anymore.

Describe the solution you'd like

WordPressVIPMinimum coding standards could stop reporting terms_exists() as a restricted function.

GaryJones commented 2 years ago

Hi @Chouby - good catch!

Looking at the code here, VIPCS does mark the term_exists() function usage as an PHPCS Error.

We still have some VIP customers using WP < 6.0, so we wouldn't be able to remove the code entirely just yet, but we can certainly update the messaging to be more accurate, and/or use the MinimumWPVersionTrait from WPCS to adjust the violation accordingly.

Rough idea:

Adding the use trait statement to the class, and then adding to here, something like:

$this->get_wp_version_from_cli( $this->phpcsFile );

if ( version_compare( $this->minimum_supported_version, '6.0', '<' ) ) {
    unset( $groups['term_exists'] );
}

With the idea that if the minimum supported version (currently 5.1 by default) is below 6.0, then we still report about term_exists() usage.

benlk commented 6 months ago

It's good to see that this has been fixed in the upstream VIP PHPCS rules. How long until @wpcomvip-vipgoci-bot starts using the updated standards? It flagged a bunch of term_exists calls in a PR just today.

GaryJones commented 6 months ago

https://github.com/Automattic/vip-go-ci/releases/tag/1.3.12 includes an update to use VIPCS 3.0.1, which is the version which incorporates #812.

This was made available on customer repositories yesterday.

If you're finding it's still getting flagged, please open a support ticket with VIP, so we can look at your specific code and the feedback on your private repo.