From fee76161e3588cf27630d8a9a43e5136ac548649 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Sun, 16 Sep 2012 16:24:33 +0000 Subject: [PATCH] Don't use hard-coded indexes when dealing with an array of roles. props elyobo. fixes #19222. git-svn-id: https://develop.svn.wordpress.org/trunk@21866 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/ajax-actions.php | 6 ++++-- wp-includes/capabilities.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 5dbe74e23b..06042da368 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -1022,13 +1022,15 @@ function wp_ajax_add_user( $action ) { $wp_list_table = _get_list_table('WP_Users_List_Table'); + $role = current( $user_object->roles ); + $x = new WP_Ajax_Response( array( 'what' => 'user', 'id' => $user_id, - 'data' => $wp_list_table->single_row( $user_object, '', $user_object->roles[0] ), + 'data' => $wp_list_table->single_row( $user_object, '', $role ), 'supplemental' => array( 'show-link' => sprintf(__( 'User %s added' ), "user-$user_id", $user_object->user_login), - 'role' => $user_object->roles[0] + 'role' => $role, ) ) ); $x->send(); diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index 49579c9fea..4d5a6f0fe1 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -786,7 +786,7 @@ class WP_User { foreach ( (array) $this->roles as $oldrole ) unset( $this->caps[$oldrole] ); - if ( 1 == count( $this->roles ) && $role == $this->roles[0] ) + if ( 1 == count( $this->roles ) && $role == current( $this->roles ) ) return; if ( !empty( $role ) ) {