/**
  * 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;
 }
 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;
     }
 }
 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;
     }
 }
Example #4
0
 /**
  * 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;
 }
 /**
  * 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;
 }