Skip to content
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

Create a sniff to ensure update_option sets autoload explicitly #74

Open
moorscode opened this issue Mar 30, 2018 · 3 comments
Open

Create a sniff to ensure update_option sets autoload explicitly #74

moorscode opened this issue Mar 30, 2018 · 3 comments

Comments

@moorscode
Copy link
Contributor

As the autoload setting has been added in a later state, the argument is not required.
Though this is a setting that should be set explicitly, as it impacts performance and memory.

@jrfnl
Copy link
Collaborator

jrfnl commented Mar 30, 2018

As the autoload setting has been added in a later state, the argument is not required.

Not sure if that's the reason. The autoload setting has always been optional for add_option() and AFAIK, has been available since the beginning, so I suspect it's more a consistency thing.

Implementation notes:

  • This should be checked for both update_option() as well as add_option().
  • WPCS contains an abstract function parameter sniff which can (should) be used as a basis.

Note: using update_option() you can change the autoload which was added when the option was created, but only when changing the value at the same time.
So if update_option() is used for adding new options: great.
If update_option() is used to actually update an existing option, it a) may not have any effect if the option already exists and b) is basically superfluous.

So some careful thought is needed about what should actually be checked for and whether this should be a warning or an error.

@moorscode
Copy link
Contributor Author

Shouldn't this just be a sniff in the WordPress Coding Standards?

@jrfnl
Copy link
Collaborator

jrfnl commented Jun 22, 2018

@moorscode I'd certainly suggest opening an issue about it for WPCS (if one doesn't exist yet). Let's see how people respond.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants