• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP WP_REST_Response类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: prepare_response_for_collection

 /**
  * Prepare a response for inserting into a collection.
  *
  * @param WP_REST_Response $response Response object.
  * @return array Response data, ready for insertion into collection data.
  */
 public function prepare_response_for_collection($response)
 {
     if (!$response instanceof WP_REST_Response) {
         return $response;
     }
     $data = (array) $response->get_data();
     $server = rest_get_server();
     if (method_exists($server, 'get_compact_response_links')) {
         $links = call_user_func(array($server, 'get_compact_response_links'), $response);
     } else {
         $links = call_user_func(array($server, 'get_response_links'), $response);
     }
     if (!empty($links)) {
         $data['_links'] = $links;
     }
     return $data;
 }
开发者ID:Korkey128k,项目名称:woocommerce,代码行数:23,代码来源:class-wp-rest-controller.php


示例2: wpsms_list

function wpsms_list(WP_REST_Request $request)
{
    $list_sms = array();
    $item = array();
    global $account_sid;
    global $auth_token;
    try {
        $client = new Services_Twilio($account_sid, $auth_token);
        foreach ($client->account->messages as $message) {
            $from = $message->from;
            $to = $message->to;
            $body = $message->body;
            $date_sent = $message->date_sent;
            array_push($item, array("from" => $from, "to" => $to, "body" => $body, "date_sent" => $date_sent));
        }
        $list_sms = array_merge($list_sms, array("list" => $item));
        $response = new WP_REST_Response($list_sms);
        $response->header('Access-Control-Allow-Origin', apply_filters('wpsms_access_control_allow_origin', '*'));
        return $response;
    } catch (Exception $ex) {
        $user_msgs = array("data" => 'ERROR:' . $ex->getMessage());
        $response = new WP_REST_Response($user_msgs);
        $response->header('Access-Control-Allow-Origin', apply_filters('wpsms_access_control_allow_origin', '*'));
    }
}
开发者ID:PatzMatias,项目名称:smsAppTwilio,代码行数:25,代码来源:rest-routes.php


示例3: me_get_modules

 /**
  * Gets a list of modules for our API endpoint
  * 
  * Callback for the GET method of the "modules" endpoint
  *
  * @since 0.1.1
  * 
  * 
  */
 function me_get_modules()
 {
     $return = Me_Utils::get_all_modules();
     $response = new WP_REST_Response($return);
     $response->header('Access-Control-Allow-Origin', apply_filters('giar_access_control_allow_origin', '*'));
     return $response;
 }
开发者ID:jastuccio,项目名称:Me,代码行数:16,代码来源:class.me.api-modules.php


示例4: 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


示例5: create_price

 public function create_price($request)
 {
     $required_keys = array('ticket_price', 'price_band_id', 'ticket_type_id');
     $meta = $request[$this->post_type . "_meta"] ? $request[$this->post_type . "_meta"] : array();
     if (count(array_intersect_key(array_flip($required_keys), $meta)) >= count($required_keys)) {
         return $this->create_item($request);
     } else {
         $error = new WP_REST_Response(array('message' => 'Insufficient parameters', 'data' => array('status' => 422)));
         $error->set_status(422);
         return $error;
     }
 }
开发者ID:rooftopcms,项目名称:rooftop-events,代码行数:12,代码来源:class-rooftop-prices-controller.php


示例6: filter_ee_metadata_into_index

 /**
  * Adds EE metadata to the index
  * @param WP_REST_Response $rest_response_obj
  * @return WP_REST_Response
  */
 public static function filter_ee_metadata_into_index($rest_response_obj)
 {
     $response_data = $rest_response_obj->get_data();
     $addons = array();
     foreach (\EE_Registry::instance()->addons as $addon) {
         $addon_json = array('name' => $addon->name(), 'version' => $addon->version());
         $addons[$addon_json['name']] = $addon_json;
     }
     $response_data['ee'] = array('version' => \EEM_System_Status::instance()->get_ee_version(), 'addons' => $addons, 'maintenance_mode' => \EE_Maintenance_Mode::instance()->real_level(), 'served_core_versions' => array_keys(\EED_Core_Rest_Api::versions_served()));
     $rest_response_obj->set_data($response_data);
     return $rest_response_obj;
 }
