PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.3.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.3.9
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / inc / abstracts / abstract-rest-controller.php

abstract-rest-controller.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.3.9, at inc/abstracts/abstract-rest-controller.php

68 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class LP_Abstract_REST_Controller
5 */
6 class LP_Abstract_REST_Controller extends WP_REST_Controller {
7
8 /**
9 * @var string
10 */
11 public $namespace = 'lp/v1';
12
13 /**
14 * @var string
15 */
16 public $rest_base = '';
17
18 /**
19 * @var array
20 */
21 public $routes = array();
22
23 public function __construct() {
24
25 }
26
27 /**
28 * Register routes for controller.
29 */
30 public function register_routes() {
31
32 if ( ! $this->routes ) {
33 return;
34 }
35
36 foreach ( $this->routes as $key => $args ) {
37 $rest_base = $this->rest_base;
38 $override = false;
39
40 if ( is_bool( end( $args ) ) ) {
41 $override = array_pop( $args );
42 }
43
44 if ( ! is_numeric( $key ) ) {
45 $rest_base = "{$rest_base}/{$key}";
46 }
47
48 register_rest_route( $this->namespace, '/' . $rest_base, $args, $override );
49 }
50 }
51
52 public function ensure_response( $data ) {
53 add_filter( 'rest_pre_serve_request', array( $this, 'print_response' ), 10, 4 );
54
55 return rest_ensure_response( $data );
56 }
57
58 /**
59 * @param boolean $false
60 * @param WP_REST_Response $result
61 * @param WP_REST_Request $request
62 * @param WP_REST_Server $server
63 */
64 public function print_response( $false, $result, $request, $server ) {
65 learn_press_send_json( $result->get_data() );
66 }
67 }
68