Skip to content
This repository has been archived by the owner on Sep 24, 2018. It is now read-only.

Commit

Permalink
Work around WP data handling failure
Browse files Browse the repository at this point in the history
  • Loading branch information
rmccue committed Jun 3, 2014
1 parent 15bb5a0 commit 2ea6448
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/class-wp-json-users.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,24 +223,22 @@ public function add_comment_author_data( $data, $comment, $context ) {
}

protected function insert_user( $data ) {
$user = new stdClass;

if ( ! empty( $data['ID'] ) ) {
$user = get_userdata( $data['ID'] );
$existing = get_userdata( $data['ID'] );

if ( ! $user ) {
if ( ! $existing ) {
return new WP_Error( 'json_user_invalid_id', __( 'Invalid user ID.' ), array( 'status' => 404 ) );
}

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

$user->ID = $existing->ID;
$update = true;
} else {
$user = new WP_User();

// Workaround for https://core.trac.wordpress.org/ticket/28019
$user->data = new stdClass;

if ( ! current_user_can( 'create_users' ) ) {
return new WP_Error( 'json_cannot_create', __( 'Sorry, you are not allowed to create users.' ), array( 'status' => 403 ) );
}
Expand Down

0 comments on commit 2ea6448

Please sign in to comment.