本文整理汇总了PHP中json_url函数的典型用法代码示例。如果您正苦于以下问题:PHP json_url函数的具体用法?PHP json_url怎么用?PHP json_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了json_url函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:Anawaz,项目名称:Simple-Related-Posts,代码行数:31,代码来源:wp-rest-api.php
示例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;
}
开发者ID:kantan2015,项目名称:simple-ga-ranking,代码行数:39,代码来源:wp-rest-api.class.php
示例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__)));
}
开发者ID:TylerEspo,项目名称:wfc_rjs_app,代码行数:28,代码来源:wfc-rjs-loads.php
示例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));
}
开发者ID:shellygraham,项目名称:livestock-framing,代码行数:27,代码来源:plugin.php
示例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);
}
开发者ID:ntwb,项目名称:BB-API,代码行数:17,代码来源:class-bbp-json-replies.php
示例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'));
}
}
开发者ID:shelob9,项目名称:jp-menu-route,代码行数:17,代码来源:class-jp-menu-api.php
示例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;
}
开发者ID:dani-ocean,项目名称:wp_angular_api,代码行数:25,代码来源:class-wp-json-meta-posts.php
示例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')));
}
开发者ID:bylertall,项目名称:fpr-angular-wp-theme,代码行数:19,代码来源:functions.php
示例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;
}
}
开发者ID:Shelob9,项目名称:wp-baldrick,代码行数:20,代码来源:framework.php
示例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');
}
开发者ID:romancandlethoughts,项目名称:Angular-Wordpress-Theme,代码行数:40,代码来源:functions.php
示例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;
}
开发者ID:shelob9,项目名称:jp-tax-query,代码行数:38,代码来源:class-jp-tax-query.php
示例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);
}
开发者ID:benediktharter,项目名称:angularjs-for-wordpress,代码行数:36,代码来源:plugin.php
示例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);
}
开发者ID:advancedwp,项目名称:awpdevelop,代码行数:24,代码来源:social-enqueue.php
示例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));
}
开发者ID:eharit,项目名称:ngloop,代码行数:39,代码来源:plugin.php
示例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);
}
开发者ID:ratan203,项目名称:wp-app-plugin,代码行数:18,代码来源:sg-api-routes.php
示例16: list_posts
//.........这里部分代码省略.........
// return array($page_id);
// }
$struct = $this->get_screen_content($page_id);
$data = array('count' => count($struct), 'screen_id' => $screen_id, 'screen_title' => $screen_attrs[$screen_id], 'screen_image' => $screen_image, 'result' => $struct);
return $data;
}
//Redirect to other function and return in room ordering service
if ($type == 'in-room-ordering') {
$screen_attrs = $this->get_screen_attrs();
//$struct = $this->get_taxonomy_terms('food_category');
$struct = $this->get_menu_category('food_category');
$total_menu_count = !empty($struct['total_menu_count']) ? $struct['total_menu_count'] : 0;
unset($struct['total_menu_count']);
$data = array('count' => count($struct), 'total_menu_count' => $total_menu_count, 'screen_id' => $screen_id, 'screen_title' => $screen_attrs[$screen_id], 'screen_image' => "", 'currency' => "\$", 'result' => $struct);
return $data;
}
//Redirect to other function and return todays events service
if ($type == 'todays-events') {
$screen_attrs = $this->get_screen_attrs();
$struct = $this->get_list_events($type);
$banner_data = $this->get_banner_image_by_slug('events');
$data = array('count' => count($struct), 'screen_id' => $screen_id, 'screen_title' => $screen_attrs[$screen_id], 'screen_image' => "", 'banner_image' => $banner_data['image'], 'description' => $banner_data['description'], 'result' => $struct);
return $data;
}
//Redirect to other function and return activity guide service
if ($type == 'activity-guide') {
$screen_attrs = $this->get_screen_attrs();
$struct = $this->get_list_activity_guide($type);
$banner_data = $this->get_banner_image_by_slug('activity-guide');
$data = array('count' => count($struct), 'screen_id' => $screen_id, 'screen_title' => $screen_attrs[$screen_id], 'screen_image' => "", 'banner_image' => $banner_data['image'], 'description' => $banner_data['description'], 'title' => 'Activities and Events', 'weekday_title' => 'Week day Activities', 'weekend_title' => 'Weekend Activities', 'result' => $struct);
return $data;
}
// Validate post types and permissions
$query['post_type'] = array();
foreach ((array) $type as $type_name) {
$post_type = get_post_type_object($type_name);
if (!(bool) $post_type || !$post_type->show_in_json) {
return new WP_Error('json_invalid_post_type', sprintf(__('The post type "%s" is not valid'), $type_name), array('status' => 403));
}
$query['post_type'][] = $post_type->name;
}
global $wp;
// Allow the same as normal WP
$valid_vars = apply_filters('query_vars', $wp->public_query_vars);
// If the user has the correct permissions, also allow use of internal
// query parameters, which are only undesirable on the frontend
//
// To disable anyway, use `add_filter('json_private_query_vars', '__return_empty_array');`
if (current_user_can($post_type->cap->edit_posts)) {
$private = apply_filters('json_private_query_vars', $wp->private_query_vars);
$valid_vars = array_merge($valid_vars, $private);
}
// Define our own in addition to WP's normal vars
$json_valid = array('posts_per_page');
$valid_vars = array_merge($valid_vars, $json_valid);
// Filter and flip for querying
$valid_vars = apply_filters('json_query_vars', $valid_vars);
$valid_vars = array_flip($valid_vars);
// Exclude the post_type query var to avoid dodging the permission
// check above
unset($valid_vars['post_type']);
foreach ($valid_vars as $var => $index) {
if (isset($filter[$var])) {
$query[$var] = apply_filters('json_query_var-' . $var, $filter[$var]);
}
}
// Special parameter handling
$query['paged'] = absint($page);
$query['posts_per_page'] = -1;
$post_query = new WP_Query();
$posts_list = $post_query->query($query);
$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 (!$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;
}
$post_data['tag_name'] = $post['post_name'];
$post_data = $this->format_get_data($post_data, $post['ID']);
$struct[] = $post_data;
}
$screen_attrs = $this->get_screen_attrs();
$data = array('count' => count($struct), 'screen_id' => $screen_id, 'screen_title' => $screen_attrs[$screen_id], 'screen_image' => "", 'result' => $struct);
$response->set_data($data);
return $response;
}
开发者ID:elangovanaspire,项目名称:bimini,代码行数:101,代码来源:class-crocs-json-posts.php
示例17: get_index
/**
* Get the site index.
*
* This endpoint describes the capabilities of the site.
*
* @todo Should we generate text documentation too based on PHPDoc?
*
* @return array Index entity
*/
public function get_index()
{
// General site data
$available = array('name' => get_option('blogname'), 'description' => get_option('blogdescription'), 'URL' => get_option('siteurl'), 'routes' => array(), 'authentication' => array(), 'meta' => array('links' => array('help' => 'https://github.com/WP-API/WP-API', 'profile' => 'https://raw.github.com/WP-API/WP-API/master/docs/schema.json')));
// Find the available routes
foreach ($this->get_routes() as $route => $callbacks) {
$data = array();
$route = preg_replace('#\\(\\?P(<\\w+?>).*?\\)#', '$1', $route);
$methods = array();
foreach (self::$method_map as $name => $bitmask) {
foreach ($callbacks as $callback) {
// Skip to the next route if any callback is hidden
if ($callback[1] & self::HIDDEN_ENDPOINT) {
continue 3;
}
if ($callback[1] & $bitmask) {
$data['supports'][] = $name;
}
if ($callback[1] & self::ACCEPT_JSON) {
$data['accepts_json'] = true;
}
// For non-variable routes, generate links
if (strpos($route, '<') === false) {
$data['meta'] = array('self' => json_url($route));
}
}
}
$available['routes'][$route] = apply_filters('json_endpoints_description', $data);
}
return apply_filters('json_index', $available);
}
开发者ID:Numerico-Informatic-Systems-Pvt-Ltd,项目名称:parkerpci,代码行数:40,代码来源:class-wp-json-server.php
示例18: prepare_post
//.........这里部分代码省略.........
// Without this, get_the_content() will give a password form.
require_once ABSPATH . 'wp-includes/class-phpass.php';
$hasher = new PasswordHash(8, true);
$value = $hasher->HashPassword($post['post_password']);
$_COOKIE['wp-postpass_' . COOKIEHASH] = wp_slash($value);
}
$GLOBALS['post'] = $post_obj;
setup_postdata($post_obj);
// prepare common post fields
$post_fields = array('title' => get_the_title($post['ID']), 'status' => $post['post_status'], 'type' => $post['post_type'], 'author' => (int) $post['post_author'], 'content' => apply_filters('the_content', $post['post_content']), 'parent' => (int) $post['post_parent'], 'link' => get_permalink($post['ID']));
$post_fields_extended = array('slug' => $post['post_name'], 'guid' => apply_filters('get_the_guid', $post['guid']), 'excerpt' => $this->prepare_excerpt($post['post_excerpt']), 'menu_order' => (int) $post['menu_order'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'sticky' => $post['post_type'] === 'post' && is_sticky($post['ID']));
$post_fields_raw = array('title_raw' => $post['post_title'], 'content_raw' => $post['post_content'], 'excerpt_raw' => $post['post_excerpt'], 'guid_raw' => $post['guid'], 'post_meta' => $this->handle_get_post_meta($post['ID']));
// Dates
$timezone = json_get_timezone();
if ($post['post_date_gmt'] === '0000-00-00 00:00:00') {
$post_fields['date'] = null;
$post_fields_extended['date_tz'] = null;
$post_fields_extended['date_gmt'] = null;
} else {
$post_date = WP_JSON_DateTime::createFromFormat('Y-m-d H:i:s', $post['post_date'], $timezone);
$post_fields['date'] = json_mysql_to_rfc3339($post['post_date']);
$post_fields_extended['date_tz'] = $post_date->format('e');
$post_fields_extended['date_gmt'] = json_mysql_to_rfc3339($post['post_date_gmt']);
}
if ($post['post_modified_gmt'] === '0000-00-00 00:00:00') {
$post_fields['modified'] = null;
$post_fields_extended['modified_tz'] = null;
$post_fields_extended['modified_gmt'] = null;
} else {
$modified_date = WP_JSON_DateTime::createFromFormat('Y-m-d H:i:s', $post['post_modified'], $timezone);
$post_fields['modified'] = json_mysql_to_rfc3339($post['post_modified']);
$post_fields_extended['modified_tz'] = $modified_date->format('e');
$post_fields_extended['modified_gmt'] = json_mysql_to_rfc3339($post['post_modified_gmt']);
}
// Authorized fields
// TODO: Send `Vary: Authorization` to clarify that the data can be
// changed by the user's auth status
if (json_check_post_permission($post, 'edit')) {
$post_fields_extended['password'] = $post['post_password'];
}
// Consider future posts as published
if ($post_fields['status'] === 'future') {
$post_fields['status'] = 'publish';
}
// Fill in blank post format
$post_fields['format'] = get_post_format($post['ID']);
if (empty($post_fields['format'])) {
$post_fields['format'] = 'standard';
}
if (0 === $post['post_parent']) {
$post_fields['parent'] = null;
}
if (('view' === $context || 'view-revision' == $context) && 0 !== $post['post_parent']) {
// Avoid nesting too deeply
// This gives post + post-extended + meta for the main post,
// post + meta for the parent and just meta for the grandparent
$parent = get_post($post['post_parent'], ARRAY_A);
$post_fields['parent'] = $this->prepare_post($parent, 'embed');
}
// Merge requested $post_fields fields into $_post
$_post = array_merge($_post, $post_fields);
// Include extended fields. We might come back to this.
$_post = array_merge($_post, $post_fields_extended);
if ('edit' === $context) {
if (json_check_post_permission($post, 'edit')) {
$_post = array_merge($_post, $post_fields_raw);
} else {
$GLOBALS['post'] = $previous_post;
if ($previous_post) {
setup_postdata($previous_post);
}
return new WP_Error('json_cannot_edit', __('Sorry, you cannot edit this post'), array('status' => 403));
}
} elseif ('view-revision' == $context) {
if (json_check_post_permission($post, 'edit')) {
$_post = array_merge($_post, $post_fields_raw);
} else {
$GLOBALS['post'] = $previous_post;
if ($previous_post) {
setup_postdata($previous_post);
}
return new WP_Error('json_cannot_view', __('Sorry, you cannot view this revision'), array('status' => 403));
}
}
// Entity meta
$links = array('self' => json_url('/posts/' . $post['ID']), 'author' => json_url('/users/' . $post['post_author']), 'collection' => json_url('/posts'));
if ('view-revision' != $context) {
$links['replies'] = json_url('/posts/' . $post['ID'] . '/comments');
$links['version-history'] = json_url('/posts/' . $post['ID'] . '/revisions');
}
$_post['meta'] = array('links' => $links);
if (!empty($post['post_parent'])) {
$_post['meta']['links']['up'] = json_url('/posts/' . (int) $post['post_parent']);
}
$GLOBALS['post'] = $previous_post;
if ($previous_post) {
setup_postdata($previous_post);
}
return apply_filters('json_prepare_post', $_post, $post, $context);
}
开发者ID:safetycat,项目名称:edibleurban,代码行数:101,代码来源:class-wp-json-posts.php
示例19: add_meta
public function add_meta($id, $data)
{
$id = (int) $id;
if (empty($id)) {
return new WP_Error('json_post_invalid_id', __('Invalid post ID.'), array('status' => 404));
}
$post = get_post($id, ARRAY_A);
if (empty($post['ID'])) {
return new WP_Error('json_post_invalid_id', __('Invalid post ID.'), array('status' => 404));
}
/* if ( ! $this->check_edit_permission( $post ) ) {
return new WP_Error( 'json_cannot_edit', __( 'Sorry, you cannot edit this post' ), array( 'status' => 403 ) );
} */
if (!array_key_exists('key', $data)) {
return new WP_Error('json_post_missing_key', __('Missing meta key.'), array('status' => 400));
}
if (!array_key_exists('value', $data)) {
return new WP_Error('json_post_missing_value', __('Missing
|
请发表评论