Title: The Order of Things
Author: Ipstenu (Mika Epstein)
Published: September 12, 2013

---

 [  ](https://profiles.wordpress.org/ipstenu/) [Ipstenu (Mika Epstein)](https://profiles.wordpress.org/ipstenu/)
3:12 pm _on_ September 12, 2013      

# The Order of Things

Since WP 3.6.1, you may get odd errors like “Call to undefined function wp_validate_redirect()”
errors in WP Admin where AJAX is used. The error is due to plugins that call `wp_get_referer()`
on init.

While this will be patched more in 3.6.2, today’s quick lesson in ‘Making your plugins
better’ is this simple note:

Doing _anything_ before plugins_loaded or init is a bad idea.

If you find an affected plugin, please feel free to report it here: https://core.
trac.wordpress.org/ticket/25294

### Share this:

 * [  Threads ](https://make.wordpress.org/plugins/2013/09/12/the-order-of-things/?share=threads)
 * [  Mastodon ](https://make.wordpress.org/plugins/2013/09/12/the-order-of-things/?share=mastodon)
 * [  Bluesky ](https://make.wordpress.org/plugins/2013/09/12/the-order-of-things/?share=bluesky)
 * [  X ](https://make.wordpress.org/plugins/2013/09/12/the-order-of-things/?share=x)
 * [  Facebook ](https://make.wordpress.org/plugins/2013/09/12/the-order-of-things/?share=facebook)
 * [  LinkedIn ](https://make.wordpress.org/plugins/2013/09/12/the-order-of-things/?share=linkedin)

 1.  ![](https://secure.gravatar.com/avatar/daa702ad5f6ce304f6f22fc88abd770a52bc3a6e865bf43f279a6537fa2ddd4a?
     s=32&d=mm&r=g)
 2.   [takien](https://profiles.wordpress.org/takien/)  3:24 pm _on_ September 12, 
     2013
 3.  Thanks for this info bro
 4.  ![](https://secure.gravatar.com/avatar/19064ed4f839086c8fd557e5d00c62cdb52cdba868e6bf100a64d8a4f0974aed?
     s=32&d=mm&r=g)
 5.   [Mike Schinkel](https://profiles.wordpress.org/mikeschinkel/)  4:10 pm _on_ September
     12, 2013
 6.  In general [@nacin](https://profiles.wordpress.org/nacin/)‘s advice that the only
     thing a pluginPlugin A plugin is a piece of software containing a group of functions
     that can be added to a WordPress website. They can extend functionality or add
     new features to your WordPress websites. WordPress plugins are written in the 
     PHP programming language and integrate seamlessly with WordPress. These can be
     free in the WordPress.org Plugin Directory [https://wordpress.org/plugins/](https://wordpress.org/plugins/)
     or can be cost-based plugin from a third-party. should be doing on inclusion is`
     add_action()` and `add_filter()` is extremely good advice, but I’m concerned it
     might be taken too literally.
 7.  There are other things that can and should be done when loading files and I’d 
     hate for people who review code for best practices for corporations but who are
     not really experienced with WordPress to add that literally to the list of required
     best practices without including some caveats.
 8.  Here are some caveats I would add to [@nacin](https://profiles.wordpress.org/nacin/)‘
     s advice as being okay to do on plugin inclusion:
 9.   * Capturing `__FILE__` or `__DIR__` into a static variable of a class for later
        use.
 10.  * Calling `spl_autoload_register()`.
 11.  * Pre-parsing of environment variables such as `$_SERVER['REQUEST_URI']` into
        static variables of classes.
 12.  * Defining architectural relationships between classes in a plugin that are beyond
        what PHPPHP PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-
        used open source general-purpose scripting language that is especially suited
        for web development and can be embedded into HTML. [https://www.php.net/manual/en/index.php](https://www.php.net/manual/en/index.php)
        provides at the language level, i.e. defining one class as a mixin to another
        and storing that information in static variables of a class.
 13.  * Possibly other things that are pure PHP/environment and/or that do not have
        an dependencies on the functions or classes in WordPress, depending on use-
        case, of course.
 14.  * ![](https://secure.gravatar.com/avatar/27180c82524020e7339e2b30818b6d8ab004c54f730f12b1434b1e365be0e175?
        s=32&d=mm&r=g)
      *  [Ipstenu (Mika Epstein)](https://profiles.wordpress.org/ipstenu/)  4:42 pm
        _on_ September 12, 2013
      * Thank you for the clarification and thoughts, Mike! 😀 +1
 15. ![](https://secure.gravatar.com/avatar/689ddc4f33541ac4a001d247e560f8805d219a95e7e42a16e0d22b9409f385cb?
     s=32&d=mm&r=g)
 16.  [Andrey "Rarst" Savchenko](https://profiles.wordpress.org/rarst/)  6:54 pm _on_
     September 12, 2013
 17. > The error is due to plugins that call wp_get_referer() on init.
 18. You probably meant on load rather than init?
 19. ![](https://secure.gravatar.com/avatar/cd257f389c91f137dab25f343b527123e887135b01921ebb6206e40cfa2eb636?
     s=32&d=mm&r=g)
 20.  [Knut Sparhell](https://profiles.wordpress.org/knutsp/)  5:05 pm _on_ September
     14, 2013
 21. Maybe more precise: Calling any WordPress functions, except add_action() and add_filter(),
     on pluginPlugin A plugin is a piece of software containing a group of functions
     that can be added to a WordPress website. They can extend functionality or add
     new features to your WordPress websites. WordPress plugins are written in the 
     PHP programming language and integrate seamlessly with WordPress. These can be
     free in the WordPress.org Plugin Directory [https://wordpress.org/plugins/](https://wordpress.org/plugins/)
     or can be cost-based plugin from a third-party. inclusion is a bad idea.
 22.  * ![](https://secure.gravatar.com/avatar/d455228fe4a12d2754c1663abe9d1df7fa699b18762bdebb98ddf39c4e90cc69?
        s=32&d=mm&r=g)
      *  [brasofilo](https://profiles.wordpress.org/brasofilo/)  5:08 am _on_ October
        17, 2013
      * Knut, just to clarify my ignorance, what do you guys refer as “pluginPlugin
        A plugin is a piece of software containing a group of functions that can be
        added to a WordPress website. They can extend functionality or add new features
        to your WordPress websites. WordPress plugins are written in the PHP programming
        language and integrate seamlessly with WordPress. These can be free in the 
        WordPress.org Plugin Directory [https://wordpress.org/plugins/](https://wordpress.org/plugins/)
        or can be cost-based plugin from a third-party. inclusion”? I suppose it’s 
        an activated plugin start up…. Normally, if it’s the case, I call
      *     ```
            if( is_admin() )
                add_action( 'plugins_loaded', 'start_everything' );
            ```
        
      * I also suppose `is_admin()` is not a bad idea, is it?

Comments are closed.

# Post navigation

[← Secure SWFUpload](https://make.wordpress.org/plugins/2013/06/21/secure-swfupload/)

[How to fix the intentionally vulnerable plugin →](https://make.wordpress.org/plugins/2013/11/24/how-to-fix-the-intentionally-vulnerable-plugin/)