开发者ID:teemuoksanen,项目名称:event-espresso-core,代码行数:17,代码来源:Meta.php


示例7: create_event_instance

 public function create_event_instance($request)
 {
     $event_id = $request['event_id'];
     $event_post = get_post($event_id);
     if ($event_post) {
         return $this->create_item($request);
     } else {
         $error = new WP_REST_Response(array('message' => 'Event not found'));
         $error->set_status(404);
         return $error;
     }
 }
开发者ID:rooftopcms,项目名称:rooftop-events,代码行数:12,代码来源:class-rooftop-event-instances-controller.php


示例8: filter_ee_metadata_into_index

 /**
  * Adds EE metadata to the index
  * @param \WP_REST_Response $rest_response_obj
  * @return \WP_REST_Response
  */
 public static function filter_ee_metadata_into_index(\WP_REST_Response $rest_response_obj)
 {
     $response_data = $rest_response_obj->get_data();
     $addons = array();
     foreach (\EE_Registry::instance()->addons as $addon) {
         $addon_json = array('name' => $addon->name(), 'version' => $addon->version());
         $addons[$addon_json['name']] = $addon_json;
     }
     $response_data['ee'] = array('version' => \EEM_System_Status::instance()->get_ee_version(), 'documentation_url' => 'https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API', 'addons' => $addons, 'maintenance_mode' => \EE_Maintenance_Mode::instance()->real_level(), 'served_core_versions' => array_keys(\EED_Core_Rest_Api::versions_served()));
     $rest_response_obj->set_data($response_data);
     return $rest_response_obj;
 }
开发者ID:aaronfrey,项目名称:PepperLillie-GSP,代码行数:17,代码来源:Meta.php


示例9: get_pins

 public function get_pins()
 {
     if (0 || false === ($return = get_transient('rmaps_all_posts'))) {
         $query = apply_filters('rmaps_get_posts_query', array('numberposts' => 20, 'post_type' => 'pin', 'post_status' => 'publish'));
         $pins = get_posts($query);
         $return = array();
         foreach ($pins as $pin) {
             $return[] = array('ID' => $pin->ID, 'title' => esc_attr($pin->post_title), 'infowindow' => wp_kses_post($pin->post_content), 'see_more' => _x('See More', 'Link', $this->textdomain), 'permalink' => esc_url(get_permalink($pin->ID)), 'lat' => esc_attr(get_post_meta($pin->ID, 'latitude', true)), 'lon' => esc_attr(get_post_meta($pin->ID, 'longitude', true)));
         }
         /** Cache the query for 3 minutes */
         set_transient('rmaps_all_posts', $return, apply_filters('rmaps_posts_ttl', 60 * 3));
     }
     $response = new \WP_REST_Response($return);
     $response->header('Access-Control-Allow-Origin', apply_filters('rmaps_access_control_allow_origin', '*'));
     return $response;
 }
开发者ID:rwrobe,项目名称:restful_maps,代码行数:16,代码来源:RESTful_Maps.php


示例10: get_activity

 /**
  * get_activity function.
  * 
  * @access public
  * @param mixed $filter
  * @return void
  */
 public function get_activity($filter)
 {
     $args = $filter;
     if (bp_has_activities($args)) {
         while (bp_activities()) {
             bp_the_activity();
             $activity = array('avatar' => bp_core_fetch_avatar(array('html' => false, 'item_id' => bp_get_activity_id())), 'action' => bp_get_activity_action(), 'content' => bp_get_activity_content_body(), 'activity_id' => bp_get_activity_id(), 'activity_username' => bp_core_get_username(bp_get_activity_user_id()), 'user_id' => bp_get_activity_user_id(), 'comment_count' => bp_activity_get_comment_count(), 'can_comment' => bp_activity_can_comment(), 'can_favorite' => bp_activity_can_favorite(), 'is_favorite' => bp_get_activity_is_favorite(), 'can_delete' => bp_activity_user_can_delete());
             $activity = apply_filters('bp_json_prepare_activity', $activity);
             $activities[] = $activity;
         }
         $data = array('activity' => $activities, 'has_more_items' => bp_activity_has_more_items());
         $data = apply_filters('bp_json_prepare_activities', $data);
     } else {
         return new WP_Error('bp_json_activity', __('No Activity Found.', 'buddypress'), array('status' => 200));
     }
     $response = new WP_REST_Response();
     $response->set_data($data);
     $response = rest_ensure_response($response);
     return $response;
 }
