当前位置: 首页>>代码示例>>PHP>>正文


PHP rest_authorization_required_code函数代码示例

本文整理汇总了PHP中rest_authorization_required_code函数的典型用法代码示例。如果您正苦于以下问题:PHP rest_authorization_required_code函数的具体用法?PHP rest_authorization_required_code怎么用?PHP rest_authorization_required_code使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了rest_authorization_required_code函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: delete_item_permissions_check

 /**
  * check if a request can delete a theme
  *
  * @param WP_REST_Request $request
  * @return WP_Error|boolean
  */
 public function delete_item_permissions_check($request)
 {
     if (!current_user_can('delete_themes')) {
         return new WP_Error('rest_forbidden', __('Sorry, you cannot delete themes'), array('status' => rest_authorization_required_code()));
     }
     return true;
 }
开发者ID:WP-API,项目名称:wp-api-plugins-themes-endpoints,代码行数:13,代码来源:class-wp-rest-themes-controller.php

示例2: update_item_permissions_check

 /**
  * Check whether a given request has permission to execute a specific system status tool.
  *
  * @param  WP_REST_Request $request Full details about the request.
  * @return WP_Error|boolean
  */
 public function update_item_permissions_check($request)
 {
     if (!wc_rest_check_manager_permissions('system_status', 'edit')) {
         return new WP_Error('woocommerce_rest_cannot_update', __('Sorry, you cannot update resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
     }
     return true;
 }
开发者ID:tlovett1,项目名称:woocommerce,代码行数:13,代码来源:class-wc-rest-system-status-tools-controller.php

示例3: get_items_permissions_check

 /**
  * Check whether a given request has permission to view system status.
  *
  * @param  WP_REST_Request $request Full details about the request.
  * @return WP_Error|boolean
  */
 public function get_items_permissions_check($request)
 {
     if (!wc_rest_check_manager_permissions('system_status', 'read')) {
         return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
     }
     return true;
 }
开发者ID:Korkey128k,项目名称:woocommerce,代码行数:13,代码来源:class-wc-rest-system-status-controller.php

示例4: get_items_permissions_check

 /**
  * Check if a given request has access to read /entry.
  *
  * @param  WP_REST_Request $request Full details about the request.
  *
  * @return WP_Error|boolean
  */
 public function get_items_permissions_check($request)
 {
     if ('edit' === $request['context'] && (!current_user_can('connections_edit_entry') || !current_user_can('connections_edit_entry_moderated'))) {
         return new WP_Error('rest_forbidden_context', __('Sorry, you are not allowed to edit these entries.', 'connections'), array('status' => rest_authorization_required_code()));
     }
     return TRUE;
 }
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:14,代码来源:class.cn-rest-entry-controller.php

示例5: 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);
 }
开发者ID:Datartisan,项目名称:datartery-wp,代码行数:34,代码来源:class-wp-rest-post-statuses-controller.php

示例6: delete_item_permissions_check

 /**
  * Check if a given request has access delete a tax.
  *
  * @param  WP_REST_Request $request Full details about the request.
  * @return boolean
  */
 public function delete_item_permissions_check($request)
 {
     if (!wc_rest_check_manager_permissions('settings', 'delete')) {
         return new WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
     }
     return true;
 }
开发者ID:unfulvio,项目名称:woocommerce,代码行数:13,代码来源:class-wc-rest-tax-classes-controller.php

