本文整理汇总了PHP中rest_url函数的典型用法代码示例。如果您正苦于以下问题:PHP rest_url函数的具体用法?PHP rest_url怎么用?PHP rest_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rest_url函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepare_item_for_response
/**
* Prepare a post status object for serialization
*
* @param stdClass $status Post status data
* @param WP_REST_Request $request
* @return WP_REST_Response Post status data
*/
public function prepare_item_for_response($status, $request)
{
if (false === $status->public && !is_user_logged_in() || true === $status->internal && is_user_logged_in()) {
return new WP_Error('rest_cannot_read_status', __('Cannot view status.'), array('status' => rest_authorization_required_code()));
}
$data = array('name' => $status->label, 'private' => (bool) $status->private, 'protected' => (bool) $status->protected, 'public' => (bool) $status->public, 'queryable' => (bool) $status->publicly_queryable, 'show_in_list' => (bool) $status->show_in_admin_all_list, 'slug' => $status->name);
$context = !empty($request['context']) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object($data, $request);
$data = $this->filter_response_by_context($data, $context);
$response = rest_ensure_response($data);
$posts_controller = new WP_REST_Posts_Controller('post');
if ('publish' === $status->name) {
$response->add_link('archives', rest_url('/wp/v2/' . $posts_controller->get_post_type_base('post')));
} else {
$response->add_link('archives', add_query_arg('status', $status->name, rest_url('/wp/v2/' . $posts_controller->get_post_type_base('post'))));
}
/**
* Filter a status returned from the API.
*
* Allows modification of the status data right before it is returned.
*
* @param WP_REST_Response $response The response object.
* @param object $status The original status object.
* @param WP_REST_Request $request Request used to generate the response.
*/
return apply_filters('rest_prepare_status', $response, $status, $request);
}
示例2: rooftop_add_content_hierarchy
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link http://errorstudio.co.uk
* @since 1.0.0
*
* @wordpress-plugin
* Plugin Name: Rooftop Content Hierarchy
* Plugin URI: http://errorstudio.co.uk
* Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area.
* Version: 1.0.0
* Author: Error
* Author URI: http://errorstudio.co.uk
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: rooftop-content-hierarchy
* Domain Path: /languages
*/
function rooftop_add_content_hierarchy($response, $post, $request)
{
$child_post_args = array('post_parent' => $post->ID, 'post_type' => $post->post_type, 'numberposts' => -1, 'post_status' => array('publish'), 'orderby' => 'menu_order', 'order' => 'ASC');
if (apply_filters('rooftop_include_drafts', false)) {
$child_post_args['post_status'][] = 'draft';
}
$ancestor_posts = array_map(function ($id) {
return get_post($id);
}, get_post_ancestors($post));
$child_posts = get_children($child_post_args);
$post_data = function ($p) {
$post_data = array();
$post_data['id'] = $p->ID;
$post_data['title'] = $p->post_title;
$post_data['type'] = $p->post_type;
$post_data['slug'] = $p->post_name;
$post_data['embeddable'] = true;
return $post_data;
};
$post_object = get_post_type_object($post->post_type);
if ($post_object && property_exists($post_object, 'rest_base')) {
$rest_base = $post_object->rest_base;
$rest_url = '/wp/v2/' . $rest_base;
foreach ($ancestor_posts as $post) {
$response->add_link('http://docs.rooftopcms.com/link_relations/ancestors', rest_url($rest_url . '/' . $post->ID), $post_data($post));
}
foreach ($child_posts as $post) {
$response->add_link('http://docs.rooftopcms.com/link_relations/children', rest_url($rest_url . '/' . $post->ID), $post_data($post));
}
}
return $response;
}
示例3: get_items
public function get_items($request)
{
$data = array();
require_once ABSPATH . '/wp-admin/includes/plugin.php';
$plugins = get_plugins();
// Exit early if empty set.
if (empty($plugins)) {
return rest_ensure_response($data);
}
// Store pagation values for headers.
$total_plugins = count($plugins);
$per_page = (int) $request['per_page'];
if (!empty($request['offset'])) {
$offset = $request['offset'];
} else {
$offset = ($request['page'] - 1) * $per_page;
}
$max_pages = ceil($total_plugins / $per_page);
$page = ceil((int) $offset / $per_page + 1);
// Find count to display per page.
if ($page > 1) {
$length = $total_plugins - $offset;
if ($length > $per_page) {
$length = $per_page;
}
} else {
$length = $total_plugins > $per_page ? $per_page : $total_plugins;
}
// Split plugins array.
$plugins = array_slice($plugins, $offset, $length);
foreach ($plugins as $obj) {
$plugin = $this->prepare_item_for_response($obj, $request);
if (is_wp_error($plugin)) {
continue;
}
$data[] = $this->prepare_response_for_collection($plugin);
}
$response = rest_ensure_response($data);
// Add pagination headers to response.
$response->header('X-WP-Total', (int) $total_plugins);
$response->header('X-WP-TotalPages', (int) $max_pages);
// Add pagination link headers to response.
$base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
if ($page > 1) {
$prev_page = $page - 1;
if ($prev_page > $max_pages) {
$prev_page = $max_pages;
}
$prev_link = add_query_arg('page', $prev_page, $base);
$response->link_header('prev', $prev_link);
}
if ($max_pages > $page) {
$next_page = $page + 1;
$next_link = add_query_arg('page', $next_page, $base);
$response->link_header('next', $next_link);
}
// Return requested collection.
return $response;
}
示例4: test_get_shipping_methods
/**
* Test getting all shipping methods.
*
* @since 2.7.0
*/
public function test_get_shipping_methods()
{
wp_set_current_user($this->user);
$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v1/shipping_methods'));
$methods = $response->get_data();
$this->assertEquals(200, $response->get_status());
$this->assertContains(array('id' => 'free_shipping', 'title' => 'Free shipping', 'description' => 'Free shipping is a special method which can be triggered with coupons and minimum spends.', '_links' => array('self' => array(array('href' => rest_url('/wc/v1/shipping_methods/free_shipping'))), 'collection' => array(array('href' => rest_url('/wc/v1/shipping_methods'))))), $methods);
}
示例5: event_ticket_type_links_filter
public function event_ticket_type_links_filter($links, $post)
{
$prefix = "rooftop-events/v2";
$links['self'] = array('href' => rest_url(trailingslashit($prefix) . 'ticket_types/' . $post->ID));
$links['collection'] = array('href' => rest_url(trailingslashit($prefix) . 'ticket_types'));
$links['about'] = array('href' => rest_url('/wp/v2/types/' . $this->post_type));
return $links;
}
示例6: test_get_payment_gateways
/**
* Test getting all payment gateways.
*
* @since 2.7.0
*/
public function test_get_payment_gateways()
{
wp_set_current_user($this->user);
$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v1/payment_gateways'));
$gateways = $response->get_data();
$this->assertEquals(200, $response->get_status());
$this->assertContains(array('id' => 'cheque', 'title' => 'Check Payments', 'description' => 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.', 'order' => '', 'enabled' => true, 'method_title' => 'Check Payments', 'method_description' => "Allows check payments. Why would you take checks in this day and age? Well you probably wouldn't but it does allow you to make test purchases for testing order emails and the 'success' pages etc.", 'settings' => $this->get_settings('WC_Gateway_Cheque'), '_links' => array('self' => array(array('href' => rest_url('/wc/v1/payment_gateways/cheque'))), 'collection' => array(array('href' => rest_url('/wc/v1/payment_gateways'))))), $gateways);
}
示例7: test_add_oembed_provider
/**
* Test if the site was added as an oEmbed provider.
*/
function test_add_oembed_provider()
{
$oembed = _wp_oembed_get_object();
wp_oembed_remove_provider(home_url('/*'));
$this->assertArrayNotHasKey(home_url('/*'), $oembed->providers);
$this->plugin()->add_oembed_provider();
$this->assertArrayHasKey(home_url('/*'), $oembed->providers);
$this->assertEquals(array(esc_url(rest_url('wp/v2/oembed')), false), $oembed->providers[home_url('/*')]);
}
示例8: qod_scripts
/**
* Enqueue scripts and styles.
*/
function qod_scripts()
{
wp_enqueue_script('jquery');
wp_enqueue_style('qod-style', get_stylesheet_uri());
wp_enqueue_style('font-awesome-cdn', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css', array(), '4.4.0');
wp_enqueue_script('qod-skip-link-focus-fix', get_template_directory_uri() . '/build/js/skip-link-focus-fix.min.js', array(), '20130115', true);
wp_enqueue_script('qod-api', get_template_directory_uri() . '/build/js/api.min.js', array('jquery'), false, true);
wp_localize_script('qod-api', 'api_vars', array('root_url' => esc_url_raw(rest_url()), 'home_url' => esc_url_raw(home_url()), 'nonce' => wp_create_nonce('wp_rest'), 'success' => 'Thanks, your quote submission was received.', 'failure' => 'Your submission could not be processed.'));
}
示例9: load_flashcards_scripts
public function load_flashcards_scripts()
{
wp_enqueue_script('front-end', get_template_directory_uri() . '/js/ui.js', array('jquery'), '.1', true);
wp_enqueue_script('app', get_template_directory_uri() . '/js/app.js', array('jquery', 'underscore'), '.1', true);
wp_enqueue_style('main-theme-styles', get_stylesheet_uri());
$theme_settings = (array) get_option('flashcard_settings');
$theme_verify_app = base64_encode($theme_settings['username'] . ':' . $theme_settings['app_key']);
wp_localize_script('app', 'wpInfo', array('api_url' => rest_url() . 'wp/v2/posts', 'template_directory' => get_template_directory_uri() . '/', 'nonce' => wp_create_nonce('wp_rest'), 'app_permission' => $theme_verify_app));
}
示例10: building_url
function building_url()
{
$categories = get_the_category();
$cats = array();
foreach ($categories as $c) {
$cats[] = $c->term_id;
}
$url = add_query_arg(array('filter[cat]' => implode(",", $cats), 'filter[posts_per_page]' => 5), rest_url('wp/v2/posts'));
return $url;
}
示例11: qod_scripts
/**
* Enqueue scripts and styles.
*/
function qod_scripts()
{
wp_enqueue_style('qod-style', get_stylesheet_uri());
wp_enqueue_style('font-awesome-cdn', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css', array(), '4.4.0');
wp_enqueue_script('qod-skip-link-focus-fix', get_template_directory_uri() . '/build/js/skip-link-focus-fix.min.js', array(), '20130115', true);
// Add API-related scripts here...
wp_enqueue_script('angular', get_template_directory_uri() . '/build/js/angular/angular.min.js', array(), false, true);
wp_enqueue_script('quotesdev-api', get_template_directory_uri() . '/build/js/api.min.js', array('angular'), false, true);
wp_localize_script('quotesdev-api', 'api_vars', array('root_url' => esc_url_raw(rest_url()), 'home_url' => esc_url_raw(home_url()), 'nonce' => wp_create_nonce('wp_rest'), 'success' => 'Submitted...Thanks', 'failure' => 'Not submitted...Try again'));
}
示例12: sourgems_scripts
/**
*
* Enqueue scripts and styles.
*
*/
function sourgems_scripts()
{
// Load our main stylesheet.
wp_enqueue_style('style', get_stylesheet_uri());
wp_enqueue_script('jquery');
wp_register_script('sourgems-script', get_template_directory_uri() . '/app.js', array(), '20150910', true);
wp_enqueue_script('sourgems-script');
//localize data for script
wp_localize_script('sourgems-script', 'AUTH', array('root' => esc_url_raw(rest_url()), 'nonce' => wp_create_nonce('wp_rest'), 'current_user_id' => get_current_user_id()));
}
示例13: get_url
/**
* Get URL for Ingot API or an API route
*
* Note URL is returned unescaped. Don't forget to late escape.
*
* @since 0.2.0
*
* @param null|string $route Optional. If null base URL is returned. Optionally provide a route name.
*
* @return string
*/
public static function get_url($route = null)
{
if ($route) {
$route = self::get_route($route);
} else {
$route = self::get_namespace();
}
$url = trailingslashit(rest_url($route));
return $url;
}
示例14: mdjm_load_scripts
/**
* Load Scripts
*
* Enqueues the required scripts.
*
* @since 1.3
* @global $post
* @return void
*/
function mdjm_load_scripts()
{
$js_dir = MDJM_PLUGIN_URL . '/assets/js/';
wp_register_script('mdjm-ajax', $js_dir . 'mdjm-ajax.js', array('jquery'), MDJM_VERSION_NUM);
wp_enqueue_script('mdjm-ajax');
wp_localize_script('mdjm-ajax', 'mdjm_vars', apply_filters('mdjm_script_vars', array('ajaxurl' => mdjm_get_ajax_url(), 'rest_url' => esc_url_raw(rest_url('mdjm/v1/')), 'ajax_loader' => MDJM_PLUGIN_URL . '/assets/images/loading.gif', 'required_date_message' => __('Please select a date', 'mobile-dj-manager'), 'availability_ajax' => mdjm_get_option('avail_ajax', false), 'available_redirect' => mdjm_get_option('availability_check_pass_page', 'text') != 'text' ? mdjm_get_formatted_url(mdjm_get_option('availability_check_pass_page')) : 'text', 'available_text' => mdjm_get_option('availability_check_pass_text', false), 'unavailable_redirect' => mdjm_get_option('availability_check_fail_page', 'text'), 'unavailable_text' => mdjm_get_option('availability_check_fail_text', false), 'is_payment' => mdjm_is_payment() ? '1' : '0', 'default_gateway' => mdjm_get_default_gateway(), 'payment_loading' => __('Please Wait...', 'mobile-dj-manager'), 'no_payment_amount' => __('Select Payment Amount', 'mobile-dj-manager'), 'no_card_name' => __('Enter the name printed on your card', 'mobile-dj-manager'), 'complete_payment' => mdjm_get_payment_button_text())));
wp_register_script('jquery-validation-plugin', '//ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js', array('jquery'));
wp_enqueue_script('jquery-validation-plugin');
wp_enqueue_script('jquery-ui-datepicker', array('jquery'));
}
示例15: event_price_list_links_filter
public function event_price_list_links_filter($links, $post)
{
$prefix = "rooftop-events/v2";
$base = "{$prefix}/price_lists";
$links['prices'] = array('href' => rest_url(trailingslashit($base) . $post->ID . '/prices'), 'embeddable' => true);
$links['self'] = array('href' => rest_url(trailingslashit($base) . $post->ID));
$links['collection'] = array('href' => rest_url($base));
$links['about'] = array('href' => rest_url('/wp/v2/types/' . $this->post_type));
return $links;
}