开发者ID:Ritesh-patel,项目名称:BP-API,代码行数:27,代码来源:bp-api-activity.php


示例11: onGithubRequest

 /**
  * This method use for handler request from Github's webhook.
  *
  * Because of github not required to response payload on response, so we can make a do_action instead of apply_filters
  *
  * @param \WP_REST_Request $request
  *
  * @return \WP_REST_Response
  */
 public function onGithubRequest(\WP_REST_Request $request)
 {
     // Create the response object
     $request_payload = json_decode($request->get_body());
     $response = new \WP_REST_Response();
     if ($request_payload) {
         ob_start();
         $repo = new Repository($request_payload->repository->git_url);
         if ($repo->exists()) {
             $event = $request->get_header('X-Github-Event');
             do_action('wppm_webhook_recived_' . $event, $repo, $request_payload);
         } else {
             $response->set_status(404);
             echo "Repo is not exist.";
         }
         $out_put = ob_get_clean();
         $response->set_data($out_put);
     } else {
         $response->set_status(500);
     }
     return $response;
 }
开发者ID:nguyenvanduocit,项目名称:WP-Git-Manager,代码行数:31,代码来源:API.php


示例12: delete_item

 /**
  * Deletes a comment.
  *
  * @since 4.7.0
  * @access public
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_Error|WP_REST_Response Response object on success, or error object on failure.
  */
 public function delete_item($request)
 {
     $id = (int) $request['id'];
     $force = isset($request['force']) ? (bool) $request['force'] : false;
     $comment = get_comment($id);
     if (empty($comment)) {
         return new WP_Error('rest_comment_invalid_id', __('Invalid comment ID.'), array('status' => 404));
     }
     /**
      * Filters whether a comment can be trashed.
      *
      * Return false to disable trash support for the post.
      *
      * @since 4.7.0
      *
      * @param bool    $supports_trash Whether the post type support trashing.
      * @param WP_Post $comment        The comment object being considered for trashing support.
      */
     $supports_trash = apply_filters('rest_comment_trashable', EMPTY_TRASH_DAYS > 0, $comment);
     $request->set_param('context', 'edit');
     if ($force) {
         $previous = $this->prepare_item_for_response($comment, $request);
         $result = wp_delete_comment($comment->comment_ID, true);
         $response = new WP_REST_Response();
         $response->set_data(array('deleted' => true, 'previous' => $previous->get_data()));
     } else {
         // If this type doesn't support trashing, error out.
         if (!$supports_trash) {
             return new WP_Error('rest_trash_not_supported', __('The comment does not support trashing. Set force=true to delete.'), array('status' => 501));
         }
         if ('trash' === $comment->comment_approved) {
             return new WP_Error('rest_already_trashed', __('The comment has already been trashed.'), array('status' => 410));
         }
         $result = wp_trash_comment($comment->comment_ID);
         $comment = get_comment($comment->comment_ID);
         $response = $this->prepare_item_for_response($comment, $request);
     }
     if (!$result) {
         return new WP_Error('rest_cannot_delete', __('The comment cannot be deleted.'), array('status' => 500));
     }
     /**
      * Fires after a comment is deleted via the REST API.
      *
      * @since 4.7.0
      *
      * @param WP_Comment       $comment  The deleted comment data.
      * @param WP_REST_Response $response The response returned from the API.
      * @param WP_REST_Request  $request  The request sent to the API.
      */
     do_action('rest_delete_comment', $comment, $response, $request);
     return $response;
 }
开发者ID:CompositeUK,项目名称:clone.WordPress-Core,代码行数:61,代码来源:class-wp-rest-comments-controller.php


