Change WordPress plugin load order

IMPORTANT NOTE
Changing the plugin load order should only be done as a last-ditch effort. If you want to interface with other plugins, it can most often be solved by hooking on plugins_loaded before running your code. That will make sure that all plugins have been loaded before your code is executed.

This snippet will reorder the plugin load list to load your plugin first.

add_action( 'activated_plugin', 'my_plugin_load_first' );
function my_plugin_load_first()
{
    $path = str_replace( WP_PLUGIN_DIR . '/', '', __FILE__ );
    if ( $plugins = get_option( 'active_plugins' ) ) {
        if ( $key = array_search( $path, $plugins ) ) {
            array_splice( $plugins, $key, 1 );
            array_unshift( $plugins, $path );
            update_option( 'active_plugins', $plugins );
        }
    }
}

Full article here

Leave a Reply

Your email address will not be published. Required fields are marked *

Markdown is allowed in comments.