Skip to content

Commit 2ea6448

Browse files
committedJun 3, 2014
Work around WP data handling failure
1 parent 15bb5a0 commit 2ea6448

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed
 

‎lib/class-wp-json-users.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -223,24 +223,22 @@ public function add_comment_author_data( $data, $comment, $context ) {
223223
}
224224

225225
protected function insert_user( $data ) {
226+
$user = new stdClass;
227+
226228
if ( ! empty( $data['ID'] ) ) {
227-
$user = get_userdata( $data['ID'] );
229+
$existing = get_userdata( $data['ID'] );
228230

229-
if ( ! $user ) {
231+
if ( ! $existing ) {
230232
return new WP_Error( 'json_user_invalid_id', __( 'Invalid user ID.' ), array( 'status' => 404 ) );
231233
}
232234

233235
if ( ! current_user_can( 'edit_user', $data['ID'] ) ) {
234236
return new WP_Error( 'json_user_cannot_edit', __( 'Sorry, you are not allowed to edit this user.' ), array( 'status' => 403 ) );
235237
}
236238

239+
$user->ID = $existing->ID;
237240
$update = true;
238241
} else {
239-
$user = new WP_User();
240-
241-
// Workaround for https://core.trac.wordpress.org/ticket/28019
242-
$user->data = new stdClass;
243-
244242
if ( ! current_user_can( 'create_users' ) ) {
245243
return new WP_Error( 'json_cannot_create', __( 'Sorry, you are not allowed to create users.' ), array( 'status' => 403 ) );
246244
}

0 commit comments

Comments
 (0)