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


PHP WP_REST_Response::get_links方法代码示例

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


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

示例1: get_response_links

 /**
  * Retrieves links from a response.
  *
  * Extracts the links from a response into a structured hash, suitable for
  * direct output.
  *
  * @since 4.4.0
  * @access public
  * @static
  *
  * @param WP_REST_Response $response Response to extract links from.
  * @return array Map of link relation to list of link hashes.
  */
 public static function get_response_links($response)
 {
     $links = $response->get_links();
     if (empty($links)) {
         return array();
     }
     // Convert links to part of the data.
     $data = array();
     foreach ($links as $rel => $items) {
         $data[$rel] = array();
         foreach ($items as $item) {
             $attributes = $item['attributes'];
             $attributes['href'] = $item['href'];
             $data[$rel][] = $attributes;
         }
     }
     return $data;
 }
开发者ID:nicholasgriffintn,项目名称:WordPress,代码行数:31,代码来源:class-wp-rest-server.php

示例2: get_response_links

 /**
  * Retrieves links from a response.
  *
  * Extracts the links from a response into a structured hash, suitable for
  * direct output.
  *
  * @since 4.4.0
  * @access public
  * @static
  *
  * @param WP_REST_Response $response Response to extract links from.
  * @return array Map of link relation to list of link hashes.
  */
 public static function get_response_links($response)
 {
     $links = $response->get_links();
     if (empty($links)) {
         return array();
     }
     // Convert links to part of the data.
     $data = array();
     $curies = $response->get_curies();
     $used_curies = array();
     foreach ($links as $rel => $items) {
         // Convert $rel URIs to their compact versions if they exist.
         foreach ($curies as $curie) {
             $href_prefix = substr($curie['href'], 0, strpos($curie['href'], '{rel}'));
             if (strpos($rel, $href_prefix) !== 0) {
                 continue;
             }
             $used_curies[$curie['name']] = $curie;
             // Relation now changes from '$uri' to '$curie:$relation'
             $rel_regex = str_replace('\\{rel\\}', '([\\w]+)', preg_quote($curie['href'], '!'));
             preg_match('!' . $rel_regex . '!', $rel, $matches);
             if ($matches) {
                 $rel = $curie['name'] . ':' . $matches[1];
             }
             break;
         }
         $data[$rel] = array();
         foreach ($items as $item) {
             $attributes = $item['attributes'];
             $attributes['href'] = $item['href'];
             $data[$rel][] = $attributes;
         }
     }
     // Push the curies onto the start of the links array.
     if ($used_curies) {
         $data = array_merge(array('curies' => array_values($used_curies)), $data);
     }
     return $data;
 }
开发者ID:andylow,项目名称:WordPress,代码行数:52,代码来源:class-wp-rest-server.php


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