It’s catch 22 – you need WordPress to use the hook system, but init
will have already fired during load (wp-settings.php
to be exact).
I would create a MU “Must Use” plugin (wp-content/mu-plugins/any-filename.php
) for all your “outside of WordPress” functionality, with something like this at the start:
if ( ! defined( 'LOADED_EXTERNAL' ) || ! LOADED_EXTERNAL )
return;
/**
* Better technique for temporarily disabling a plugin on-the-fly.
*
* @param array $plugins
* @return array
*/
function wpse_147541_active_plugins( $plugins ) {
if ( $plugin = array_search( 'facetwp/index.php', $plugins ) )
unset( $plugins[ $plugin ] );
return $plugins;
}
add_filter( 'option_active_plugins', 'wpse_147541_active_plugins' );
// More awesome code!
And then in your external file:
define( 'LOADED_EXTERNAL', true );
require 'wp-load.php'; // No need for globalising variables, they'll all be in scope
The reason I advocate a MU plugin is that they run before regular plugins, so you’ll have time to intercept “FacetWP” (or any other plugins for that matter) from loading.