From 6f8e01adf208071d4d1fe3f33b8fdff117705981 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 16 Jan 2015 01:49:25 +0000 Subject: [PATCH] In `WP_User`, `->get_role_caps()` and `->update_user_level_from_caps()` must be called inside `->add_cap()` and `->remove_cap()` after updating user meta. `->has_cap()` checks are currently failing directly after calling `->add_cap()`. Adds unit test. Props rachelbaker. Fixes #28374. Built from https://develop.svn.wordpress.org/trunk@31190 git-svn-id: http://core.svn.wordpress.org/trunk@31171 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/capabilities.php | 9 +++++++-- wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index 56ca7738a0..aa3bb2af2f 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -934,6 +934,8 @@ class WP_User { public function add_cap( $cap, $grant = true ) { $this->caps[$cap] = $grant; update_user_meta( $this->ID, $this->cap_key, $this->caps ); + $this->get_role_caps(); + $this->update_user_level_from_caps(); } /** @@ -945,10 +947,13 @@ class WP_User { * @param string $cap Capability name. */ public function remove_cap( $cap ) { - if ( ! isset( $this->caps[$cap] ) ) + if ( ! isset( $this->caps[ $cap ] ) ) { return; - unset( $this->caps[$cap] ); + } + unset( $this->caps[ $cap ] ); update_user_meta( $this->ID, $this->cap_key, $this->caps ); + $this->get_role_caps(); + $this->update_user_level_from_caps(); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 78b846ca3e..0310ba5d00 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31189'; +$wp_version = '4.2-alpha-31190'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.