Reputation: 33
I am looking for a solution that will NOT activate a certain plugin on a SINGLE PAGE.
I have tried to play around with the attached code (offered by @Kamil Grzegorczyk on Wordpress Disable Plugin on Specific Pages/Posts) but with no success.
add_filter( 'option_active_plugins', 'lg_disable_cart66_plugin' );
function lg_disable_cart66_plugin($plugins){
if(strpos($_SERVER['REQUEST_URI'], '/store/') === FALSE AND strpos($_SERVER['REQUEST_URI'], '/wp-admin/') === FALSE) {
$key = array_search( 'cart66/cart66.php' , $plugins );
if ( false !== $key ) unset( $plugins[$key] );
}
return $plugins;
}
I have also tried to us plugin organizer but it is not helping to NOT activate a certain plugin on a SINGLE PAGE.
BTW, if anyone got a code that can only activate certain plugins such as Contact form no 7 by tracing their shortcode on a post/page that will be brilliant! Something like if x page/post has a shortcode that contains 'contact form no 7' then activate Contact form no 7 plugin, else, do not activate.
Anyway, at this stage, an easy to go solution will do :)
Thanks.
Upvotes: 0
Views: 1676
Reputation:
"BTW, if anyone got a code that can only activate certain plugins such as Contact form no 7 by tracing their shortcode on a post/page that will be brilliant! Something like if x page/post has a shortcode that contains 'contact form no 7' then activate Contact form no 7 plugin, else, do not activate." - This is not possible. Reading the source code wp-blog-header.php should make this clear.
$wp_did_header = true;
// Load the WordPress library.
require_once( dirname( __FILE__ ) . '/wp-load.php' );
// Set up the WordPress query.
wp();
// Load the theme template.
require_once( ABSPATH . WPINC . '/template-loader.php' );
Plugins are loaded by wp-settings.php which is loaded by wp-load.php. The post content of a request is retrieved from the database by WP::query_posts() which is called by the function wp(). So, plugins are already loaded before the post content is even retrieved from the database.
Where did you put the code:
add_filter( 'option_active_plugins', 'lg_disable_cart66_plugin' );
This cannot be put in a regular plugin since it must execute BEFORE plugins are loaded. (You cannot tell a plugin not to load in code that is already loaded.) It also cannot be put in functions.php since functions.php is loaded AFTER plugins are loaded. Did you read the comment about mu-plugins? "must use" plugins are loaded before regular plugins. All of this can be found in wp-settings.php - I highly recommend reading it - it is an easy read and you will understand how WordPress initializes itself.
Upvotes: 2