當前位置: 首頁>>代碼示例>>PHP>>正文


PHP WP_REST_Request::from_url方法代碼示例

本文整理匯總了PHP中WP_REST_Request::from_url方法的典型用法代碼示例。如果您正苦於以下問題:PHP WP_REST_Request::from_url方法的具體用法?PHP WP_REST_Request::from_url怎麽用?PHP WP_REST_Request::from_url使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在WP_REST_Request的用法示例。


在下文中一共展示了WP_REST_Request::from_url方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: embed_links

 /**
  * Embeds the links from the data into the request.
  *
  * @since 4.4.0
  * @access protected
  *
  * @param array $data Data from the request.
  * @return array {
  *     Data with sub-requests embedded.
  *
  *     @type array [$_links]    Links.
  *     @type array [$_embedded] Embeddeds.
  * }
  */
 protected function embed_links($data)
 {
     if (empty($data['_links'])) {
         return $data;
     }
     $embedded = array();
     foreach ($data['_links'] as $rel => $links) {
         // Ignore links to self, for obvious reasons.
         if ('self' === $rel) {
             continue;
         }
         $embeds = array();
         foreach ($links as $item) {
             // Determine if the link is embeddable.
             if (empty($item['embeddable'])) {
                 // Ensure we keep the same order.
                 $embeds[] = array();
                 continue;
             }
             // Run through our internal routing and serve.
             $request = WP_REST_Request::from_url($item['href']);
             if (!$request) {
                 $embeds[] = array();
                 continue;
             }
             // Embedded resources get passed context=embed.
             if (empty($request['context'])) {
                 $request['context'] = 'embed';
             }
             $response = $this->dispatch($request);
             /** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */
             $response = apply_filters('rest_post_dispatch', rest_ensure_response($response), $this, $request);
             $embeds[] = $this->response_to_data($response, false);
         }
         // Determine if any real links were found.
         $has_links = count(array_filter($embeds));
         if ($has_links) {
             $embedded[$rel] = $embeds;
         }
     }
     if (!empty($embedded)) {
         $data['_embedded'] = $embedded;
     }
     return $data;
 }
開發者ID:nicholasgriffintn,項目名稱:WordPress,代碼行數:59,代碼來源:class-wp-rest-server.php

示例2: test_from_url_invalid

 /**
  * @dataProvider data_from_url
  */
 public function test_from_url_invalid($permalink_structure)
 {
     update_option('permalink_structure', $permalink_structure);
     $using_site = site_url('/wp/v2/posts/1');
     $request = WP_REST_Request::from_url($using_site);
     $this->assertFalse($request);
     $using_home = home_url('/wp/v2/posts/1');
     $request = WP_REST_Request::from_url($using_home);
     $this->assertFalse($request);
 }
開發者ID:aaemnnosttv,項目名稱:develop.git.wordpress.org,代碼行數:13,代碼來源:rest-request.php


注:本文中的WP_REST_Request::from_url方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。