override pluggable.php functions

The short answer to your question is yes; however, the methods to do this are a little bit hacky and generally I would recommend against all of them unless absolutely necessary.

Since pluggable functions actually replace the stock function by way of function_exists() whichever plugin that “plugs” the function first will win. What you want to do is ensure your plugin loads first globally.

Plugins are loaded according to their order in an array stored in the wp_options table. This array is sorted alphabetically. Knowing that, you have 2 options.

  1. Make it very likely that your plugin is alphabetically first. I believe that @ is considered alphabetically first in php, so if you start your plugin name with something like @@MyPlugin then it should get loaded first.
  2. Change the order of the array stored in the database using the activated_plugin hook. I did a quick google search and found that someone had already written a function here. I’ve re-posted it below in case the link goes dead.

    add_action( 'activated_plugin', 'my_plugin_load_first' );
    function my_plugin_load_first(){
        $path = str_replace( WP_PLUGIN_DIR . "https://wordpress.stackexchange.com/", '', __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 );
            }
        }
    }
    

    Place this function in your plugin and it will re-order the array so that your plugin is loaded first.

The other option that you have is to omit the if( function_exists()) statement when you declare your version of the function. If you do that, and someone else has plugged that function then php will exit with a fatal error “function already exists”. This will have the effect of preventing someone else from plugging the function but it will also prevent the site from loading so I doubt that is a viable option for you.