wp/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php
equal
deleted
inserted
replaced
608 |
608 |
609 if ( is_wp_error( $user ) ) { |
609 if ( is_wp_error( $user ) ) { |
610 return $user; |
610 return $user; |
611 } |
611 } |
612 |
612 |
|
613 $fields = $this->get_fields_for_response( $request ); |
|
614 |
613 $prepared = array( |
615 $prepared = array( |
614 'uuid' => $item['uuid'], |
616 'uuid' => $item['uuid'], |
615 'app_id' => empty( $item['app_id'] ) ? '' : $item['app_id'], |
617 'app_id' => empty( $item['app_id'] ) ? '' : $item['app_id'], |
616 'name' => $item['name'], |
618 'name' => $item['name'], |
617 'created' => gmdate( 'Y-m-d\TH:i:s', $item['created'] ), |
619 'created' => gmdate( 'Y-m-d\TH:i:s', $item['created'] ), |
625 |
627 |
626 $prepared = $this->add_additional_fields_to_object( $prepared, $request ); |
628 $prepared = $this->add_additional_fields_to_object( $prepared, $request ); |
627 $prepared = $this->filter_response_by_context( $prepared, $request['context'] ); |
629 $prepared = $this->filter_response_by_context( $prepared, $request['context'] ); |
628 |
630 |
629 $response = new WP_REST_Response( $prepared ); |
631 $response = new WP_REST_Response( $prepared ); |
630 $response->add_links( $this->prepare_links( $user, $item ) ); |
632 |
|
633 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { |
|
634 $response->add_links( $this->prepare_links( $user, $item ) ); |
|
635 } |
631 |
636 |
632 /** |
637 /** |
633 * Filters the REST API response for an application password. |
638 * Filters the REST API response for an application password. |
634 * |
639 * |
635 * @since 5.6.0 |
640 * @since 5.6.0 |
651 * @return array The list of links. |
656 * @return array The list of links. |
652 */ |
657 */ |
653 protected function prepare_links( WP_User $user, $item ) { |
658 protected function prepare_links( WP_User $user, $item ) { |
654 return array( |
659 return array( |
655 'self' => array( |
660 'self' => array( |
656 'href' => rest_url( sprintf( '%s/users/%d/application-passwords/%s', $this->namespace, $user->ID, $item['uuid'] ) ), |
661 'href' => rest_url( |
|
662 sprintf( |
|
663 '%s/users/%d/application-passwords/%s', |
|
664 $this->namespace, |
|
665 $user->ID, |
|
666 $item['uuid'] |
|
667 ) |
|
668 ), |
657 ), |
669 ), |
658 ); |
670 ); |
659 } |
671 } |
660 |
672 |
661 /** |
673 /** |
705 |
717 |
706 if ( empty( $user ) || ! $user->exists() ) { |
718 if ( empty( $user ) || ! $user->exists() ) { |
707 return $error; |
719 return $error; |
708 } |
720 } |
709 |
721 |
710 if ( is_multisite() && ! is_user_member_of_blog( $user->ID ) ) { |
722 if ( is_multisite() && ! user_can( $user->ID, 'manage_sites' ) && ! is_user_member_of_blog( $user->ID ) ) { |
711 return $error; |
723 return $error; |
712 } |
724 } |
713 |
725 |
714 if ( ! wp_is_application_passwords_available_for_user( $user ) ) { |
726 if ( ! wp_is_application_passwords_available_for_user( $user ) ) { |
715 return new WP_Error( |
727 return new WP_Error( |