| Server IP : 217.11.249.137 / Your IP : 216.73.216.54 Web Server : Apache System : FreeBSD triton.blueboard.cz 13.5-STABLE FreeBSD 13.5-STABLE stable/13-a3d32f9e6 GENERIC amd64 User : www ( 80) PHP Version : 8.0.30 Disable Function : ini_restore, show_source, socket_select, socket_create_listen, socket_create_pair, socket_listen, socket_strerror, shell_exec, proc_nice, proc_terminate, readlink, symlink, link, pfsocketopen, ini_alter, dl, pcntl_exec, pcntl_fork, pcntl_signal, pcntl_waitpid, pcntl_wexitstatus, pcntl_wifexited, pcntl_wifsignaled, pcntl_wifsignaled, pcntl_wifstoped, pcntl_wifstopsig, pcntl_wtermsig, socket_accept, socket_bind, socket_create, socket_create_listen, popen, zlib_decode MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /data/www/24781/extramagazin_cz/www/wp-content/plugins/amp/src/Admin/ |
Upload File : |
<?php
/**
* Class RESTPreloader.
*
* @package AmpProject\AmpWP
*/
namespace AmpProject\AmpWP\Admin;
use AmpProject\AmpWP\Infrastructure\Service;
/**
* Preloads REST responses for client-side applications to prevent having to call fetch on page load.
*
* @package AmpProject\AmpWP
* @since 2.0
* @internal
*/
final class RESTPreloader implements Service {
/**
* Paths to preload.
*
* @var array
*/
private $paths = [];
/**
* Adds a REST path to be preloaded.
*
* @param string $path A REST path to cache for apiFetch middleware.
*/
public function add_preloaded_path( $path ) {
// Delay adding the preload_data action hook until after a path is added.
if ( empty( $this->paths ) ) {
add_action( 'admin_enqueue_scripts', [ $this, 'preload_data' ], 99 );
}
if ( ! in_array( $path, $this->paths, true ) ) {
$this->paths[] = $path;
}
}
/**
* Preloads data using apiFetch preloading middleware.
*/
public function preload_data() {
if ( ! function_exists( 'rest_preload_api_request' ) ) { // Not available pre-5.0.
return;
}
$preload_data = array_reduce( $this->paths, 'rest_preload_api_request', [] );
wp_add_inline_script(
'wp-api-fetch',
sprintf( 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );', wp_json_encode( $preload_data ) ),
'after'
);
}
}