PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
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
← All changes | inc/class-lp-global.php +308 -308 4.3.94.4.8 View file →
@@ -1,308 +1,308 @@
1 -<?php
2 -
3 -/**
4 - * Class LP_Global
5 - */
6 -class LP_Global {
7 - /**
8 - * @var array
9 - */
10 - public static $users = array();
11 -
12 - /**
13 - * @var array
14 - */
15 - public static $courses = array();
16 -
17 - /**
18 - * @var array
19 - */
20 - public static $lessons = array();
21 -
22 - /**
23 - * @var array
24 - */
25 - public static $quizzes = array();
26 -
27 - /**
28 - * @var array
29 - */
30 - public static $questions = array();
31 -
32 - /**
33 - * @var bool
34 - */
35 - protected static $_user = false;
36 -
37 - /**
38 - * @var bool
39 - */
40 - protected static $_course = false;
41 -
42 - /**
43 - * @var bool
44 - */
45 - protected static $_course_item = false;
46 -
47 - /**
48 - * @var LP_Profile
49 - */
50 - protected static $_profile = false;
51 -
52 - /**
53 - * @var array
54 - */
55 - public static $custom_posts = array();
56 -
57 - /**
58 - * @var array
59 - *
60 - * @since 3.3.0
61 - */
62 - public static $object_support_features = array();
63 -
64 - /**
65 - * @return LP_Quiz|LP_Lesson
66 - */
67 - public static function course_item() {
68 - global $lp_course_item;
69 -
70 - return $lp_course_item;
71 - }
72 -
73 - public static function set_course_item( $course_item ) {
74 - global $lp_course_item;
75 -
76 - if ( self::$_course_item === false ) {
77 - self::$_course_item = $lp_course_item;
78 - }
79 -
80 - $lp_course_item = $course_item;
81 - }
82 -
83 - /**
84 - * @param bool $get_only_id
85 - * Todo: new call not use $get_only_id, only call LP_Global::courses()
86 - * Recommend use learn_press_get_course()
87 - *
88 - * @editor tungnx
89 - * @since 3.0.0
90 - * @version 1.0.1
91 - * @return LP_Course|bool|int
92 - */
93 - public static function course( $get_only_id = false ) {
94 - $lp_course = learn_press_get_course();
95 -
96 - // Fix for old version use param $get_only_id
97 - if ( $get_only_id ) {
98 - if ( $lp_course ) {
99 - return $lp_course->get_id();
100 - } else {
101 - return 0;
102 - }
103 - } else {
104 - return $lp_course;
105 - }
106 - }
107 -
108 - /**
109 - * @deprecated 4.1.7.3
110 - */
111 - public static function set_course( $course ) {
112 - _deprecated_function( __FUNCTION__, '4.1.7.3' );
113 - global $lp_course;
114 -
115 - if ( self::$_course === false ) {
116 - self::$_course = $lp_course;
117 - }
118 - $lp_course = $course;
119 - }
120 -
121 - /**
122 - * @return LP_User|LP_User_Guest|false
123 - */
124 - public static function user() {
125 - /**
126 - * @see learn_press_setup_user
127 - */
128 - global $lp_user;
129 -
130 - return $lp_user;
131 - }
132 -
133 - /**
134 - * Alias of course item for highlighting in dev
135 - *
136 - * @return LP_Quiz|bool
137 - */
138 - public static function course_item_quiz() {
139 - $item = self::course_item();
140 -
141 - return $item instanceof LP_Quiz ? $item : false;
142 - }
143 -
144 - /**
145 - * @return LP_Question
146 - */
147 - public static function quiz_question() {
148 - global $lp_quiz_question;
149 -
150 - return $lp_quiz_question;
151 - }
152 -
153 - /**
154 - * Reset global variables to default
155 - * @deprecated 4.1.7.3
156 - */
157 - public static function reset() {
158 - _deprecated_function( __FUNCTION__, '4.1.7.3' );
159 - global $lp_user, $lp_course, $lp_course_item, $lp_quiz_question;
160 -
161 - if ( self::$_user ) {
162 - $lp_user = self::$_user;
163 - }
164 -
165 - if ( self::$_course ) {
166 - $lp_course = self::$_course;
167 - }
168 -
169 - if ( self::$_course_item ) {
170 - $lp_course_item = self::$_course_item;
171 - }
172 - }
173 -
174 - /**
175 - * @param bool $global
176 - * @param bool $reset
177 - *
178 - * @return LP_Profile|WP_Error
179 - */
180 - public static function profile( $global = false, $reset = false ) {
181 - global $profile;
182 -
183 - return LP_Profile::instance();
184 - }
185 -
186 - /**
187 - * @deprecated 4.2.6.2
188 - */
189 - public static function init() {
190 - _deprecated_function( __METHOD__, '4.2.6.2' );
191 - return;
192 - global $profile;
193 - self::$_profile = $profile = LP_Profile::instance( get_current_user_id() );
194 - }
195 -
196 - /**
197 - * @param $key
198 - *
199 - * @return bool|mixed
200 - */
201 - public static function get_custom_posts( $key ) {
202 - if ( array_key_exists( $key, self::$custom_posts ) ) {
203 - return self::$custom_posts[ $key ];
204 - }
205 -
206 - return false;
207 - }
208 -
209 - /**
210 - * @param string $object_type
211 - * @param string $feature
212 - * @param string $type
213 - *
214 - * @return mixed
215 - * @since 3.3.0
216 - *
217 - */
218 - public static function add_object_feature( $object_type, $feature, $type = 'yes' ) {
219 - $namespace = explode( '.', $object_type );
220 - $object_type = $namespace[0];
221 - $namespace = isset( $namespace[1] ) ? $namespace[1] : false;
222 -
223 - if ( ! isset( self::$object_support_features[ $object_type ] ) ) {
224 - self::$object_support_features[ $object_type ] = array();
225 - }
226 -
227 - if ( $namespace ) {
228 - if ( ! isset( self::$object_support_features[ $object_type ][ $namespace ] ) ) {
229 - self::$object_support_features[ $object_type ][ $namespace ] = array();
230 - }
231 -
232 - return self::$object_support_features[ $object_type ][ $namespace ][ $feature ] = $type === null ? 'yes' : $type;
233 - }
234 -
235 - return self::$object_support_features[ $object_type ][ $feature ] = $type === null ? 'yes' : $type;
236 - }
237 -
238 - /**
239 - * Checks if an object is support a feature.
240 - *
241 - * @param string $object_type
242 - * @param string $feature
243 - * @param mixed $type
244 - *
245 - * @return bool
246 - * @since 3.3.0
247 - *
248 - */
249 - public static function object_is_support_feature( $object_type, $feature, $type = null ) {
250 - $objects = self::$object_support_features;
251 - $namespace = explode( '.', $object_type );
252 - $object_type = $namespace[0];
253 - $namespace = isset( $namespace[1] ) ? $namespace[1] : false;
254 -
255 - if ( empty( $objects[ $object_type ] ) ) {
256 - return false;
257 - }
258 -
259 - if ( $namespace && empty( $objects[ $object_type ][ $namespace ] ) ) {
260 - return false;
261 - }
262 -
263 - if ( $namespace ) {
264 - $is_support = array_key_exists( $feature, $objects[ $object_type ][ $namespace ] ) ? true : false;
265 -
266 - if ( $type && $is_support ) {
267 - return $objects[ $object_type ][ $namespace ][ $feature ] === $type;
268 - }
269 -
270 - return $is_support;
271 - }
272 -
273 - $is_support = array_key_exists( $feature, $objects[ $object_type ] ) ? true : false;
274 -
275 - if ( $type && $is_support ) {
276 - return $objects[ $object_type ][ $feature ] === $type;
277 - }
278 -
279 - return $is_support;
280 - }
281 -
282 - /**
283 - * Get all features that an object support.
284 - *
285 - * @param string $object_type
286 - *
287 - * @return array|mixed
288 - * @since 3.3.0
289 - *
290 - */
291 - public static function get_object_supports( $object_type ) {
292 - $namespace = explode( '.', $object_type );
293 - $object_type = $namespace[0];
294 - $namespace = isset( $namespace[1] ) ? $namespace[1] : false;
295 -
296 - if ( empty( self::$object_support_features[ $object_type ] ) ) {
297 - return array();
298 - }
299 -
300 - if ( $namespace ) {
301 - if ( empty( self::$object_support_features[ $object_type ][ $namespace ] ) ) {
302 - return array();
303 - }
304 - }
305 -
306 - return self::$object_support_features[ $object_type ];
307 - }
308 -}
1 +<?php
2 +
3 +/**
4 + * Class LP_Global
5 + */
6 +class LP_Global {
7 + /**
8 + * @var array
9 + */
10 + public static $users = array();
11 +
12 + /**
13 + * @var array
14 + */
15 + public static $courses = array();
16 +
17 + /**
18 + * @var array
19 + */
20 + public static $lessons = array();
21 +
22 + /**
23 + * @var array
24 + */
25 + public static $quizzes = array();
26 +
27 + /**
28 + * @var array
29 + */
30 + public static $questions = array();
31 +
32 + /**
33 + * @var bool
34 + */
35 + protected static $_user = false;
36 +
37 + /**
38 + * @var bool
39 + */
40 + protected static $_course = false;
41 +
42 + /**
43 + * @var bool
44 + */
45 + protected static $_course_item = false;
46 +
47 + /**
48 + * @var LP_Profile
49 + */
50 + protected static $_profile = false;
51 +
52 + /**
53 + * @var array
54 + */
55 + public static $custom_posts = array();
56 +
57 + /**
58 + * @var array
59 + *
60 + * @since 3.3.0
61 + */
62 + public static $object_support_features = array();
63 +
64 + /**
65 + * @return LP_Quiz|LP_Lesson
66 + */
67 + public static function course_item() {
68 + global $lp_course_item;
69 +
70 + return $lp_course_item;
71 + }
72 +
73 + public static function set_course_item( $course_item ) {
74 + global $lp_course_item;
75 +
76 + if ( self::$_course_item === false ) {
77 + self::$_course_item = $lp_course_item;
78 + }
79 +
80 + $lp_course_item = $course_item;
81 + }
82 +
83 + /**
84 + * @param bool $get_only_id
85 + * Todo: new call not use $get_only_id, only call LP_Global::courses()
86 + * Recommend use learn_press_get_course()
87 + *
88 + * @editor tungnx
89 + * @since 3.0.0
90 + * @version 1.0.1
91 + * @return LP_Course|bool|int
92 + */
93 + public static function course( $get_only_id = false ) {
94 + $lp_course = learn_press_get_course();
95 +
96 + // Fix for old version use param $get_only_id
97 + if ( $get_only_id ) {
98 + if ( $lp_course ) {
99 + return $lp_course->get_id();
100 + } else {
101 + return 0;
102 + }
103 + } else {
104 + return $lp_course;
105 + }
106 + }
107 +
108 + /**
109 + * @deprecated 4.1.7.3
110 + */
111 + public static function set_course( $course ) {
112 + _deprecated_function( __FUNCTION__, '4.1.7.3' );
113 + global $lp_course;
114 +
115 + if ( self::$_course === false ) {
116 + self::$_course = $lp_course;
117 + }
118 + $lp_course = $course;
119 + }
120 +
121 + /**
122 + * @return LP_User|LP_User_Guest|false
123 + */
124 + public static function user() {
125 + /**
126 + * @see learn_press_setup_user
127 + */
128 + global $lp_user;
129 +
130 + return $lp_user;
131 + }
132 +
133 + /**
134 + * Alias of course item for highlighting in dev
135 + *
136 + * @return LP_Quiz|bool
137 + */
138 + public static function course_item_quiz() {
139 + $item = self::course_item();
140 +
141 + return $item instanceof LP_Quiz ? $item : false;
142 + }
143 +
144 + /**
145 + * @return LP_Question
146 + */
147 + public static function quiz_question() {
148 + global $lp_quiz_question;
149 +
150 + return $lp_quiz_question;
151 + }
152 +
153 + /**
154 + * Reset global variables to default
155 + * @deprecated 4.1.7.3
156 + */
157 + public static function reset() {
158 + _deprecated_function( __FUNCTION__, '4.1.7.3' );
159 + global $lp_user, $lp_course, $lp_course_item, $lp_quiz_question;
160 +
161 + if ( self::$_user ) {
162 + $lp_user = self::$_user;
163 + }
164 +
165 + if ( self::$_course ) {
166 + $lp_course = self::$_course;
167 + }
168 +
169 + if ( self::$_course_item ) {
170 + $lp_course_item = self::$_course_item;
171 + }
172 + }
173 +
174 + /**
175 + * @param bool $global
176 + * @param bool $reset
177 + *
178 + * @return LP_Profile|WP_Error
179 + */
180 + public static function profile( $global = false, $reset = false ) {
181 + global $profile;
182 +
183 + return LP_Profile::instance();
184 + }
185 +
186 + /**
187 + * @deprecated 4.2.6.2
188 + */
189 + public static function init() {
190 + _deprecated_function( __METHOD__, '4.2.6.2' );
191 + return;
192 + global $profile;
193 + self::$_profile = $profile = LP_Profile::instance( get_current_user_id() );
194 + }
195 +
196 + /**
197 + * @param $key
198 + *
199 + * @return bool|mixed
200 + */
201 + public static function get_custom_posts( $key ) {
202 + if ( array_key_exists( $key, self::$custom_posts ) ) {
203 + return self::$custom_posts[ $key ];
204 + }
205 +
206 + return false;
207 + }
208 +
209 + /**
210 + * @param string $object_type
211 + * @param string $feature
212 + * @param string $type
213 + *
214 + * @return mixed
215 + * @since 3.3.0
216 + *
217 + */
218 + public static function add_object_feature( $object_type, $feature, $type = 'yes' ) {
219 + $namespace = explode( '.', $object_type );
220 + $object_type = $namespace[0];
221 + $namespace = isset( $namespace[1] ) ? $namespace[1] : false;
222 +
223 + if ( ! isset( self::$object_support_features[ $object_type ] ) ) {
224 + self::$object_support_features[ $object_type ] = array();
225 + }
226 +
227 + if ( $namespace ) {
228 + if ( ! isset( self::$object_support_features[ $object_type ][ $namespace ] ) ) {
229 + self::$object_support_features[ $object_type ][ $namespace ] = array();
230 + }
231 +
232 + return self::$object_support_features[ $object_type ][ $namespace ][ $feature ] = $type === null ? 'yes' : $type;
233 + }
234 +
235 + return self::$object_support_features[ $object_type ][ $feature ] = $type === null ? 'yes' : $type;
236 + }
237 +
238 + /**
239 + * Checks if an object is support a feature.
240 + *
241 + * @param string $object_type
242 + * @param string $feature
243 + * @param mixed $type
244 + *
245 + * @return bool
246 + * @since 3.3.0
247 + *
248 + */
249 + public static function object_is_support_feature( $object_type, $feature, $type = null ) {
250 + $objects = self::$object_support_features;
251 + $namespace = explode( '.', $object_type );
252 + $object_type = $namespace[0];
253 + $namespace = isset( $namespace[1] ) ? $namespace[1] : false;
254 +
255 + if ( empty( $objects[ $object_type ] ) ) {
256 + return false;
257 + }
258 +
259 + if ( $namespace && empty( $objects[ $object_type ][ $namespace ] ) ) {
260 + return false;
261 + }
262 +
263 + if ( $namespace ) {
264 + $is_support = array_key_exists( $feature, $objects[ $object_type ][ $namespace ] ) ? true : false;
265 +
266 + if ( $type && $is_support ) {
267 + return $objects[ $object_type ][ $namespace ][ $feature ] === $type;
268 + }
269 +
270 + return $is_support;
271 + }
272 +
273 + $is_support = array_key_exists( $feature, $objects[ $object_type ] ) ? true : false;
274 +
275 + if ( $type && $is_support ) {
276 + return $objects[ $object_type ][ $feature ] === $type;
277 + }
278 +
279 + return $is_support;
280 + }
281 +
282 + /**
283 + * Get all features that an object support.
284 + *
285 + * @param string $object_type
286 + *
287 + * @return array|mixed
288 + * @since 3.3.0
289 + *
290 + */
291 + public static function get_object_supports( $object_type ) {
292 + $namespace = explode( '.', $object_type );
293 + $object_type = $namespace[0];
294 + $namespace = isset( $namespace[1] ) ? $namespace[1] : false;
295 +
296 + if ( empty( self::$object_support_features[ $object_type ] ) ) {
297 + return array();
298 + }
299 +
300 + if ( $namespace ) {
301 + if ( empty( self::$object_support_features[ $object_type ][ $namespace ] ) ) {
302 + return array();
303 + }
304 + }
305 +
306 + return self::$object_support_features[ $object_type ];
307 + }
308 +}