PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.5
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.5
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-api.php

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

93 lines 1.4 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_API_Base
5 *
6 * Base class for api
7 *
8 * @since 3.2.6
9 */
10 abstract class LP_Abstract_API {
11 /**
12 * @var string
13 */
14 public $version = 'v1';
15
16 /**
17 * @var string
18 */
19 public $endpoint = '';
20
21 /**
22 * @var WC_REST_Controller[]|string[]
23 */
24 public $controllers = array();
25
26 /**
27 * LP_API_Base constructor.
28 */
29 public function __construct() {
30 $this->rest_api_init();
31 }
32
33 /**
34 * Init REST.
35 *
36 * @since 3.2.6
37 */
38 public function rest_api_init() {
39 if ( ! class_exists( 'WP_REST_Server' ) ) {
40 return;
41 }
42
43 if ( ! LP_Helper::isRestApiLP() ) {
44 return;
45 }
46
47 $this->rest_api_includes();
48
49 add_action( 'rest_api_init', array( $this, 'rest_api_register_routes' ), 10 );
50
51 }
52
53 public function rest_api_includes() {
54
55 }
56
57 /**
58 * Register routes
59 *
60 * @since 3.2.6
61 */
62 public function rest_api_register_routes() {
63 if ( ! $this->controllers ) {
64 return;
65 }
66
67 $controllers = array();
68
69 foreach ( $this->controllers as $name => $controller ) {
70
71 if ( is_string( $controller ) ) {
72 $name = $controller;
73 $controllers[ $name ] = new $controller();
74 } else {
75 $controllers[ $name ] = $controller;
76 }
77
78 $controllers[ $name ]->register_routes();
79 }
80
81 $this->controllers = $controllers;
82 }
83
84 /**
85 * Check permission if user is administrator.
86 *
87 * @return bool
88 */
89 public static function check_admin_permission(): bool {
90 return current_user_can( ADMIN_ROLE );
91 }
92 }
93