本文整理汇总了PHP中WP_REST_Request::get_body_params方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_REST_Request::get_body_params方法的具体用法?PHP WP_REST_Request::get_body_params怎么用?PHP WP_REST_Request::get_body_params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_REST_Request
的用法示例。
在下文中一共展示了WP_REST_Request::get_body_params方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: report
/**
* Create report from REST request and get response.
*
* @access public
*
* @param WP_REST_Request $request Current request.
* @return WP_REST_Response $response Response for /reports endpoint.
*/
public function report(\WP_REST_Request $request)
{
Reports::create($request->get_body_params());
return self::reports($request);
}
示例2: api_get_posts
/**
* Retrieve a list of posts matching a search query or a single post by
* ID
*
* @since 0.1
*/
public function api_get_posts(WP_REST_Request $request)
{
$params = stripslashes_deep($request->get_body_params());
if (!isset($params['s']) && !isset($params['ID'])) {
return array();
}
if (!isset($params['return'])) {
$params['return'] = array('ID' => 'ID', 'title' => 'title', 'description' => 'post_type_label');
}
$args = array('posts_per_page' => 50);
if (isset($params['s'])) {
$args['s'] = sanitize_text_field($params['s']);
}
if (isset($params['ID'])) {
$args['post__in'] = is_array($params['ID']) ? array_map('absint', $params['ID']) : array(absint($params['ID']));
}
if (isset($params['post_type'])) {
$args['post_type'] = is_array($params['post_type']) ? array_map('sanitize_text_field', $params['post_type']) : sanitize_text_field($params['post_type']);
}
if (isset($params['posts_per_page'])) {
$args['posts_per_page'] = absint($params['posts_per_page']);
}
$query = new WP_Query($args);
$posts = array();
while ($query->have_posts()) {
$query->the_post();
$match = array();
foreach ($params['return'] as $key => $type) {
$match[$key] = $this->api_get_posts_post_data($type);
}
$posts[] = $match;
}
if (isset($params['s'])) {
return array('s' => $params['s'], 'posts' => $posts);
} elseif (isset($params['ID'])) {
return array('ID' => $params['ID'], 'posts' => empty($posts) ? array() : $posts[0]);
}
return array();
}