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

Use WP core functions to check globals (WP_ADMIN, DOING...) #747

Closed
herrvigg opened this issue Oct 20, 2019 · 1 comment
Closed

Use WP core functions to check globals (WP_ADMIN, DOING...) #747

herrvigg opened this issue Oct 20, 2019 · 1 comment
Labels
core Core functionalities, including the admin section

Comments

@herrvigg
Copy link
Collaborator

Reading directly the global WP defines such as WP_ADMIN, DOING_AJAX, DOING_CRON is a bad practice. Many checks are done just by looking if the global is defined. In theory a variable such as DOING_AJAX could be defined but set to false, which would have many undesired effects. In practice, it should not be the case because it's properly defined in WP. But this might be overridden in a nasty way in the code.

In any case, we should rather use the appropriate WP functions instead.

* WP_ADMIN -> is_admin()
* DOING_AJAX -> wp_doing_ajax() # from WP 4.7
* DOING_CRON -> wp_doing_cron() # from WP 4.8
* WP_CLI -> no function but we should check the value properly

There is another very good reason, these function can be linked to hooks such as wp_doing_cron or wp_doing_ajax, which might be set by other plugins.

@herrvigg
Copy link
Collaborator Author

Released in 3.7.1.

@herrvigg herrvigg added the core Core functionalities, including the admin section label Nov 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core functionalities, including the admin section
Projects
None yet
Development

No branches or pull requests

1 participant