示例13: test_link_embedding_error

 /**
  * @depends test_link_embedding_params
  */
 public function test_link_embedding_error()
 {
     // Register our testing route
     $this->server->register_route('test', '/test/embeddable', array('methods' => 'GET', 'callback' => array($this, 'embedded_response_callback')));
     $response = new WP_REST_Response();
     $response->add_link('up', rest_url('/test/embeddable?error=1'), array('embeddable' => true));
     $data = $this->server->response_to_data($response, true);
     $this->assertArrayHasKey('_embedded', $data);
     $this->assertArrayHasKey('up', $data['_embedded']);
     // Check that errors are embedded correctly
     $up = $data['_embedded']['up'];
     $this->assertCount(1, $up);
     $this->assertInstanceOf('WP_REST_Response', $up[0]);
     $this->assertEquals(403, $up[0]->get_status());
     $up_data = $up[0]->get_data();
     $this->assertEquals('wp-api-test-error', $up_data[0]['code']);
     $this->assertEquals('Test message', $up_data[0]['message']);
 }
开发者ID:nathansh,项目名称:gifzone,代码行数:21,代码来源:test-rest-server.php


示例14: ingot_rest_response

/**
 * Create a REST response
 *
 * @param array|object|\WP_Error $data Response data
 * @param int $code Optional. Status cod. Default is 200
 * @param int|null $total Optional. if is an integer, will be used to set X-Ingot-Total header
 *
 * @return \WP_REST_Response|\WP_Error
 */
function ingot_rest_response($data, $code = 200, $total = null)
{
    if (!is_wp_error($data)) {
        if (404 == $code || empty($data)) {
            $response = new \WP_REST_Response(null, 404);
        } else {
            $response = new \WP_REST_Response($data, $code);
        }
        if (0 < absint($total)) {
            $response->header('X-Ingot-Total', (int) \ingot\testing\crud\group::total());
        }
        return $response;
    } else {
        return $data;
    }
}
开发者ID:Ramoonus,项目名称:ingot,代码行数:25,代码来源:functions.php


示例15: send_response

 /**
  * Sends a response, but also makes sure to attach headers that
  * are handy for debugging.
  * Specifically, we assume folks will want to know what exactly was the DB query that got run,
  * what exactly was the Models query that got run, what capabilities came into play, what fields were omitted from
  * the response, others?
  *
  * @param array|\WP_Error|\Exception $response
  * @return \WP_REST_Response
  */
 public function send_response($response)
 {
     if ($response instanceof \Exception) {
         $response = new \WP_Error($response->getCode(), $response->getMessage());
     }
     if ($response instanceof \WP_Error) {
         $response = $this->_add_ee_errors_to_response($response);
         $rest_response = $this->_create_rest_response_from_wp_error($response);
     } else {
         $rest_response = new \WP_REST_Response($response, 200);
     }
     $headers = array();
     if ($this->_debug_mode && is_array($this->_debug_info)) {
         foreach ($this->_debug_info as $debug_key => $debug_info) {
             if (is_array($debug_info)) {
                 $debug_info = json_encode($debug_info);
             }
             $headers['X-EE4-Debug-' . ucwords($debug_key)] = $debug_info;
         }
     }
     $headers = array_merge($headers, $this->_get_headers_from_ee_notices());
     $rest_response->set_headers($headers);
     return $rest_response;
 }
开发者ID:adrianjonmiller,项目名称:hearts-being-healed,代码行数:34,代码来源:Base.php


示例16: output

 /**
  * Sends a response to the API request.
  *
  * @since	1.4
  * @param	int		$status_code	Status code.
  * @return	void
  */
 public function output($status_code = 200)
 {
     $response = new WP_REST_Response(array('result' => true));
     $response->set_status($status_code);
     $response->header('Content-type', 'application/json');
     $response->set_data($this->data);
     echo wp_json_encode($response);
     die;
 }
开发者ID:mdjm,项目名称:mobile-dj-manager,代码行数:16,代码来源:class-mdjm-api.php


