钩子load-$pagenow
也可以使用。将其放入必须使用的插件中可防止其停用。通过添加一个简单的过滤器,我们可以隐藏MUs,使其不会出现在仪表板中(here, 更详细的技术)。
<?php
/*
Plugin Name: Cannot delete user
Description: Blocks the deletion of the user with ID == (adjust bellow)
Author: brasofilo
Plugin URI: https://wordpress.stackexchange.com/q/113907/12615
Requires: PHP 5.3+
*/
add_filter( \'show_advanced_plugins\', \'__return_false\' );
add_action( \'load-users.php\', function()
{
# Not a delete screen, do nothing
if( !isset( $_REQUEST[\'action\'] ) || \'delete\' != $_REQUEST[\'action\'] )
return;
# User(s) not set, do nothing
if( !isset( $_REQUEST[\'user\'] ) && !isset( $_REQUEST[\'users\'] ) )
return;
# Single user - adjust ID
if( isset( $_REQUEST[\'user\'] ) && \'USER_ID\' == $_REQUEST[\'user\'] )
wp_die(
\'Cannot delete this user.\',
\'Error\',
array( \'response\' => 500, \'back_link\' => true )
);
# Bulk users - adjust ID
if( isset( $_REQUEST[\'users\'] ) && in_array( \'USER_ID\', $_REQUEST[\'users\'] ) )
wp_die(
\'Cannot delete this user.\',
\'Error\',
array( \'response\' => 500, \'back_link\' => true )
);
});