Skip to content

Instantly share code, notes, and snippets.

@lukecav
Forked from damiencarbery/disable-cf7.php
Last active August 27, 2019 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukecav/ada74c86180e3caaf51b67e7f957db4d to your computer and use it in GitHub Desktop.
Save lukecav/ada74c86180e3caaf51b67e7f957db4d to your computer and use it in GitHub Desktop.
Disable PayPal for WooCommerce plugin on all pages other than cart and checkout
<?php
/*
Plugin Name: Disable PayPal for WooCommerce Plugin
Plugin URI: https://github.com/lukecav
Description: Disable PayPal for WooCommerce plugin on all pages other than cart and checkout.
Author: Luke Cavanagh
Version: 1.0.0
*/
add_filter( 'option_active_plugins', 'disable_plugins_per_page' );
function disable_plugins_per_page( $plugin_list ) {
// Quit immediately if in admin area.
if ( is_admin() ) {
return $plugin_list;
}
$disable_plugins = array (
// Plugin Name => Urls *not* to disable on.
'paypal-for-woocommerce/paypal-for-woocommerce.php' => array( '/cart/', '/checkout/' ),
);
$plugins_to_disable = array();
foreach ( $plugin_list as $plugin ) {
if (true == array_key_exists( $plugin, $disable_plugins ) ) {
//error_log( "Found $plugin in list of active plugins." );
if ( false === array_search( $_SERVER['REQUEST_URI'], $disable_plugins[ $plugin ] ) ) {
//error_log( "Disable $plugin on ".$_SERVER['REQUEST_URI']."." );
$plugins_to_disable[] = $plugin;
}
}
}
// If there are plugins to disable then remove them from the list,
// otherwise return the original list.
if ( count( $plugins_to_disable ) ) {
$new_list = array_diff( $plugin_list, $plugins_to_disable );
return $new_list;
}
else {
return $plugin_list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment