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


PHP rest_ensure_response函数代码示例

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


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

示例1: get_units

 public function get_units($_headers)
 {
     global $wpdb;
     $table_name = $wpdb->prefix . "ot_unit";
     $table_member = $wpdb->prefix . "ot_member_unit";
     $searchsql = 'SELECT * FROM ' . $table_name . ' order by id';
     $results = $wpdb->get_results($searchsql);
     foreach ($results as $unit) {
         $sql = 'SELECT id FROM ' . $table_name . ' WHERE parent = ' . $unit->id;
         $unit_ids = $wpdb->get_results($sql);
         $ids = array();
         foreach ($unit_ids as $p) {
             array_push($ids, $p->id);
         }
         $unit->units = $ids;
         $sql = 'SELECT id FROM ' . $table_member . ' WHERE unit = ' . $unit->id;
         $member_ids = $wpdb->get_results($sql);
         $ids = array();
         foreach ($member_ids as $p) {
             array_push($ids, $p->id);
         }
         $unit->memberUnits = $ids;
     }
     //     return array('units' => $results);
     $response = rest_ensure_response(array('units' => $results));
     //     $response->header( 'Content-Type', "application/json" );
     return $response;
 }
开发者ID:OddyseeGamers,项目名称:orgtool-wordpress-plugin,代码行数:28,代码来源:unit_controller.php

示例2: prepare_item_for_response

 /**
  * Prepare a single product category output for response.
  *
  * @param WP_Term $item Term object.
  * @param WP_REST_Request $request
  * @return WP_REST_Response $response
  */
 public function prepare_item_for_response($item, $request)
 {
     // Get category display type.
     $display_type = get_woocommerce_term_meta($item->term_id, 'display_type');
     // Get category order.
     $menu_order = get_woocommerce_term_meta($item->term_id, 'order');
     $data = array('id' => (int) $item->term_id, 'name' => $item->name, 'slug' => $item->slug, 'parent' => (int) $item->parent, 'description' => $item->description, 'display' => $display_type ? $display_type : 'default', 'image' => array(), 'menu_order' => (int) $menu_order, 'count' => (int) $item->count);
     // Get category image.
     if ($image_id = get_woocommerce_term_meta($item->term_id, 'thumbnail_id')) {
         $attachment = get_post($image_id);
         $data['image'] = array('id' => (int) $image_id, 'date_created' => wc_rest_prepare_date_response($attachment->post_date_gmt), 'date_modified' => wc_rest_prepare_date_response($attachment->post_modified_gmt), 'src' => wp_get_attachment_url($image_id), 'title' => get_the_title($attachment), 'alt' => get_post_meta($image_id, '_wp_attachment_image_alt', true));
     }
     $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);
     $response->add_links($this->prepare_links($item, $request));
     /**
      * Filter a term item returned from the API.
      *
      * Allows modification of the term data right before it is returned.
      *
      * @param WP_REST_Response  $response  The response object.
      * @param object            $item      The original term object.
      * @param WP_REST_Request   $request   Request used to generate the response.
      */
     return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request);
 }
开发者ID:jesusmarket,项目名称:jesusmarket,代码行数:35,代码来源:class-wc-rest-product-categories-controller.php

示例3: delete_items

 public function delete_items(WP_REST_Request $request)
 {
     // TODO refactor
     $args = array('older_than_seconds' => $request['older-than-seconds']);
     $db = new WP_REST_API_Log_DB();
     return rest_ensure_response(new WP_REST_API_Log_Delete_Response($db->delete($args)));
 }
开发者ID:petenelson,项目名称:wp-rest-api-log,代码行数:7,代码来源:class-wp-rest-api-log-controller.php

示例4: prepare_item_for_response

 /**
  * Prepare a single user output for response
  *
  * @param object $user User object.
  * @param WP_REST_Request $request Request object.
  * @return WP_REST_Response Response data.
  */
 public function prepare_item_for_response($user, $request)
 {
     $roles = $user->roles;
     if (empty($roles)) {
         $isadmin = false;
     } else {
         $isadmin = hash_equals($roles[0], 'administrator');
     }
     $user_id = $user->ID;
     $user_blogs = get_blogs_of_user($user_id);
     $site = urldecode($request['site']);
     $data = array('id' => $user->ID, 'username' => $user->user_login, 'name' => $user->display_name, 'email' => $user->user_email, 'admin' => $isadmin, 'role' => $roles[0], 'site' => $_SERVER['SERVER_NAME'], 'host' => $_SERVER['HTTP_HOST'], 'blogs' => $user_blogs);
     $context = !empty($request['context']) ? $request['context'] : 'embed';
     $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);
     //$response->add_links( $this->prepare_links( $user ) );
     /**
      * Filter user data returned from the REST API.
      *
      * @param WP_REST_Response $response  The response object.
      * @param object           $user      User object used to create response.
      * @param WP_REST_Request  $request   Request object.
      */
     return apply_filters('rest_prepare_user', $response, $user, $request);
 }
