BP_REST_Attachments_Blog_Avatar_Endpoint::get_item( WP_REST_Request $request )
Fetch an existing blog avatar.
Description
Parameters
- $request
-
(Required) Full details about the request.
Return
(WP_REST_Response|WP_Error)
Source
File: bp-blogs/classes/class-bp-rest-attachments-blog-avatar-endpoint.php
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | public function get_item( $request ) { if ( empty ( $this ->blog->admin_user_id ) ) { return new WP_Error( 'bp_rest_blog_avatar_get_item_user_failed' , __( 'There was a problem confirming the blog\'s user admin is valid.' , 'buddyboss' ), array ( 'status' => 500, ) ); } $admin_user_admin = (int) $this ->blog->admin_user_id; $args = array (); foreach ( array ( 'full' , 'thumb' ) as $type ) { $args [ $type ] = bp_get_blog_avatar( array ( 'type' => $type , 'blog_id' => $request [ 'id' ], 'admin_user_id' => $admin_user_admin , 'html' => (bool) $request [ 'html' ], 'alt' => $request [ 'alt' ], 'no_grav' => (bool) $request [ 'no_user_gravatar' ], ) ); } // Get the avatar object. $avatar = $this ->get_avatar_object( $args ); if ( ! $avatar ->full && ! $avatar ->thumb ) { return new WP_Error( 'bp_rest_attachments_blog_avatar_no_image' , __( 'Sorry, there was a problem fetching the blog avatar.' , 'buddyboss' ), array ( 'status' => 500, ) ); } $retval = array ( $this ->prepare_response_for_collection( $this ->prepare_item_for_response( $avatar , $request ) ), ); $response = rest_ensure_response( $retval ); /** * Fires after a blog avatar is fetched via the REST API. * * @since 0.1.0 * * @param stdClass $avatar The avatar object. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request The request sent to the API. */ do_action( 'bp_rest_attachments_blog_avatar_get_item' , $avatar , $response , $request ); return $response ; } |
Changelog
Version | Description |
---|---|
0.1.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.