本文整理汇总了PHP中json_url函数的典型用法代码示例。如果您正苦于以下问题:PHP json_url函数的具体用法?PHP json_url怎么用?PHP json_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了json_url函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_related
public function get_related($id = '', $filter = array(), $context = 'view')
{
$option = get_option('sirp_options');
$num = !empty($filter['num']) ? (int) $filter['num'] : (int) $option['display_num'];
$ids = sirp_get_related_posts_id_api($num, $id);
$posts_list = array();
foreach ($ids as $id) {
$posts_list[] = get_post($id['ID']);
}
$response = new WP_JSON_Response();
if (!$posts_list) {
$response->set_data(array());
return $response;
}
$struct = array();
$response->header('Last-Modified', mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0) . ' GMT');
foreach ($posts_list as $post) {
$post = get_object_vars($post);
if (!$this->check_read_permission($post)) {
continue;
}
$response->link_header('item', json_url('/posts/' . $post['ID']), array('title' => $post['post_title']));
$post_data = $this->prepare_post($post, $context);
if (is_wp_error($post_data)) {
continue;
}
$struct[] = $post_data;
}
$response->set_data($struct);
return $response;
}
示例2: get_ranking
/**
* Retrieve ranking
*
* Overrides the $type to set to 'post', then passes through to the post
* endpoints.
*
* @see WP_JSON_Posts::get_posts()
*/
public function get_ranking($filter = array(), $context = 'view')
{
$ids = sga_ranking_get_date($filter);
$posts_list = array();
foreach ($ids as $id) {
$posts_list[] = get_post($id);
}
$response = new WP_JSON_Response();
if (!$posts_list) {
$response->set_data(array());
return $response;
}
// holds all the posts data
$struct = array();
$response->header('Last-Modified', mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0) . ' GMT');
foreach ($posts_list as $post) {
$post = get_object_vars($post);
// Do we have permission to read this post?
if (!$this->check_read_permission($post)) {
continue;
}
$response->link_header('item', json_url('/posts/' . $post['ID']), array('title' => $post['post_title']));
$post_data = $this->prepare_post($post, $context);
if (is_wp_error($post_data)) {
continue;
}
$struct[] = $post_data;
}
$response->set_data($struct);
return $response;
}
示例3: angularScripts
function angularScripts()
{
wp_enqueue_style('bootstrap', plugin_dir_url(__FILE__) . 'css/bootstrap.min.css');
wp_enqueue_style('rjs-styles', plugin_dir_url(__FILE__) . 'css/styles.css');
// Angular Core
wp_enqueue_script('angular-core', plugin_dir_url(__FILE__) . 'js/angular.min.js', array('jquery'), NULL, false);
wp_enqueue_script('angular-resource', plugin_dir_url(__FILE__) . 'js/angular-resource.min.js', array('angular-core'), NULL, false);
wp_enqueue_script('angular-bootstrap-tables', plugin_dir_url(__FILE__) . 'js/angular-smart-table.min.js', array('angular-core'), NULL, false);
wp_enqueue_script('angular-sanitize', plugin_dir_url(__FILE__) . 'js/angular-sanitize.min.js', array('jquery'), NULL, false);
wp_enqueue_script('angular-route', plugin_dir_url(__FILE__) . 'js/angular-route.min.js', array('jquery'), NULL, false);
wp_enqueue_script('html-janitor', plugin_dir_url(__FILE__) . 'js/html-janitor.js', array('jquery'), NULL, false);
wp_enqueue_script('angular-app', plugin_dir_url(__FILE__) . 'js/angular-app.js', array('html-janitor'), NULL, false);
wp_enqueue_script('bootstrap-main', plugin_dir_url(__FILE__) . 'js/bootstrap.min.js', array('jquery'), NULL, false);
wp_enqueue_script('rjs-core-js', plugin_dir_url(__FILE__) . 'js/rjs.jquery.fn.js', array('jquery'), NULL, false);
wp_enqueue_script('bootstrap-angularjs', plugin_dir_url(__FILE__) . 'js/ui-bootstrap-angular.min.js', array('bootstrap-main'), NULL, false);
// Angular Factories
/*wp_enqueue_script(
'angular-factories', plugin_dir_url( __FILE__ ).
'js/angular-factories.js', array('angular-app'), NULL, false );*/
// Angular Directives
/*wp_enqueue_script(
'angular-post-directives', plugin_dir_url( __FILE__ ).
'js/angular-posts-directives.js', array('angular-factories'), NULL, false );*/
// Template Directory
$template_directory = array('post_load' => plugin_dir_url(__FILE__) . 'partials/post-load.html', 'post_truck' => plugin_dir_url(__FILE__) . 'partials/post-truck.html', 'post_archive' => plugin_dir_url(__FILE__) . 'partials/archive-load.html', 'favorite_postings' => plugin_dir_url(__FILE__) . 'partials/favorite-postings.html', 'archive_truck' => plugin_dir_url(__FILE__) . 'partials/archive-truck.html', 'rjs_pagination' => plugin_dir_url(__FILE__) . 'partials/rjs.pagination.html');
// Localize Variables
wp_localize_script('angular-core', 'wfcLocalized', array('site' => get_bloginfo('wpurl'), 'base' => json_url(), 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('wp_json'), 'template_directory' => $template_directory, 'today_date' => date("Y-m-d", strtotime("today midnight")), 'plugin_path' => plugin_dir_url(__FILE__)));
}
示例4: angularScripts
function angularScripts()
{
// Angular Core
wp_enqueue_script('angular-core', plugin_dir_url(__FILE__) . 'js/angular.min.js', array('jquery'), null, false);
wp_enqueue_script('angular-app', plugin_dir_url(__FILE__) . 'js/angular-app.js', array('jquery'), null, false);
// Angular Factories
wp_enqueue_script('angular-factories', plugin_dir_url(__FILE__) . 'js/angular-factories.js', array('angular-app'), null, false);
// Angular Directives
wp_enqueue_script('angular-post-directives', plugin_dir_url(__FILE__) . 'js/angular-posts-directives.js', array('angular-factories'), null, false);
// Template Directory
$template_directory = array('list_detail' => plugin_dir_url(__FILE__) . 'angularjs-templates/list-detail.html', 'single_detail' => plugin_dir_url(__FILE__) . 'angularjs-templates/single-detail.html', 'new_post' => plugin_dir_url(__FILE__) . 'angularjs-templates/new-post.html', 'post_content' => plugin_dir_url(__FILE__) . 'angularjs-templates/post-content.html');
// TEMPLATE OVERRIDES
if (file_exists(get_template_directory() . '/angularjs-templates/list-detail.html')) {
$template_directory['list_detail'] = get_bloginfo('template_directory') . '/angularjs-templates/list-detail.html';
}
if (file_exists(get_template_directory() . '/angularjs-templates/single-detail.html')) {
$template_directory['list_detail'] = get_bloginfo('template_directory') . '/angularjs-templates/single-detail.html';
}
if (file_exists(get_template_directory() . '/angularjs-templates/new-post.html')) {
$template_directory['new_post'] = get_bloginfo('template_directory') . '/angularjs-templates/new-post.html';
}
if (file_exists(get_template_directory() . '/angularjs-templates/post-content.html')) {
$template_directory['post_content'] = get_bloginfo('template_directory') . '/angularjs-templates/post-content.html';
}
// Localize Variables
wp_localize_script('angular-core', 'wpAngularVars', array('site' => get_bloginfo('wpurl'), 'base' => json_url(), 'nonce' => wp_create_nonce('wp_json'), 'template_directory' => $template_directory));
}
示例5: prepare_post
/**
* Prepare post data
*
* @param array $post The unprepared post data
* @param array $fields The subset of post type fields to return
* @return array The prepared post data
*/
protected function prepare_post($post, $context = 'view')
{
$_post = parent::prepare_post($post, $context);
// Override entity meta keys with the correct links
$_post['meta']['links']['self'] = json_url($this->base . '/' . get_page_uri($post['ID']));
if (!empty($post['post_parent'])) {
$_post['meta']['links']['up'] = json_url($this->base . '/' . get_page_uri((int) $post['post_parent']));
}
return apply_filters('json_prepare_page', $_post, $post, $context);
}
示例6: get_menus
/**
* Get all registered menus.
*
* @return WP_Error|WP_JSON_ResponseInterface
*/
public function get_menus()
{
$menus = get_registered_nav_menus();
if ($menus) {
$response = json_ensure_response($menus);
$response->set_status(201);
$response->header('Location', json_url('jpwp/menus/'));
return $response;
} else {
return new WP_Error('jwp_api_error' . __FUNCTION__, __('Menus could not be returned.', 'jpwp-api'));
}
}
示例7: add_meta
/**
* Add meta to a post.
*
* Ensures that the correct location header is sent with the response.
*
* @param int $id Post ID
* @param array $data {
* @type string|null $key Meta key
* @type string|null $key Meta value
* }
* @return bool|WP_Error
*/
public function add_meta($id, $data)
{
$response = parent::add_meta($id, $data);
if (is_wp_error($response)) {
return $response;
}
$data = (object) $response->get_data();
$response = new WP_JSON_Response();
$response->header('Location', json_url('/posts/' . $id . '/meta/' . $data->ID));
$response->set_data($data);
$response = json_ensure_response($response);
return $response;
}
示例8: my_scripts
function my_scripts()
{
wp_register_script('angularjs', get_template_directory_uri() . '/bower_components/angular/angular.min.js', array(), null, false);
wp_register_script('angular-ui-router', get_template_directory_uri() . '/bower_components/angular-ui-router/release/angular-ui-router.min.js', array(), null, false);
wp_register_script('angular-sanitize', get_template_directory_uri() . '/bower_components/angular-sanitize/angular-sanitize.min.js', array(), null, false);
wp_register_script('angular-smooth-scroll', get_template_directory_uri() . '/bower_components/ngSmoothScroll/angular-smooth-scroll.min.js', array(), null, false);
wp_register_script('angular-animate', get_template_directory_uri() . '/bower_components/angular-animate/angular-animate.min.js', array(), null, false);
wp_register_script('angular-spinkit', get_template_directory_uri() . '/bower_components/angular-spinkit/build/angular-spinkit.min.js', array(), null, false);
wp_register_script('angular-strap', get_template_directory_uri() . '/bower_components/angular-strap/dist/angular-strap.min.js', array(), null, false);
wp_register_script('angular-strap-tpl', get_template_directory_uri() . '/bower_components/lodash/lodash.min.js', array(), null, false);
wp_register_script('lodash', get_template_directory_uri() . '/bower_components/angular-strap/dist/angular-strap.tpl.min.js', array(), null, false);
wp_register_script('reward-style', 'http://widgets.rewardstyle.com/js/shopthepost.js', array(), null, false);
wp_enqueue_script('my-scripts', get_template_directory_uri() . '/js/app.js', array('angularjs', 'angular-ui-router', 'angular-sanitize', 'angular-smooth-scroll', 'angular-animate', 'angular-spinkit', 'angular-strap', 'angular-strap-tpl', 'lodash', 'reward-style'));
wp_enqueue_style('flaticon.css', get_template_directory_uri() . '/assets/icons/flaticon.css');
wp_enqueue_style('angular-motion.css', get_template_directory_uri() . '/bower_components/angular-motion/dist/angular-motion.min.css');
wp_enqueue_style('angular-spinkit.css', get_template_directory_uri() . '/bower_components/angular-spinkit/build/angular-spinkit.min.css');
wp_enqueue_style('style.css', get_stylesheet_uri());
wp_localize_script('my-scripts', 'WPAPI', array('apiUrl' => json_url(), 'apiNonce' => wp_create_nonce('wp_json')));
}
示例9: baldrick_pods_endpoint
function baldrick_pods_endpoint()
{
if (defined('PODS_VERSION') && defined('PODS_JSON_API_VERSION')) {
//add the basic pods endpoints
$endpoints['pods'] = json_url('pods');
$endpoints['pods-api'] = json_url('pods-api');
//get name of all registered Pods
$pods = pods_api()->load_pods(array('names' => true));
//add end point foreach if there are registered Pods
if (is_array($pods) && !empty($pods)) {
$endpoint_types = array('pods', 'pods_api');
foreach ($pods as $pod) {
foreach ($endpoint_types as $type) {
$endpoints = array_merge($endpoints, array("{$type}/{$pod}" => json_url("{$type}/{$pod}")));
}
}
}
return $endpoints;
}
}
示例10: MyScripts
function MyScripts()
{
$query = new WP_Query();
$JSON = $query->get_posts();
//MODERNIZR
wp_enqueue_script('modernizr', get_bloginfo('template_directory') . '/js/modernizr-1.5.min.js', array('jquery'), null, false);
wp_enqueue_script('modernizr');
//LESS CSS JS
wp_enqueue_script('less', get_bloginfo('template_directory') . '/js/less-1.3.1.min.js', array('jquery'), null, false);
wp_enqueue_script('less');
//TINYMCE
wp_enqueue_script('tinymce', get_bloginfo('template_directory') . '/js/tinymce.min.js', array('jquery'), null, false);
wp_enqueue_script('tinymce-second', get_bloginfo('template_directory') . '/js/jquery.tinymce.min.js', array('tinymce'), null, false);
//ANGULAR
wp_enqueue_script('angular-core', '//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.js', array('jquery'), null, false);
wp_enqueue_script('angular-route', '//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-route.min.js', array('angular-core'), null, false);
wp_enqueue_script('angular-resource', '//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-resource.min.js', array('angular-route'), null, false);
wp_enqueue_script('angular-app', get_bloginfo('template_directory') . '/js/angular-app.js', array('angular-core'), null, false);
//ANGULAR SMART NAV
wp_enqueue_script('angular-route', get_bloginfo('template_directory') . '/js/angular-route.js', array('angular-core'), null, false);
//ANGULAR UI
wp_enqueue_script('angular-ie', get_bloginfo('template_directory') . '/js/angular-ui-ieshiv.min.js', array('angular-core'), null, false);
wp_enqueue_script('angular-tinymce', get_bloginfo('template_directory') . '/js/ui-tinymce.js', array('angular-core'), null, false);
wp_enqueue_style('angular-ui-css', get_bloginfo('template_directory') . '/js/angular-ui.css', false, '1.0', 'all');
wp_enqueue_script('angular-bs-ui', get_bloginfo('template_directory') . '/js/ui-bootstrap-tpls-0.10.0.min.js', array('angular-core'), null, false);
//BOOTSTRAP
wp_enqueue_style('bootstrap-core', get_bloginfo('template_directory') . '/css/bootstrap.min.css', false, '1.0', 'all');
wp_enqueue_script('boostrap-js', get_bloginfo('template_directory') . '/js/bootstrap.min.js', array('jquery'), null, false);
//LOCALIZE
wp_localize_script('angular-core', 'MyAjax', array('ajaxurl' => admin_url('admin-ajax.php'), 'resturl' => get_bloginfo('wpurl') . '/wp-json'));
wp_localize_script('angular-core', 'Directory', array('url' => get_bloginfo('template_directory'), 'site' => get_bloginfo('wpurl')));
wp_localize_script('angular-core', 'wpApiOptions', array('base' => json_url(), 'nonce' => wp_create_nonce('wp_json')));
// LESS CSS
wp_enqueue_style('less-css', get_bloginfo('template_directory') . '/more-style.less', false, '1.0', 'all');
wp_enqueue_style('less-css');
wp_enqueue_style('less-css-css', get_bloginfo('template_directory') . '/more-style.css', false, '1.0', 'all');
// INCLUDE WHEN READY: wp_enqueue_style('less-css-css');
//TINY MCE
wp_enqueue_script('tiny_mce');
}
示例11: tax_query
public function tax_query($data)
{
$allowed = array('post_type', 'tax_query');
foreach ($data as $key => $value) {
if (!in_array($key, $allowed)) {
unset($data[$key]);
}
}
if (!is_array($data) || empty($data) || !isset($data['tax_query'])) {
return new WP_Error('jp_api_tax_query', __('Invalid tax query.'), array('status' => 500));
}
$post_query = new WP_Query();
$posts_list = $post_query->query($data);
$response = new WP_JSON_Response();
$response->query_navigation_headers($post_query);
if (!$posts_list) {
$response->set_data(array());
return $response;
}
// holds all the posts data
$struct = array();
$response->header('Last-Modified', mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0) . ' GMT');
foreach ($posts_list as $post) {
$post = get_object_vars($post);
// Do we have permission to read this post?
if (json_check_post_permission($post, 'read')) {
continue;
}
$response->link_header('item', json_url('/posts/' . $post['ID']), array('title' => $post['post_title']));
$post_data = $this->prepare_post($post, 'view');
if (is_wp_error($post_data)) {
continue;
}
$struct[] = $post_data;
}
$response->set_data($struct);
return $response;
}
示例12: angularScripts
function angularScripts()
{
// Angular Core
wp_enqueue_script('angular-core', plugin_dir_url(__FILE__) . 'js/angular.min.js', array('jquery'), null, false);
wp_enqueue_script('angular-sanitize', plugin_dir_url(__FILE__) . 'js/angular-sanitize.min.js', array('jquery'), null, false);
wp_enqueue_script('html-janitor', plugin_dir_url(__FILE__) . 'js/html-janitor.js', array('jquery'), null, false);
wp_enqueue_script('angular-app', plugin_dir_url(__FILE__) . 'js/angular-app.js', array('html-janitor'), null, false);
// Angular Factories
wp_enqueue_script('angular-factories', plugin_dir_url(__FILE__) . 'js/angular-factories.js', array('angular-app'), null, false);
// Angular Directives
wp_enqueue_script('angular-post-directives', plugin_dir_url(__FILE__) . 'js/angular-posts-directives.js', array('angular-factories'), null, false);
// Template Directory
$template_directory = array('list_detail' => plugin_dir_url(__FILE__) . 'angularjs-templates/list-detail.html', 'single_detail' => plugin_dir_url(__FILE__) . 'angularjs-templates/single-detail.html', 'new_post' => plugin_dir_url(__FILE__) . 'angularjs-templates/new-post.html', 'post_content' => plugin_dir_url(__FILE__) . 'angularjs-templates/post-content.html');
// TEMPLATE OVERRIDES
if (file_exists(get_stylesheet_directory() . '/angularjs-templates/list-detail.html')) {
$template_directory['list_detail'] = get_stylesheet_directory_uri() . '/angularjs-templates/list-detail.html';
}
if (file_exists(get_stylesheet_directory() . '/angularjs-templates/single-detail.html')) {
$template_directory['single_detail'] = get_stylesheet_directory_uri() . '/angularjs-templates/single-detail.html';
}
if (file_exists(get_stylesheet_directory() . '/angularjs-templates/new-post.html')) {
$template_directory['new_post'] = get_stylesheet_directory_uri() . '/angularjs-templates/new-post.html';
}
if (file_exists(get_stylesheet_directory() . '/angularjs-templates/post-content.html')) {
$template_directory['post_content'] = get_stylesheet_directory_uri() . '/angularjs-templates/post-content.html';
}
$angularjs_for_wp_localize = array('site' => get_bloginfo('wpurl'), 'nonce' => wp_create_nonce('wp_json'), 'template_directory' => $template_directory);
if (function_exists('json_url')) {
$angularjs_for_wp_localize['base'] = json_url();
}
if (function_exists('rest_get_url_prefix')) {
$angularjs_for_wp_localize['base'] = get_bloginfo('wpurl') . '/' . rest_get_url_prefix() . '/wp/v2';
}
// Localize Variables
wp_localize_script('angular-core', 'wpAngularVars', $angularjs_for_wp_localize);
}
示例13: __social_scripts_enqueue
function __social_scripts_enqueue()
{
$dev = false;
if ($dev) {
wp_enqueue_script('hello-js', API_SOCIAL_URL . '/assets/js/hello.all.js', array('jquery'), API_SOCIAL_LOGIN_VERSION, false);
wp_enqueue_script('social-js', API_SOCIAL_URL . '/assets/js/social.js', array('hello-js'), API_SOCIAL_LOGIN_VERSION, false);
} else {
wp_enqueue_script('hello-js', API_SOCIAL_URL . '/build/js/hello.all.min.js', array('jquery'), API_SOCIAL_LOGIN_VERSION, false);
wp_enqueue_script('social-js', API_SOCIAL_URL . '/build/js/social.min.js', array('hello-js'), API_SOCIAL_LOGIN_VERSION, false);
}
$app_data = array('api_url' => get_bloginfo('wpurl') . '/wp-json');
if (function_exists('rest_get_url_prefix')) {
$app_data['api_url'] = get_bloginfo('wpurl') . '/' . rest_get_url_prefix() . '/social_login';
} elseif (function_exists('json_url')) {
$app_data['api_url'] = json_url();
}
$social_app = $this->__get_social_apps();
foreach ($social_app as $key => $value) {
if (!empty($value)) {
$app_data[$key] = $value;
}
}
wp_localize_script('social-js', 'socialLogin', $app_data);
}
示例14: angular_wp_api_scripts
/**
* Enqueue script & localize data
*/
function angular_wp_api_scripts()
{
// Leave if WP-API is not activated
if (!defined('JSON_API_VERSION')) {
return;
}
// Leave if not specifically requested from the theme or a plugin
if (!($config = get_theme_support('angular-wp-api'))) {
return;
}
// Array of dependencies
$script_dependencies = null;
// Data for localization
$script_data = null;
// Script dependency from theme support
if (isset($config[0])) {
$script_dependencies = $config[0];
}
// Script data from theme support
if (isset($config[1])) {
$script_data = $config[1];
}
// Data for localization
$script_data['base'] = json_url();
$script_data['nonce'] = wp_create_nonce('wp_json');
// Provide user id if logged in
if (is_user_logged_in()) {
$script_data['user_id'] = get_current_user_id();
} else {
$script_data['user_id'] = 0;
}
// Enqueue the script after dependency, in the footer
wp_enqueue_script('angular-wp-api', plugins_url('angular-wp-api.min.js', __FILE__), apply_filters('angular_wp_api_script_dependencies', $script_dependencies), '', true);
// Localize filterable data for script
wp_localize_script('angular-wp-api', 'wpAPIData', apply_filters('angular_wp_api_local_data', $script_data));
}
示例15: prepare_user
protected function prepare_user($user, $context = 'view')
{
$user_fields = array('ID' => $user->ID, 'username' => $user->user_login, 'name' => $user->display_name, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'nickname' => $user->nickname, 'slug' => $user->user_nicename, 'URL' => $user->user_url, 'avatar' => json_get_avatar_url($user->user_email), 'description' => $user->description);
$user_fields['registered'] = date('c', strtotime($user->user_registered));
if ($context === 'view' || $context === 'edit') {
$user_fields['roles'] = $user->roles;
$user_fields['capabilities'] = $user->allcaps;
$user_fields['email'] = false;
}
if ($context === 'edit') {
// The user's specific caps should only be needed if you're editing
// the user, as allcaps should handle most uses
$user_fields['email'] = $user->user_email;
$user_fields['extra_capabilities'] = $user->caps;
}
$user_fields['meta'] = array('links' => array('self' => json_url('/users/' . $user->ID), 'archives' => json_url('/users/' . $user->ID . '/posts')));
return apply_filters('json_prepare_user', $user_fields, $user, $context);
}