-
-
Notifications
You must be signed in to change notification settings - Fork 510
✨ New WordPress.WP.OptionAutoload sniff #2520
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
Open
rodrigoprimo
wants to merge
26
commits into
WordPress:develop
Choose a base branch
from
rodrigoprimo:new-option-autoload
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
fb40a73
✨ New WordPress.WP.OptionAutoload sniff
rodrigoprimo f9f2b95
Apply suggestions from code review
rodrigoprimo f18b9ed
Attemp to improve the XML documentation by combining standards
rodrigoprimo 18c8a31
Fix unintentional coding standard violation in a test case
rodrigoprimo 1b5b8bf
Update some tests to have more function name case variations
rodrigoprimo 5ac7e1c
Update some tests to have more whitespaces, comments and annotations
rodrigoprimo d5ec3a2
Use `false === isset()` instead of `! isset()` for consistency with t…
rodrigoprimo a777a97
Improve sniff performance by changing the format of some properties
rodrigoprimo 39524bc
Apply suggestions from code review
rodrigoprimo 62532db
Remove unused parameter
rodrigoprimo 60a85c9
Rename test case file to be able to add more test case files with syn…
rodrigoprimo c8bee3d
Handle case when $array_token is false + add a test for it
rodrigoprimo f506c0b
Improve sniff XML doc following suggestions from code review
rodrigoprimo 5b58aba
Add link to external blog post about when to use the autoload flag
rodrigoprimo e85d37f
Add backticks to all function calls in the docblocks
rodrigoprimo d6dbd92
Rename property `valid_values_other_functions` to `valid_values_wp_se…
rodrigoprimo c17ed01
Explain in the docblock the array properties where all values are `true`
rodrigoprimo 21a5350
Ensure all `@param array` tags explain the structure of the array
rodrigoprimo 325f3ba
Only record `param missing` metric when the autoload parameter is opt…
rodrigoprimo 4944d88
Use array union instead of `array_merge()` to create the list of know…
rodrigoprimo 2b48e41
Use one error code for fixable internal values and another for non-fi…
rodrigoprimo 4c7b209
Update if condition to explicitly check what is expected and add a te…
rodrigoprimo 2a5815a
Add another test without whitespaces surrounding the parameter to tes…
rodrigoprimo 6c930ea
Add a comment explaining why `null` needs special treatment on line 361
rodrigoprimo 4c7d770
Explicitly check if $param_second_token is an integer
rodrigoprimo e13b23b
Move the third block of the documentation up as suggestion during cod…
rodrigoprimo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?xml version="1.0"?> | ||
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd" | ||
title="Option Autoload" | ||
> | ||
<standard> | ||
<![CDATA[ | ||
When using `add_option()`, `update_option()`, `wp_set_options_autoload()`, | ||
`wp_set_option_autoload()`, or `wp_set_option_autoload_values()`, it is recommended to | ||
explicitly set the autoload parameter to ensure predictable behavior. | ||
The autoload flag determines whether the option is automatically loaded on every page load, | ||
which can impact site performance. | ||
]]> | ||
</standard> | ||
<standard> | ||
<![CDATA[ | ||
Even though the autoload parameter is optional for `add_option()` and `update_option()`, it is | ||
strongly recommended to always explicitly set it. | ||
]]> | ||
</standard> | ||
<code_comparison> | ||
<code title="Valid: Explicitly setting the autoload parameter."> | ||
<![CDATA[ | ||
add_option( | ||
'my_option', | ||
'value', | ||
'', | ||
<em>true</em> | ||
); | ||
]]> | ||
</code> | ||
<code title="Invalid: Autoload parameter missing."> | ||
<![CDATA[ | ||
add_option( | ||
'my_option', | ||
'value', | ||
'' | ||
); | ||
]]> | ||
</code> | ||
</code_comparison> | ||
<standard> | ||
<![CDATA[ | ||
The following values should be used when setting the autoload parameter depending on the function: | ||
|
||
- For `add_option()` and `update_option()`: `true`, `false`, or `null`. | ||
- For `wp_set_option_autoload_values()`, `wp_set_option_autoload()`, and | ||
`wp_set_options_autoload()`: `true` or `false`. | ||
|
||
Using 'yes' or 'no' is deprecated since WordPress 6.6.0. Plugin/theme code should also not use | ||
values for the parameter which are for WP core internal use only. | ||
|
||
Any other values, including `null` for functions other than `add_option()` and `update_option()`, | ||
are invalid. | ||
]]> | ||
</standard> | ||
<code_comparison> | ||
<code title="Valid: Using a boolean value or `null`"> | ||
<![CDATA[ | ||
wp_set_options_autoload( | ||
array('option1', 'option2'), | ||
<em>true</em> | ||
); | ||
|
||
update_option( | ||
'my_option', | ||
'value', | ||
<em>null</em> | ||
); | ||
]]> | ||
</code> | ||
<code title="Invalid: Using deprecated, internal-only, or invalid values"> | ||
<![CDATA[ | ||
add_option( | ||
'my_option', | ||
'value', | ||
'', | ||
<em>'yes'</em> | ||
); | ||
|
||
wp_set_option_autoload( | ||
'my_option', | ||
<em>null</em> | ||
); | ||
|
||
wp_set_option_autoload_values( | ||
array( | ||
'option1' => <em>'auto-on'</em>, | ||
'option2' => <em>'off'</em> | ||
) | ||
); | ||
|
||
wp_set_options_autoload( | ||
array('option1', 'option2'), | ||
<em>1</em> | ||
); | ||
]]> | ||
</code> | ||
</code_comparison> | ||
</documentation> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the valid example have an example from both function groups ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done