PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7.3.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7.3.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 / class-lp-global.php

class-lp-global.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.7.3.1, at inc/class-lp-global.php

322 lines 6.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_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 * Check if current course item is viewing is a $type
85 *
86 * @param string $type
87 *
88 * @return bool
89 * @deprecated 4.1.7.3
90 */
91 /*public static function is_course_item_type( $type ) {
92 $item = self::course_item();
93
94 if ( $item ) {
95 return $type === get_post_type( $item->get_id() );
96 }
97
98 return false;
99 }*/
100
101 /**
102 * @param bool $get_only_id
103 * Todo: new call not use $get_only_id, only call LP_Global::courses()
104 * Recommend use learn_press_get_course()
105 *
106 * @editor tungnx
107 * @since 3.0.0
108 * @version 1.0.1
109 * @return LP_Course|bool|int
110 */
111 public static function course( $get_only_id = false ) {
112 $lp_course = learn_press_get_course();
113
114 // Fix for old version use param $get_only_id
115 if ( $get_only_id ) {
116 if ( $lp_course ) {
117 return $lp_course->get_id();
118 } else {
119 return 0;
120 }
121 } else {
122 return $lp_course;
123 }
124 }
125
126 /**
127 * @deprecated 4.1.7.3
128 */
129 public static function set_course( $course ) {
130 _deprecated_function( __FUNCTION__, '4.1.7.3' );
131 global $lp_course;
132
133 if ( self::$_course === false ) {
134 self::$_course = $lp_course;
135 }
136 $lp_course = $course;
137 }
138
139 /**
140 * @return LP_User|LP_User_Guest|false
141 */
142 public static function user() {
143 /**
144 * @see learn_press_setup_user
145 */
146 global $lp_user;
147
148 return $lp_user;
149 }
150
151 /**
152 * Alias of course item for highlighting in dev
153 *
154 * @return LP_Quiz|bool
155 */
156 public static function course_item_quiz() {
157 $item = self::course_item();
158
159 return $item instanceof LP_Quiz ? $item : false;
160 }
161
162 /**
163 * @return LP_Question
164 */
165 public static function quiz_question() {
166 global $lp_quiz_question;
167
168 return $lp_quiz_question;
169 }
170
171 /**
172 * Reset global variables to default
173 * @deprecated 4.1.7.3
174 */
175 public static function reset() {
176 _deprecated_function( __FUNCTION__, '4.1.7.3' );
177 global $lp_user, $lp_course, $lp_course_item, $lp_quiz_question;
178
179 if ( self::$_user ) {
180 $lp_user = self::$_user;
181 }
182
183 if ( self::$_course ) {
184 $lp_course = self::$_course;
185 }
186
187 if ( self::$_course_item ) {
188 $lp_course_item = self::$_course_item;
189 }
190 }
191
192 /**
193 * @param bool $global
194 * @param bool $reset
195 *
196 * @return LP_Profile|WP_Error
197 */
198 public static function profile( $global = false, $reset = false ) {
199 global $profile;
200
201 return LP_Profile::instance();
202 }
203
204 public static function init() {
205 global $profile;
206 self::$_profile = $profile = LP_Profile::instance( get_current_user_id() );
207 }
208
209 /**
210 * @param $key
211 *
212 * @return bool|mixed
213 */
214 public static function get_custom_posts( $key ) {
215 if ( array_key_exists( $key, self::$custom_posts ) ) {
216 return self::$custom_posts[ $key ];
217 }
218
219 return false;
220 }
221
222 /**
223 * @param string $object_type
224 * @param string $feature
225 * @param string $type
226 *
227 * @return mixed
228 * @since 3.3.0
229 *
230 */
231 public static function add_object_feature( $object_type, $feature, $type = 'yes' ) {
232 $namespace = explode( '.', $object_type );
233 $object_type = $namespace[0];
234 $namespace = isset( $namespace[1] ) ? $namespace[1] : false;
235
236 if ( ! isset( self::$object_support_features[ $object_type ] ) ) {
237 self::$object_support_features[ $object_type ] = array();
238 }
239
240 if ( $namespace ) {
241 if ( ! isset( self::$object_support_features[ $object_type ][ $namespace ] ) ) {
242 self::$object_support_features[ $object_type ][ $namespace ] = array();
243 }
244
245 return self::$object_support_features[ $object_type ][ $namespace ][ $feature ] = $type === null ? 'yes' : $type;
246 }
247
248 return self::$object_support_features[ $object_type ][ $feature ] = $type === null ? 'yes' : $type;
249 }
250
251 /**
252 * Checks if an object is support a feature.
253 *
254 * @param string $object_type
255 * @param string $feature
256 * @param mixed $type
257 *
258 * @return bool
259 * @since 3.3.0
260 *
261 */
262 public static function object_is_support_feature( $object_type, $feature, $type = null ) {
263 $objects = self::$object_support_features;
264 $namespace = explode( '.', $object_type );
265 $object_type = $namespace[0];
266 $namespace = isset( $namespace[1] ) ? $namespace[1] : false;
267
268 if ( empty( $objects[ $object_type ] ) ) {
269 return false;
270 }
271
272 if ( $namespace && empty( $objects[ $object_type ][ $namespace ] ) ) {
273 return false;
274 }
275
276 if ( $namespace ) {
277 $is_support = array_key_exists( $feature, $objects[ $object_type ][ $namespace ] ) ? true : false;
278
279 if ( $type && $is_support ) {
280 return $objects[ $object_type ][ $namespace ][ $feature ] === $type;
281 }
282
283 return $is_support;
284 }
285
286 $is_support = array_key_exists( $feature, $objects[ $object_type ] ) ? true : false;
287
288 if ( $type && $is_support ) {
289 return $objects[ $object_type ][ $feature ] === $type;
290 }
291
292 return $is_support;
293 }
294
295 /**
296 * Get all features that an object support.
297 *
298 * @param string $object_type
299 *
300 * @return array|mixed
301 * @since 3.3.0
302 *
303 */
304 public static function get_object_supports( $object_type ) {
305 $namespace = explode( '.', $object_type );
306 $object_type = $namespace[0];
307 $namespace = isset( $namespace[1] ) ? $namespace[1] : false;
308
309 if ( empty( self::$object_support_features[ $object_type ] ) ) {
310 return array();
311 }
312
313 if ( $namespace ) {
314 if ( empty( self::$object_support_features[ $object_type ][ $namespace ] ) ) {
315 return array();
316 }
317 }
318
319 return self::$object_support_features[ $object_type ];
320 }
321 }
322