| @@ -1,83 +1,83 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * REST API: LP_Jwt_Auth | |
| 4 | - * | |
| 5 | - * @package LPJWTAuth | |
| 6 | - * @since 1.0.0 | |
| 7 | - * @author Nhamdv <daonham95@gmail.com> | |
| 8 | - */ | |
| 9 | - | |
| 10 | -class LP_Jwt_Auth { | |
| 11 | - public static $_instance = null; | |
| 12 | - | |
| 13 | - protected $name; | |
| 14 | - | |
| 15 | - protected $version; | |
| 16 | - | |
| 17 | - public function __construct() { | |
| 18 | - $this->name = 'learnpress'; | |
| 19 | - $this->version = 'v1'; | |
| 20 | - | |
| 21 | - // Is enable rest api? | |
| 22 | - // if ( LP_Settings::instance()->get( 'enable_jwt_rest_api' ) !== 'yes' ) { | |
| 23 | - // return; | |
| 24 | - // } | |
| 25 | - | |
| 26 | - $this->includes(); | |
| 27 | - $this->define_hooks(); | |
| 28 | - } | |
| 29 | - | |
| 30 | - private function includes() { | |
| 31 | - // JWT Classes. | |
| 32 | - if ( ! class_exists( '\LP\Firebase\JWT\JWT' ) ) { | |
| 33 | - foreach ( glob( LP_PLUGIN_PATH . 'inc/jwt/includes/php-jwt/*.php' ) as $filename ) { | |
| 34 | - require_once $filename; | |
| 35 | - } | |
| 36 | - } | |
| 37 | - | |
| 38 | - // Authentic. | |
| 39 | - require_once LP_PLUGIN_PATH . 'inc/jwt/includes/class-jwt-public.php'; | |
| 40 | - | |
| 41 | - // Include Rest API. | |
| 42 | - require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-controller.php'; | |
| 43 | - require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-posts-controller.php'; | |
| 44 | - require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-courses-v1-controller.php'; | |
| 45 | - require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-lessons-v1-controller.php'; | |
| 46 | - require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-quiz-v1-controller.php'; | |
| 47 | - require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-questions-v1-controller.php'; | |
| 48 | - require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-users-v1-controller.php'; | |
| 49 | - require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-course-category-v1-controller.php'; | |
| 50 | - require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-sections-v1-controller.php'; | |
| 51 | - require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-section-items-v1-controller.php'; | |
| 52 | - | |
| 53 | - require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/lp-rest-function.php'; | |
| 54 | - require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/class-rest-api.php'; | |
| 55 | - } | |
| 56 | - | |
| 57 | - private function define_hooks() { | |
| 58 | - // Authentic. | |
| 59 | - $public = new LP_Jwt_Public( $this->name, $this->version ); | |
| 60 | - | |
| 61 | - add_action( 'rest_api_init', array( $public, 'register_routes' ) ); | |
| 62 | - add_filter( 'rest_api_init', array( $public, 'add_cors_support' ) ); | |
| 63 | - add_filter( 'rest_pre_dispatch', array( $public, 'rest_pre_dispatch' ), 10, 2 ); | |
| 64 | - add_filter( 'determine_current_user', array( $public, 'determine_current_user' ), 30 ); | |
| 65 | - | |
| 66 | - // Rest API | |
| 67 | - add_action( 'init', array( $this, 'load_rest_api' ) ); | |
| 68 | - } | |
| 69 | - | |
| 70 | - public function load_rest_api() { | |
| 71 | - LP_Jwt_RestApi::instance()->init(); | |
| 72 | - } | |
| 73 | - | |
| 74 | - public static function instance() { | |
| 75 | - if ( is_null( self::$_instance ) ) { | |
| 76 | - self::$_instance = new LP_Jwt_Auth(); | |
| 77 | - } | |
| 78 | - | |
| 79 | - return self::$_instance; | |
| 80 | - } | |
| 81 | -} | |
| 82 | - | |
| 83 | -LP_Jwt_Auth::instance(); | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * REST API: LP_Jwt_Auth | |
| 4 | + * | |
| 5 | + * @package LPJWTAuth | |
| 6 | + * @since 1.0.0 | |
| 7 | + * @author Nhamdv <daonham95@gmail.com> | |
| 8 | + */ | |
| 9 | + | |
| 10 | +class LP_Jwt_Auth { | |
| 11 | + public static $_instance = null; | |
| 12 | + | |
| 13 | + protected $name; | |
| 14 | + | |
| 15 | + protected $version; | |
| 16 | + | |
| 17 | + public function __construct() { | |
| 18 | + $this->name = 'learnpress'; | |
| 19 | + $this->version = 'v1'; | |
| 20 | + | |
| 21 | + // Is enable rest api? | |
| 22 | + // if ( LP_Settings::instance()->get( 'enable_jwt_rest_api' ) !== 'yes' ) { | |
| 23 | + // return; | |
| 24 | + // } | |
| 25 | + | |
| 26 | + $this->includes(); | |
| 27 | + $this->define_hooks(); | |
| 28 | + } | |
| 29 | + | |
| 30 | + private function includes() { | |
| 31 | + // JWT Classes. | |
| 32 | + if ( ! class_exists( '\LP\Firebase\JWT\JWT' ) ) { | |
| 33 | + foreach ( glob( LP_PLUGIN_PATH . 'inc/jwt/includes/php-jwt/*.php' ) as $filename ) { | |
| 34 | + require_once $filename; | |
| 35 | + } | |
| 36 | + } | |
| 37 | + | |
| 38 | + // Authentic. | |
| 39 | + require_once LP_PLUGIN_PATH . 'inc/jwt/includes/class-jwt-public.php'; | |
| 40 | + | |
| 41 | + // Include Rest API. | |
| 42 | + require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-controller.php'; | |
| 43 | + require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-posts-controller.php'; | |
| 44 | + require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-courses-v1-controller.php'; | |
| 45 | + require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-lessons-v1-controller.php'; | |
| 46 | + require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-quiz-v1-controller.php'; | |
| 47 | + require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-questions-v1-controller.php'; | |
| 48 | + require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-users-v1-controller.php'; | |
| 49 | + require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-course-category-v1-controller.php'; | |
| 50 | + require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-sections-v1-controller.php'; | |
| 51 | + require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/version1/class-lp-rest-section-items-v1-controller.php'; | |
| 52 | + | |
| 53 | + require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/lp-rest-function.php'; | |
| 54 | + require_once LP_PLUGIN_PATH . 'inc/jwt/rest-api/class-rest-api.php'; | |
| 55 | + } | |
| 56 | + | |
| 57 | + private function define_hooks() { | |
| 58 | + // Authentic. | |
| 59 | + $public = new LP_Jwt_Public( $this->name, $this->version ); | |
| 60 | + | |
| 61 | + add_action( 'rest_api_init', array( $public, 'register_routes' ) ); | |
| 62 | + add_filter( 'rest_api_init', array( $public, 'add_cors_support' ) ); | |
| 63 | + add_filter( 'rest_pre_dispatch', array( $public, 'rest_pre_dispatch' ), 10, 2 ); | |
| 64 | + add_filter( 'determine_current_user', array( $public, 'determine_current_user' ), 30 ); | |
| 65 | + | |
| 66 | + // Rest API | |
| 67 | + add_action( 'init', array( $this, 'load_rest_api' ) ); | |
| 68 | + } | |
| 69 | + | |
| 70 | + public function load_rest_api() { | |
| 71 | + LP_Jwt_RestApi::instance()->init(); | |
| 72 | + } | |
| 73 | + | |
| 74 | + public static function instance() { | |
| 75 | + if ( is_null( self::$_instance ) ) { | |
| 76 | + self::$_instance = new LP_Jwt_Auth(); | |
| 77 | + } | |
| 78 | + | |
| 79 | + return self::$_instance; | |
| 80 | + } | |
| 81 | +} | |
| 82 | + | |
| 83 | +LP_Jwt_Auth::instance(); | |