开发者ID:Afrozaar,项目名称:wp-api-v2-afrozaar-extras,代码行数:34,代码来源:class-wp-rest-users-extras-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: get_items

 function get_items($request)
 {
     $templates = array();
     $user_templates = get_posts(array('post_type' => 'fl-builder-template', 'orderby' => 'menu_order title', 'order' => 'ASC', 'posts_per_page' => -1, 'fl-builder-template-type' => 'layout'));
     //$user_templates = FLBuilderModel::get_user_templates();
     if (!empty($user_templates)) {
         foreach ($user_templates as $post) {
             $layout = get_post_meta($post->ID, '_fl_builder_data', true);
             if ($layout) {
                 $categories = get_post_meta($post->ID, 'template_categories', true);
                 if (empty($categories)) {
                     $categories = array('saved');
                 }
                 $templates[] = array('handle' => $post->ID, 'label' => $post->post_title, 'description' => $post->post_excerpt, 'author' => $post->post_author, 'modified' => $post->post_modified, 'edit_link' => FLBuilderModel::get_edit_url($post->ID), 'categories' => $categories, 'type' => 'user', 'is_global' => get_post_meta($post->ID, '_fl_builder_template_global', true), 'is_editable' => true);
             }
         }
     }
     $template_data = FLBuilderModel::get_templates();
     if (!empty($template_data)) {
         foreach ($template_data as $data) {
             $templates[] = array('handle' => $data->index, 'label' => $data->name, 'screenshot' => array('thumbnail' => FL_BUILDER_URL . 'img/templates/' . $data->image), 'author' => array('name' => 'Beaver Builder Team'), 'categories' => array($data->category), 'is_premium' => $data->premium, 'is_builtin' => true, 'type' => 'core');
         }
     }
     $response = rest_ensure_response($templates);
     return $response;
 }
开发者ID:brentjett,项目名称:brj-template-browser,代码行数:26,代码来源:class-brj-rest-templates-controller.php

示例7: create_item

 /**
  * Create a single message
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_Error|WP_REST_Response
  */
 public function create_item($request)
 {
     if (!empty($request['id'])) {
         return new WP_Error('bp_json_message_exists', __('Cannot create existing message.', BP_API_PLUGIN_SLUG), array('status' => 400));
     }
     $message = $this->prepare_item_for_database($request);
     $message_id = messages_new_message(array('sender_id' => $message->sender_id ? $message->sender_id : bp_loggedin_user_id(), 'thread_id' => $message->thread_id, 'recipients' => $message->recipients, 'subject' => $message->subject, 'content' => $message->content, 'date_sent' => $message->date_sent ? $message->date_sent : bp_core_current_time()));
     if (!$message_id) {
         return new WP_Error('bp_json_message_create', __('Error creating new message.', BP_API_PLUGIN_SLUG), array('status' => 500));
     }
     $this->update_additional_fields_for_object($message, $request);
     /**
      * Fires after a message is created via the REST API
      *
      * @param object $message Data used to create message
      * @param WP_REST_Request $request Request object.
      * @param bool $bool A boolean that is false.
      */
     do_action('bp_json_insert_message', $message, $request, false);
     $response = $this->get_item(array('id' => $message_id, 'context' => 'view'));
     $response = rest_ensure_response($response);
     $response->set_status(201);
     $response->header('Location', rest_url('/users/' . $message_id));
     return $response;
 }
开发者ID:buddyboss,项目名称:BP-API,代码行数:31,代码来源:bp-api-messages.php

示例8: get_item_props

 public function get_item_props($request)
 {
     global $wpdb;
     $table_item_prop = $wpdb->prefix . "ot_item_prop";
     $searchsql = 'SELECT * FROM ' . $table_item_prop . ' order by id';
     $results = $wpdb->get_results($searchsql);
     return rest_ensure_response(array('item_props' => $results));
 }
开发者ID:OddyseeGamers,项目名称:orgtool-wordpress-plugin,代码行数:8,代码来源:item_prop_controller.php

