Edit File by line
/home/barbar84/public_h.../wp-inclu...
File: rest-api.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* REST API functions.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage REST_API
[5] Fix | Delete
* @since 4.4.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Version number for our API.
[10] Fix | Delete
*
[11] Fix | Delete
* @var string
[12] Fix | Delete
*/
[13] Fix | Delete
define( 'REST_API_VERSION', '2.0' );
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* Registers a REST API route.
[17] Fix | Delete
*
[18] Fix | Delete
* Note: Do not use before the {@see 'rest_api_init'} hook.
[19] Fix | Delete
*
[20] Fix | Delete
* @since 4.4.0
[21] Fix | Delete
* @since 5.1.0 Added a `_doing_it_wrong()` notice when not called on or after the `rest_api_init` hook.
[22] Fix | Delete
* @since 5.5.0 Added a `_doing_it_wrong()` notice when the required `permission_callback` argument is not set.
[23] Fix | Delete
*
[24] Fix | Delete
* @param string $namespace The first URL segment after core prefix. Should be unique to your package/plugin.
[25] Fix | Delete
* @param string $route The base URL for route you are adding.
[26] Fix | Delete
* @param array $args Optional. Either an array of options for the endpoint, or an array of arrays for
[27] Fix | Delete
* multiple methods. Default empty array.
[28] Fix | Delete
* @param bool $override Optional. If the route already exists, should we override it? True overrides,
[29] Fix | Delete
* false merges (with newer overriding if duplicate keys exist). Default false.
[30] Fix | Delete
* @return bool True on success, false on error.
[31] Fix | Delete
*/
[32] Fix | Delete
function register_rest_route( $namespace, $route, $args = array(), $override = false ) {
[33] Fix | Delete
if ( empty( $namespace ) ) {
[34] Fix | Delete
/*
[35] Fix | Delete
* Non-namespaced routes are not allowed, with the exception of the main
[36] Fix | Delete
* and namespace indexes. If you really need to register a
[37] Fix | Delete
* non-namespaced route, call `WP_REST_Server::register_route` directly.
[38] Fix | Delete
*/
[39] Fix | Delete
_doing_it_wrong( 'register_rest_route', __( 'Routes must be namespaced with plugin or theme name and version.' ), '4.4.0' );
[40] Fix | Delete
return false;
[41] Fix | Delete
} elseif ( empty( $route ) ) {
[42] Fix | Delete
_doing_it_wrong( 'register_rest_route', __( 'Route must be specified.' ), '4.4.0' );
[43] Fix | Delete
return false;
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
$clean_namespace = trim( $namespace, '/' );
[47] Fix | Delete
[48] Fix | Delete
if ( $clean_namespace !== $namespace ) {
[49] Fix | Delete
_doing_it_wrong( __FUNCTION__, __( 'Namespace must not start or end with a slash.' ), '5.4.2' );
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
if ( ! did_action( 'rest_api_init' ) ) {
[53] Fix | Delete
_doing_it_wrong(
[54] Fix | Delete
'register_rest_route',
[55] Fix | Delete
sprintf(
[56] Fix | Delete
/* translators: %s: rest_api_init */
[57] Fix | Delete
__( 'REST API routes must be registered on the %s action.' ),
[58] Fix | Delete
'<code>rest_api_init</code>'
[59] Fix | Delete
),
[60] Fix | Delete
'5.1.0'
[61] Fix | Delete
);
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
if ( isset( $args['args'] ) ) {
[65] Fix | Delete
$common_args = $args['args'];
[66] Fix | Delete
unset( $args['args'] );
[67] Fix | Delete
} else {
[68] Fix | Delete
$common_args = array();
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
if ( isset( $args['callback'] ) ) {
[72] Fix | Delete
// Upgrade a single set to multiple.
[73] Fix | Delete
$args = array( $args );
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
$defaults = array(
[77] Fix | Delete
'methods' => 'GET',
[78] Fix | Delete
'callback' => null,
[79] Fix | Delete
'args' => array(),
[80] Fix | Delete
);
[81] Fix | Delete
[82] Fix | Delete
foreach ( $args as $key => &$arg_group ) {
[83] Fix | Delete
if ( ! is_numeric( $key ) ) {
[84] Fix | Delete
// Route option, skip here.
[85] Fix | Delete
continue;
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
$arg_group = array_merge( $defaults, $arg_group );
[89] Fix | Delete
$arg_group['args'] = array_merge( $common_args, $arg_group['args'] );
[90] Fix | Delete
[91] Fix | Delete
if ( ! isset( $arg_group['permission_callback'] ) ) {
[92] Fix | Delete
_doing_it_wrong(
[93] Fix | Delete
__FUNCTION__,
[94] Fix | Delete
sprintf(
[95] Fix | Delete
/* translators: 1: The REST API route being registered, 2: The argument name, 3: The suggested function name. */
[96] Fix | Delete
__( 'The REST API route definition for %1$s is missing the required %2$s argument. For REST API routes that are intended to be public, use %3$s as the permission callback.' ),
[97] Fix | Delete
'<code>' . $clean_namespace . '/' . trim( $route, '/' ) . '</code>',
[98] Fix | Delete
'<code>permission_callback</code>',
[99] Fix | Delete
'<code>__return_true</code>'
[100] Fix | Delete
),
[101] Fix | Delete
'5.5.0'
[102] Fix | Delete
);
[103] Fix | Delete
}
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
$full_route = '/' . $clean_namespace . '/' . trim( $route, '/' );
[107] Fix | Delete
rest_get_server()->register_route( $clean_namespace, $full_route, $args, $override );
[108] Fix | Delete
return true;
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Registers a new field on an existing WordPress object type.
[113] Fix | Delete
*
[114] Fix | Delete
* @since 4.7.0
[115] Fix | Delete
*
[116] Fix | Delete
* @global array $wp_rest_additional_fields Holds registered fields, organized
[117] Fix | Delete
* by object type.
[118] Fix | Delete
*
[119] Fix | Delete
* @param string|array $object_type Object(s) the field is being registered
[120] Fix | Delete
* to, "post"|"term"|"comment" etc.
[121] Fix | Delete
* @param string $attribute The attribute name.
[122] Fix | Delete
* @param array $args {
[123] Fix | Delete
* Optional. An array of arguments used to handle the registered field.
[124] Fix | Delete
*
[125] Fix | Delete
* @type callable|null $get_callback Optional. The callback function used to retrieve the field value. Default is
[126] Fix | Delete
* 'null', the field will not be returned in the response. The function will
[127] Fix | Delete
* be passed the prepared object data.
[128] Fix | Delete
* @type callable|null $update_callback Optional. The callback function used to set and update the field value. Default
[129] Fix | Delete
* is 'null', the value cannot be set or updated. The function will be passed
[130] Fix | Delete
* the model object, like WP_Post.
[131] Fix | Delete
* @type array|null $schema Optional. The schema for this field.
[132] Fix | Delete
* Default is 'null', no schema entry will be returned.
[133] Fix | Delete
* }
[134] Fix | Delete
*/
[135] Fix | Delete
function register_rest_field( $object_type, $attribute, $args = array() ) {
[136] Fix | Delete
$defaults = array(
[137] Fix | Delete
'get_callback' => null,
[138] Fix | Delete
'update_callback' => null,
[139] Fix | Delete
'schema' => null,
[140] Fix | Delete
);
[141] Fix | Delete
[142] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[143] Fix | Delete
[144] Fix | Delete
global $wp_rest_additional_fields;
[145] Fix | Delete
[146] Fix | Delete
$object_types = (array) $object_type;
[147] Fix | Delete
[148] Fix | Delete
foreach ( $object_types as $object_type ) {
[149] Fix | Delete
$wp_rest_additional_fields[ $object_type ][ $attribute ] = $args;
[150] Fix | Delete
}
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
/**
[154] Fix | Delete
* Registers rewrite rules for the REST API.
[155] Fix | Delete
*
[156] Fix | Delete
* @since 4.4.0
[157] Fix | Delete
*
[158] Fix | Delete
* @see rest_api_register_rewrites()
[159] Fix | Delete
* @global WP $wp Current WordPress environment instance.
[160] Fix | Delete
*/
[161] Fix | Delete
function rest_api_init() {
[162] Fix | Delete
rest_api_register_rewrites();
[163] Fix | Delete
[164] Fix | Delete
global $wp;
[165] Fix | Delete
$wp->add_query_var( 'rest_route' );
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
/**
[169] Fix | Delete
* Adds REST rewrite rules.
[170] Fix | Delete
*
[171] Fix | Delete
* @since 4.4.0
[172] Fix | Delete
*
[173] Fix | Delete
* @see add_rewrite_rule()
[174] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[175] Fix | Delete
*/
[176] Fix | Delete
function rest_api_register_rewrites() {
[177] Fix | Delete
global $wp_rewrite;
[178] Fix | Delete
[179] Fix | Delete
add_rewrite_rule( '^' . rest_get_url_prefix() . '/?$', 'index.php?rest_route=/', 'top' );
[180] Fix | Delete
add_rewrite_rule( '^' . rest_get_url_prefix() . '/(.*)?', 'index.php?rest_route=/$matches[1]', 'top' );
[181] Fix | Delete
add_rewrite_rule( '^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/?$', 'index.php?rest_route=/', 'top' );
[182] Fix | Delete
add_rewrite_rule( '^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/(.*)?', 'index.php?rest_route=/$matches[1]', 'top' );
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* Registers the default REST API filters.
[187] Fix | Delete
*
[188] Fix | Delete
* Attached to the {@see 'rest_api_init'} action
[189] Fix | Delete
* to make testing and disabling these filters easier.
[190] Fix | Delete
*
[191] Fix | Delete
* @since 4.4.0
[192] Fix | Delete
*/
[193] Fix | Delete
function rest_api_default_filters() {
[194] Fix | Delete
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
[195] Fix | Delete
// Deprecated reporting.
[196] Fix | Delete
add_action( 'deprecated_function_run', 'rest_handle_deprecated_function', 10, 3 );
[197] Fix | Delete
add_filter( 'deprecated_function_trigger_error', '__return_false' );
[198] Fix | Delete
add_action( 'deprecated_argument_run', 'rest_handle_deprecated_argument', 10, 3 );
[199] Fix | Delete
add_filter( 'deprecated_argument_trigger_error', '__return_false' );
[200] Fix | Delete
add_action( 'doing_it_wrong_run', 'rest_handle_doing_it_wrong', 10, 3 );
[201] Fix | Delete
add_filter( 'doing_it_wrong_trigger_error', '__return_false' );
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
// Default serving.
[205] Fix | Delete
add_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
[206] Fix | Delete
add_filter( 'rest_post_dispatch', 'rest_send_allow_header', 10, 3 );
[207] Fix | Delete
add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
[208] Fix | Delete
[209] Fix | Delete
add_filter( 'rest_pre_dispatch', 'rest_handle_options_request', 10, 3 );
[210] Fix | Delete
add_filter( 'rest_index', 'rest_add_application_passwords_to_index' );
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
/**
[214] Fix | Delete
* Registers default REST API routes.
[215] Fix | Delete
*
[216] Fix | Delete
* @since 4.7.0
[217] Fix | Delete
*/
[218] Fix | Delete
function create_initial_rest_routes() {
[219] Fix | Delete
foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
[220] Fix | Delete
$controller = $post_type->get_rest_controller();
[221] Fix | Delete
[222] Fix | Delete
if ( ! $controller ) {
[223] Fix | Delete
continue;
[224] Fix | Delete
}
[225] Fix | Delete
[226] Fix | Delete
$controller->register_routes();
[227] Fix | Delete
[228] Fix | Delete
if ( post_type_supports( $post_type->name, 'revisions' ) ) {
[229] Fix | Delete
$revisions_controller = new WP_REST_Revisions_Controller( $post_type->name );
[230] Fix | Delete
$revisions_controller->register_routes();
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
if ( 'attachment' !== $post_type->name ) {
[234] Fix | Delete
$autosaves_controller = new WP_REST_Autosaves_Controller( $post_type->name );
[235] Fix | Delete
$autosaves_controller->register_routes();
[236] Fix | Delete
}
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
// Post types.
[240] Fix | Delete
$controller = new WP_REST_Post_Types_Controller;
[241] Fix | Delete
$controller->register_routes();
[242] Fix | Delete
[243] Fix | Delete
// Post statuses.
[244] Fix | Delete
$controller = new WP_REST_Post_Statuses_Controller;
[245] Fix | Delete
$controller->register_routes();
[246] Fix | Delete
[247] Fix | Delete
// Taxonomies.
[248] Fix | Delete
$controller = new WP_REST_Taxonomies_Controller;
[249] Fix | Delete
$controller->register_routes();
[250] Fix | Delete
[251] Fix | Delete
// Terms.
[252] Fix | Delete
foreach ( get_taxonomies( array( 'show_in_rest' => true ), 'object' ) as $taxonomy ) {
[253] Fix | Delete
$controller = $taxonomy->get_rest_controller();
[254] Fix | Delete
[255] Fix | Delete
if ( ! $controller ) {
[256] Fix | Delete
continue;
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
$controller->register_routes();
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
// Users.
[263] Fix | Delete
$controller = new WP_REST_Users_Controller;
[264] Fix | Delete
$controller->register_routes();
[265] Fix | Delete
[266] Fix | Delete
// Application Passwords
[267] Fix | Delete
$controller = new WP_REST_Application_Passwords_Controller();
[268] Fix | Delete
$controller->register_routes();
[269] Fix | Delete
[270] Fix | Delete
// Comments.
[271] Fix | Delete
$controller = new WP_REST_Comments_Controller;
[272] Fix | Delete
$controller->register_routes();
[273] Fix | Delete
[274] Fix | Delete
$search_handlers = array(
[275] Fix | Delete
new WP_REST_Post_Search_Handler(),
[276] Fix | Delete
new WP_REST_Term_Search_Handler(),
[277] Fix | Delete
new WP_REST_Post_Format_Search_Handler(),
[278] Fix | Delete
);
[279] Fix | Delete
[280] Fix | Delete
/**
[281] Fix | Delete
* Filters the search handlers to use in the REST search controller.
[282] Fix | Delete
*
[283] Fix | Delete
* @since 5.0.0
[284] Fix | Delete
*
[285] Fix | Delete
* @param array $search_handlers List of search handlers to use in the controller. Each search
[286] Fix | Delete
* handler instance must extend the `WP_REST_Search_Handler` class.
[287] Fix | Delete
* Default is only a handler for posts.
[288] Fix | Delete
*/
[289] Fix | Delete
$search_handlers = apply_filters( 'wp_rest_search_handlers', $search_handlers );
[290] Fix | Delete
[291] Fix | Delete
$controller = new WP_REST_Search_Controller( $search_handlers );
[292] Fix | Delete
$controller->register_routes();
[293] Fix | Delete
[294] Fix | Delete
// Block Renderer.
[295] Fix | Delete
$controller = new WP_REST_Block_Renderer_Controller;
[296] Fix | Delete
$controller->register_routes();
[297] Fix | Delete
[298] Fix | Delete
// Block Types.
[299] Fix | Delete
$controller = new WP_REST_Block_Types_Controller();
[300] Fix | Delete
$controller->register_routes();
[301] Fix | Delete
[302] Fix | Delete
// Settings.
[303] Fix | Delete
$controller = new WP_REST_Settings_Controller;
[304] Fix | Delete
$controller->register_routes();
[305] Fix | Delete
[306] Fix | Delete
// Themes.
[307] Fix | Delete
$controller = new WP_REST_Themes_Controller;
[308] Fix | Delete
$controller->register_routes();
[309] Fix | Delete
[310] Fix | Delete
// Plugins.
[311] Fix | Delete
$controller = new WP_REST_Plugins_Controller();
[312] Fix | Delete
$controller->register_routes();
[313] Fix | Delete
[314] Fix | Delete
// Block Directory.
[315] Fix | Delete
$controller = new WP_REST_Block_Directory_Controller();
[316] Fix | Delete
$controller->register_routes();
[317] Fix | Delete
[318] Fix | Delete
// Site Health.
[319] Fix | Delete
$site_health = WP_Site_Health::get_instance();
[320] Fix | Delete
$controller = new WP_REST_Site_Health_Controller( $site_health );
[321] Fix | Delete
$controller->register_routes();
[322] Fix | Delete
}
[323] Fix | Delete
[324] Fix | Delete
/**
[325] Fix | Delete
* Loads the REST API.
[326] Fix | Delete
*
[327] Fix | Delete
* @since 4.4.0
[328] Fix | Delete
*
[329] Fix | Delete
* @global WP $wp Current WordPress environment instance.
[330] Fix | Delete
*/
[331] Fix | Delete
function rest_api_loaded() {
[332] Fix | Delete
if ( empty( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
[333] Fix | Delete
return;
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
/**
[337] Fix | Delete
* Whether this is a REST Request.
[338] Fix | Delete
*
[339] Fix | Delete
* @since 4.4.0
[340] Fix | Delete
* @var bool
[341] Fix | Delete
*/
[342] Fix | Delete
define( 'REST_REQUEST', true );
[343] Fix | Delete
[344] Fix | Delete
// Initialize the server.
[345] Fix | Delete
$server = rest_get_server();
[346] Fix | Delete
[347] Fix | Delete
// Fire off the request.
[348] Fix | Delete
$route = untrailingslashit( $GLOBALS['wp']->query_vars['rest_route'] );
[349] Fix | Delete
if ( empty( $route ) ) {
[350] Fix | Delete
$route = '/';
[351] Fix | Delete
}
[352] Fix | Delete
$server->serve_request( $route );
[353] Fix | Delete
[354] Fix | Delete
// We're done.
[355] Fix | Delete
die();
[356] Fix | Delete
}
[357] Fix | Delete
[358] Fix | Delete
/**
[359] Fix | Delete
* Retrieves the URL prefix for any API resource.
[360] Fix | Delete
*
[361] Fix | Delete
* @since 4.4.0
[362] Fix | Delete
*
[363] Fix | Delete
* @return string Prefix.
[364] Fix | Delete
*/
[365] Fix | Delete
function rest_get_url_prefix() {
[366] Fix | Delete
/**
[367] Fix | Delete
* Filters the REST URL prefix.
[368] Fix | Delete
*
[369] Fix | Delete
* @since 4.4.0
[370] Fix | Delete
*
[371] Fix | Delete
* @param string $prefix URL prefix. Default 'wp-json'.
[372] Fix | Delete
*/
[373] Fix | Delete
return apply_filters( 'rest_url_prefix', 'wp-json' );
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
/**
[377] Fix | Delete
* Retrieves the URL to a REST endpoint on a site.
[378] Fix | Delete
*
[379] Fix | Delete
* Note: The returned URL is NOT escaped.
[380] Fix | Delete
*
[381] Fix | Delete
* @since 4.4.0
[382] Fix | Delete
*
[383] Fix | Delete
* @todo Check if this is even necessary
[384] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[385] Fix | Delete
*
[386] Fix | Delete
* @param int|null $blog_id Optional. Blog ID. Default of null returns URL for current blog.
[387] Fix | Delete
* @param string $path Optional. REST route. Default '/'.
[388] Fix | Delete
* @param string $scheme Optional. Sanitization scheme. Default 'rest'.
[389] Fix | Delete
* @return string Full URL to the endpoint.
[390] Fix | Delete
*/
[391] Fix | Delete
function get_rest_url( $blog_id = null, $path = '/', $scheme = 'rest' ) {
[392] Fix | Delete
if ( empty( $path ) ) {
[393] Fix | Delete
$path = '/';
[394] Fix | Delete
}
[395] Fix | Delete
[396] Fix | Delete
$path = '/' . ltrim( $path, '/' );
[397] Fix | Delete
[398] Fix | Delete
if ( is_multisite() && get_blog_option( $blog_id, 'permalink_structure' ) || get_option( 'permalink_structure' ) ) {
[399] Fix | Delete
global $wp_rewrite;
[400] Fix | Delete
[401] Fix | Delete
if ( $wp_rewrite->using_index_permalinks() ) {
[402] Fix | Delete
$url = get_home_url( $blog_id, $wp_rewrite->index . '/' . rest_get_url_prefix(), $scheme );
[403] Fix | Delete
} else {
[404] Fix | Delete
$url = get_home_url( $blog_id, rest_get_url_prefix(), $scheme );
[405] Fix | Delete
}
[406] Fix | Delete
[407] Fix | Delete
$url .= $path;
[408] Fix | Delete
} else {
[409] Fix | Delete
$url = trailingslashit( get_home_url( $blog_id, '', $scheme ) );
[410] Fix | Delete
// nginx only allows HTTP/1.0 methods when redirecting from / to /index.php.
[411] Fix | Delete
// To work around this, we manually add index.php to the URL, avoiding the redirect.
[412] Fix | Delete
if ( 'index.php' !== substr( $url, 9 ) ) {
[413] Fix | Delete
$url .= 'index.php';
[414] Fix | Delete
}
[415] Fix | Delete
[416] Fix | Delete
$url = add_query_arg( 'rest_route', $path, $url );
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
if ( is_ssl() && isset( $_SERVER['SERVER_NAME'] ) ) {
[420] Fix | Delete
// If the current host is the same as the REST URL host, force the REST URL scheme to HTTPS.
[421] Fix | Delete
if ( parse_url( get_home_url( $blog_id ), PHP_URL_HOST ) === $_SERVER['SERVER_NAME'] ) {
[422] Fix | Delete
$url = set_url_scheme( $url, 'https' );
[423] Fix | Delete
}
[424] Fix | Delete
}
[425] Fix | Delete
[426] Fix | Delete
if ( is_admin() && force_ssl_admin() ) {
[427] Fix | Delete
/*
[428] Fix | Delete
* In this situation the home URL may be http:, and `is_ssl()` may be false,
[429] Fix | Delete
* but the admin is served over https: (one way or another), so REST API usage
[430] Fix | Delete
* will be blocked by browsers unless it is also served over HTTPS.
[431] Fix | Delete
*/
[432] Fix | Delete
$url = set_url_scheme( $url, 'https' );
[433] Fix | Delete
}
[434] Fix | Delete
[435] Fix | Delete
/**
[436] Fix | Delete
* Filters the REST URL.
[437] Fix | Delete
*
[438] Fix | Delete
* Use this filter to adjust the url returned by the get_rest_url() function.
[439] Fix | Delete
*
[440] Fix | Delete
* @since 4.4.0
[441] Fix | Delete
*
[442] Fix | Delete
* @param string $url REST URL.
[443] Fix | Delete
* @param string $path REST route.
[444] Fix | Delete
* @param int|null $blog_id Blog ID.
[445] Fix | Delete
* @param string $scheme Sanitization scheme.
[446] Fix | Delete
*/
[447] Fix | Delete
return apply_filters( 'rest_url', $url, $path, $blog_id, $scheme );
[448] Fix | Delete
}
[449] Fix | Delete
[450] Fix | Delete
/**
[451] Fix | Delete
* Retrieves the URL to a REST endpoint.
[452] Fix | Delete
*
[453] Fix | Delete
* Note: The returned URL is NOT escaped.
[454] Fix | Delete
*
[455] Fix | Delete
* @since 4.4.0
[456] Fix | Delete
*
[457] Fix | Delete
* @param string $path Optional. REST route. Default empty.
[458] Fix | Delete
* @param string $scheme Optional. Sanitization scheme. Default 'rest'.
[459] Fix | Delete
* @return string Full URL to the endpoint.
[460] Fix | Delete
*/
[461] Fix | Delete
function rest_url( $path = '', $scheme = 'rest' ) {
[462] Fix | Delete
return get_rest_url( null, $path, $scheme );
[463] Fix | Delete
}
[464] Fix | Delete
[465] Fix | Delete
/**
[466] Fix | Delete
* Do a REST request.
[467] Fix | Delete
*
[468] Fix | Delete
* Used primarily to route internal requests through WP_REST_Server.
[469] Fix | Delete
*
[470] Fix | Delete
* @since 4.4.0
[471] Fix | Delete
*
[472] Fix | Delete
* @param WP_REST_Request|string $request Request.
[473] Fix | Delete
* @return WP_REST_Response REST response.
[474] Fix | Delete
*/
[475] Fix | Delete
function rest_do_request( $request ) {
[476] Fix | Delete
$request = rest_ensure_request( $request );
[477] Fix | Delete
return rest_get_server()->dispatch( $request );
[478] Fix | Delete
}
[479] Fix | Delete
[480] Fix | Delete
/**
[481] Fix | Delete
* Retrieves the current REST server instance.
[482] Fix | Delete
*
[483] Fix | Delete
* Instantiates a new instance if none exists already.
[484] Fix | Delete
*
[485] Fix | Delete
* @since 4.5.0
[486] Fix | Delete
*
[487] Fix | Delete
* @global WP_REST_Server $wp_rest_server REST server instance.
[488] Fix | Delete
*
[489] Fix | Delete
* @return WP_REST_Server REST server instance.
[490] Fix | Delete
*/
[491] Fix | Delete
function rest_get_server() {
[492] Fix | Delete
/* @var WP_REST_Server $wp_rest_server */
[493] Fix | Delete
global $wp_rest_server;
[494] Fix | Delete
[495] Fix | Delete
if ( empty( $wp_rest_server ) ) {
[496] Fix | Delete
/**
[497] Fix | Delete
* Filters the REST Server Class.
[498] Fix | Delete
*
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function