示例7: update_items_permissions_check

 /**
  * Check whether a given request has permission to edit payment gateways.
  *
  * @param  WP_REST_Request $request Full details about the request.
  * @return WP_Error|boolean
  */
 public function update_items_permissions_check($request)
 {
     if (!wc_rest_check_manager_permissions('payment_gateways', 'edit')) {
         return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
     }
     return true;
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:13,代码来源:class-wc-rest-payment-gateways-controller.php

示例8: get_item_permissions_check

 /**
  * Check if a given request has access to read a webhook develivery.
  *
  * @param  WP_REST_Request $request Full details about the request.
  * @return WP_Error|boolean
  */
 public function get_item_permissions_check($request)
 {
     $post = get_post((int) $request['product_id']);
     if ($post && !wc_rest_check_post_permissions('product', 'read', $post->ID)) {
         return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
     }
     return true;
 }
开发者ID:unfulvio,项目名称:woocommerce,代码行数:14,代码来源:class-wc-rest-product-reviews-controller.php

示例9: get_items_permissions_check

 /**
  * Check whether a given request has permission to read customers.
  *
  * @param  WP_REST_Request $request Full details about the request.
  * @return WP_Error|boolean
  */
 public function get_items_permissions_check($request)
 {
     $customer = get_user_by('id', (int) $request['customer_id']);
     if (!$customer) {
         return new WP_Error('woocommerce_rest_customer_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
     }
     if (!wc_rest_check_user_permissions('read', $customer->id)) {
         return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
     }
     return true;
 }
开发者ID:tlovett1,项目名称:woocommerce,代码行数:17,代码来源:class-wc-rest-customer-downloads-controller.php

示例10: get_items_permissions_check

 /**
  * Check if a given request has access to get revisions
  *
  * @param WP_REST_Request $request Full data about the request.
  * @return WP_Error|bool
  */
 public function get_items_permissions_check($request)
 {
     $parent = get_post($request['parent_id']);
     if (!$parent) {
         return true;
     }
     $parent_post_type_obj = get_post_type_object($parent->post_type);
     if (!current_user_can($parent_post_type_obj->cap->edit_post, $parent->ID)) {
         return new WP_Error('rest_cannot_read', __('Sorry, you cannot view revisions of this post.'), array('status' => rest_authorization_required_code()));
     }
     return true;
 }
开发者ID:crazyyy,项目名称:octagram,代码行数:18,代码来源:class-wp-rest-revisions-controller.php

示例11: get_item_permissions_check

 /**
  * Check if a given request has access to read a post status.
  *
  * @param  WP_REST_Request $request Full details about the request.
  * @return WP_Error|boolean
  */
 public function get_item_permissions_check($request)
 {
     $status = get_post_status_object($request['status']);
     if (empty($status)) {
         return new WP_Error('rest_status_invalid', __('Invalid resource.'), array('status' => 404));
     }
     $check = $this->check_read_permission($status);
     if (!$check) {
         return new WP_Error('rest_cannot_read_status', __('Cannot view resource.'), array('status' => rest_authorization_required_code()));
     }
     return true;
 }
开发者ID:xeiter,项目名称:timeplannr,代码行数:18,代码来源:class-wp-rest-post-statuses-controller.php

示例12: get_item_permissions_check

 /**
  * Check if a given request has access a taxonomy
  *
  * @param  WP_REST_Request $request Full details about the request.
  * @return WP_Error|boolean
  */
 public function get_item_permissions_check($request)
 {
     $tax_obj = get_taxonomy($request['taxonomy']);
     if ($tax_obj) {
         if (empty($tax_obj->show_in_rest)) {
             return false;
         }
         if ('edit' === $request['context'] && !current_user_can($tax_obj->cap->manage_terms)) {
             return new WP_Error('rest_forbidden_context', __('Sorry, you are not allowed to manage this taxonomy.'), array('status' => rest_authorization_required_code()));
         }
     }
     return true;
 }
开发者ID:Datartisan,项目名称:datartery-wp,代码行数:19,代码来源:class-wp-rest-taxonomies-controller.php

示例13: get_item

 /**
  * Get a specific post type
  *
  * @param WP_REST_Request $request
  * @return array|WP_Error
  */
 public function get_item($request)
 {
     $obj = get_post_type_object($request['type']);
     if (empty($obj)) {
         return new WP_Error('rest_type_invalid', __('Invalid type.'), array('status' => 404));
     }
     if (empty($obj->show_in_rest)) {
         return new WP_Error('rest_cannot_read_type', __('Cannot view type.'), array('status' => rest_authorization_required_code()));
     }
     if ('edit' === $request['context'] && !current_user_can($obj->cap->edit_posts)) {
         return new WP_Error('rest_forbidden_context', __('Sorry, you are not allowed to manage this type.'), array('status' => rest_authorization_required_code()));
     }
     return $this->prepare_item_for_response($obj, $request);
 }
开发者ID:deepaksinghdhanik,项目名称:ng-wp,代码行数:20,代码来源:class-wp-rest-post-types-controller.php

示例14: create_item_permissions_check

 /**
  * Checks if a given request has access to create an attachment.
  *
  * @since 4.7.0
  * @access public
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_Error|true Boolean true if the attachment may be created, or a WP_Error if not.
  */
 public function create_item_permissions_check($request)
 {
     $ret = parent::create_item_permissions_check($request);
     if (!$ret || is_wp_error($ret)) {
         return $ret;
     }
     if (!current_user_can('upload_files')) {
         return new WP_Error('rest_cannot_create', __('Sorry, you are not allowed to upload media on this site.'), array('status' => 400));
     }
     // Attaching media to a post requires ability to edit said post.
     if (!empty($request['post'])) {
         $parent = get_post((int) $request['post']);
         $post_parent_type = get_post_type_object($parent->post_type);
         if (!current_user_can($post_parent_type->cap->edit_post, $request['post'])) {
             return new WP_Error('rest_cannot_edit', __('Sorry, you are not allowed to upload media to this post.'), array('status' => rest_authorization_required_code()));
         }
     }
     return true;
 }
开发者ID:johnpbloch,项目名称:wordpress,代码行数:28,代码来源:class-wp-rest-attachments-controller.php

示例15: prepare_item_for_response

 /**
  * Prepare a post type object for serialization
  *
  * @param stdClass $post_type Post type data
  * @param WP_REST_Request $request
  * @return array Post type data
  */
 public function prepare_item_for_response($post_type, $request)
 {
     if (false === $post_type->public) {
         return new WP_Error('rest_cannot_read_type', __('Cannot view type.'), array('status' => rest_authorization_required_code()));
     }
     $data = array('description' => $post_type->description, 'hierarchical' => $post_type->hierarchical, 'labels' => $post_type->labels, 'name' => $post_type->label, 'slug' => $post_type->name);
     $context = !empty($request['context']) ? $request['context'] : 'view';
     $data = $this->filter_response_by_context($data, $context);
     $data = $this->add_additional_fields_to_object($data, $request);
     // Wrap the data in a response object.
     $response = rest_ensure_response($data);
     $base = !empty($post_type->rest_base) ? $post_type->rest_base : $post_type->name;
     $response->add_links(array('collection' => array('href' => rest_url('wp/v2/types')), 'item' => array('href' => rest_url(sprintf('wp/v2/%s', $base)))));
     /**
      * Filter a post type returned from the API.
      *
      * Allows modification of the post type data right before it is returned.
      *
      * @param WP_REST_Response  $response   The response object.
      * @param object            $item       The original post type object.
      * @param WP_REST_Request   $request    Request used to generate the response.
      */
     return apply_filters('rest_prepare_post_type', $response, $post_type, $request);
 }
开发者ID:alexandrinos,项目名称:wp-api-rest,代码行数:31,代码来源:class-wp-rest-post-types-controller.php


注:本文中的rest_authorization_required_code函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。