本文整理汇总了PHP中WP_REST_Request::get_url_params方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_REST_Request::get_url_params方法的具体用法?PHP WP_REST_Request::get_url_params怎么用?PHP WP_REST_Request::get_url_params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_REST_Request
的用法示例。
在下文中一共展示了WP_REST_Request::get_url_params方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_item
/**
* Get a variant's HTML
*
* @since 0.4.0
*
* @param \WP_REST_Request $request Full data about the request.
* @return \WP_Error|\WP_REST_Request
*/
public function get_item($request)
{
return $this->not_yet_response();
$context = $request->get_param('context');
$url = $request->get_url_params();
$id = helpers::v('ID', $url, 0);
if (0 == absint($id) || !is_array(\ingot\testing\crud\variant::read($id))) {
return new \WP_Error('ingot-invalid-test');
} elseif ('context' != 'view') {
return new \WP_Error('ingot-test-context-invalid');
} else {
if ('view' == $context) {
$test = \ingot\testing\crud\variantP::read($id);
$html = ingot_click_test($test);
return ingot_rest_response($html);
}
}
}
示例2: batch_items
/**
* Bulk create, update and delete items.
*
* @since 2.7.0
* @param WP_REST_Request $request Full details about the request.
* @return array Of WP_Error or WP_REST_Response.
*/
public function batch_items($request)
{
$items = array_filter($request->get_params());
$params = $request->get_url_params();
$product_id = $params['product_id'];
$body_params = array();
foreach (array('update', 'create', 'delete') as $batch_type) {
if (!empty($items[$batch_type])) {
$injected_items = array();
foreach ($items[$batch_type] as $item) {
$injected_items[] = array_merge(array('product_id' => $product_id), $item);
}
$body_params[$batch_type] = $injected_items;
}
}
$request = new WP_REST_Request($request->get_method());
$request->set_body_params($body_params);
return parent::batch_items($request);
}
示例3: get_session_by_url_params
/**
* @param \WP_REST_Request $request Full data about the request.
*
* @return array|mixed|null|object|void
*/
protected function get_session_by_url_params($request)
{
$url = $request->get_url_params();
$id = helpers::v('id', $url, 0);
if (0 != absint($id) && is_array($session = \ingot\testing\crud\session::read($id))) {
return $session;
} else {
return new \WP_Error('ingot-invalid-session');
}
}
示例4: batch_items
/**
* Bulk create, update and delete items.
*
* @since 2.7.0
* @param WP_REST_Request $request Full details about the request.
* @return array Of WP_Error or WP_REST_Response.
*/
public function batch_items($request)
{
// Get the request params.
$items = array_filter($request->get_params());
/*
* Since our batch settings update is group-specific and matches based on the route,
* we inject the URL parameters (containing group) into the batch items
*/
if (!empty($items['update'])) {
$to_update = array();
foreach ($items['update'] as $item) {
$to_update[] = array_merge($request->get_url_params(), $item);
}
$request = new WP_REST_Request($request->get_method());
$request->set_body_params(array('update' => $to_update));
}
return parent::batch_items($request);
}
示例5: get_price
/**
* Get price of a product
*
* @since 1.1.0
*
* @param \WP_REST_Request $request Full data about the request.
* @return \WP_Error|\WP_REST_Response
*/
public function get_price($request)
{
$price = price::get_price($request->get_param('plugin'), $request->get_url_params()['id']);
return ingot_rest_response(['price' => $price]);
}
示例6: update_posts
/**
* Update groups associated with a post
*
* @since 1.0.0
*
* @param \WP_REST_Request $request Full data about the request.
* @return \WP_Error|\WP_REST_Response
*/
public function update_posts($request)
{
$url = $request->get_url_params();
$post_id = (int) helpers::v('id', $url, 0);
$post = get_post($post_id);
if (!is_a($post, 'WP_POST')) {
return ingot_rest_response(['message' => esc_html__('No group found', 'ingot')]);
}
$obj = new posts($post);
$obj->add($request->get_param('group_ids'));
return ingot_rest_response($obj->get_groups());
}
示例7: get_stats
/**
* Get stats for a group
*
* @since 0.4.0
*
* @param \WP_REST_Request $request Full data about the request.
* @return \WP_Error|\WP_REST_Response
*/
public function get_stats($request)
{
$url = $request->get_url_params();
$id = helpers::v('id', $url, 0);
$group = group::read($id);
if (!is_array($group)) {
if (is_wp_error($group)) {
return $group;
}
return ingot_rest_response(['message' => esc_html__('No group found', 'ingot')]);
}
$obj = new \ingot\testing\object\group($group);
$stats = $obj->get_stats();
if ('admin' == $request->get_param('context')) {
$names = $obj->names();
if (!empty($stats['variants']) && !empty($names['variants'])) {
foreach ($names['variants'] as $v_id => $name) {
if (isset($stats['variants'][$v_id])) {
$stats['variants'][$v_id] = (array) $stats['variants'][$v_id];
$stats['variants'][$v_id]['name'] = $name;
$stats['variants'][$v_id] = (object) $stats['variants'][$v_id];
}
}
}
$stats['names'] = $names;
}
return ingot_rest_response($stats, 200);
}