Automattic / Automattic/VIP-Coding-Standards
Make suggestion when autoload resolves to true
- Dominant language
- PHP
- Stars
- 261
- Forks
- 44
- Avg merge
- 19m
- Merged PRs (30d)
- 1
Description
## What problem would the enhancement address for VIP?
Options get marked as autoload=yes when being added, unless there is an explicit setting to no.
For VIP clients, we should flag when it is yes, to remind and encourage developers to consider whether it should be autoload=no, which can help with performance.
## Describe the solution you'd like
PHPCS Warning when `'yes'` or `true` is supplied or implied when calling `add_option()` or `update_option()`.
## What code should be reported as a violation?
```
add_option( 'my_option', 'my_value', '', 'yes' );
add_option( 'my_option', 'my_value', '', true ); // Can be 'yes' string or boolean.
add_option( 'my_option', 'my_value', '' );
add_option( 'my_option', 'my_value' );
add_option( 'my_option' );
update_option( 'my_option', 'my_value', 'yes' );
update_option( 'my_option', 'my_value', true ); // Can be 'yes' string or boolean.
```
## What code should *not* be reported as a violation?
```
add_option( 'my_option', 'my_value', '', 'no' );
add_option( 'my_option', 'my_value', '', false );
update_option( 'my_option', 'my_value', 'no' );
update_option( 'my_option', 'my_value', false );
```
## Additional context
Some items may indeed be valid to be autoloaded, so it's not an Error in all cases.
This may seem like a bit of noise for some cases, but I think it counts as a good reminder. We can link the error message to [our public docs about autoloading](https://wpvip.com/documentation/vip-go/working-with-wp_options/#autoloading).
Contributor guide
Assessment
This issue has not been assessed yet.