/** * Get URL to a REST endpoint on a site. * * @todo Check if this is even necessary * * @param int $blog_id Blog ID. Optional. The ID of the multisite blog to get URL for. Default null of null returns URL for current blog. * @param string $path Optional. REST route. Default empty. * @param string $scheme Optional. Sanitization scheme. Default 'json'. * @return string Full URL to the endpoint. */ function get_vp_rest_url($blog_id = null, $path = '', $scheme = 'json') { if (get_option('permalink_structure')) { $url = trailingslashit(get_home_url($blog_id, vp_rest_get_url_prefix(), $scheme)); if (!empty($path) && is_string($path) && strpos($path, '..') === false) { $url .= '/' . ltrim($path, '/'); } } else { $url = trailingslashit(get_home_url($blog_id, '', $scheme)); if (empty($path)) { $path = '/'; } else { $path = '/' . ltrim($path, '/'); } $url = add_query_arg('vp_rest_route', $path, $url); } /** * Filter the REST URL. * * @since 1.0 * * @param string $url REST URL. * @param string $path REST route. * @param int $blod_ig Blog ID. * @param string $scheme Sanitization scheme. */ return apply_filters('vp_rest_url', $url, $path, $blog_id, $scheme); }
<?php $apiConfig = array('root' => get_site_url(), 'urlPrefix' => vp_rest_get_url_prefix(), 'queryParam' => 'vp_rest_route', 'permalinkStructure' => get_option('permalink_structure'), 'nonce' => wp_create_nonce('wp_rest')); ?> <script> var VP_API_Config = <?php echo json_encode($apiConfig); ?> </script> <?php wp_enqueue_style('versionpress_gui_style', plugins_url('../public/gui/app.css', __FILE__)); wp_enqueue_script('versionpress_gui_script', plugins_url('../public/gui/app.js', __FILE__));