Priority -1000 for WordPress Hooks, Actions and Filters

I recently came across some code which set the priority parameter for an add_action() call to -1000.

I’d never seen a negative number, or such a large number used for a WordPress action or filter’s priority. Turns out, it’s actually necessary to use such a value to run a callback before anything else. Which is essential to translate a plugin’s description on the manage plugins page.

Here’s the offending snippet I received as a patch to the Social Connect plugin:

 function sc_social_connect_l10n() {
 $plugin_dir = basename( dirname( __FILE__ ) );
 load_plugin_textdomain( 'social_connect', null, "$plugin_dir/languages" );
 add_action( 'init', 'sc_social_connect_l10n', -1000 );

I was a little wary of such a priority value because a Google on the subject turned up nothing. Having spoken to a few other WordPress developers, it seems to be perfectly legitimate, so I hope this post will put others with concerns at ease.

About Brent

Born to code.
This entry was posted in Blogdex, WordPress and tagged , , , . Bookmark the permalink.

2 Responses to Priority -1000 for WordPress Hooks, Actions and Filters

  1. scribu says:

    Or they could just use the ‘plugins_loaded’ hook with the default priority (10).

  2. Artprima says:

    Thanks for sharing this info. Just needed to use it in my plugin.

Comments are closed.