本文档详细记录了自 WordPress 4.7.0 版本公开发布以来,WP REST API 的变更历史。内容按版本号(从 5.6 到 4.7.1)降序排列,涵盖了新功能引入、端点更新、性能优化、安全增强及错误修复等方面,为开发者提供 API 演进的全景视图。
This document details changes to the WP REST API since its public release in version 4.7.0.
multipleOf JSON Schema keyword. r49063minProperties and maxProperties JSON Schema keywords. r49053patternProperties JSON Schema keyword. r49082anyOf and oneOf JSON Schema keywords. r49246wp.apiRequest. r49133Accept header in wp.apiRequest. r49716register_theme_feature() API for use in the Themes endpoint. r48171 Link header to the list of exposed cors headers. 48112Content-Disposition, Content-MD5 and X-WP-Nonce as allowed cors headers. r48452format keyword if the type is a string. r48300uuid JSON Schema format. 47753hex-color JSON Schema format. r47450pattern JSON Schema keyword. r47810minItems, maxItems, and uniqueItems JSON Schema keywords. r47923 r48357minLength and maxLength JSON Schema keywords. r47627WP_REST_Request::set_param(). r47559HTTP_RAW_POST_DATA global variable. r47926_doing_it_wrong when registering a route without a permission_callback. r48526_doing_it_wrong when using the wp_send_json() family of functions during a REST API request. r48361rest_ensure_response() upgrades WP_HTTP_Response to WP_REST_Response. r47849is_home() during a REST API request. r48053WP_REST_Controller::get_endpoint_args_for_item_schema(). r47911_doing_it_wrong warning when registering an “array” setting without an items schema. r47325REDIRECT_HTTP_AUTHORIZATION header. r47239_doing_it_wrong warning if a taxonomy’s specified rest_base is already in use by a different resource. r47037/themes endpoint response. r47258OPTIONS requests for non-variable routes. r47326get_item_schema on controller instances for performance. r45811self link relation in the search endpoint. r46434null as the post date property to reset post to initial “floating” date value. r46249204 or body is null. r45809object and array types in register_meta() schemas. r45807_fields query parameter. r46184edit context after PUT or POST request. r46098date_floating property on status endpoint response objects. r46252validate_user_can_query_private_statuses() attachments controller method. r44934urlencode_deep() in get_items() methods to ensure they are encoded correctly. r45267rest_post_search_query filter to allow query arguments to be manipulated for a post search query. r44482_doing_it_wrong() warning if register_rest_route() is called before the rest_api_init hook. r44568wp/v2/search route implementing a new WP_REST_Search_Controller. Search types are handled by extending WP_REST_Search_Handler, and the active search type may be filtered using the wp_rest_search_handlers filter. #39965wp/v2/blocks route to retrieve individual reusable blocks. Requires authentication. #45098attachment. Autosaves endpoints utilize the new WP_REST_Autosaves_Controller class, and saves only the id, title, post_content and excerpt for a post. Autosaves are enabled even for post types which do not support revisions. Requires authentication. #43316wp/v2/block-renderer/<name> routes to return dynamically generated markup for server-rendered blocks. The name component of the URL is structured as namespace/block-id, e.g. core/archives. Requires authentication. #45098wp/v2/themes endpoint to expose supported theme features to the block editor. This endpoint only returns data for the active theme. Requires authentication. #45016wp/v2/types/wp_block endpoint to expose block labels and capabilities relating to the new hidden post type wp_block. #45098show_in_rest as true to be visible in the block editor.wp_is_json_request() function to detemine if request is expecting a JSON response, and contextually silence PHP warnings if so. r43730edit context now return two additional properties, permalink_temlate and generated_slug. r43720?_fields= filter when applying custom post properties with register_rest_field. r43736read_private_posts capability to query for private posts. r43694unfiltered_html capability using JSON Hyper Schema targetSchema. r43682block_version property on the post object to denote the presence and version of blocks within the post. r43770rest_after_* action hooks that fire after all write operations have completed. r42864?_fields= global query parameter to limit the properties included in response objects to a specified subset. #38131object_subtype argument to the $args parameter for register_meta(): this parameter allows developers to specify the object subtypes (i.e. specific post types or taxonomies) for which the registered meta will appear when show_in_rest is true. Introduce new wrapper methods register_post_meta() and register_term_meta() which are recommended instead of register_meta when working with post or term meta. r43378wp-api.js client: Correctly interpret settings resource as a model rather than a collection. r41126PUT (and other) requests for nginx servers by tweaking REST API URLs. r41140WP_REST_Request::remove_header(). r40577Origin: null from file: URLs. r40600$post variable when preparing revisions. r40601featured_media in embed responses. r40602author, modified, and parent sort order options for posts. r40605parse-embed AJAX action. This is the first usage of the WP REST API in wp-admin. r40628X-WP-Deprecated* headers as often. r40782Last-Modified headers with authenticated requests. r40805$request->set_param() for some requests. r40815https when necessary. r40843gmt_offset and timezone_string to the base /wp-json response. r40336WP_REST_Posts_Controller::check_read_permission(). r40337slug parameters of the respective endpoints. r40426, r40427PATH_INFO. r40079status property in view context responses from the Posts endpoints. r40081wp-api.js client: Use _.extend instead of _.union when merging objects. r40084DELETE requests. r40113wp-api.js client: Fix route discovery for custom namespaces. r40117sticky posts filter when no posts are sticky. r40136false in 'rest_allow_anonymous_comments'. r39566wp-api.js client: Fix setup of models used by wp.api.collections objects. r39604password argument for the GET /wp/v2/media endpoint. r39610GET /wp/v2/media endpoint. r39629get_theme_support( 'post-formats' ) is not an array. r39630rest_*_collection_params filter docs and fix the terms filter. r39631sanitization_callback to be set to null to bypass built-in sanitization. r39642