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


PHP WP_REST_Response::header方法代码示例

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


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

示例1:

 /**
  * 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

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

 public function test_envelope()
 {
     $data = array('amount of arbitrary data' => 'alot');
     $status = 987;
     $headers = array('Arbitrary-Header' => 'value', 'Multiple' => 'maybe, yes');
     $response = new WP_REST_Response($data, $status);
     $response->header('Arbitrary-Header', 'value');
     // Check header concatenation as well.
     $response->header('Multiple', 'maybe');
     $response->header('Multiple', 'yes', false);
     $envelope_response = $this->server->envelope_response($response, false);
     // The envelope should still be a response, but with defaults.
     $this->assertInstanceOf('WP_REST_Response', $envelope_response);
     $this->assertEquals(200, $envelope_response->get_status());
     $this->assertEmpty($envelope_response->get_headers());
     $this->assertEmpty($envelope_response->get_links());
     $enveloped = $envelope_response->get_data();
     $this->assertEquals($data, $enveloped['body']);
     $this->assertEquals($status, $enveloped['status']);
     $this->assertEquals($headers, $enveloped['headers']);
 }
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:21,代码来源:rest-server.php

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

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

示例6: send_unauthorized_headers

 /**
  * If the consumer_key and consumer_secret $_GET parameters are NOT provided
  * and the Basic auth headers are either not present or the consumer secret does not match the consumer
  * key provided, then return the correct Basic headers and an error message.
  *
  * @param WP_REST_Response $response Current response being served.
  * @return WP_REST_Response
  */
 public function send_unauthorized_headers($response)
 {
     global $wc_rest_authentication_error;
     if (is_wp_error($wc_rest_authentication_error) && is_ssl()) {
         $auth_message = __('WooCommerce API - Use a consumer key in the username field and a consumer secret in the password field.', 'woocommerce');
         $response->header('WWW-Authenticate', 'Basic realm="' . $auth_message . '"', true);
     }
     return $response;
 }
开发者ID:tlovett1,项目名称:woocommerce,代码行数:17,代码来源:class-wc-rest-authentication.php

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

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


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