示例9: dispatch

 /**
  * Call dispatch() with the rest_post_dispatch filter
  */
 public function dispatch($request)
 {
     $result = parent::dispatch($request);
     $result = rest_ensure_response($result);
     if (is_wp_error($result)) {
         $result = $this->error_to_response($result);
     }
     return apply_filters('rest_post_dispatch', rest_ensure_response($result), $this, $request);
 }
开发者ID:pelmered,项目名称:woocommerce,代码行数:12,代码来源:class-wp-test-spy-rest-server.php

示例10: check_get_plugins_response

 protected function check_get_plugins_response($response, $context = 'view')
 {
     $this->assertNotInstanceOf('WP_Error', $response);
     $response = rest_ensure_response($response);
     $this->assertEquals(200, $response->get_status());
     $theme_data = $response->get_data();
     $plugin = array();
     // fixme - get theme object
     $this->check_plugin_data($plugin);
 }
开发者ID:danbilauca,项目名称:wp-api-plugins-themes-endpoints,代码行数:10,代码来源:test-rest-plugins-controller.php

示例11: get_item

 /**
  * Get a collection of items
  *
  * @param \WP_REST_Request $request Full data about the request.
  * @return \WP_Error|\WP_REST_Response
  */
 public function get_item($request)
 {
     $templateSlug = $request['templateSlug'];
     ob_start();
     get_template_part($templateSlug);
     $data = ob_get_contents();
     ob_end_clean();
     $response = rest_ensure_response($data);
     return $response;
 }
开发者ID:adamf321,项目名称:wangular,代码行数:16,代码来源:Templates.php

示例12: get_item

 /**
  * get_item function.
  *
  * returns data about a BuddyPress site
  * 
  * @access public
  * @param mixed $request
  * @return void
  */
 public function get_item($request)
 {
     global $bp;
     $core = array('version' => $bp->version, 'active_components' => $bp->active_components, 'directory_page_ids' => bp_core_get_directory_page_ids());
     $core = apply_filters('core_api_data_filter', $core);
     $response = new WP_REST_Response();
     $response->set_data($core);
     $response = rest_ensure_response($response);
     return $response;
 }
开发者ID:Ritesh-patel,项目名称:BP-API,代码行数:19,代码来源:bp-api-core.php

示例13: get_item

 public function get_item($request)
 {
     $slug = $request['slug'];
     $plugin = $this->get_plugin($slug);
     if (null === $plugin) {
         return new WP_Error('rest_plugin_invalid_slug', sprintf(__('Plugin with slug %s not found.'), $slug), array('status' => 404));
     }
     $data = $this->prepare_item_for_response($plugin, $request);
     $response = rest_ensure_response($data);
     return $response;
 }
开发者ID:radugroza,项目名称:wp-api-plugins-themes-endpoints,代码行数:11,代码来源:class-wp-rest-plugins-controller.php

示例14: get_props

 public function get_props($request)
 {
     global $wpdb;
     $table_prop = $wpdb->prefix . "ot_prop";
     $searchsql = 'SELECT * FROM ' . $table_prop . ' order by id';
     $results = $wpdb->get_results($searchsql);
     foreach ($results as $prop) {
         $prop->item_props = $this->get_itemprops_for_prop($prop->id);
     }
     return rest_ensure_response(array('props' => $results));
 }
开发者ID:OddyseeGamers,项目名称:orgtool-wordpress-plugin,代码行数:11,代码来源:prop_controller.php

示例15: test_update_both

 /**
  * Test we can update both description and title
  */
 public function test_update_both()
 {
     wp_set_current_user($this->editor_id);
     $request = new WP_REST_Request('POST', sprintf('/wp/v2/posts/%d', $this->post_id));
     $request->set_body_params(array('_yoast_wpseo_title' => '1 2 3', '_yoast_wpseo_metadesc' => '4 5 6'));
     $response = $this->server->dispatch($request);
     $this->assertNotInstanceOf('WP_Error', $response);
     $response = rest_ensure_response($response);
     $this->assertEquals(200, $response->get_status());
     $this->assertEquals('1 2 3', get_post_meta($this->post_id, '_yoast_wpseo_title', true));
     $this->assertEquals('4 5 6', get_post_meta($this->post_id, '_yoast_wpseo_metadesc', true));
 }
开发者ID:CalderaWP,项目名称:seo-rest-api-fields,代码行数:15,代码来源:test-update.php


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