get_field_schema example

                    $formats = array_values( get_post_format_slugs() );

                    $schema['properties']['format'] = array(
                        'description' => __( 'The format for the post.' ),
                        'type'        => 'string',
                        'enum'        => $formats,
                        'context'     => array( 'view', 'edit' ),
                    );
                    break;

                case 'custom-fields':
                    $schema['properties']['meta'] = $this->meta->get_field_schema();
                    break;

            }
        }

        if ( 'post' === $this->post_type ) {
            $schema['properties']['sticky'] = array(
                'description' => __( 'Whether or not the post should be treated as sticky.' ),
                'type'        => 'boolean',
                'context'     => array( 'view', 'edit' ),
            );
        }

    public function register_field() {
        _deprecated_function( __METHOD__, '5.6.0' );

        register_rest_field(
            $this->get_rest_field_type(),
            'meta',
            array(
                'get_callback'    => array( $this, 'get_value' ),
                'update_callback' => array( $this, 'update_value' ),
                'schema'          => $this->get_field_schema(),
            )
        );
    }

    /** * Retrieves the meta field value. * * @since 4.7.0 * * @param int $object_id Object ID to fetch meta for. * @param WP_REST_Request $request Full details about the request. * @return array Array containing the meta values keyed by name. */
$taxonomy = get_taxonomy( $this->taxonomy );

        if ( $taxonomy->hierarchical ) {
            $schema['properties']['parent'] = array(
                'description' => __( 'The parent term ID.' ),
                'type'        => 'integer',
                'context'     => array( 'view', 'edit' ),
            );
        }

        $schema['properties']['meta'] = $this->meta->get_field_schema();

        $this->schema = $schema;

        return $this->add_additional_fields_schema( $this->schema );
    }

    /** * Retrieves the query params for collections. * * @since 4.7.0 * * @return array Collection parameters. */


            $schema['properties']['avatar_urls'] = array(
                'description' => __( 'Avatar URLs for the user.' ),
                'type'        => 'object',
                'context'     => array( 'embed', 'view', 'edit' ),
                'readonly'    => true,
                'properties'  => $avatar_properties,
            );
        }

        $schema['properties']['meta'] = $this->meta->get_field_schema();

        $this->schema = $schema;

        return $this->add_additional_fields_schema( $this->schema );
    }

    /** * Retrieves the query params for collections. * * @since 4.7.0 * * @return array Collection parameters. */


            $schema['properties']['author_avatar_urls'] = array(
                'description' => __( 'Avatar URLs for the comment author.' ),
                'type'        => 'object',
                'context'     => array( 'view', 'edit', 'embed' ),
                'readonly'    => true,
                'properties'  => $avatar_properties,
            );
        }

        $schema['properties']['meta'] = $this->meta->get_field_schema();

        $this->schema = $schema;

        return $this->add_additional_fields_schema( $this->schema );
    }

    /** * Retrieves the query params for collections. * * @since 4.7.0 * * @return array Comments collection parameters. */
'type' => 'integer',
                ),
                'context'     => array( 'view', 'edit' ),
            );

            if ( 'nav_menu' === $taxonomy->name ) {
                $schema['properties'][ $base ]['type'] = 'integer';
                unset( $schema['properties'][ $base ]['items'] );
            }
        }

        $schema['properties']['meta'] = $this->meta->get_field_schema();

        $schema_links = $this->get_schema_links();

        if ( $schema_links ) {
            $schema['links'] = $schema_links;
        }

        $this->schema = $schema;

        return $this->add_additional_fields_schema( $this->schema );
    }

    
Home | Imprint | This part of the site doesn't use cookies.