[wp-trac] [WordPress Trac] #53395: Cannot use wp_is_mobile() in Network activated plugins

WordPress Trac noreply at wordpress.org
Mon Jun 14 16:53:14 UTC 2021


#53395: Cannot use wp_is_mobile() in Network activated plugins
--------------------------+------------------------------
 Reporter:  promz         |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Plugins       |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  multisite
--------------------------+------------------------------
Changes (by SergeyBiryukov):

 * focuses:   => multisite
 * component:  General => Plugins


Comment:

 Hi there, welcome back to WordPress Trac! Thanks for the report.

 `wp_is_mobile()` is located in `wp-includes/vars.php`, which is indeed
 [source:tags/5.7.2/src/wp-settings.php?marks=371#L363 loaded later than
 most other PHP files] in `wp-settings.php`.

 That said, it is considered a best practice in WordPress not to run any
 code directly on plugin inclusion, as the environment is not fully
 initialized yet, and run on the appropriate action instead, e.g.
 `plugins_loaded` or `init`.

 Moving the `wp_is_mobile()` call to a function or method that runs on a
 specific action should resolve the issue here.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53395#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list