| 395 | | $object[ $field_name ] = call_user_func( $field_options['get_callback'], $object, $field_name, $request, $this->get_object_type() ); |
| | 396 | /** |
| | 397 | * Sentinel value which the callback can return in order |
| | 398 | * to indicate that this field should not be added |
| | 399 | * |
| | 400 | * We're relying on the fact that object identity returns |
| | 401 | * whether two objects are the same instance of the same |
| | 402 | * class. That means it will be impossible to confuse a |
| | 403 | * value created inside the callback with this value. |
| | 404 | * |
| | 405 | * @example |
| | 406 | * function my_get_callback( $object, $field_name, $request, $object_type, $skip_field ) { |
| | 407 | * // only attach video meta to video attachments |
| | 408 | * if ( 0 !== strpos( $object->post_mime_type, 'video/' ) { |
| | 409 | * return $skip_field; |
| | 410 | * } |
| | 411 | * |
| | 412 | * return calculate_expensive_metadata( $object->ID ); |
| | 413 | * } |
| | 414 | * |
| | 415 | */ |
| | 416 | $skip_field = new stdClass; |
| | 417 | $field_value = call_user_func( $field_options['get_callback'], $object, $field_name, $request, $this->get_object_type(), $skip_field ); |
| | 418 | |
| | 419 | if ( $field_value === $skip_field ) { |
| | 420 | continue; |
| | 421 | } |
| | 422 | |
| | 423 | $object[ $field_name ] = $field_value; |