0

The following filter works great for preventing plugins from being deactivated...

add_filter( 'plugin_action_links', 'disable_plugin_deactivation', 10, 4 );

with...

// array_key_exists( 'edit', $actions )...
// array_key_exists( 'deactivate', $actions )...

...But is there a similar filter or array_key, that prevents plugins from displaying their uninstall link on the plugins.php file?

Thanks

  • Are you talking about editors as in "people that just want to edit articles", or editors as in "users with the role editor"? The latter should not be able to delete plugins imho. – janh Nov 9 '17 at 14:40
  • Allow me to revise my original question....I overlooked my objective... – klewis Nov 9 '17 at 14:51
  • I don't think there's a direct way for that. You might be able to use register_deactivation_hook() to hook into the deactivation event and then just use activate_plugin() to immediately reactivate it. It's not the cleanest of ways, but should be pretty straightforward (if I'm not missing something major). – janh Nov 9 '17 at 15:35
  • please forgive me janh, allow me to revise my question once again... – klewis Nov 9 '17 at 21:27
2

Yes, you can use the same filter, just remove the delete key of the $actions array. If you want to remove the "delete" link for the plugin "myplugin", you'd go for something like this:

add_filter("plugin_action_links", function($actions, $plugin_file, $plugin_data, $context) {
    if($plugin_file == "myplugin/myplugin.php") {
        unset($actions["delete"]);
    }
    return $actions;
}, 10, 4);

Obviously, you cannot put this into the plugin itself, since it will have been deactivated or the delete link will not show up (link to deactivate the plugin will be in its place). Also, be aware that this will only remove the link, it will not stop a determined user with the appropriate privileges from sending that request manually.

  • Your logic makes perfect sense...but how did you know that the $actions[] value was "delete" is there a list of values I can also view/access? – klewis Nov 9 '17 at 22:34
  • I didn't know a filter, so I tried to find out where the links are crafted and what filter I might use to influence that. The single_row() method in wp-admin/includes/class-wp-plugins-list-table.php does handle that, and includes the possible actions in an array $actions: deactivate, activate, details, edit, and delete. – janh Nov 9 '17 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.