Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include super admins to the users list in Exclude settings #835

Merged
merged 5 commits into from
Mar 18, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions classes/class-author.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ function __get( $name ) {
}
}

/**
* @return string
*/
function __toString() {
return $this->get_display_name();
}

/**
* Get the display name of the user
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down
16 changes: 10 additions & 6 deletions classes/class-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ function column_default( $item, $column_name ) {
$user->get_avatar_img( 80 ),
$user->get_display_name(),
$user->is_deleted() ? sprintf( '<br /><small class="deleted">%s</small>', esc_html__( 'Deleted User', 'stream' ) ) : '',
$user->get_role() ? sprintf( '<br /><small>%s</small>', $user->get_role() ) : '',
$user->get_agent() ? sprintf( '<br /><small>%s</small>', $user->get_agent_label( $user->get_agent() ) ) : ''
sprintf( '<br /><small>%s</small>', $user->get_role() ),
sprintf( '<br /><small>%s</small>', $user->get_agent_label( $user->get_agent() ) )
);
break;

Expand Down Expand Up @@ -464,10 +464,14 @@ function( $user_id ) {
);

if ( is_multisite() && is_super_admin() ) {
$super_admins = get_super_admins();
foreach ( $super_admins as $admin ) {
$users[] = get_user_by( 'login', $admin );
}
$super_admins = array_map(
function( $login ) {
$user = get_user_by( 'login', $login );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This array is an array of Authors, not WP_Users. Hence the change.

return new Author( $user->ID );
},
get_super_admins()
);
$users = array_unique( array_merge( $users, $super_admins ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array unique so we don't have duplicates if a Super Admin is also an Administrator for the site.

}

$users[] = new Author( 0, array( 'is_wp_cli' => true ) );
Expand Down
7 changes: 6 additions & 1 deletion classes/class-log.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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,
Expand Down