本文整理汇总了PHP中WP_REST_Response::set_status方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_REST_Response::set_status方法的具体用法?PHP WP_REST_Response::set_status怎么用?PHP WP_REST_Response::set_status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_REST_Response
的用法示例。
在下文中一共展示了WP_REST_Response::set_status方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create_price
public function create_price($request)
{
$required_keys = array('ticket_price', 'price_band_id', 'ticket_type_id');
$meta = $request[$this->post_type . "_meta"] ? $request[$this->post_type . "_meta"] : array();
if (count(array_intersect_key(array_flip($required_keys), $meta)) >= count($required_keys)) {
return $this->create_item($request);
} else {
$error = new WP_REST_Response(array('message' => 'Insufficient parameters', 'data' => array('status' => 422)));
$error->set_status(422);
return $error;
}
}
示例2: create_event_instance
public function create_event_instance($request)
{
$event_id = $request['event_id'];
$event_post = get_post($event_id);
if ($event_post) {
return $this->create_item($request);
} else {
$error = new WP_REST_Response(array('message' => 'Event not found'));
$error->set_status(404);
return $error;
}
}
示例3: onGithubRequest
/**
* This method use for handler request from Github's webhook.
*
* Because of github not required to response payload on response, so we can make a do_action instead of apply_filters
*
* @param \WP_REST_Request $request
*
* @return \WP_REST_Response
*/
public function onGithubRequest(\WP_REST_Request $request)
{
// Create the response object
$request_payload = json_decode($request->get_body());
$response = new \WP_REST_Response();
if ($request_payload) {
ob_start();
$repo = new Repository($request_payload->repository->git_url);
if ($repo->exists()) {
$event = $request->get_header('X-Github-Event');
do_action('wppm_webhook_recived_' . $event, $repo, $request_payload);
} else {
$response->set_status(404);
echo "Repo is not exist.";
}
$out_put = ob_get_clean();
$response->set_data($out_put);
} else {
$response->set_status(500);
}
return $response;
}
示例4: 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;
}
示例5: unset
/**
* Update a location.
*
* @param WP_REST_Request $request
*
* @return WP_Error|WP_REST_Response
*/
function update_location(WP_REST_Request $request)
{
// Get the location data
//
$result = $this->slplus->currentLocation->get_location($request['id']);
if (is_wp_error($result)) {
return $result;
}
// Set the incoming parameters array for the update
//
$location_data = $request->get_params();
unset($location_data['id']);
$location_data['sl_id'] = $this->slplus->currentLocation->id;
foreach ($location_data as $key => $value) {
if (is_numeric($key)) {
unset($location_data[$key]);
}
}
// Error During Prep
//
if (empty($location_data)) {
return new WP_Error('slp_missing_location_data', $this->slplus->text_manager->get_error_text('slp_missing_location_data'), array('status' => 404));
}
// Update Location
//
$result = $this->slplus->currentLocation->add_to_database($location_data, 'update', false);
// Error During Update
//
if ($result !== 'updated') {
return new WP_Error('slp_location_not_updated', $this->slplus->text_manager->get_error_text('slp_location_not_updated'), array('status' => 404));
}
$response_data = array('message_slug' => 'location_updated', 'message' => __('Location updated. ', 'store-locator-le'), 'location_id' => $this->slplus->currentLocation->id);
$response = new WP_REST_Response($response_data);
$response->set_status(201);
return $response;
}