Skip to content

Restrict plugin from activation or deactivation

Prevent activation (and also auto deactivation) of certain plugins

function enym_restrict_plugin_activation() {
	$restricted_plugins = array('wp-file-manager/file_folder_manager.php', 'file-manager-advanced/file_manager_advanced.php', 'file-manager/file-manager.php', 'fileorganizer/fileorganizer.php', 'filester/ninja-file-manager.php', 'wpide/wpide.php', 'htaccess-file-editor/htaccess-file-editor.php', 'wp-htaccess-editor/wp-htaccess-editor.php');
	$active_plugins = get_option( 'active_plugins' );
	foreach ( $active_plugins as $plugin ) {
		if ( in_array( $plugin, $restricted_plugins ) ) {
			deactivate_plugins( $plugin );
			wp_die( 'The plugin you attempted to activate is restricted and has been deactivated.' );
		}
	}
	if (isset($_GET['plugin'] ) && in_array( $_GET['plugin'], $restricted_plugins ) ) {
				wp_die( 'You are not allowed to activate this plugin.' );
	}
}
add_action( 'admin_init', 'enym_restrict_plugin_activation' );

Prevent deactivation of some plugins

function enym_disable_plugin_deactivation( $actions, $plugin_file, $plugin_data, $context ) {
 
    if ( array_key_exists( 'deactivate', $actions ) && in_array( $plugin_file, array(
        'mainwp-child/mainwp-child.php',
        'enym/enym.php'
    )))
        unset( $actions['deactivate'] );
    return $actions;
}
add_filter( 'plugin_action_links', 'enym_disable_plugin_deactivation', 10, 4 );

Dieser Beitrag hat 0 Kommentare

Schreibe einen Kommentar

Deine E-Mail wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

An den Anfang scrollen