本文整理汇总了PHP中get_rest_url函数的典型用法代码示例。如果您正苦于以下问题:PHP get_rest_url函数的具体用法?PHP get_rest_url怎么用?PHP get_rest_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_rest_url函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load_scripts
function load_scripts()
{
wp_enqueue_script('admin-app', JS_APP_URL . 'build/js/admin-app-scripts.js', array('jquery'), PLUGIN_VERSION, false);
wp_enqueue_script('react-components', JS_APP_URL . 'build/js/all-components.js', array('admin-app'), PLUGIN_VERSION, true);
wp_enqueue_style('admin-app-styles', JS_APP_URL . 'build/css/styles.css', array(), PLUGIN_VERSION, 'all');
wp_localize_script('admin-app', 'admin_app_local', array('api_url' => get_rest_url(), 'template_directory' => JS_APP_URL . 'templates', 'nonce' => wp_create_nonce('wp_rest')));
}
示例2: json_api_client_js
/**
* Plugin Name: WP-API Client JS
*/
function json_api_client_js()
{
$scripts = wp_scripts();
$src = plugins_url('build/js/wp-api.js', __FILE__);
if (isset($scripts->registered['wp-api'])) {
$scripts->registered['wp-api']->src = $src;
} else {
wp_register_script('wp-api', $src, array('jquery', 'underscore', 'backbone'), '1.0', true);
}
/**
* @var \WP_REST_Server $wp_rest_server
*/
global $wp_rest_server;
if (empty($wp_rest_server)) {
/** This filter is documented in wp-includes/rest-api.php */
$wp_rest_server_class = apply_filters('wp_rest_server_class', 'WP_REST_Server');
$wp_rest_server = new $wp_rest_server_class();
/** This filter is documented in wp-includes/rest-api.php */
do_action('rest_api_init', $wp_rest_server);
}
$schema_request = new WP_REST_Request('GET', '/wp/v2');
$schema_response = $wp_rest_server->dispatch($schema_request);
$schema = null;
if (!$schema_response->is_error()) {
$schema = $schema_response->get_data();
}
$settings = array('root' => esc_url_raw(get_rest_url()), 'nonce' => wp_create_nonce('wp_rest'), 'versionString' => 'wp/v2/', 'schema' => $schema);
wp_localize_script('wp-api', 'wpApiSettings', $settings);
}
示例3: rest_register_scripts
/**
* Registers REST API JavaScript helpers.
*
* @since 4.4.0
*
* @see wp_register_scripts()
*/
function rest_register_scripts()
{
// Use minified scripts if SCRIPT_DEBUG is not on.
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
wp_register_script('wp-api', plugins_url('wp-api' . $suffix . '.js', __FILE__), array('jquery', 'backbone', 'underscore'), '1.2', true);
$settings = array('root' => esc_url_raw(get_rest_url()), 'nonce' => wp_create_nonce('wp_rest'), 'versionString' => 'wp/v2/');
wp_localize_script('wp-api', 'wpApiSettings', $settings);
}
示例4: register_scripts
/**
* Register assets
*/
public final function register_scripts()
{
// JS Cookie
wp_register_script('js-cookie', _2ch_plugin_dir_url('/dist/js/js.cookie.js'), array(), '2.1.0', true);
// Google reCAPTCHA
wp_register_script('recaptcha', 'https://www.google.com/recaptcha/api.js?render=explicit&onload=nichanCallback', array(), null, false);
// Form helper
wp_register_script('2ch-form', _2ch_plugin_dir_url('/dist/js/2ch.js'), array('jquery-form', 'js-cookie', 'recaptcha'), PLUGIN_2CH_VERSION, true);
wp_localize_script('2ch-form', 'NichanVars', array('root' => get_rest_url(), 'nonce' => wp_create_nonce('wp_rest'), 'callback' => false, 'message' => __('Comment has been posted and waiting form moderation.', '2ch')));
}
示例5: rest_output_link_header
/**
* Send a Link header for the API.
*/
function rest_output_link_header()
{
if (headers_sent()) {
return;
}
$api_root = get_rest_url();
if (empty($api_root)) {
return;
}
header('Link: <' . esc_url_raw($api_root) . '>; rel="https://github.com/WP-API/WP-API"', false);
}
示例6: enqueue
/**
* Enqueue scripts and styles - only called when builder is active.
* @return void
*/
function enqueue()
{
if (class_exists('FLBuilderModel') && FLBuilderModel::is_builder_active()) {
// Enqueue Stylesheets
wp_enqueue_style('fl-template-browser', plugins_url('/css/template-browser.css', dirname(__FILE__)), array('open-sans'));
// Enqueue Scripts
wp_enqueue_script('fl-template-browser', plugins_url('/js/min/template-browser-min.js', dirname(__FILE__)), array('backbone', 'wp-util'));
$data = array('collections' => BRJ_TemplateCollection::get_collections(), 'libraries' => array_values(BRJ_TemplateLibrary::get_libraries()), 'root' => esc_url_raw(get_rest_url()), 'nonce' => wp_create_nonce('wp_rest'));
wp_localize_script('fl-template-browser', 'BRJ_StoreInitialData', $data);
}
}
示例7: json_api_client_js
/**
* Plugin Name: WP-API Client JS
*/
function json_api_client_js()
{
/**
* Check if WP API functionality exists. Not using is_plugin_active in prepartion for
*/
if (!function_exists('rest_get_url_prefix')) {
return;
}
wp_enqueue_script('wp-api', plugins_url('wp-api.js', __FILE__), array('jquery', 'underscore', 'backbone'), '1.0', true);
$settings = array('root' => esc_url_raw(get_rest_url()), 'nonce' => wp_create_nonce('wp_rest'));
wp_localize_script('wp-api', 'WP_API_Settings', $settings);
}
示例8: get_items
/**
* Get menu locations.
*
* @since 1.2.0
* @param $request
* @return array All registered menus locations
*/
public function get_items($request)
{
$rest_url = get_rest_url() . $this->namespace . '/' . $this->base;
$locations = get_nav_menu_locations();
$registered_menus = get_registered_nav_menus();
$rest_menus = array();
if ($locations && $registered_menus) {
foreach ($registered_menus as $slug => $label) {
$rest_menus[] = array($slug => array('ID' => $locations[$slug], 'label' => $label, 'meta' => array('links' => array('collection' => $rest_url, 'self' => $rest_url . '/' . $slug)), 'tree' => $this->get_menu_tree($slug)));
}
}
return $rest_menus;
}
示例9: fed_scripts
function fed_scripts()
{
wp_enqueue_style('wp-stripe-fed-styles', WP_STRIPE_URL . '/build/front-end/css/wp-stripe-fed-styles.css', array(), WP_STRIPE_VERSION, 'all');
wp_enqueue_script('wp-stripe-fed-scripts', WP_STRIPE_URL . '/build/front-end/js/stripe-wp-fed-scripts.js', array('jquery'), WP_STRIPE_VERSION, false);
$local_object = array('api_url' => get_rest_url(), 'template_directory' => WP_STRIPE_URL . 'templates', 'nonce' => wp_create_nonce('wp_rest'));
if (get_option('stripe_wp_confirmation_type', false) == 'page' && get_option('stripe_wp_confirmation_page', false)) {
$local_object['confirmation'] = array('type' => 'page', 'page' => get_permalink(get_option('stripe_wp_confirmation_page', false)));
}
if (get_option('stripe_wp_confirmation_type', false) == 'message' && get_option('stripe_wp_confirmation_message', false)) {
$local_object['confirmation'] = array('type' => 'message', 'message' => get_permalink(get_option('stripe_wp_confirmation_message', false)));
}
wp_localize_script('wp-stripe-fed-scripts', 'stripe_wp_local', $local_object);
}
示例10: test_get_items
/**
* Test that list endpoint returns expected format
*/
public function test_get_items()
{
$ev = Utils::create_test_event();
// Don't test internal events with this test
$internal_events = array('a8c_cron_control_force_publish_missed_schedules', 'a8c_cron_control_confirm_scheduled_posts', 'a8c_cron_control_clean_legacy_data', 'a8c_cron_control_purge_completed_events');
foreach ($internal_events as $internal_event) {
wp_clear_scheduled_hook($internal_event);
}
$request = new \WP_REST_Request('POST', '/' . \Automattic\WP\Cron_Control\REST_API::API_NAMESPACE . '/' . \Automattic\WP\Cron_Control\REST_API::ENDPOINT_LIST);
$request->set_body(wp_json_encode(array('secret' => \WP_CRON_CONTROL_SECRET)));
$request->set_header('content-type', 'application/json');
$response = $this->server->dispatch($request);
$data = $response->get_data();
$this->assertResponseStatus(200, $response);
$this->assertArrayHasKey('events', $data);
$this->assertArrayHasKey('endpoint', $data);
$this->assertResponseData(array('events' => array(array('timestamp' => $ev['timestamp'], 'action' => md5($ev['action']), 'instance' => md5(maybe_serialize($ev['args'])))), 'endpoint' => get_rest_url(null, \Automattic\WP\Cron_Control\REST_API::API_NAMESPACE . '/' . \Automattic\WP\Cron_Control\REST_API::ENDPOINT_RUN)), $response);
}
示例11: print_settings
/**
* Print the JavaScript settings.
*/
public function print_settings()
{
?>
<script type="text/javascript">
window.wp = window.wp || {};
window.wp.react = window.wp.react || {};
window.wp.react.settings = {
emoji_url: '<?php
echo REACT_URL . '/static/emoji.json';
?>
',
endpoint: '<?php
echo get_rest_url(null, $this->api->namespace . '/' . $this->api->rest_base);
?>
'
}
</script>
<?php
}
示例12: get_events
/**
* List events pending for the current period
*/
public function get_events()
{
$events = get_option('cron');
// That was easy
if (!is_array($events) || empty($events)) {
return array('events' => null);
}
// Simplify array format for further processing
$events = collapse_events_array($events);
// Select only those events to run in the next sixty seconds
// Will include missed events as well
$current_events = $internal_events = array();
$current_window = strtotime(sprintf('+%d seconds', JOB_QUEUE_WINDOW_IN_SECONDS));
foreach ($events as $event) {
// Skip events whose time hasn't come
if ($event['timestamp'] > $current_window) {
continue;
}
// Skip events that don't have any callbacks hooked to their actions, unless their execution is requested
if (!$this->action_has_callback_or_should_run_anyway($event)) {
continue;
}
// Necessary data to identify an individual event
// `$event['action']` is hashed to avoid information disclosure
// Core hashes `$event['instance']` for us
$event_data_public = array('timestamp' => $event['timestamp'], 'action' => md5($event['action']), 'instance' => $event['instance']);
// Queue internal events separately to avoid them being blocked
if (is_internal_event($event['action'])) {
$internal_events[] = $event_data_public;
} else {
$current_events[] = $event_data_public;
}
}
// Limit batch size to avoid resource exhaustion
if (count($current_events) > JOB_QUEUE_SIZE) {
$current_events = $this->reduce_queue($current_events);
}
// Combine with Internal Events and return necessary data to process the event queue
return array('events' => array_merge($current_events, $internal_events), 'endpoint' => get_rest_url(null, REST_API::API_NAMESPACE . '/' . REST_API::ENDPOINT_RUN));
}
示例13: wp_enqueue_scripts
function wp_enqueue_scripts()
{
global $post;
$rest_server = rest_get_server();
if ($this->has_fee()) {
wp_enqueue_style('wp-core-ui', $this->url('/css/wp-core-ui.css'), false, self::VERSION, 'screen');
wp_enqueue_style('wp-core-ui-colors', $this->url('/css/wp-core-ui-colors.css'), false, self::VERSION, 'screen');
wp_enqueue_style('wp-auth-check');
wp_enqueue_script('wp-auth-check');
wp_enqueue_script('fee-tinymce', $this->url('/vendor/tinymce.js'), array(), self::TINYMCE_VERSION, true);
wp_enqueue_script('fee-tinymce-image', $this->url('/js/tinymce.image.js'), array('fee-tinymce'), self::VERSION, true);
wp_enqueue_script('fee-tinymce-theme', $this->url('/js/tinymce.theme.js'), array('fee-tinymce'), self::VERSION, true);
foreach (array('lists', 'paste', 'wordpress', 'wplink', 'wptextpattern', 'wpview') as $plugin) {
wp_enqueue_script('fee-' . $plugin, $this->url('/vendor/' . $plugin . '.js'), array('fee-tinymce'), self::VERSION, true);
}
$tinymce_plugins = array('wordpress', 'feeImage', 'wptextpattern', 'wplink', 'wpview', 'paste', 'lists');
$tinymce_toolbar = array('bold', 'italic', 'strikethrough', 'link');
$tinymce = array('selector' => '.fee-content', 'plugins' => implode(' ', array_unique(apply_filters('fee_tinymce_plugins', $tinymce_plugins))), 'toolbar' => apply_filters('fee_tinymce_toolbar', $tinymce_toolbar), 'theme' => 'fee', 'inline' => true, 'relative_urls' => false, 'convert_urls' => false, 'browser_spellcheck' => true, 'placeholder' => apply_filters('fee_content_placeholder', __('Just write…')), 'wpeditimage_html5_captions' => current_theme_supports('html5', 'caption'), 'end_container_on_empty_block' => true);
$request = new WP_REST_Request('GET', '/wp/v2/' . ($post->post_type === 'page' ? 'pages' : 'posts') . '/' . $post->ID);
$request->set_query_params(array('context' => 'edit'));
$result = $rest_server->dispatch($request);
wp_enqueue_script('fee', $this->url('/js/fee.js'), array('fee-tinymce', 'wp-util', 'heartbeat', 'editor', 'wp-api', 'media-views'), self::VERSION, true);
wp_localize_script('fee', 'feeData', array('tinymce' => apply_filters('fee_tinymce_config', $tinymce), 'post' => $result->get_data(), 'lock' => !wp_check_post_lock($post->ID) ? implode(':', wp_set_post_lock($post->ID)) : false, 'titlePlaceholder' => apply_filters('enter_title_here', __('Enter title here'), $post), 'editURL' => get_edit_post_link()));
$request = new WP_REST_Request('GET', '/wp/v2');
$result = $rest_server->dispatch($request);
wp_localize_script('wp-api', 'wpApiSettings', array('root' => esc_url_raw(get_rest_url()), 'nonce' => wp_create_nonce('wp_rest'), 'versionString' => 'wp/v2/', 'schema' => $result->get_data(), 'cacheSchema' => true));
wp_enqueue_media(array('post' => $post));
wp_deregister_script('mce-view');
wp_enqueue_script('mce-view', $this->url('/vendor/mce-view.js'), array('shortcode', 'jquery', 'media-views', 'media-audiovideo'), self::VERSION, true);
wp_enqueue_script('mce-view-register', $this->url('/js/mce-view-register.js'), array('mce-view', 'fee'), self::VERSION, true);
wp_localize_script('mce-view-register', 'mce_view_register', array('post_id' => $post->ID));
wp_enqueue_style('tinymce-core', $this->url('/css/tinymce.core.css'), false, self::VERSION, 'screen');
wp_enqueue_style('tinymce-view', $this->url('/css/tinymce.view.css'), false, self::VERSION, 'screen');
wp_enqueue_style('fee', $this->url('/css/fee.css'), false, self::VERSION, 'screen');
wp_enqueue_style('dashicons');
}
if (current_user_can('edit_posts')) {
if (is_singular()) {
require_once ABSPATH . '/wp-admin/includes/post.php';
$user_id = wp_check_post_lock($post->ID);
$user = get_userdata($user_id);
}
wp_enqueue_script('fee-adminbar', $this->url('/js/fee-adminbar.js'), array('wp-util', 'wp-api'), self::VERSION, true);
wp_localize_script('fee-adminbar', 'fee_adminbar', array('lock' => is_singular() && $user_id ? $user->display_name : false, 'supportedPostTypes' => $this->get_supported_post_types(), 'postNew' => admin_url('post-new.php'), 'nonce' => wp_create_nonce('fee-new')));
}
}
示例14: boot_preview_script
/**
* Boot script for Customizer preview.
*
* @action wp_head
*/
public function boot_preview_script()
{
global $wp_customize;
wp_print_scripts(array('customize-rest-resources-preview-manager'));
$dirty_setting_values = array();
foreach (array_keys($wp_customize->unsanitized_post_values()) as $setting_id) {
if (!preg_match('#^rest_resource\\[#', $setting_id)) {
continue;
}
$setting = $wp_customize->get_setting($setting_id);
if ($setting) {
$dirty_setting_values[$setting_id] = $setting->value();
}
}
$args = array('previewedTheme' => $wp_customize->get_stylesheet(), 'previewNonce' => wp_create_nonce('preview-customize_' . $wp_customize->get_stylesheet()), 'restApiRoot' => get_rest_url(), 'initialDirtySettingValues' => $dirty_setting_values);
?>
<script>
/* global CustomizeRestResources */
CustomizeRestResources.manager = new CustomizeRestResources.RestResourcesPreviewManager( <?php
echo wp_json_encode($args);
?>
);
</script>
<?php
}
示例15: anadama_scripts
/**
* Enqueue scripts and styles.
*/
function anadama_scripts()
{
wp_enqueue_style('anadama-style', get_stylesheet_uri());
wp_enqueue_script('anadama-react', get_template_directory_uri() . '/js/app.js', array('jquery'), ANADAMA_VERSION, true);
wp_localize_script('anadama-react', 'AnadamaSettings', array('nonce' => wp_create_nonce('wp_rest'), 'user' => get_current_user_id(), 'title' => get_bloginfo('name', 'display'), 'URL' => array('root' => esc_url_raw(get_rest_url(null, '/wp/v2')), 'menuRoot' => esc_url_raw(get_rest_url(null, '/wp-api-menus/v2')), 'base' => esc_url_raw(home_url()))));
}