Useful Snippets

Useful Snippets


This blog is used to collect useful snippets related to Linux, PHP, MySQL and more. Feel free to post comments with improvements or questions!

September 2020
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
282930  

Categories


Change WordPress plugin load order

Stanislav KhromovStanislav Khromov

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

PHP

Web Developer at Aftonbladet (Schibsted Media Group)
Any opinions on this blog are my own and do not reflect the views of my employer.
LinkedIn
Twitter
WordPress.org Profile
Visit my other blog

Comments 0
There are currently no comments.