PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7.1
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.1.7.1, at inc/abstracts/abstract-rest-api.php

89 lines 1.5 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 $this->rest_api_includes();
44
45 add_action( 'rest_api_init', array( $this, 'rest_api_register_routes' ), 10 );
46
47 }
48
49 public function rest_api_includes() {
50 // include_once realpath( LP_PLUGIN_PATH . 'inc/rest-api/class-lp-rest-authentication.php' );
51 }
52
53 /**
54 * Register routes
55 *
56 * @since 3.2.6
57 */
58 public function rest_api_register_routes() {
59 if ( ! $this->controllers ) {
60 return;
61 }
62
63 $controllers = array();
64
65 foreach ( $this->controllers as $name => $controller ) {
66
67 if ( is_string( $controller ) ) {
68 $name = $controller;
69 $controllers[ $name ] = new $controller();
70 } else {
71 $controllers[ $name ] = $controller;
72 }
73
74 $controllers[ $name ]->register_routes();
75 }
76
77 $this->controllers = $controllers;
78 }
79
80 /**
81 * Check permission if user is administrator.
82 *
83 * @return bool
84 */
85 public static function check_admin_permission(): bool {
86 return current_user_can( ADMIN_ROLE );
87 }
88 }
89