diff --git a/classes/class-author.php b/classes/class-author.php index 6b9608ca1..c9a589c88 100644 --- a/classes/class-author.php +++ b/classes/class-author.php @@ -59,6 +59,13 @@ function __get( $name ) { } } + /** + * @return string + */ + function __toString() { + return $this->get_display_name(); + } + /** * Get the display name of the user * @@ -173,14 +180,16 @@ function get_avatar_src( $size = 80 ) { function get_role() { global $wp_roles; + $user_role = ''; + if ( ! empty( $this->meta['user_role'] ) && isset( $wp_roles->role_names[ $this->meta['user_role'] ] ) ) { $user_role = $wp_roles->role_names[ $this->meta['user_role'] ]; } elseif ( ! empty( $this->meta['user_role_label'] ) ) { $user_role = $this->meta['user_role_label']; } elseif ( isset( $this->user->roles[0] ) && isset( $wp_roles->role_names[ $this->user->roles[0] ] ) ) { $user_role = $wp_roles->role_names[ $this->user->roles[0] ]; - } else { - $user_role = ''; + } elseif ( is_multisite() && is_super_admin( $this->id ) ) { + $user_role = $wp_roles->role_names['administrator']; } return $user_role; @@ -223,13 +232,6 @@ function is_doing_wp_cron() { ); } - /** - * @return string - */ - function __toString() { - return $this->get_display_name(); - } - /** * Look at the environment to detect if an agent is being used * diff --git a/classes/class-list-table.php b/classes/class-list-table.php index a7b3b3b09..0bb79f144 100644 --- a/classes/class-list-table.php +++ b/classes/class-list-table.php @@ -276,8 +276,8 @@ function column_default( $item, $column_name ) { $user->get_avatar_img( 80 ), $user->get_display_name(), $user->is_deleted() ? sprintf( '
%s', esc_html__( 'Deleted User', 'stream' ) ) : '', - $user->get_role() ? sprintf( '
%s', $user->get_role() ) : '', - $user->get_agent() ? sprintf( '
%s', $user->get_agent_label( $user->get_agent() ) ) : '' + sprintf( '
%s', $user->get_role() ), + sprintf( '
%s', $user->get_agent_label( $user->get_agent() ) ) ); break; @@ -463,6 +463,17 @@ function( $user_id ) { get_users( array( 'fields' => 'ID' ) ) ); + if ( is_multisite() && is_super_admin() ) { + $super_admins = array_map( + function( $login ) { + $user = get_user_by( 'login', $login ); + return new Author( $user->ID ); + }, + get_super_admins() + ); + $users = array_unique( array_merge( $users, $super_admins ) ); + } + $users[] = new Author( 0, array( 'is_wp_cli' => true ) ); foreach ( $users as $user ) { diff --git a/classes/class-log.php b/classes/class-log.php index 7d8cb50e5..f53bae43b 100644 --- a/classes/class-log.php +++ b/classes/class-log.php @@ -43,6 +43,8 @@ public function __construct( $plugin ) { * @return mixed True if updated, otherwise false|WP_Error */ public function log( $connector, $message, $args, $object_id, $context, $action, $user_id = null ) { + global $wp_roles; + if ( is_null( $user_id ) ) { $user_id = get_current_user_id(); } @@ -106,10 +108,13 @@ function( &$v ) { if ( ! empty( $user->roles ) ) { $roles = array_values( $user->roles ); - $role = $roles[0]; + $role = $roles[0]; + } elseif ( is_multisite() && is_super_admin() && $wp_roles->is_role( 'administrator' ) ) { + $role = 'administrator'; } else { $role = ''; } + $recordarr = array( 'object_id' => (int) $object_id, 'site_id' => (int) is_multisite() ? get_current_site()->id : 1, diff --git a/classes/class-settings.php b/classes/class-settings.php index a2bf197b7..830f9a319 100644 --- a/classes/class-settings.php +++ b/classes/class-settings.php @@ -114,12 +114,29 @@ public function get_users() { if ( 0 === $users->get_total() ) { wp_send_json_error( $response ); } + $users_array = $users->results; + + if ( is_multisite() && is_super_admin() ) { + $super_admins = get_super_admins(); + foreach ( $super_admins as $admin ) { + $user = get_user_by( 'login', $admin ); + $users_array[] = $user; + } + } $response->status = true; $response->message = ''; $response->users = array(); + $users_added_to_response = array(); + + foreach ( $users_array as $key => $user ) { + // exclude duplications: + if ( array_key_exists( $user->ID, $users_added_to_response ) ) { + continue; + } else { + $users_added_to_response[ $user->ID ] = true; + } - foreach ( $users->results as $key => $user ) { $author = new Author( $user->ID ); $args = array( @@ -142,6 +159,13 @@ public function get_users() { $response->users[] = $args; } + usort( + $response->users, + function( $a, $b ) { + return strcmp( $a['text'], $b['text'] ); + } + ); + if ( empty( $search ) || preg_match( '/wp|cli|system|unknown/i', $search ) ) { $author = new Author( 0 ); $response->users[] = array(