/**
  * Retrieve the current user
  *
  * @param string $context
  * @return mixed See
  */
 public function get_current_user($context = 'view')
 {
     $current_user_id = get_current_user_id();
     if (empty($current_user_id)) {
         return new WP_Error('json_not_logged_in', __('You are not currently logged in.'), array('status' => 401));
     }
     $response = $this->get_user($current_user_id, $context);
     if (is_wp_error($response)) {
         return $response;
     }
     if (!$response instanceof WP_JSON_ResponseInterface) {
         $response = new WP_JSON_Response($response);
     }
     $data = $response->get_data();
     $response->header('Location', $data['meta']['links']['self']);
     $response->set_status(302);
     return $response;
 }
Exemplo n.º 2
0
 public function test_update_user()
 {
     $pw_before = $this->user_obj->user_pass;
     $data = array('first_name' => 'New Name');
     $response = $this->endpoint->edit_user($this->user, $data);
     $this->assertNotInstanceOf('WP_Error', $response);
     if (!$response instanceof WP_JSON_ResponseInterface) {
         $response = new WP_JSON_Response($response);
     }
     // Check that we succeeded
     $this->assertEquals(200, $response->get_status());
     // Check that the name has been updated correctly
     $new_data = $response->get_data();
     $this->assertEquals($data['first_name'], $new_data['first_name']);
     $user = get_userdata($this->user);
     $this->assertEquals($user->first_name, $data['first_name']);
     // Check that we haven't inadvertently changed the user's password,
     // as per https://core.trac.wordpress.org/ticket/21429
     $this->assertEquals($pw_before, $user->user_pass);
 }