function test_plugins() { $plugins = array('hello-dolly.php'); $this->assertTrue(can_force_delete_plugins(self::$user_can, self::$nonce, self::$action, $plugins)); $plugins = array(); $can_delete = can_force_delete_plugins(self::$user_can, self::$nonce, self::$action, $plugins); $this->assertInstanceOf('WP_Error', $can_delete); if (is_wp_error($can_delete)) { $this->assertEquals('plugins', $can_delete->get_error_code()); } $can_delete = can_force_delete_plugins(self::$user_can, self::$nonce, self::$action); $this->assertInstanceOf('WP_Error', $can_delete); if (is_wp_error($can_delete)) { $this->assertEquals('plugins', $can_delete->get_error_code()); } }
License URI: https://www.gnu.org/licenses/gpl-2.0.html Text Domain: force-delete-plugins */ // If this file is called directly, abort. if (!defined('WPINC')) { die; } /** * Hooks into WordPress */ add_action('current_screen', function () { $user_can = current_user_can('activate_plugins'); $action = _get_list_table('WP_Plugins_List_Table')->current_action(); $plugins = isset($_POST['checked']) ? (array) $_POST['checked'] : array(); $referer = wp_verify_nonce(isset($_REQUEST['_wpnonce']) ? $_REQUEST['_wpnonce'] : null, 'bulk-plugins'); $can_force_delete_plugins = can_force_delete_plugins($user_can, $referer, $action, $plugins); if (!is_wp_error($can_force_delete_plugins)) { deactivate_plugins($plugins, false, is_network_admin()); } }); /** * Checks if user tried to deactivate plugins * * @param bool $user_can * @param bool $referer * @param string $action * @param array $plugins * * @return bool|WP_Error */ function can_force_delete_plugins($user_can, $referer, $action, $plugins = array())