You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 asDOING_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.
There is another very good reason, these function can be linked to hooks such as
wp_doing_cron
orwp_doing_ajax
, which might be set by other plugins.The text was updated successfully, but these errors were encountered: