Skip to main content
added 762 characters in body
Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147

This is a classic XY problem question, the original problem you face is:

"How do I prevent a client from disabling the woocommerce plugin"

For which mu-plugins was your solution, to which you are now asking for a fix for your solution, aka a fix for a fix, never a good sign.

So addressing your original problem we have twothree approaches:

Fail gracefully and make it clear how to fix things

If WooCommerce is disabled, warn the user that it has been disabled, fail gracefully, and put links to the reactivation button here there and everywhere. The client should very quickly get the message that what they did will break the site

Disable the disable link

e.g. for the facebook open graph plugin:

test

add_filter( 'plugin_action_links', 'disable_plugin_deactivation', 10, 4 );
function disable_plugin_deactivation( $actions, $plugin_file, $plugin_data, $context ) {
    // Remove edit link for all
    if ( array_key_exists( 'edit', $actions ) )
        unset( $actions['edit'] );
    // Remove deactivate link for crucial plugins
    if ( array_key_exists( 'deactivate', $actions ) && in_array( $plugin_file, array(
        'facebook-open-graph-meta-in-wordpress/fbogmeta.php'
    )))
        unset( $actions['deactivate'] );
    return $actions;
}

Disable The Plugin Menu Itself

Or best of all, removeThe client can't disable a plugin if they cant see the plugins page entirely:

function remove_menus () {
    global $menu;
    $restricted = array( __('Plugins') );
    end ($menu);
    while (prev($menu)){
        $value = explode(' ',$menu[key($menu)][0]);
        if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
    }
}
add_action('admin_menu', 'remove_menus');

I would recommend both failing gracefully, and disabling the plugins menu. Fail gracefully and your code will be more robust, and robust code is profitable code ( those hours you saved turn into days worth of painful support and mysterious bugs ). A client won't know you can disable a plugin if they're unaware there is a plugin menu to begin with.

This is a classic XY problem question, the original problem you face is:

"How do I prevent a client from disabling the woocommerce plugin"

For which mu-plugins was your solution, to which you are now asking for a fix for your solution, aka a fix for a fix, never a good sign.

So addressing your original problem we have two approaches:

Fail gracefully and make it clear how to fix things

If WooCommerce is disabled, warn the user that it has been disabled, fail gracefully, and put links to the reactivation button here there and everywhere. The client should very quickly get the message that what they did will break the site

Disable the disable link

e.g. for the facebook open graph plugin:

test

add_filter( 'plugin_action_links', 'disable_plugin_deactivation', 10, 4 );
function disable_plugin_deactivation( $actions, $plugin_file, $plugin_data, $context ) {
    // Remove edit link for all
    if ( array_key_exists( 'edit', $actions ) )
        unset( $actions['edit'] );
    // Remove deactivate link for crucial plugins
    if ( array_key_exists( 'deactivate', $actions ) && in_array( $plugin_file, array(
        'facebook-open-graph-meta-in-wordpress/fbogmeta.php'
    )))
        unset( $actions['deactivate'] );
    return $actions;
}

Or best of all, remove the plugins page entirely.

This is a classic XY problem question, the original problem you face is:

"How do I prevent a client from disabling the woocommerce plugin"

For which mu-plugins was your solution, to which you are now asking for a fix for your solution, aka a fix for a fix, never a good sign.

So addressing your original problem we have three approaches:

Fail gracefully and make it clear how to fix things

If WooCommerce is disabled, warn the user that it has been disabled, fail gracefully, and put links to the reactivation button here there and everywhere. The client should very quickly get the message that what they did will break the site

Disable the disable link

e.g. for the facebook open graph plugin:

test

add_filter( 'plugin_action_links', 'disable_plugin_deactivation', 10, 4 );
function disable_plugin_deactivation( $actions, $plugin_file, $plugin_data, $context ) {
    // Remove edit link for all
    if ( array_key_exists( 'edit', $actions ) )
        unset( $actions['edit'] );
    // Remove deactivate link for crucial plugins
    if ( array_key_exists( 'deactivate', $actions ) && in_array( $plugin_file, array(
        'facebook-open-graph-meta-in-wordpress/fbogmeta.php'
    )))
        unset( $actions['deactivate'] );
    return $actions;
}

Disable The Plugin Menu Itself

The client can't disable a plugin if they cant see the plugins page:

function remove_menus () {
    global $menu;
    $restricted = array( __('Plugins') );
    end ($menu);
    while (prev($menu)){
        $value = explode(' ',$menu[key($menu)][0]);
        if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
    }
}
add_action('admin_menu', 'remove_menus');

I would recommend both failing gracefully, and disabling the plugins menu. Fail gracefully and your code will be more robust, and robust code is profitable code ( those hours you saved turn into days worth of painful support and mysterious bugs ). A client won't know you can disable a plugin if they're unaware there is a plugin menu to begin with.

added 74 characters in body
Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147

This is a classic XY problem question, the original problem you face is:

"How do I prevent a client from disabling the woocommerce plugin"

For which mu-plugins was your solution, to which you are now asking for a fix for your solution, aka a fix for a fix, never a good sign.

So addressing your original problem we have two approaches:

Fail gracefully and make it clear how to fix things

If WooCommerce is disabled, warn the user that it has been disabled, fail gracefully, and put links to the reactivation button here there and everywhere. The client should very quickly get the message that what they did will break the site

Disable the disable link

Disable the disable link, e.g. for the facebook open graph plugin:

test

add_filter( 'plugin_action_links', 'disable_plugin_deactivation', 10, 4 );
function disable_plugin_deactivation( $actions, $plugin_file, $plugin_data, $context ) {
    // Remove edit link for all
    if ( array_key_exists( 'edit', $actions ) )
        unset( $actions['edit'] );
    // Remove deactivate link for crucial plugins
    if ( array_key_exists( 'deactivate', $actions ) && in_array( $plugin_file, array(
        'facebook-open-graph-meta-in-wordpress/fbogmeta.php'
    )))
        unset( $actions['deactivate'] );
    return $actions;
}

Or best of all, remove the plugins page entirely.

This is a classic XY problem question, the original problem you face is:

"How do I prevent a client from disabling the woocommerce plugin"

For which mu-plugins was your solution, to which you are now asking for a fix for your solution, aka a fix for a fix, never a good sign.

So addressing your original problem we have:

If WooCommerce is disabled, warn the user that it has been disabled, fail gracefully, and put links to the reactivation button here there and everywhere. The client should very quickly get the message that what they did will break the site

Disable the disable link, e.g. for the facebook open graph plugin:

test

add_filter( 'plugin_action_links', 'disable_plugin_deactivation', 10, 4 );
function disable_plugin_deactivation( $actions, $plugin_file, $plugin_data, $context ) {
    // Remove edit link for all
    if ( array_key_exists( 'edit', $actions ) )
        unset( $actions['edit'] );
    // Remove deactivate link for crucial plugins
    if ( array_key_exists( 'deactivate', $actions ) && in_array( $plugin_file, array(
        'facebook-open-graph-meta-in-wordpress/fbogmeta.php'
    )))
        unset( $actions['deactivate'] );
    return $actions;
}

Or best of all, remove the plugins page entirely.

This is a classic XY problem question, the original problem you face is:

"How do I prevent a client from disabling the woocommerce plugin"

For which mu-plugins was your solution, to which you are now asking for a fix for your solution, aka a fix for a fix, never a good sign.

So addressing your original problem we have two approaches:

Fail gracefully and make it clear how to fix things

If WooCommerce is disabled, warn the user that it has been disabled, fail gracefully, and put links to the reactivation button here there and everywhere. The client should very quickly get the message that what they did will break the site

Disable the disable link

e.g. for the facebook open graph plugin:

test

add_filter( 'plugin_action_links', 'disable_plugin_deactivation', 10, 4 );
function disable_plugin_deactivation( $actions, $plugin_file, $plugin_data, $context ) {
    // Remove edit link for all
    if ( array_key_exists( 'edit', $actions ) )
        unset( $actions['edit'] );
    // Remove deactivate link for crucial plugins
    if ( array_key_exists( 'deactivate', $actions ) && in_array( $plugin_file, array(
        'facebook-open-graph-meta-in-wordpress/fbogmeta.php'
    )))
        unset( $actions['deactivate'] );
    return $actions;
}

Or best of all, remove the plugins page entirely.

Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147

This is a classic XY problem question, the original problem you face is:

"How do I prevent a client from disabling the woocommerce plugin"

For which mu-plugins was your solution, to which you are now asking for a fix for your solution, aka a fix for a fix, never a good sign.

So addressing your original problem we have:

If WooCommerce is disabled, warn the user that it has been disabled, fail gracefully, and put links to the reactivation button here there and everywhere. The client should very quickly get the message that what they did will break the site

Disable the disable link, e.g. for the facebook open graph plugin:

test

add_filter( 'plugin_action_links', 'disable_plugin_deactivation', 10, 4 );
function disable_plugin_deactivation( $actions, $plugin_file, $plugin_data, $context ) {
    // Remove edit link for all
    if ( array_key_exists( 'edit', $actions ) )
        unset( $actions['edit'] );
    // Remove deactivate link for crucial plugins
    if ( array_key_exists( 'deactivate', $actions ) && in_array( $plugin_file, array(
        'facebook-open-graph-meta-in-wordpress/fbogmeta.php'
    )))
        unset( $actions['deactivate'] );
    return $actions;
}

Or best of all, remove the plugins page entirely.