示例17: test_removing_links_for_href

 public function test_removing_links_for_href()
 {
     $response = new WP_REST_Response();
     $response->add_link('self', 'http://example.com/');
     $response->add_link('self', 'https://example.com/');
     $response->remove_link('self', 'https://example.com/');
     $data = $this->server->response_to_data($response, false);
     $this->assertArrayHasKey('_links', $data);
     $this->assertArrayHasKey('self', $data['_links']);
     $self_not_filtered = array('href' => 'http://example.com/');
     $this->assertEquals($self_not_filtered, $data['_links']['self'][0]);
 }
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:12,代码来源:rest-server.php


示例18: get_index

 /**
  * Retrieves the site index.
  *
  * This endpoint describes the capabilities of the site.
  *
  * @since 4.4.0
  * @access public
  *
  * @param array $request {
  *     Request.
  *
  *     @type string $context Context.
  * }
  * @return array Index entity
  */
 public function get_index($request)
 {
     // General site data.
     $available = array('name' => get_option('blogname'), 'description' => get_option('blogdescription'), 'url' => get_option('siteurl'), 'home' => home_url(), 'namespaces' => array_keys($this->namespaces), 'authentication' => array(), 'routes' => $this->get_data_for_routes($this->get_routes(), $request['context']));
     $response = new WP_REST_Response($available);
     $response->add_link('help', 'http://v2.wp-api.org/');
     /**
      * Filters the API root index data.
      *
      * This contains the data describing the API. This includes information
      * about supported authentication schemes, supported namespaces, routes
      * available on the API, and a small amount of data about the site.
      *
      * @since 4.4.0
      *
      * @param WP_REST_Response $response Response data.
      */
     return apply_filters('rest_index', $response);
 }
开发者ID:nicholasgriffintn,项目名称:WordPress,代码行数:34,代码来源:class-wp-rest-server.php


示例19: assertResponseData

 /**
  * Check response data.
  *
  * @since 4.4.0
  *
  * @param array            $data
  * @param WP_REST_Response $response
  */
 protected function assertResponseData($data, $response)
 {
     $response_data = $response->get_data();
     $tested_data = array();
     foreach ($data as $key => $value) {
         if (isset($response_data[$key])) {
             $tested_data[$key] = $response_data[$key];
         } else {
             $tested_data[$key] = null;
         }
     }
     $this->assertEquals($data, $tested_data);
 }
开发者ID:automattic,项目名称:jetpack,代码行数:21,代码来源:test_class.rest-api-endpoints.php


示例20: rest_send_allow_header

/**
 * Sends the "Allow" header to state all methods that can be sent to the current route.
 *
 * @since 4.4.0
 *
 * @param WP_REST_Response $response Current response being served.
 * @param WP_REST_Server   $server   ResponseHandler instance (usually WP_REST_Server).
 * @param WP_REST_Request  $request  The request that was used to make current response.
 * @return WP_REST_Response Response to be served, with "Allow" header if route has allowed methods.
 */
function rest_send_allow_header($response, $server, $request)
{
    $matched_route = $response->get_matched_route();
    if (!$matched_route) {
        return $response;
    }
    $routes = $server->get_routes();
    $allowed_methods = array();
    // Get the allowed methods across the routes.
    foreach ($routes[$matched_route] as $_handler) {
        foreach ($_handler['methods'] as $handler_method => $value) {
            if (!empty($_handler['permission_callback'])) {
                $permission = call_user_func($_handler['permission_callback'], $request);
                $allowed_methods[$handler_method] = true === $permission;
            } else {
                $allowed_methods[$handler_method] = true;
            }
        }
    }
    // Strip out all the methods that are not allowed (false values).
    $allowed_methods = array_filter($allowed_methods);
    if ($allowed_methods) {
        $response->header('Allow', implode(', ', array_map('strtoupper', array_keys($allowed_methods))));
    }
    return $response;
}
开发者ID:023yangbo,项目名称:WordPress,代码行数:36,代码来源:rest-api.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP WP_REST_Server类代码示例发布时间:2022-05-23
下一篇:
PHP WP_REST_Request类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap