BP_REST_XProfile_Fields_Endpoint::get_item( WP_REST_Request $request )
Retrieve single XProfile field.
Description
Parameters
- $request
-
(Required) Full data about the request.
Return
(WP_REST_Response|WP_Error)
Source
File: bp-xprofile/classes/class-bp-rest-xprofile-fields-endpoint.php
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | public function get_item( $request ) { $field = $this ->get_xprofile_field_object( $request ); if ( empty ( $field ->id ) ) { return new WP_Error( 'bp_rest_invalid_id' , __( 'Invalid field ID.' , 'buddyboss' ), array ( 'status' => 404, ) ); } if ( ! empty ( $request ->get_param( 'user_id' ) ) ) { $field ->data = new stdClass(); // Ensure that the requester is allowed to see this field. $hidden_user_fields = bp_xprofile_get_hidden_fields_for_user( $request ->get_param( 'user_id' ) ); if ( in_array( $field ->id, $hidden_user_fields , true ) ) { $field ->data->value = __( 'Value suppressed.' , 'buddyboss' ); } else { // Get the raw value for the field. $field ->data->value = BP_XProfile_ProfileData::get_value_byid( $field ->id, $request ->get_param( 'user_id' ) ); } } $retval = $this ->prepare_response_for_collection( $this ->prepare_item_for_response( $field , $request ) ); $response = rest_ensure_response( $retval ); /** * Fires after XProfile field is fetched via the REST API. * * @param BP_XProfile_Field $field Fetched field object. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request The request sent to the API. * * @since 0.1.0 */ do_action( 'bp_rest_xprofile_fields_get_item' , $field , $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.