Make WordPress Core

Changeset 35687


Ignore:
Timestamp:
11/18/2015 08:38:25 PM (8 years ago)
Author:
johnbillion
Message:

Remove register_api_field() from core. This is the only core function that utilises the $wp_rest_additional_fields global, and doesn't belong as part of the infrastructure.

See https://github.com/WP-API/WP-API/pull/1748

Fixes #34730

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/rest-functions.php

    r35651 r35687  
    6565
    6666/**
    67  * Registers a new field on an existing WordPress object type.
    68  *
    69  * @since 4.4.0
    70  *
    71  * @global array $wp_rest_additional_fields Holds registered fields, organized
    72  *                                          by object type.
    73  *
    74  * @param string|array $object_type Object(s) the field is being registered
    75  *                                  to, "post"|"term"|"comment" etc.
    76  * @param string $attribute         The attribute name.
    77  * @param array  $args {
    78  *     Optional. An array of arguments used to handle the registered field.
    79  *
    80  *     @type string|array|null $get_callback    Optional. The callback function used to retrieve the field
    81  *                                              value. Default is 'null', the field will not be returned in
    82  *                                              the response.
    83  *     @type string|array|null $update_callback Optional. The callback function used to set and update the
    84  *                                              field value. Default is 'null', the value cannot be set or
    85  *                                              updated.
    86  *     @type string|array|null $schema          Optional. The callback function used to create the schema for
    87  *                                              this field. Default is 'null', no schema entry will be returned.
    88  * }
    89  */
    90 function register_api_field( $object_type, $attribute, $args = array() ) {
    91     $defaults = array(
    92         'get_callback'    => null,
    93         'update_callback' => null,
    94         'schema'          => null,
    95     );
    96 
    97     $args = wp_parse_args( $args, $defaults );
    98 
    99     global $wp_rest_additional_fields;
    100 
    101     $object_types = (array) $object_type;
    102 
    103     foreach ( $object_types as $object_type ) {
    104         $wp_rest_additional_fields[ $object_type ][ $attribute ] = $args;
    105     }
    106 }
    107 
    108 /**
    10967 * Registers rewrite rules for the API.
    11068 *
Note: See TracChangeset for help on using the changeset viewer.