Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/sal
File: class.json-api-links.php
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
[0] Fix | Delete
/**
[1] Fix | Delete
* WPCOM_JSON_API_Links class.
[2] Fix | Delete
*
[3] Fix | Delete
* @package automattic/jetpack
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[7] Fix | Delete
exit( 0 );
[8] Fix | Delete
}
[9] Fix | Delete
[10] Fix | Delete
require_once __DIR__ . '/../class.json-api.php';
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Base class for WPCOM_JSON_API_Links.
[14] Fix | Delete
*/
[15] Fix | Delete
class WPCOM_JSON_API_Links {
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* An instance of the WPCOM_JSON_API.
[19] Fix | Delete
*
[20] Fix | Delete
* @var WPCOM_JSON_API
[21] Fix | Delete
*/
[22] Fix | Delete
private $api;
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* A WPCOM_JSON_API_Links instance.
[26] Fix | Delete
*
[27] Fix | Delete
* @var WPCOM_JSON_API_Links
[28] Fix | Delete
*/
[29] Fix | Delete
private static $instance;
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* An array of the closest supported version of an endpoint to the current endpoint.
[33] Fix | Delete
*
[34] Fix | Delete
* @var array
[35] Fix | Delete
*/
[36] Fix | Delete
private $closest_endpoint_cache_by_version = array();
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* An array including the current api endpoint as well as the max versions found if that endpoint doesn't exist.
[40] Fix | Delete
*
[41] Fix | Delete
* @var array
[42] Fix | Delete
*/
[43] Fix | Delete
private $matches_by_version = array();
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* An array including the cached endpoint path versions.
[47] Fix | Delete
*
[48] Fix | Delete
* @var array
[49] Fix | Delete
*/
[50] Fix | Delete
private $cache_result = null;
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Creates a new instance of the WPCOM_JSON_API_Links class.
[54] Fix | Delete
*
[55] Fix | Delete
* @return WPCOM_JSON_API_Links
[56] Fix | Delete
*/
[57] Fix | Delete
public static function getInstance() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
[58] Fix | Delete
if ( null === self::$instance ) {
[59] Fix | Delete
self::$instance = new self();
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
return self::$instance;
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
/**
[66] Fix | Delete
* WPCOM_JSON_API_Links constructor.
[67] Fix | Delete
*
[68] Fix | Delete
* Method protected for singleton.
[69] Fix | Delete
*/
[70] Fix | Delete
protected function __construct() {
[71] Fix | Delete
$this->api = WPCOM_JSON_API::init();
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* An empty, private __clone method to prohibit cloning of this instance.
[76] Fix | Delete
*/
[77] Fix | Delete
private function __clone() { }
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Overriding PHP's default __wakeup method to prvent unserializing of the instance, and return an error message.
[81] Fix | Delete
*
[82] Fix | Delete
* @return never
[83] Fix | Delete
*/
[84] Fix | Delete
public function __wakeup() {
[85] Fix | Delete
die( "Please don't __wakeup WPCOM_JSON_API_Links" );
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
/**
[89] Fix | Delete
* Generate a URL to an endpoint
[90] Fix | Delete
*
[91] Fix | Delete
* Used to construct meta links in API responses
[92] Fix | Delete
*
[93] Fix | Delete
* @param mixed ...$args Optional arguments to be appended to URL.
[94] Fix | Delete
* @return string Endpoint URL
[95] Fix | Delete
**/
[96] Fix | Delete
public function get_link( ...$args ) {
[97] Fix | Delete
$format = array_shift( $args );
[98] Fix | Delete
$base = WPCOM_JSON_API__BASE;
[99] Fix | Delete
[100] Fix | Delete
$path = array_pop( $args );
[101] Fix | Delete
[102] Fix | Delete
if ( $path ) {
[103] Fix | Delete
$path = '/' . ltrim( $path, '/' );
[104] Fix | Delete
// tack the path onto the end of the format string.
[105] Fix | Delete
// have to escape %'s in the path as %% because
[106] Fix | Delete
// we're about to pass it through sprintf and we don't
[107] Fix | Delete
// want it to see the % as a placeholder.
[108] Fix | Delete
$format .= str_replace( '%', '%%', $path );
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
// Escape any % in args before using sprintf.
[112] Fix | Delete
$escaped_args = array();
[113] Fix | Delete
foreach ( $args as $arg_key => $arg_value ) {
[114] Fix | Delete
$escaped_args[ $arg_key ] = str_replace( '%', '%%', $arg_value );
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
$relative_path = vsprintf( $format, $escaped_args );
[118] Fix | Delete
[119] Fix | Delete
if ( ! wp_startswith( $relative_path, '.' ) ) {
[120] Fix | Delete
// Generic version. Match the requested version as best we can.
[121] Fix | Delete
$api_version = $this->get_closest_version_of_endpoint( $format, $relative_path );
[122] Fix | Delete
$base = substr( $base, 0, - 1 ) . $api_version;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
// escape any % in the relative path before running it through sprintf again.
[126] Fix | Delete
$relative_path = str_replace( '%', '%%', $relative_path );
[127] Fix | Delete
// http, WPCOM_JSON_API__BASE, ... , path.
[128] Fix | Delete
// %s , %s , $format, %s.
[129] Fix | Delete
return esc_url_raw( sprintf( "https://%s$relative_path", $base ) );
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
/**
[133] Fix | Delete
* Generate the /me prefixed endpoint URL
[134] Fix | Delete
*
[135] Fix | Delete
* Used to construct meta links in API responses, specific to WordPress.com user account pages.
[136] Fix | Delete
*
[137] Fix | Delete
* @param string $path Optional path to be appended to the URL.
[138] Fix | Delete
* @return string /me endpoint URL
[139] Fix | Delete
**/
[140] Fix | Delete
public function get_me_link( $path = '' ) {
[141] Fix | Delete
return $this->get_link( '/me', $path );
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* Generate the endpoint URL for taxonomies
[146] Fix | Delete
*
[147] Fix | Delete
* Used to construct meta links in API responses, specific to taxonomies.
[148] Fix | Delete
*
[149] Fix | Delete
* @param int $blog_id The site's Jetpack blog ID.
[150] Fix | Delete
* @param int $taxonomy_id The taxonomy ID (for example of the category, tag).
[151] Fix | Delete
* @param string $taxonomy_type The taxonomy type (for example category, tag).
[152] Fix | Delete
* @param string $path Optional path to be appended to the URL.
[153] Fix | Delete
* @return string Endpoint URL including taxonomy information.
[154] Fix | Delete
**/
[155] Fix | Delete
public function get_taxonomy_link( $blog_id, $taxonomy_id, $taxonomy_type, $path = '' ) {
[156] Fix | Delete
switch ( $taxonomy_type ) {
[157] Fix | Delete
case 'category':
[158] Fix | Delete
return $this->get_link( '/sites/%d/categories/slug:%s', $blog_id, $taxonomy_id, $path );
[159] Fix | Delete
[160] Fix | Delete
case 'post_tag':
[161] Fix | Delete
return $this->get_link( '/sites/%d/tags/slug:%s', $blog_id, $taxonomy_id, $path );
[162] Fix | Delete
[163] Fix | Delete
default:
[164] Fix | Delete
return $this->get_link( '/sites/%d/taxonomies/%s/terms/slug:%s', $blog_id, $taxonomy_type, $taxonomy_id, $path );
[165] Fix | Delete
}
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
/**
[169] Fix | Delete
* Generate the endpoint URL for media links
[170] Fix | Delete
*
[171] Fix | Delete
* Used to construct meta links in API responses, specific to media links.
[172] Fix | Delete
*
[173] Fix | Delete
* @param int $blog_id The site's Jetpack blog ID.
[174] Fix | Delete
* @param int $media_id The media item ID.
[175] Fix | Delete
* @param string $path Optional path to be appended to the URL.
[176] Fix | Delete
* @return string Endpoint URL including media information.
[177] Fix | Delete
**/
[178] Fix | Delete
public function get_media_link( $blog_id, $media_id, $path = '' ) {
[179] Fix | Delete
return $this->get_link( '/sites/%d/media/%d', $blog_id, $media_id, $path );
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
/**
[183] Fix | Delete
* Generate the site link endpoint URL
[184] Fix | Delete
*
[185] Fix | Delete
* Used to construct meta links in API responses, specific to /site links.
[186] Fix | Delete
*
[187] Fix | Delete
* @param int $blog_id The site's Jetpack blog ID.
[188] Fix | Delete
* @param string $path Optional path to be appended to the URL.
[189] Fix | Delete
* @return string Endpoint URL including site information.
[190] Fix | Delete
**/
[191] Fix | Delete
public function get_site_link( $blog_id, $path = '' ) {
[192] Fix | Delete
return $this->get_link( '/sites/%d', $blog_id, $path );
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
/**
[196] Fix | Delete
* Generate the posts endpoint URL
[197] Fix | Delete
*
[198] Fix | Delete
* Used to construct meta links in API responses, specific to posts links.
[199] Fix | Delete
*
[200] Fix | Delete
* @param int $blog_id The site's Jetpack blog ID.
[201] Fix | Delete
* @param int $post_id The post ID.
[202] Fix | Delete
* @param string $path Optional path to be appended to the URL.
[203] Fix | Delete
* @return string Endpoint URL including post information.
[204] Fix | Delete
**/
[205] Fix | Delete
public function get_post_link( $blog_id, $post_id, $path = '' ) {
[206] Fix | Delete
return $this->get_link( '/sites/%d/posts/%d', $blog_id, $post_id, $path );
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* Generate the comments endpoint URL
[211] Fix | Delete
*
[212] Fix | Delete
* Used to construct meta links in API responses, specific to comments links.
[213] Fix | Delete
*
[214] Fix | Delete
* @param int $blog_id The site's Jetpack blog ID.
[215] Fix | Delete
* @param int $comment_id The comment ID.
[216] Fix | Delete
* @param string $path Optional path to be appended to the URL.
[217] Fix | Delete
* @return string Endpoint URL including comment information.
[218] Fix | Delete
**/
[219] Fix | Delete
public function get_comment_link( $blog_id, $comment_id, $path = '' ) {
[220] Fix | Delete
return $this->get_link( '/sites/%d/comments/%d', $blog_id, $comment_id, $path );
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
/**
[224] Fix | Delete
* Generate the endpoint URL for Publicize connections
[225] Fix | Delete
*
[226] Fix | Delete
* Used to construct meta links in API responses, specific to Publicize connections.
[227] Fix | Delete
*
[228] Fix | Delete
* @param int $blog_id The site's Jetpack blog ID.
[229] Fix | Delete
* @param int $publicize_connection_id The ID of the Publicize connection.
[230] Fix | Delete
* @param string $path Optional path to be appended to the URL.
[231] Fix | Delete
* @return string Endpoint URL including Publicize connection information.
[232] Fix | Delete
**/
[233] Fix | Delete
public function get_publicize_connection_link( $blog_id, $publicize_connection_id, $path = '' ) {
[234] Fix | Delete
return $this->get_link( '.1/sites/%d/publicize-connections/%d', $blog_id, $publicize_connection_id, $path );
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
/**
[238] Fix | Delete
* Generate the endpoint URL for a single Publicize connection including a Keyring connection
[239] Fix | Delete
*
[240] Fix | Delete
* Used to construct meta links in API responses, specific to a single Publicize and Keyring connection.
[241] Fix | Delete
*
[242] Fix | Delete
* @param int $keyring_token_id The ID of the Keyring connection.
[243] Fix | Delete
* @param string $path Optional path to be appended to the URL.
[244] Fix | Delete
* @return string Endpoint URL including specific Keyring connection information for a specific Publicize connection.
[245] Fix | Delete
**/
[246] Fix | Delete
public function get_publicize_connections_link( $keyring_token_id, $path = '' ) {
[247] Fix | Delete
return $this->get_link( '.1/me/publicize-connections/?keyring_connection_ID=%d', $keyring_token_id, $path );
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
/**
[251] Fix | Delete
* Generate the endpoint URL for a single Keyring connection
[252] Fix | Delete
*
[253] Fix | Delete
* Used to construct meta links in API responses, specific to a Keyring connections.
[254] Fix | Delete
*
[255] Fix | Delete
* @param int $keyring_token_id The ID of the Keyring connection.
[256] Fix | Delete
* @param string $path Optional path to be appended to the URL.
[257] Fix | Delete
* @return string Endpoint URL including specific Keyring connection.
[258] Fix | Delete
**/
[259] Fix | Delete
public function get_keyring_connection_link( $keyring_token_id, $path = '' ) {
[260] Fix | Delete
return $this->get_link( '.1/me/keyring-connections/%d', $keyring_token_id, $path );
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
/**
[264] Fix | Delete
* Generate the endpoint URL for an external service that can be integrated with via Keyring
[265] Fix | Delete
*
[266] Fix | Delete
* Used to construct meta links in API responses, specific to an external service.
[267] Fix | Delete
*
[268] Fix | Delete
* @param int $external_service The ID of the external service.
[269] Fix | Delete
* @param string $path Optional path to be appended to the URL.
[270] Fix | Delete
* @return string Endpoint URL including information about an external service that WordPress.com or Jetpack sites can integrate with via keyring.
[271] Fix | Delete
**/
[272] Fix | Delete
public function get_external_service_link( $external_service, $path = '' ) {
[273] Fix | Delete
return $this->get_link( '.1/meta/external-services/%s', $external_service, $path );
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
/**
[277] Fix | Delete
* Try to find the closest supported version of an endpoint to the current endpoint
[278] Fix | Delete
*
[279] Fix | Delete
* For example, if we were looking at the path /animals/panda:
[280] Fix | Delete
* - if the current endpoint is v1.3 and there is a v1.3 of /animals/%s available, we return 1.3
[281] Fix | Delete
* - if the current endpoint is v1.3 and there is no v1.3 of /animals/%s known, we fall back to the
[282] Fix | Delete
* maximum available version of /animals/%s, e.g. 1.1
[283] Fix | Delete
*
[284] Fix | Delete
* This method is used in get_link() to construct meta links for API responses.
[285] Fix | Delete
*
[286] Fix | Delete
* @param string $template_path The generic endpoint path, e.g. /sites/%s .
[287] Fix | Delete
* @param string $path The current endpoint path, relative to the version, e.g. /sites/12345 .
[288] Fix | Delete
* @param string $request_method Request method used to access the endpoint path .
[289] Fix | Delete
* @return string The current version, or otherwise the maximum version available
[290] Fix | Delete
*/
[291] Fix | Delete
public function get_closest_version_of_endpoint( $template_path, $path, $request_method = 'GET' ) {
[292] Fix | Delete
$closest_endpoint_cache_by_version = & $this->closest_endpoint_cache_by_version;
[293] Fix | Delete
[294] Fix | Delete
$closest_endpoint_cache = & $closest_endpoint_cache_by_version[ $this->api->version ];
[295] Fix | Delete
if ( ! $closest_endpoint_cache ) {
[296] Fix | Delete
$closest_endpoint_cache_by_version[ $this->api->version ] = array();
[297] Fix | Delete
$closest_endpoint_cache = & $closest_endpoint_cache_by_version[ $this->api->version ];
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
if ( ! isset( $closest_endpoint_cache[ $template_path ] ) ) {
[301] Fix | Delete
$closest_endpoint_cache[ $template_path ] = array();
[302] Fix | Delete
} elseif ( isset( $closest_endpoint_cache[ $template_path ][ $request_method ] ) ) {
[303] Fix | Delete
return $closest_endpoint_cache[ $template_path ][ $request_method ];
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
$path = untrailingslashit( $path );
[307] Fix | Delete
[308] Fix | Delete
// /help is a special case - always use the current request version
[309] Fix | Delete
if ( wp_endswith( $path, '/help' ) ) {
[310] Fix | Delete
$closest_endpoint_cache[ $template_path ][ $request_method ] = $this->api->version;
[311] Fix | Delete
return $this->api->version;
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
$matches_by_version = & $this->matches_by_version;
[315] Fix | Delete
[316] Fix | Delete
// try to match out of saved matches.
[317] Fix | Delete
if ( ! isset( $matches_by_version[ $this->api->version ] ) ) {
[318] Fix | Delete
$matches_by_version[ $this->api->version ] = array();
[319] Fix | Delete
}
[320] Fix | Delete
foreach ( $matches_by_version[ $this->api->version ] as $match ) {
[321] Fix | Delete
$regex = $match->regex;
[322] Fix | Delete
if ( preg_match( "#^$regex\$#", $path ) ) {
[323] Fix | Delete
$closest_endpoint_cache[ $template_path ][ $request_method ] = $match->version;
[324] Fix | Delete
return $match->version;
[325] Fix | Delete
}
[326] Fix | Delete
}
[327] Fix | Delete
[328] Fix | Delete
$endpoint_path_versions = $this->get_endpoint_path_versions();
[329] Fix | Delete
$last_path_segment = $this->get_last_segment_of_relative_path( $path );
[330] Fix | Delete
$max_version_found = null;
[331] Fix | Delete
[332] Fix | Delete
foreach ( $endpoint_path_versions as $endpoint_last_path_segment => $endpoints ) {
[333] Fix | Delete
[334] Fix | Delete
// Does the last part of the path match the path key? (e.g. 'posts')
[335] Fix | Delete
// If the last part contains a placeholder (e.g. %s), we want to carry on.
[336] Fix | Delete
// phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual
[337] Fix | Delete
if ( $last_path_segment != $endpoint_last_path_segment && ! strstr( $endpoint_last_path_segment, '%' ) ) {
[338] Fix | Delete
continue;
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
foreach ( $endpoints as $endpoint ) {
[342] Fix | Delete
// Does the request method match?
[343] Fix | Delete
if ( ! in_array( $request_method, $endpoint['request_methods'], true ) ) {
[344] Fix | Delete
continue;
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
$endpoint_path = untrailingslashit( (string) $endpoint['path'] );
[348] Fix | Delete
$endpoint_path_regex = str_replace( array( '%s', '%d' ), array( '([^/?&]+)', '(\d+)' ), $endpoint_path );
[349] Fix | Delete
[350] Fix | Delete
if ( ! preg_match( "#^$endpoint_path_regex\$#", $path ) ) {
[351] Fix | Delete
continue;
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
// Make sure the endpoint exists at the same version.
[355] Fix | Delete
if ( null !== $this->api->version &&
[356] Fix | Delete
version_compare( $this->api->version, $endpoint['min_version'], '>=' ) &&
[357] Fix | Delete
version_compare( $this->api->version, $endpoint['max_version'], '<=' )
[358] Fix | Delete
) {
[359] Fix | Delete
array_push(
[360] Fix | Delete
$matches_by_version[ $this->api->version ],
[361] Fix | Delete
(object) array(
[362] Fix | Delete
'version' => $this->api->version,
[363] Fix | Delete
'regex' => $endpoint_path_regex,
[364] Fix | Delete
)
[365] Fix | Delete
);
[366] Fix | Delete
$closest_endpoint_cache[ $template_path ][ $request_method ] = $this->api->version;
[367] Fix | Delete
return $this->api->version;
[368] Fix | Delete
}
[369] Fix | Delete
[370] Fix | Delete
// If the endpoint doesn't exist at the same version, record the max version we found.
[371] Fix | Delete
if ( empty( $max_version_found ) || version_compare( $max_version_found['version'], $endpoint['max_version'], '<' ) ) {
[372] Fix | Delete
$max_version_found = array(
[373] Fix | Delete
'version' => $endpoint['max_version'],
[374] Fix | Delete
'regex' => $endpoint_path_regex,
[375] Fix | Delete
);
[376] Fix | Delete
}
[377] Fix | Delete
}
[378] Fix | Delete
}
[379] Fix | Delete
[380] Fix | Delete
// If the endpoint version is less than the requested endpoint version, return the max version found.
[381] Fix | Delete
if ( ! empty( $max_version_found ) ) {
[382] Fix | Delete
array_push(
[383] Fix | Delete
$matches_by_version[ $this->api->version ],
[384] Fix | Delete
(object) $max_version_found
[385] Fix | Delete
);
[386] Fix | Delete
$closest_endpoint_cache[ $template_path ][ $request_method ] = $max_version_found['version'];
[387] Fix | Delete
return $max_version_found['version'];
[388] Fix | Delete
}
[389] Fix | Delete
[390] Fix | Delete
// Otherwise, use the API version of the current request.
[391] Fix | Delete
return $this->api->version;
[392] Fix | Delete
}
[393] Fix | Delete
[394] Fix | Delete
/**
[395] Fix | Delete
* Get an array of endpoint paths with their associated versions
[396] Fix | Delete
*
[397] Fix | Delete
* @return array Array of endpoint paths, min_versions and max_versions, keyed by last segment of path
[398] Fix | Delete
**/
[399] Fix | Delete
protected function get_endpoint_path_versions() {
[400] Fix | Delete
[401] Fix | Delete
if ( ! empty( $this->cache_result ) ) {
[402] Fix | Delete
return $this->cache_result;
[403] Fix | Delete
}
[404] Fix | Delete
[405] Fix | Delete
/*
[406] Fix | Delete
* Create a map of endpoints and their min/max versions keyed by the last segment of the path (e.g. 'posts')
[407] Fix | Delete
* This reduces the search space when finding endpoint matches in get_closest_version_of_endpoint()
[408] Fix | Delete
*/
[409] Fix | Delete
$endpoint_path_versions = array();
[410] Fix | Delete
[411] Fix | Delete
foreach ( $this->api->endpoints as $key => $endpoint_objects ) {
[412] Fix | Delete
[413] Fix | Delete
// @todo As with the todo in class.json-api.php, we need to determine if anything depends on this being serialized and hence unserialized, rather than e.g. JSON.
[414] Fix | Delete
// The key contains a serialized path, min_version and max_version.
[415] Fix | Delete
list( $path, $min_version, $max_version ) = unserialize( $key ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize -- Legacy, see serialization at class.json-api.php.
[416] Fix | Delete
[417] Fix | Delete
// Grab the last component of the relative path to use as the top-level key.
[418] Fix | Delete
$last_path_segment = $this->get_last_segment_of_relative_path( $path );
[419] Fix | Delete
[420] Fix | Delete
$endpoint_path_versions[ $last_path_segment ][] = array(
[421] Fix | Delete
'path' => $path,
[422] Fix | Delete
'min_version' => $min_version,
[423] Fix | Delete
'max_version' => $max_version,
[424] Fix | Delete
'request_methods' => array_keys( $endpoint_objects ),
[425] Fix | Delete
);
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
$this->cache_result = $endpoint_path_versions;
[429] Fix | Delete
[430] Fix | Delete
return $endpoint_path_versions;
[431] Fix | Delete
}
[432] Fix | Delete
[433] Fix | Delete
/**
[434] Fix | Delete
* Grab the last segment of a relative path
[435] Fix | Delete
*
[436] Fix | Delete
* @param string $path Path.
[437] Fix | Delete
* @return string Last path segment
[438] Fix | Delete
*/
[439] Fix | Delete
protected function get_last_segment_of_relative_path( $path ) {
[440] Fix | Delete
$path_parts = array_filter( explode( '/', $path ) );
[441] Fix | Delete
[442] Fix | Delete
if ( empty( $path_parts ) ) {
[443] Fix | Delete
return null;
[444] Fix | Delete
}
[445] Fix | Delete
[446] Fix | Delete
return end( $path_parts );
[447] Fix | Delete
}
[448] Fix | Delete
}
[449] Fix | Delete
[450] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function