Skip to content

Instantly share code, notes, and snippets.

@musamamasood
Last active March 2, 2022 12:38
Show Gist options
  • Save musamamasood/f9e3a3ff04e992ce0fc777536df8ffd2 to your computer and use it in GitHub Desktop.
Save musamamasood/f9e3a3ff04e992ce0fc777536df8ffd2 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Disable Plugin for URl
Plugin URI: https://www.glowlogix.com
Description: Disable plugins for for specific backend pages.
Author: Muhammad Usama M.
Version: 1.0.0
*/
add_filter( 'option_active_plugins', 'disable_plugins_per_page' );
function disable_plugins_per_page( $plugin_list ) {
// Quit immediately if not post edit area.
global $pagenow;
if (( $pagenow == 'post.php' || $pagenow == 'edit.php' )) {
$disable_plugins = array (
// Plugin Name
'hello.php',
'developer/developer.php'
);
$plugins_to_disable = array();
foreach ( $plugin_list as $plugin ) {
if ( true == in_array( $plugin, $disable_plugins ) ) {
//error_log( "Found $plugin in list of active plugins." );
$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;
}
}
return $plugin_list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment