-
-
Notifications
You must be signed in to change notification settings - Fork 522
✨ 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
Draft
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.
+1,154
−0
Draft
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
f8fdd6f
✨ New WordPress.WP.OptionAutoload sniff
rodrigoprimo b47e08a
Apply suggestions from code review
rodrigoprimo 715b43a
Attemp to improve the XML documentation by combining standards
rodrigoprimo 4cf89cf
Fix unintentional coding standard violation in a test case
rodrigoprimo 3ca5d1f
Update some tests to have more function name case variations
rodrigoprimo 5571c8e
Update some tests to have more whitespaces, comments and annotations
rodrigoprimo b11700f
Use `false === isset()` instead of `! isset()` for consistency with t…
rodrigoprimo d86b341
Improve sniff performance by changing the format of some properties
rodrigoprimo 5ca8075
Apply suggestions from code review
rodrigoprimo 86740fb
Remove unused parameter
rodrigoprimo a9a3e8a
Rename test case file to be able to add more test case files with syn…
rodrigoprimo 69cf066
Handle case when $array_token is false + add a test for it
rodrigoprimo a07dbf3
Improve sniff XML doc following suggestions from code review
rodrigoprimo 06b2551
Add link to external blog post about when to use the autoload flag
rodrigoprimo 86c88b8
Add backticks to all function calls in the docblocks
rodrigoprimo b882b8e
Rename property `valid_values_other_functions` to `valid_values_wp_se…
rodrigoprimo 088a645
Explain in the docblock the array properties where all values are `true`
rodrigoprimo 198677d
Ensure all `@param array` tags explain the structure of the array
rodrigoprimo 6e18b20
Only record `param missing` metric when the autoload parameter is opt…
rodrigoprimo 2752fff
Use array union instead of `array_merge()` to create the list of know…
rodrigoprimo 1465df0
Use one error code for fixable internal values and another for non-fi…
rodrigoprimo 1975fcc
Update if condition to explicitly check what is expected and add a te…
rodrigoprimo 3f728aa
Add another test without whitespaces surrounding the parameter to tes…
rodrigoprimo 57237b0
Add a comment explaining why `null` needs special treatment on line 361
rodrigoprimo c7bd613
Explicitly check if $param_second_token is an integer
rodrigoprimo b8f7cf6
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
Some comments aren't visible on the classic Files Changed page.
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