Version Description
(2022-09-16) = ~ Fixed: non-LP plugins causing errors.
Download this release
Release Info
Developer | ThimPress |
Plugin | LearnPress – WordPress LMS Plugin |
Version | 4.1.7.1 |
Comparing to | |
See all releases |
Code changes from version 4.1.7 to 4.1.7.1
- assets/js/dist/frontend/courses.js +5 -5
- assets/src/apps/js/frontend/courses.js +5 -5
- inc/admin/class-lp-setup-wizard.php +3 -5
- inc/admin/views/meta-boxes/course/settings.php +1 -82
- inc/admin/views/meta-boxes/fields/select.php +5 -0
- inc/class-lp-install.php +0 -340
- inc/class-lp-page-controller.php +157 -204
- inc/class-lp-query.php +1 -1
- inc/class-lp-theme-support.php +0 -41
- inc/lp-core-functions.php +10 -1
- inc/rest-api/v1/frontend/class-lp-rest-courses-controller.php +12 -116
- languages/learnpress-es-co.po +1 -1
- languages/learnpress-es.po +1 -1
- languages/learnpress.pot +1 -1
- learnpress.php +54 -49
- mu-plugin/class-lp-mu-plugin.php +140 -0
- readme.txt +4 -1
assets/js/dist/frontend/courses.js
CHANGED
@@ -10,8 +10,8 @@ let skeleton;
|
|
10 |
let skeletonClone;
|
11 |
let isLoading = false;
|
12 |
let firstLoad = 1;
|
13 |
-
let elNoLoadAjaxFirst
|
14 |
-
let elArchive
|
15 |
|
16 |
if (lpGlobalSettings.is_course_archive) {
|
17 |
const queryString = window.location.search;
|
@@ -39,10 +39,10 @@ const lpArchiveCourse = () => {
|
|
39 |
|
40 |
if (!elNoLoadAjaxFirst) {
|
41 |
lpArchiveRequestCourse(filterCourses);
|
42 |
-
} else {
|
43 |
-
lpArchivePaginationCourse();
|
44 |
-
lpArchiveSearchCourse();
|
45 |
}
|
|
|
|
|
|
|
46 |
};
|
47 |
|
48 |
window.lpArchiveRequestCourse = (args, callBackSuccess) => {
|
10 |
let skeletonClone;
|
11 |
let isLoading = false;
|
12 |
let firstLoad = 1;
|
13 |
+
let elNoLoadAjaxFirst;
|
14 |
+
let elArchive;
|
15 |
|
16 |
if (lpGlobalSettings.is_course_archive) {
|
17 |
const queryString = window.location.search;
|
39 |
|
40 |
if (!elNoLoadAjaxFirst) {
|
41 |
lpArchiveRequestCourse(filterCourses);
|
|
|
|
|
|
|
42 |
}
|
43 |
+
|
44 |
+
lpArchivePaginationCourse();
|
45 |
+
lpArchiveSearchCourse();
|
46 |
};
|
47 |
|
48 |
window.lpArchiveRequestCourse = (args, callBackSuccess) => {
|
assets/src/apps/js/frontend/courses.js
CHANGED
@@ -5,8 +5,8 @@ let skeleton;
|
|
5 |
let skeletonClone;
|
6 |
let isLoading = false;
|
7 |
let firstLoad = 1;
|
8 |
-
let elNoLoadAjaxFirst
|
9 |
-
let elArchive
|
10 |
|
11 |
if ( lpGlobalSettings.is_course_archive ) {
|
12 |
const queryString = window.location.search;
|
@@ -36,10 +36,10 @@ const lpArchiveCourse = () => {
|
|
36 |
|
37 |
if ( ! elNoLoadAjaxFirst ) {
|
38 |
lpArchiveRequestCourse( filterCourses );
|
39 |
-
} else {
|
40 |
-
lpArchivePaginationCourse();
|
41 |
-
lpArchiveSearchCourse();
|
42 |
}
|
|
|
|
|
|
|
43 |
};
|
44 |
|
45 |
window.lpArchiveRequestCourse = ( args, callBackSuccess ) => {
|
5 |
let skeletonClone;
|
6 |
let isLoading = false;
|
7 |
let firstLoad = 1;
|
8 |
+
let elNoLoadAjaxFirst;
|
9 |
+
let elArchive;
|
10 |
|
11 |
if ( lpGlobalSettings.is_course_archive ) {
|
12 |
const queryString = window.location.search;
|
36 |
|
37 |
if ( ! elNoLoadAjaxFirst ) {
|
38 |
lpArchiveRequestCourse( filterCourses );
|
|
|
|
|
|
|
39 |
}
|
40 |
+
|
41 |
+
lpArchivePaginationCourse();
|
42 |
+
lpArchiveSearchCourse();
|
43 |
};
|
44 |
|
45 |
window.lpArchiveRequestCourse = ( args, callBackSuccess ) => {
|
inc/admin/class-lp-setup-wizard.php
CHANGED
@@ -112,14 +112,9 @@ class LP_Setup_Wizard {
|
|
112 |
}
|
113 |
|
114 |
if ( 'finish' === LP_Request::get_string( 'step' ) ) {
|
115 |
-
|
116 |
-
// LP_Install::create_options();
|
117 |
-
|
118 |
update_option( 'learn_press_setup_wizard_completed', 'yes' );
|
119 |
}
|
120 |
|
121 |
-
// LP_Install::create_tables();
|
122 |
-
|
123 |
$this->save();
|
124 |
|
125 |
// Refresh new changes
|
@@ -158,6 +153,9 @@ class LP_Setup_Wizard {
|
|
158 |
die();
|
159 |
}
|
160 |
|
|
|
|
|
|
|
161 |
public function save() {
|
162 |
$step = LP_Request::get_string( 'lp-setup-step' );
|
163 |
|
112 |
}
|
113 |
|
114 |
if ( 'finish' === LP_Request::get_string( 'step' ) ) {
|
|
|
|
|
|
|
115 |
update_option( 'learn_press_setup_wizard_completed', 'yes' );
|
116 |
}
|
117 |
|
|
|
|
|
118 |
$this->save();
|
119 |
|
120 |
// Refresh new changes
|
153 |
die();
|
154 |
}
|
155 |
|
156 |
+
/**
|
157 |
+
* @TODO tungnx - need review
|
158 |
+
*/
|
159 |
public function save() {
|
160 |
$step = LP_Request::get_string( 'lp-setup-step' );
|
161 |
|
inc/admin/views/meta-boxes/course/settings.php
CHANGED
@@ -184,87 +184,6 @@ class LP_Meta_Box_Course extends LP_Meta_Box {
|
|
184 |
);
|
185 |
}
|
186 |
|
187 |
-
/**
|
188 |
-
* @editor tungnx
|
189 |
-
* @modify 4.1.5 - replace to lp_price function
|
190 |
-
*/
|
191 |
-
/*public function price( $thepostid ) {
|
192 |
-
$post = get_post( $thepostid );
|
193 |
-
|
194 |
-
$thepostid = ! empty( $thepostid ) ? $thepostid : absint( $post->ID );
|
195 |
-
|
196 |
-
$message = '';
|
197 |
-
$price = get_post_meta( $thepostid, '_lp_price', true );
|
198 |
-
$payment = get_post_meta( $thepostid, '_lp_payment', true );
|
199 |
-
$sale_price = '';
|
200 |
-
$start_date = '';
|
201 |
-
$end_date = '';
|
202 |
-
|
203 |
-
if ( $payment != 'free' ) {
|
204 |
-
$sale_price = get_post_meta( $thepostid, '_lp_sale_price', true );
|
205 |
-
$start_date = get_post_meta( $thepostid, '_lp_sale_start', true );
|
206 |
-
$end_date = get_post_meta( $thepostid, '_lp_sale_end', true );
|
207 |
-
}
|
208 |
-
|
209 |
-
return apply_filters(
|
210 |
-
'lp/course/meta-box/fields/price',
|
211 |
-
array(
|
212 |
-
'_lp_price' => new LP_Meta_Box_Text_Field(
|
213 |
-
esc_html__( 'Regular price', 'learnpress' ),
|
214 |
-
sprintf( __( 'Set a regular price (<strong>%s</strong>). Leave it blank for <strong>Free</strong>.', 'learnpress' ), learn_press_get_currency() ),
|
215 |
-
$price,
|
216 |
-
array(
|
217 |
-
'type_input' => 'number',
|
218 |
-
'custom_attributes' => array(
|
219 |
-
'min' => '0',
|
220 |
-
'step' => '0.01',
|
221 |
-
),
|
222 |
-
'style' => 'width: 70px;',
|
223 |
-
'class' => 'lp_meta_box_regular_price',
|
224 |
-
)
|
225 |
-
),
|
226 |
-
'_lp_sale_price' => new LP_Meta_Box_Text_Field(
|
227 |
-
esc_html__( 'Sale price', 'learnpress' ),
|
228 |
-
'<a href="#" class="lp_sale_price_schedule">' . esc_html__( 'Schedule', 'learnpress' ) . '</a>',
|
229 |
-
$sale_price,
|
230 |
-
array(
|
231 |
-
'type_input' => 'number',
|
232 |
-
'custom_attributes' => array(
|
233 |
-
'min' => '0',
|
234 |
-
'step' => '0.01',
|
235 |
-
),
|
236 |
-
'style' => 'width: 70px;',
|
237 |
-
'class' => 'lp_meta_box_sale_price',
|
238 |
-
)
|
239 |
-
),
|
240 |
-
'_lp_sale_start' => new LP_Meta_Box_Date_Field(
|
241 |
-
esc_html__( 'Sale start dates', 'learnpress' ),
|
242 |
-
'',
|
243 |
-
'',
|
244 |
-
array(
|
245 |
-
'wrapper_class' => 'lp_sale_start_dates_fields',
|
246 |
-
'placeholder' => _x( 'From…', 'placeholder', 'learnpress' ),
|
247 |
-
)
|
248 |
-
),
|
249 |
-
'_lp_sale_end' => new LP_Meta_Box_Date_Field(
|
250 |
-
esc_html__( 'Sale end dates', 'learnpress' ),
|
251 |
-
'',
|
252 |
-
'',
|
253 |
-
array(
|
254 |
-
'wrapper_class' => 'lp_sale_end_dates_fields',
|
255 |
-
'placeholder' => _x( 'To…', 'placeholder', 'learnpress' ),
|
256 |
-
'cancel' => true,
|
257 |
-
)
|
258 |
-
),
|
259 |
-
'_lp_no_required_enroll' => new LP_Meta_Box_Checkbox_Field(
|
260 |
-
esc_html__( 'No requirement enroll', 'learnpress' ),
|
261 |
-
esc_html__( 'Students can see the content of all course items and do the quiz without login.', 'learnpress' ),
|
262 |
-
'no'
|
263 |
-
),
|
264 |
-
)
|
265 |
-
);
|
266 |
-
}*/
|
267 |
-
|
268 |
/**
|
269 |
* Setting course price
|
270 |
*
|
@@ -332,7 +251,7 @@ class LP_Meta_Box_Course extends LP_Meta_Box {
|
|
332 |
)
|
333 |
),
|
334 |
'_lp_no_required_enroll' => new LP_Meta_Box_Checkbox_Field(
|
335 |
-
esc_html__( 'No requirement
|
336 |
esc_html__( 'Students can see the content of all course items and do the quiz without login.', 'learnpress' ),
|
337 |
'no'
|
338 |
),
|
184 |
);
|
185 |
}
|
186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
/**
|
188 |
* Setting course price
|
189 |
*
|
251 |
)
|
252 |
),
|
253 |
'_lp_no_required_enroll' => new LP_Meta_Box_Checkbox_Field(
|
254 |
+
esc_html__( 'No enroll requirement', 'learnpress' ),
|
255 |
esc_html__( 'Students can see the content of all course items and do the quiz without login.', 'learnpress' ),
|
256 |
'no'
|
257 |
),
|
inc/admin/views/meta-boxes/fields/select.php
CHANGED
@@ -109,6 +109,11 @@ class LP_Meta_Box_Select_Field extends LP_Meta_Box_Field {
|
|
109 |
return;
|
110 |
}
|
111 |
|
|
|
|
|
|
|
|
|
|
|
112 |
if ( $multiple_meta ) {
|
113 |
$get_values = get_post_meta( $post_id, $this->id ) ?? array();
|
114 |
$new_values = LP_Helper::sanitize_params_submitted( $_POST[ $this->id ] ?? [] );
|
109 |
return;
|
110 |
}
|
111 |
|
112 |
+
if ( ! empty( $this->extra['custom_save'] ) ) {
|
113 |
+
do_action( 'learnpress/admin/metabox/select/save', $this->id, $_POST[ $this->id ], $post_id );
|
114 |
+
return;
|
115 |
+
}
|
116 |
+
|
117 |
if ( $multiple_meta ) {
|
118 |
$get_values = get_post_meta( $post_id, $this->id ) ?? array();
|
119 |
$new_values = LP_Helper::sanitize_params_submitted( $_POST[ $this->id ] ?? [] );
|
inc/class-lp-install.php
CHANGED
@@ -41,15 +41,6 @@ if ( ! function_exists( 'LP_Install' ) ) {
|
|
41 |
return self::$instance;
|
42 |
}
|
43 |
|
44 |
-
/**
|
45 |
-
* Init action.
|
46 |
-
*/
|
47 |
-
public static function init() {
|
48 |
-
// add_action( 'learn-press/activate', array( __CLASS__, 'on_activate' ) );
|
49 |
-
// add_action( 'admin_init', array( __CLASS__, 'do_install' ) );
|
50 |
-
// add_action( 'admin_init', array( __CLASS__, 'subscription_button' ) );
|
51 |
-
}
|
52 |
-
|
53 |
/**
|
54 |
* Do something after LP is activated.
|
55 |
*
|
@@ -104,15 +95,6 @@ if ( ! function_exists( 'LP_Install' ) ) {
|
|
104 |
}
|
105 |
}
|
106 |
|
107 |
-
public static function subscription_button() {
|
108 |
-
// Only administrator of the site can do this
|
109 |
-
if ( ! current_user_can( 'administrator' ) ) {
|
110 |
-
return;
|
111 |
-
}
|
112 |
-
|
113 |
-
LP_Admin_Notice::instance()->add( 'tools/subscription-button.php', '', true, 'newsletter-button' );
|
114 |
-
}
|
115 |
-
|
116 |
/**
|
117 |
* Run installation after LearnPress is activated.
|
118 |
*
|
@@ -146,114 +128,6 @@ if ( ! function_exists( 'LP_Install' ) ) {
|
|
146 |
//}*/
|
147 |
}
|
148 |
|
149 |
-
protected static function _clear_backgrounds() {
|
150 |
-
global $wpdb;
|
151 |
-
|
152 |
-
$query = $wpdb->prepare(
|
153 |
-
"
|
154 |
-
DELETE FROM {$wpdb->options} WHERE option_name LIKE %s
|
155 |
-
",
|
156 |
-
$wpdb->esc_like( 'lp_schedule_items_batch_' ) . '%'
|
157 |
-
);
|
158 |
-
$wpdb->query( $query );
|
159 |
-
|
160 |
-
$query = $wpdb->prepare(
|
161 |
-
"
|
162 |
-
DELETE FROM {$wpdb->options} WHERE option_name LIKE %s
|
163 |
-
",
|
164 |
-
$wpdb->esc_like( 'lp_installer_batch_' ) . '%'
|
165 |
-
);
|
166 |
-
$wpdb->query( $query );
|
167 |
-
}
|
168 |
-
|
169 |
-
/**
|
170 |
-
* Update default options for LP
|
171 |
-
*
|
172 |
-
* @editor tungnx - comment - not use on v4.1.6.6
|
173 |
-
*/
|
174 |
-
/*public static function create_options() {
|
175 |
-
$settings_classes = array(
|
176 |
-
'LP_Settings_General' => include_once LP_PLUGIN_PATH . '/inc/admin/settings/class-lp-settings-general.php',
|
177 |
-
'LP_Settings_Courses' => include_once LP_PLUGIN_PATH . '/inc/admin/settings/class-lp-settings-courses.php',
|
178 |
-
'LP_Settings_Profile' => include_once LP_PLUGIN_PATH . '/inc/admin/settings/class-lp-settings-profile.php',
|
179 |
-
'LP_Settings_Payments' => include_once LP_PLUGIN_PATH . '/inc/admin/settings/class-lp-settings-payments.php',
|
180 |
-
);
|
181 |
-
|
182 |
-
ob_start();
|
183 |
-
$str = array();
|
184 |
-
|
185 |
-
foreach ( $settings_classes as $c => $class ) {
|
186 |
-
if ( ! is_object( $class ) ) {
|
187 |
-
$class = @new $c();
|
188 |
-
}
|
189 |
-
|
190 |
-
$options = array();
|
191 |
-
|
192 |
-
if ( is_callable( array( $class, 'get_settings' ) ) ) {
|
193 |
-
$options = $class->get_settings( '', '' );
|
194 |
-
}
|
195 |
-
|
196 |
-
if ( ! $options ) {
|
197 |
-
continue;
|
198 |
-
}
|
199 |
-
|
200 |
-
foreach ( $options as $option ) {
|
201 |
-
if ( ! isset( $option['id'] ) ) {
|
202 |
-
continue;
|
203 |
-
}
|
204 |
-
|
205 |
-
$default_value = '';
|
206 |
-
|
207 |
-
if ( array_key_exists( 'default', $option ) ) {
|
208 |
-
$default_value = $option['default'];
|
209 |
-
} elseif ( array_key_exists( 'std', $option ) ) {
|
210 |
-
$default_value = $option['std'];
|
211 |
-
}
|
212 |
-
|
213 |
-
if ( $default_value === '' || $default_value === null ) {
|
214 |
-
continue;
|
215 |
-
}
|
216 |
-
|
217 |
-
if ( ! preg_match( '~^learn_press_~', $option['id'] ) ) {
|
218 |
-
$option_name = 'learn_press_' . $option['id'];
|
219 |
-
} else {
|
220 |
-
$option_name = $option['id'];
|
221 |
-
}
|
222 |
-
|
223 |
-
// Don't update existing option
|
224 |
-
if ( false !== get_option( $option_name ) ) {
|
225 |
-
continue;
|
226 |
-
}
|
227 |
-
|
228 |
-
// If option name doesn't like an array then update directly.
|
229 |
-
if ( ! preg_match( '/\[|\]/', $option_name ) ) {
|
230 |
-
update_option( $option_name, $default_value, 'yes' );
|
231 |
-
continue;
|
232 |
-
}
|
233 |
-
|
234 |
-
// Concat option as query string to parse it later
|
235 |
-
$value = maybe_serialize( $default_value );
|
236 |
-
$str[] = "{$option_name}=$value";
|
237 |
-
}
|
238 |
-
}
|
239 |
-
|
240 |
-
// Parse query string to get options
|
241 |
-
if ( $str ) {
|
242 |
-
$str = join( '&', $str );
|
243 |
-
$options = array();
|
244 |
-
parse_str( $str, $options );
|
245 |
-
|
246 |
-
if ( $options ) {
|
247 |
-
foreach ( $options as $name => $value ) {
|
248 |
-
$value = LP_Helper::maybe_unserialize( $value );
|
249 |
-
update_option( $name, $value, 'yes' );
|
250 |
-
}
|
251 |
-
}
|
252 |
-
}
|
253 |
-
|
254 |
-
ob_get_clean();
|
255 |
-
}*/
|
256 |
-
|
257 |
/**
|
258 |
* Create tables required for LP
|
259 |
*/
|
@@ -270,166 +144,6 @@ if ( ! function_exists( 'LP_Install' ) ) {
|
|
270 |
}
|
271 |
}
|
272 |
|
273 |
-
/**
|
274 |
-
* Delete transients
|
275 |
-
*/
|
276 |
-
private static function _delete_transients() {
|
277 |
-
global $wpdb;
|
278 |
-
$sql = "
|
279 |
-
DELETE a, b FROM $wpdb->options a, $wpdb->options b
|
280 |
-
WHERE a.option_name LIKE %s
|
281 |
-
AND a.option_name NOT LIKE %s
|
282 |
-
AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )
|
283 |
-
AND b.option_value < %d
|
284 |
-
";
|
285 |
-
$wpdb->query(
|
286 |
-
$wpdb->prepare(
|
287 |
-
$sql,
|
288 |
-
$wpdb->esc_like( '_transient_' ) . '%',
|
289 |
-
$wpdb->esc_like( '_transient_timeout_' ) . '%',
|
290 |
-
time()
|
291 |
-
)
|
292 |
-
);
|
293 |
-
}
|
294 |
-
|
295 |
-
/**
|
296 |
-
* Remove learnpress page if total of learn page > 10
|
297 |
-
*
|
298 |
-
* @return mixed
|
299 |
-
* @depecated 4.1.6.4
|
300 |
-
*/
|
301 |
-
/*public static function _remove_pages() {
|
302 |
-
global $wpdb;
|
303 |
-
|
304 |
-
// Get all pages
|
305 |
-
$sql = $wpdb->prepare(
|
306 |
-
"
|
307 |
-
SELECT *
|
308 |
-
FROM {$wpdb->posts} p
|
309 |
-
INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id AND pm.meta_key= %s AND p.post_type = %s
|
310 |
-
",
|
311 |
-
'_learn_press_page',
|
312 |
-
'page'
|
313 |
-
);
|
314 |
-
|
315 |
-
$page_ids = $wpdb->get_col( $sql );
|
316 |
-
|
317 |
-
if ( sizeof( $page_ids ) < 10 ) {
|
318 |
-
return $page_ids;
|
319 |
-
}
|
320 |
-
|
321 |
-
// Delete pages
|
322 |
-
$query = $wpdb->prepare(
|
323 |
-
"
|
324 |
-
DELETE FROM p, pm
|
325 |
-
USING {$wpdb->posts} AS p LEFT JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id AND p.post_type = %s
|
326 |
-
WHERE p.post_status = %s
|
327 |
-
AND p.ID IN(" . implode( ',', $page_ids ) . ')
|
328 |
-
',
|
329 |
-
'page',
|
330 |
-
'publish'
|
331 |
-
);
|
332 |
-
|
333 |
-
$wpdb->query( $query );
|
334 |
-
|
335 |
-
$pages = self::$_pages;
|
336 |
-
foreach ( $pages as $page ) {
|
337 |
-
delete_option( "learn_press_{$page}_page_id" );
|
338 |
-
}
|
339 |
-
|
340 |
-
return array();
|
341 |
-
}*/
|
342 |
-
|
343 |
-
/**
|
344 |
-
* Create default pages for LP
|
345 |
-
*/
|
346 |
-
/*public static function _create_pages() {
|
347 |
-
global $wpdb;
|
348 |
-
|
349 |
-
// Just delete duplicated pages
|
350 |
-
$created_page = self::_remove_pages();
|
351 |
-
$pages = self::$_pages;
|
352 |
-
|
353 |
-
foreach ( $pages as $page ) {
|
354 |
-
// If page already existed
|
355 |
-
$page_id = get_option( "learn_press_{$page}_page_id" );
|
356 |
-
|
357 |
-
if ( $page_id && get_post_type( $page_id ) == 'page' && get_post_status( $page_id ) == 'publish' ) {
|
358 |
-
continue;
|
359 |
-
}
|
360 |
-
|
361 |
-
$page_id = self::_search_page( $page, $pages );
|
362 |
-
|
363 |
-
if ( ! $page_id ) {
|
364 |
-
// Check if page has already existed
|
365 |
-
switch ( $page ) {
|
366 |
-
case 'courses':
|
367 |
-
$_lpr_settings_pages = (array) get_option( '_lpr_settings_pages' );
|
368 |
-
|
369 |
-
if ( ! empty( $_lpr_settings_pages['general'] ) ) {
|
370 |
-
if ( ! empty( $_lpr_settings_pages['general']['courses_page_id'] ) ) {
|
371 |
-
$page_id = $_lpr_settings_pages['general']['courses_page_id'];
|
372 |
-
}
|
373 |
-
}
|
374 |
-
break;
|
375 |
-
case 'profile':
|
376 |
-
$_lpr_settings_general = (array) get_option( '_lpr_settings_general' );
|
377 |
-
if ( ! empty( $_lpr_settings_general['set_page'] ) && $_lpr_settings_general['set_page'] == 'lpr_profile' ) {
|
378 |
-
$page_id = $wpdb->get_var(
|
379 |
-
$wpdb->prepare(
|
380 |
-
"
|
381 |
-
SELECT ID
|
382 |
-
FROM $wpdb->posts p
|
383 |
-
INNER JOIN $wpdb->postmeta pm ON p.ID = pm.post_id AND pm.meta_key = %s AND pm.meta_value = %d
|
384 |
-
",
|
385 |
-
'_lpr_is_profile_page',
|
386 |
-
1
|
387 |
-
)
|
388 |
-
);
|
389 |
-
}
|
390 |
-
break;
|
391 |
-
}
|
392 |
-
|
393 |
-
if ( ! $page_id ) {
|
394 |
-
if ( $page === 'courses' ) {
|
395 |
-
$page_title = 'All Courses';
|
396 |
-
} else {
|
397 |
-
$page_title = ucwords( str_replace( '_', ' ', $page ) );
|
398 |
-
}
|
399 |
-
|
400 |
-
if ( $page === 'profile' ) {
|
401 |
-
$page_content = '<!-- wp:shortcode -->[' . apply_filters( 'learn-press/shortcode/profile/tag', 'learn_press_profile' ) . ']<!-- /wp:shortcode -->';
|
402 |
-
} else {
|
403 |
-
$page_content = '';
|
404 |
-
}
|
405 |
-
|
406 |
-
$page_slug = 'lp-' . str_replace( '_', '-', $page );
|
407 |
-
|
408 |
-
$inserted = wp_insert_post(
|
409 |
-
array(
|
410 |
-
'post_title' => $page_title,
|
411 |
-
'post_name' => $page_slug,
|
412 |
-
'post_status' => 'publish',
|
413 |
-
'post_type' => 'page',
|
414 |
-
'comment_status' => 'closed',
|
415 |
-
'post_content' => isset( $page_content ) ? $page_content : '',
|
416 |
-
'post_author' => get_current_user_id(),
|
417 |
-
)
|
418 |
-
);
|
419 |
-
if ( $inserted ) {
|
420 |
-
$page_id = $inserted;
|
421 |
-
}
|
422 |
-
}
|
423 |
-
}
|
424 |
-
if ( $page_id ) {
|
425 |
-
update_option( "learn_press_{$page}_page_id", $page_id );
|
426 |
-
update_post_meta( $page_id, '_learn_press_page', $page );
|
427 |
-
}
|
428 |
-
}
|
429 |
-
|
430 |
-
flush_rewrite_rules();
|
431 |
-
}*/
|
432 |
-
|
433 |
/**
|
434 |
* Create default pages for LP
|
435 |
*/
|
@@ -484,60 +198,6 @@ if ( ! function_exists( 'LP_Install' ) ) {
|
|
484 |
}
|
485 |
}
|
486 |
|
487 |
-
/**
|
488 |
-
* Search LP page to see if they are already created.
|
489 |
-
*
|
490 |
-
* @param $type
|
491 |
-
* @param $types
|
492 |
-
*
|
493 |
-
* @return int|mixed
|
494 |
-
* @depecated 4.1.6.4
|
495 |
-
*/
|
496 |
-
/*protected static function _search_page( $type, $types ) {
|
497 |
-
static $pages = array();
|
498 |
-
|
499 |
-
if ( empty( $pages[ $type ] ) ) {
|
500 |
-
global $wpdb;
|
501 |
-
$in_types = array_fill( 0, sizeof( $types ), '%s' );
|
502 |
-
$args = array( '_learn_press_page' );
|
503 |
-
$args = array_merge( $args, $types );
|
504 |
-
$args[] = 'publish';
|
505 |
-
$query = $wpdb->prepare(
|
506 |
-
"
|
507 |
-
SELECT ID, pm.meta_value as type
|
508 |
-
FROM {$wpdb->posts} p
|
509 |
-
INNER JOIN {$wpdb->postmeta} pm ON pm.post_id = p.ID AND pm.meta_key = %s AND pm.meta_value IN(" . join( ',',
|
510 |
-
$in_types ) . ')
|
511 |
-
WHERE p.post_status = %s
|
512 |
-
',
|
513 |
-
$args
|
514 |
-
);
|
515 |
-
|
516 |
-
if ( $rows = $wpdb->get_results( $query ) ) {
|
517 |
-
foreach ( $rows as $row ) {
|
518 |
-
$pages[ $row->type ] = $row->ID;
|
519 |
-
}
|
520 |
-
}
|
521 |
-
}
|
522 |
-
|
523 |
-
$page_id = ! empty( $pages[ $type ] ) ? $pages[ $type ] : 0;
|
524 |
-
|
525 |
-
return $page_id;
|
526 |
-
}*/
|
527 |
-
|
528 |
-
/**
|
529 |
-
* @depecated 4.1.6.4
|
530 |
-
*/
|
531 |
-
private static function _create_cron_jobs() {
|
532 |
-
_deprecated_function( __FUNCTION__, '4.1.6.4' );
|
533 |
-
wp_clear_scheduled_hook( 'learn_press_cleanup_sessions' );
|
534 |
-
wp_schedule_event(
|
535 |
-
time(),
|
536 |
-
apply_filters( 'learn_press_cleanup_session_recurrence', 'twicedaily' ),
|
537 |
-
'learn_press_cleanup_sessions'
|
538 |
-
);
|
539 |
-
}
|
540 |
-
|
541 |
/**
|
542 |
* Check installed all tables required for LearnPress.
|
543 |
*
|
41 |
return self::$instance;
|
42 |
}
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
/**
|
45 |
* Do something after LP is activated.
|
46 |
*
|
95 |
}
|
96 |
}
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
/**
|
99 |
* Run installation after LearnPress is activated.
|
100 |
*
|
128 |
//}*/
|
129 |
}
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
/**
|
132 |
* Create tables required for LP
|
133 |
*/
|
144 |
}
|
145 |
}
|
146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
/**
|
148 |
* Create default pages for LP
|
149 |
*/
|
198 |
}
|
199 |
}
|
200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
/**
|
202 |
* Check installed all tables required for LearnPress.
|
203 |
*
|
inc/class-lp-page-controller.php
CHANGED
@@ -11,12 +11,12 @@ class LP_Page_Controller {
|
|
11 |
*
|
12 |
* @var int
|
13 |
*/
|
14 |
-
protected $_queried_object = 0;
|
15 |
|
16 |
/**
|
17 |
* @var int
|
18 |
*/
|
19 |
-
protected $_filter_content_priority = 10000;
|
20 |
|
21 |
/**
|
22 |
* Flag for 404 content.
|
@@ -29,7 +29,7 @@ class LP_Page_Controller {
|
|
29 |
* LP_Page_Controller constructor.
|
30 |
*/
|
31 |
protected function __construct() {
|
32 |
-
add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ),
|
33 |
add_filter( 'template_include', array( $this, 'template_loader' ), 10 );
|
34 |
add_filter( 'template_include', array( $this, 'check_pages' ), 30 );
|
35 |
add_filter( 'template_include', array( $this, 'auto_shortcode' ), 50 );
|
@@ -49,7 +49,6 @@ class LP_Page_Controller {
|
|
49 |
|
50 |
// Set link profile to admin menu
|
51 |
add_action( 'admin_bar_menu', array( $this, 'learn_press_edit_admin_bar' ) );
|
52 |
-
add_action( 'plugins_loaded', array( $this, 'lp_rest_api_called' ), 1 );
|
53 |
|
54 |
// Web hook detected PayPal request.
|
55 |
add_action( 'init', [ $this, 'check_webhook_paypal_ipn' ] );
|
@@ -57,31 +56,6 @@ class LP_Page_Controller {
|
|
57 |
add_filter( 'rest_send_nocache_headers', array( $this, 'check_x_wp_nonce_cache' ) );
|
58 |
}
|
59 |
|
60 |
-
/**
|
61 |
-
* Optimize when Rest API LP called
|
62 |
-
*
|
63 |
-
* @return void
|
64 |
-
*/
|
65 |
-
public function lp_rest_api_called() {
|
66 |
-
if ( LP_Helper::isRestApiLP() ) {
|
67 |
-
if ( ! defined( 'SHORTINIT' ) ) {
|
68 |
-
define( 'SHORTINIT', true );
|
69 |
-
}
|
70 |
-
|
71 |
-
// Remove hook wp_loaded because query default WP run on it (it hooks 'pre_get_posts',...)
|
72 |
-
remove_all_actions( 'after_setup_theme' );
|
73 |
-
remove_all_actions( 'setup_theme' );
|
74 |
-
remove_all_actions( 'muplugins_loaded' );
|
75 |
-
remove_all_actions( 'network_plugin_loaded' );
|
76 |
-
remove_all_actions( 'mu_plugin_loaded' );
|
77 |
-
remove_all_actions( 'plugin_loaded' );
|
78 |
-
remove_all_actions( 'wp_loaded' );
|
79 |
-
//remove_all_actions( 'plugins_loaded' );
|
80 |
-
remove_all_actions( 'pre_get_posts' );
|
81 |
-
remove_all_actions( 'parse_query' );
|
82 |
-
}
|
83 |
-
}
|
84 |
-
|
85 |
/**
|
86 |
* Check notify papal call when done.
|
87 |
*
|
@@ -710,7 +684,8 @@ class LP_Page_Controller {
|
|
710 |
*
|
711 |
* @return WP_Query
|
712 |
* @editor tungnx
|
713 |
-
* @
|
|
|
714 |
* @throws Exception
|
715 |
*/
|
716 |
public function pre_get_posts( WP_Query $q ): WP_Query {
|
@@ -719,192 +694,159 @@ class LP_Page_Controller {
|
|
719 |
return $q;
|
720 |
}
|
721 |
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
$this->_queried_object = ! empty( $q->queried_object_id ) ? $q->queried_object : false;
|
753 |
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
$page_courses_id = learn_press_get_page_id( 'courses' );
|
759 |
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
765 |
|
766 |
-
|
767 |
-
|
768 |
-
*/
|
769 |
-
if ( $q->is_page() && 'page' == get_option( 'show_on_front' ) && $page_courses_id && $q->get( 'page_id' ) == $page_courses_id ) {
|
770 |
-
$is_archive_course = 1;
|
771 |
-
|
772 |
-
/*
|
773 |
-
global $wp_post_types;
|
774 |
-
|
775 |
-
$course_page = get_post( $page_courses_id );
|
776 |
-
$this->_queried_object = $course_page;
|
777 |
-
$wp_post_types[ LP_COURSE_CPT ]->ID = $course_page->ID;
|
778 |
-
$wp_post_types[ LP_COURSE_CPT ]->post_title = $course_page->post_title;
|
779 |
-
$wp_post_types[ LP_COURSE_CPT ]->post_name = $course_page->post_name;
|
780 |
-
$wp_post_types[ LP_COURSE_CPT ]->post_type = $course_page->post_type;
|
781 |
-
$wp_post_types[ LP_COURSE_CPT ]->ancestors = get_ancestors( $course_page->ID, $course_page->post_type );*/
|
782 |
-
}
|
783 |
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
788 |
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
* Current, apply only for LP, not apply for theme Thimpress, because theme override
|
799 |
-
*/
|
800 |
-
$q->set( 'posts_per_page', 1 );
|
801 |
-
$q->set( 'posts_per_archive_page', 1 );
|
802 |
-
$q->set( 'nopaging', true );
|
803 |
-
} else {
|
804 |
-
$filter = new LP_Course_Filter();
|
805 |
-
$filter->only_fields = [ 'ID' ];
|
806 |
-
$filter->max_limit = $filter->limit = 1000;
|
807 |
-
$is_need_check_in_arr = false;
|
808 |
-
$limit = LP_Settings::get_option( 'archive_course_limit', 6 );
|
809 |
-
|
810 |
-
$q->set( 'posts_per_page', $limit );
|
811 |
-
// $q->set( 'cache_results', true ); // it default true
|
812 |
-
|
813 |
-
// Search courses by keyword
|
814 |
-
// $q->set( 's', $_REQUEST['c_search'] ?? '' );
|
815 |
-
if ( ! empty( $_REQUEST['c_search'] ) ) {
|
816 |
-
$filter->post_title = LP_Helper::sanitize_params_submitted( $_REQUEST['c_search'] );
|
817 |
-
$is_need_check_in_arr = true;
|
818 |
-
}
|
819 |
|
820 |
-
|
821 |
-
if ( ! empty( $author_ids_str ) ) {
|
822 |
-
$q->set( 'author', $author_ids_str );
|
823 |
}
|
824 |
|
825 |
-
|
826 |
-
|
827 |
-
if ( isset( $_REQUEST['sort_by'] ) ) {
|
828 |
-
$sort_by = LP_Helper::sanitize_params_submitted( $_REQUEST['sort_by'] );
|
829 |
-
if ( 'on_paid' === $sort_by ) {
|
830 |
-
$meta_query[] = array(
|
831 |
-
'key' => '_lp_price',
|
832 |
-
'value' => 0,
|
833 |
-
'compare' => '>',
|
834 |
-
);
|
835 |
-
}
|
836 |
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
);
|
843 |
-
}
|
844 |
-
}
|
845 |
-
$q->set( 'meta_query', $meta_query );
|
846 |
-
// End Meta query
|
847 |
-
|
848 |
-
// Tax query
|
849 |
-
$tax_query = [];
|
850 |
-
$term_ids_str = LP_Helper::sanitize_params_submitted( urldecode( $_REQUEST['term_id'] ?? '' ) );
|
851 |
-
if ( ! empty( $term_ids_str ) ) {
|
852 |
-
$term_ids = explode( ',', $term_ids_str );
|
853 |
-
|
854 |
-
$tax_query[] = array(
|
855 |
-
'taxonomy' => 'course_category',
|
856 |
-
'field' => 'term_id',
|
857 |
-
'terms' => $term_ids,
|
858 |
-
'operator' => 'IN',
|
859 |
-
);
|
860 |
-
}
|
861 |
|
862 |
-
|
863 |
-
|
|
|
|
|
|
|
864 |
|
865 |
-
|
866 |
-
if ( isset( $_REQUEST['c_author'] ) ) {
|
867 |
-
$author_ids = LP_Helper::sanitize_params_submitted( $_REQUEST['c_author'] );
|
868 |
-
$q->set( 'author__in', $author_ids );
|
869 |
}
|
870 |
-
// End Author query
|
871 |
-
|
872 |
-
// Order query
|
873 |
-
if ( isset( $_REQUEST['order_by'] ) ) {
|
874 |
-
$order_by = LP_Helper::sanitize_params_submitted( $_REQUEST['order_by'] );
|
875 |
-
$order = 'DESC';
|
876 |
-
|
877 |
-
switch ( $order_by ) {
|
878 |
-
case 'post_title':
|
879 |
-
$order_by = 'title';
|
880 |
-
$order = 'ASC';
|
881 |
-
break;
|
882 |
-
case 'popular':
|
883 |
-
$filter->order_by = 'popular';
|
884 |
-
$order_by = 'post__in';
|
885 |
-
$is_need_check_in_arr = true;
|
886 |
-
break;
|
887 |
-
default:
|
888 |
-
$order_by = 'date';
|
889 |
-
break;
|
890 |
-
}
|
891 |
|
892 |
-
|
893 |
-
|
894 |
-
|
|
|
895 |
|
896 |
-
if ( $
|
897 |
-
$
|
898 |
-
if ( ! empty( $posts_in ) ) {
|
899 |
-
$posts_in = LP_Database::get_values_by_key( $posts_in );
|
900 |
-
$q->set( 'post__in', $posts_in );
|
901 |
-
} else {
|
902 |
-
$q->set( 'post__in', 0 );
|
903 |
-
}
|
904 |
}
|
905 |
|
906 |
-
|
907 |
}
|
|
|
|
|
|
|
|
|
|
|
908 |
}
|
909 |
|
910 |
return $q;
|
@@ -920,13 +862,13 @@ class LP_Page_Controller {
|
|
920 |
* @since 3.2.7.5
|
921 |
*/
|
922 |
public function set_link_item_course_default_wp_to_page_404( $q ) {
|
923 |
-
|
|
|
|
|
924 |
return $q;
|
925 |
}
|
926 |
|
927 |
-
|
928 |
-
|
929 |
-
if ( isset( $q->query_vars['post_type'] ) && in_array( $q->query_vars['post_type'], $post_type_apply_404 ) ) {
|
930 |
$flag_load_404 = true;
|
931 |
$user = wp_get_current_user();
|
932 |
$post_author = 0;
|
@@ -956,6 +898,8 @@ class LP_Page_Controller {
|
|
956 |
if ( $flag_load_404 ) {
|
957 |
learn_press_404_page();
|
958 |
}
|
|
|
|
|
959 |
}
|
960 |
}
|
961 |
|
@@ -1002,11 +946,20 @@ class LP_Page_Controller {
|
|
1002 |
* @author tungnx
|
1003 |
*/
|
1004 |
public static function page_current(): string {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1005 |
if ( learn_press_is_checkout() ) {
|
1006 |
return LP_PAGE_CHECKOUT;
|
1007 |
} elseif ( LP_Global::course_item_quiz() ) {
|
1008 |
return LP_PAGE_QUIZ;
|
1009 |
-
} elseif ( learn_press_is_course() &&
|
1010 |
return LP_PAGE_SINGLE_COURSE_CURRICULUM;
|
1011 |
} elseif ( learn_press_is_courses() ) {
|
1012 |
return LP_PAGE_COURSES;
|
11 |
*
|
12 |
* @var int
|
13 |
*/
|
14 |
+
//protected $_queried_object = 0;
|
15 |
|
16 |
/**
|
17 |
* @var int
|
18 |
*/
|
19 |
+
//protected $_filter_content_priority = 10000;
|
20 |
|
21 |
/**
|
22 |
* Flag for 404 content.
|
29 |
* LP_Page_Controller constructor.
|
30 |
*/
|
31 |
protected function __construct() {
|
32 |
+
add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ), -1 );
|
33 |
add_filter( 'template_include', array( $this, 'template_loader' ), 10 );
|
34 |
add_filter( 'template_include', array( $this, 'check_pages' ), 30 );
|
35 |
add_filter( 'template_include', array( $this, 'auto_shortcode' ), 50 );
|
49 |
|
50 |
// Set link profile to admin menu
|
51 |
add_action( 'admin_bar_menu', array( $this, 'learn_press_edit_admin_bar' ) );
|
|
|
52 |
|
53 |
// Web hook detected PayPal request.
|
54 |
add_action( 'init', [ $this, 'check_webhook_paypal_ipn' ] );
|
56 |
add_filter( 'rest_send_nocache_headers', array( $this, 'check_x_wp_nonce_cache' ) );
|
57 |
}
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
/**
|
60 |
* Check notify papal call when done.
|
61 |
*
|
684 |
*
|
685 |
* @return WP_Query
|
686 |
* @editor tungnx
|
687 |
+
* @since 3.0.0
|
688 |
+
* @version 4.1.3
|
689 |
* @throws Exception
|
690 |
*/
|
691 |
public function pre_get_posts( WP_Query $q ): WP_Query {
|
694 |
return $q;
|
695 |
}
|
696 |
|
697 |
+
try {
|
698 |
+
if ( LP_Page_Controller::page_current() === LP_PAGE_COURSES ) {
|
699 |
+
if ( ( LP_Settings_Courses::is_ajax_load_courses() && ! LP_Settings_Courses::is_no_load_ajax_first_courses() ) ) {
|
700 |
+
LP()->template( 'course' )->remove_callback( 'learn-press/after-courses-loop', 'loop/course/pagination.php', 10 );
|
701 |
+
/**
|
702 |
+
* If page is archive course - query set posts_per_page = 1
|
703 |
+
* For fastest - because when page loaded - call API to load list courses
|
704 |
+
*
|
705 |
+
* Current, apply only for LP, not apply for theme Thimpress, because theme override
|
706 |
+
*/
|
707 |
+
$q->set( 'posts_per_page', 1 );
|
708 |
+
$q->set( 'posts_per_archive_page', 1 );
|
709 |
+
$q->set( 'nopaging', true );
|
710 |
+
} else {
|
711 |
+
$filter = new LP_Course_Filter();
|
712 |
+
$filter->only_fields = [ 'ID' ];
|
713 |
+
$filter->limit = -1;
|
714 |
+
$is_need_check_in_arr = false;
|
715 |
+
$limit = LP_Settings::get_option( 'archive_course_limit', 6 );
|
716 |
+
|
717 |
+
$q->set( 'posts_per_page', $limit );
|
718 |
+
// $q->set( 'cache_results', true ); // it default true
|
719 |
+
|
720 |
+
// Search courses by keyword
|
721 |
+
// $q->set( 's', $_REQUEST['c_search'] ?? '' );
|
722 |
+
if ( ! empty( $_REQUEST['c_search'] ) ) {
|
723 |
+
$filter->post_title = LP_Helper::sanitize_params_submitted( $_REQUEST['c_search'] );
|
724 |
+
$is_need_check_in_arr = true;
|
725 |
+
}
|
|
|
|
|
726 |
|
727 |
+
$author_ids_str = LP_Helper::sanitize_params_submitted( $_REQUEST['c_authors'] ?? 0 );
|
728 |
+
if ( ! empty( $author_ids_str ) ) {
|
729 |
+
$q->set( 'author', $author_ids_str );
|
730 |
+
}
|
|
|
731 |
|
732 |
+
// Meta query
|
733 |
+
$meta_query = [];
|
734 |
+
if ( isset( $_REQUEST['sort_by'] ) ) {
|
735 |
+
$sort_by = LP_Helper::sanitize_params_submitted( $_REQUEST['sort_by'] );
|
736 |
+
if ( 'on_paid' === $sort_by ) {
|
737 |
+
$meta_query[] = array(
|
738 |
+
'key' => '_lp_price',
|
739 |
+
'value' => 0,
|
740 |
+
'compare' => '>',
|
741 |
+
);
|
742 |
+
}
|
743 |
+
|
744 |
+
if ( 'on_free' === $sort_by ) {
|
745 |
+
$meta_query[] = array(
|
746 |
+
'key' => '_lp_price',
|
747 |
+
'value' => 0,
|
748 |
+
'compare' => '=',
|
749 |
+
);
|
750 |
+
}
|
751 |
+
}
|
752 |
+
$q->set( 'meta_query', $meta_query );
|
753 |
+
// End Meta query
|
754 |
+
|
755 |
+
// Tax query
|
756 |
+
$tax_query = [];
|
757 |
+
$term_ids_str = LP_Helper::sanitize_params_submitted( urldecode( $_REQUEST['term_id'] ?? '' ) );
|
758 |
+
if ( ! empty( $term_ids_str ) ) {
|
759 |
+
$term_ids = explode( ',', $term_ids_str );
|
760 |
+
|
761 |
+
$tax_query[] = array(
|
762 |
+
'taxonomy' => 'course_category',
|
763 |
+
'field' => 'term_id',
|
764 |
+
'terms' => $term_ids,
|
765 |
+
'operator' => 'IN',
|
766 |
+
);
|
767 |
+
}
|
768 |
|
769 |
+
$q->set( 'tax_query', $tax_query );
|
770 |
+
// End Tax query
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
771 |
|
772 |
+
// Author query
|
773 |
+
if ( isset( $_REQUEST['c_author'] ) ) {
|
774 |
+
$author_ids = LP_Helper::sanitize_params_submitted( $_REQUEST['c_author'] );
|
775 |
+
$q->set( 'author__in', $author_ids );
|
776 |
+
}
|
777 |
+
// End Author query
|
778 |
+
|
779 |
+
// Order query
|
780 |
+
if ( isset( $_REQUEST['order_by'] ) ) {
|
781 |
+
$order_by = LP_Helper::sanitize_params_submitted( $_REQUEST['order_by'] );
|
782 |
+
$order = 'DESC';
|
783 |
+
|
784 |
+
switch ( $order_by ) {
|
785 |
+
case 'post_title':
|
786 |
+
$order_by = 'title';
|
787 |
+
$order = 'ASC';
|
788 |
+
break;
|
789 |
+
case 'popular':
|
790 |
+
$filter->order_by = 'popular';
|
791 |
+
$order_by = 'post__in';
|
792 |
+
$is_need_check_in_arr = true;
|
793 |
+
break;
|
794 |
+
default:
|
795 |
+
$order_by = 'date';
|
796 |
+
break;
|
797 |
+
}
|
798 |
+
|
799 |
+
$q->set( 'orderby', $order_by );
|
800 |
+
$q->set( 'order', $order );
|
801 |
+
}
|
802 |
|
803 |
+
if ( $is_need_check_in_arr ) {
|
804 |
+
$posts_in = LP_Course::get_courses( $filter );
|
805 |
+
if ( ! empty( $posts_in ) ) {
|
806 |
+
$posts_in = LP_Database::get_values_by_key( $posts_in );
|
807 |
+
$q->set( 'post__in', $posts_in );
|
808 |
+
} else {
|
809 |
+
$q->set( 'post__in', 0 );
|
810 |
+
}
|
811 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
812 |
|
813 |
+
$q = apply_filters( 'lp/page-courses/query/legacy', $q );
|
|
|
|
|
814 |
}
|
815 |
|
816 |
+
return $q;
|
817 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
818 |
|
819 |
+
// Exclude item not assign
|
820 |
+
if ( $q->is_search() ) {
|
821 |
+
// Exclude item not assign any course
|
822 |
+
$course_item_types = learn_press_get_course_item_types();
|
823 |
+
$list_ids_exclude = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
824 |
|
825 |
+
foreach ( $course_item_types as $item_type ) {
|
826 |
+
$filter = new LP_Post_Type_Filter();
|
827 |
+
$filter->post_type = $item_type;
|
828 |
+
$exclude_item = LP_Course_DB::getInstance()->get_item_ids_unassigned( $filter );
|
829 |
+
$exclude_item = LP_Course_DB::get_values_by_key( $exclude_item );
|
830 |
|
831 |
+
$list_ids_exclude = array_merge( $list_ids_exclude, $exclude_item );
|
|
|
|
|
|
|
832 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
833 |
|
834 |
+
// Exclude question not assign any quiz
|
835 |
+
$question_ids = LP_Question_DB::getInstance()->get_questions_not_assign_quiz();
|
836 |
+
$question_ids = LP_Course_DB::get_values_by_key( $question_ids );
|
837 |
+
$list_ids_exclude = array_merge( $list_ids_exclude, $question_ids );
|
838 |
|
839 |
+
if ( ! empty( $list_ids_exclude ) ) {
|
840 |
+
$q->set( 'post__not_in', $list_ids_exclude );
|
|
|
|
|
|
|
|
|
|
|
|
|
841 |
}
|
842 |
|
843 |
+
return $q;
|
844 |
}
|
845 |
+
|
846 |
+
// Handle 404 if user are viewing course item directly.
|
847 |
+
$this->set_link_item_course_default_wp_to_page_404( $q );
|
848 |
+
} catch ( Throwable $e ) {
|
849 |
+
error_log( $e->getMessage() );
|
850 |
}
|
851 |
|
852 |
return $q;
|
862 |
* @since 3.2.7.5
|
863 |
*/
|
864 |
public function set_link_item_course_default_wp_to_page_404( $q ) {
|
865 |
+
$post_type_apply_404 = apply_filters( 'lp/page-controller/', array( LP_LESSON_CPT, LP_QUIZ_CPT, LP_QUESTION_CPT, 'lp_assignment' ) );
|
866 |
+
|
867 |
+
if ( ! isset( $q->query_vars['post_type'] ) || ! in_array( $q->query_vars['post_type'], $post_type_apply_404 ) ) {
|
868 |
return $q;
|
869 |
}
|
870 |
|
871 |
+
try {
|
|
|
|
|
872 |
$flag_load_404 = true;
|
873 |
$user = wp_get_current_user();
|
874 |
$post_author = 0;
|
898 |
if ( $flag_load_404 ) {
|
899 |
learn_press_404_page();
|
900 |
}
|
901 |
+
} catch ( Throwable $e ) {
|
902 |
+
error_log( $e->getMessage() );
|
903 |
}
|
904 |
}
|
905 |
|
946 |
* @author tungnx
|
947 |
*/
|
948 |
public static function page_current(): string {
|
949 |
+
/**
|
950 |
+
* @var WP_Query $wp_query
|
951 |
+
*/
|
952 |
+
global $wp_query;
|
953 |
+
|
954 |
+
if ( ! is_object( $wp_query ) || ! $wp_query->get_queried_object() ) {
|
955 |
+
return '';
|
956 |
+
}
|
957 |
+
|
958 |
if ( learn_press_is_checkout() ) {
|
959 |
return LP_PAGE_CHECKOUT;
|
960 |
} elseif ( LP_Global::course_item_quiz() ) {
|
961 |
return LP_PAGE_QUIZ;
|
962 |
+
} elseif ( learn_press_is_course() && LP_Global::course_item() ) {
|
963 |
return LP_PAGE_SINGLE_COURSE_CURRICULUM;
|
964 |
} elseif ( learn_press_is_courses() ) {
|
965 |
return LP_PAGE_COURSES;
|
inc/class-lp-query.php
CHANGED
@@ -18,7 +18,7 @@ class LP_Query {
|
|
18 |
public function __construct() {
|
19 |
add_action( 'init', array( $this, 'add_rewrite_tags' ), 1000, 0 );
|
20 |
add_action( 'init', array( $this, 'add_rewrite_rules' ), 1000, 0 );
|
21 |
-
add_action( 'parse_query', array( $this, 'parse_request' ), 1000, 1 );
|
22 |
/**
|
23 |
* Add searching post by taxonomies
|
24 |
*/
|
18 |
public function __construct() {
|
19 |
add_action( 'init', array( $this, 'add_rewrite_tags' ), 1000, 0 );
|
20 |
add_action( 'init', array( $this, 'add_rewrite_rules' ), 1000, 0 );
|
21 |
+
//add_action( 'parse_query', array( $this, 'parse_request' ), 1000, 1 );
|
22 |
/**
|
23 |
* Add searching post by taxonomies
|
24 |
*/
|
inc/class-lp-theme-support.php
DELETED
@@ -1,41 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Class LP_Theme_Support
|
5 |
-
*
|
6 |
-
* @since 4.x.x
|
7 |
-
*/
|
8 |
-
class LP_Theme_Support {
|
9 |
-
|
10 |
-
/**
|
11 |
-
* @var LP_Theme_Support_Base
|
12 |
-
*/
|
13 |
-
public $theme = null;
|
14 |
-
|
15 |
-
/**
|
16 |
-
* LP_Theme_Support constructor.
|
17 |
-
*/
|
18 |
-
public function __construct() {
|
19 |
-
$template = get_template();
|
20 |
-
$theme_support = LP_PLUGIN_PATH . "inc/theme-support/{$template}/class-{$template}.php";
|
21 |
-
|
22 |
-
if ( file_exists( $theme_support ) ) {
|
23 |
-
$this->theme = include_once $theme_support;
|
24 |
-
}
|
25 |
-
}
|
26 |
-
|
27 |
-
/**
|
28 |
-
* @return LP_Theme_Support
|
29 |
-
*/
|
30 |
-
public static function instance() {
|
31 |
-
static $instance = null;
|
32 |
-
|
33 |
-
if ( ! $instance ) {
|
34 |
-
$instance = new self();
|
35 |
-
}
|
36 |
-
|
37 |
-
return $instance;
|
38 |
-
}
|
39 |
-
}
|
40 |
-
|
41 |
-
return LP_Theme_Support::instance();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inc/lp-core-functions.php
CHANGED
@@ -1733,7 +1733,16 @@ if ( ! function_exists( 'learn_press_is_course_tag' ) ) {
|
|
1733 |
|
1734 |
if ( ! function_exists( 'learn_press_is_course' ) ) {
|
1735 |
function learn_press_is_course() {
|
1736 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1737 |
}
|
1738 |
}
|
1739 |
|
1733 |
|
1734 |
if ( ! function_exists( 'learn_press_is_course' ) ) {
|
1735 |
function learn_press_is_course() {
|
1736 |
+
/**
|
1737 |
+
* @var WP_Query $wp_query
|
1738 |
+
*/
|
1739 |
+
global $wp_query;
|
1740 |
+
|
1741 |
+
if ( $wp_query->get_queried_object() ) {
|
1742 |
+
return is_singular( array( LP_COURSE_CPT ) );
|
1743 |
+
} else {
|
1744 |
+
return false;
|
1745 |
+
}
|
1746 |
}
|
1747 |
}
|
1748 |
|
inc/rest-api/v1/frontend/class-lp-rest-courses-controller.php
CHANGED
@@ -264,100 +264,6 @@ class LP_REST_Courses_Controller extends LP_Abstract_REST_Controller {
|
|
264 |
return apply_filters( 'lp/rest-api/frontend/course/archive_course/response', $response );
|
265 |
}
|
266 |
|
267 |
-
/*public function archive_course( WP_REST_Request $request ) {
|
268 |
-
$response = new LP_REST_Response();
|
269 |
-
$response->data = new stdClass();
|
270 |
-
|
271 |
-
$s = isset( $request['s'] ) ? sanitize_text_field( $request['s'] ) : false;
|
272 |
-
$page = isset( $request['paged'] ) ? absint( wp_unslash( $request['paged'] ) ) : 1;
|
273 |
-
$order = isset( $request['order'] ) ? wp_unslash( $request['order'] ) : false;
|
274 |
-
$orderby = isset( $request['orderby'] ) ? wp_unslash( $request['orderby'] ) : false;
|
275 |
-
$taxonomy = isset( $request['taxonomy'] ) ? wp_unslash( $request['taxonomy'] ) : false;
|
276 |
-
$term_id = isset( $request['term_id'] ) ? wp_unslash( $request['term_id'] ) : false;
|
277 |
-
$user_id = isset( $request['userID'] ) ? absint( wp_unslash( $request['userID'] ) ) : false;
|
278 |
-
$limit = LP_Settings::get_option( 'archive_course_limit', -1 );
|
279 |
-
|
280 |
-
$args = array(
|
281 |
-
'posts_per_page' => $limit,
|
282 |
-
'paged' => $page,
|
283 |
-
'post_type' => LP_COURSE_CPT,
|
284 |
-
);
|
285 |
-
|
286 |
-
if ( ! empty( $s ) ) {
|
287 |
-
$args['s'] = $s;
|
288 |
-
}
|
289 |
-
|
290 |
-
if ( ! empty( $taxonomy ) && ! empty( $term_id ) ) {
|
291 |
-
$args['tax_query'] = array(
|
292 |
-
array(
|
293 |
-
'taxonomy' => $taxonomy,
|
294 |
-
'field' => 'term_id',
|
295 |
-
'terms' => $term_id,
|
296 |
-
),
|
297 |
-
);
|
298 |
-
|
299 |
-
$term_link = get_term_link( $term_id, $taxonomy );
|
300 |
-
}
|
301 |
-
|
302 |
-
if ( ! empty( $order ) ) {
|
303 |
-
$args['order'] = $order;
|
304 |
-
}
|
305 |
-
|
306 |
-
if ( ! empty( $orderby ) ) {
|
307 |
-
$args['orderby'] = $orderby;
|
308 |
-
}
|
309 |
-
|
310 |
-
if ( $user_id && learn_press_user_maybe_is_a_teacher( $user_id ) ) {
|
311 |
-
$args['post_status'] = array( 'publish', 'private' );
|
312 |
-
}
|
313 |
-
|
314 |
-
$args = apply_filters( 'lp/rest-api/frontend/course/archive_course/query_args', $args, $request );
|
315 |
-
|
316 |
-
$query = new WP_Query( $args );
|
317 |
-
|
318 |
-
$num_pages = ! empty( $query->max_num_pages ) ? $query->max_num_pages : 1;
|
319 |
-
|
320 |
-
$archive_link = get_post_type_archive_link( LP_COURSE_CPT );
|
321 |
-
|
322 |
-
if ( isset( $term_link ) && ! is_wp_error( $term_link ) ) {
|
323 |
-
$archive_link = $term_link;
|
324 |
-
}
|
325 |
-
|
326 |
-
$base = esc_url_raw( str_replace( 999999999, '%#%', get_pagenum_link( 999999999, false ) ) );
|
327 |
-
|
328 |
-
global $wp;
|
329 |
-
$base = str_replace( home_url( $wp->request ) . '/', $archive_link, $base );
|
330 |
-
|
331 |
-
$response->data->pagination = learn_press_get_template_content(
|
332 |
-
'loop/course/pagination.php',
|
333 |
-
array(
|
334 |
-
'total' => $num_pages,
|
335 |
-
'paged' => $page,
|
336 |
-
'base' => $base,
|
337 |
-
)
|
338 |
-
);
|
339 |
-
|
340 |
-
ob_start();
|
341 |
-
|
342 |
-
if ( $query->have_posts() ) {
|
343 |
-
global $post;
|
344 |
-
|
345 |
-
while ( $query->have_posts() ) {
|
346 |
-
$query->the_post();
|
347 |
-
learn_press_get_template_part( 'content', 'course' );
|
348 |
-
}
|
349 |
-
|
350 |
-
wp_reset_postdata();
|
351 |
-
} else {
|
352 |
-
LP()->template( 'course' )->no_courses_found();
|
353 |
-
}
|
354 |
-
|
355 |
-
$response->status = 'success';
|
356 |
-
$response->data->content = ob_get_clean();
|
357 |
-
|
358 |
-
return rest_ensure_response( apply_filters( 'lp/rest-api/frontend/course/archive_course/response', $response ) );
|
359 |
-
}*/
|
360 |
-
|
361 |
/**
|
362 |
* Rest API for Enroll in single course.
|
363 |
*
|
@@ -520,21 +426,6 @@ class LP_REST_Courses_Controller extends LP_Abstract_REST_Controller {
|
|
520 |
throw new Exception( esc_html__( 'Error: Cannot purchase course!.', 'learnpress' ) );
|
521 |
}
|
522 |
|
523 |
-
// Allow Repurchase.
|
524 |
-
/*$latest_user_item_id = $wpdb->get_var(
|
525 |
-
$wpdb->prepare(
|
526 |
-
"SELECT MAX(user_item_id) user_item_id
|
527 |
-
FROM {$wpdb->learnpress_user_items}
|
528 |
-
WHERE ref_type = %s
|
529 |
-
AND item_type = %s
|
530 |
-
AND item_id = %d
|
531 |
-
AND user_id = %d",
|
532 |
-
LP_ORDER_CPT,
|
533 |
-
LP_COURSE_CPT,
|
534 |
-
$course_id,
|
535 |
-
$user->get_id()
|
536 |
-
)
|
537 |
-
);*/
|
538 |
$latest_user_item_id = 0;
|
539 |
|
540 |
$filter = new LP_User_Items_Filter();
|
@@ -669,10 +560,10 @@ class LP_REST_Courses_Controller extends LP_Abstract_REST_Controller {
|
|
669 |
|
670 |
// Set status, start_time, end_time of course to enrolled.
|
671 |
$user_course_data->set_status( LP_COURSE_ENROLLED )
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
|
677 |
// Remove items' course user learned.
|
678 |
$filter_remove = new LP_User_Items_Filter();
|
@@ -760,7 +651,7 @@ class LP_REST_Courses_Controller extends LP_Abstract_REST_Controller {
|
|
760 |
* @author minhpd
|
761 |
* @editor tungnx
|
762 |
* @since 4.1.4
|
763 |
-
* @version 1.0.
|
764 |
*/
|
765 |
public function continue_course( WP_REST_Request $request ) {
|
766 |
$params = $request->get_params();
|
@@ -773,8 +664,13 @@ class LP_REST_Courses_Controller extends LP_Abstract_REST_Controller {
|
|
773 |
$course_id = absint( $params['courseId'] ?? 0 );
|
774 |
$user_id = absint( $params['userId'] ?? 0 );
|
775 |
|
776 |
-
$user
|
777 |
-
$course
|
|
|
|
|
|
|
|
|
|
|
778 |
$sections_items = $course->get_full_sections_and_items_course();
|
779 |
$total_items = $course->count_items();
|
780 |
|
264 |
return apply_filters( 'lp/rest-api/frontend/course/archive_course/response', $response );
|
265 |
}
|
266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
/**
|
268 |
* Rest API for Enroll in single course.
|
269 |
*
|
426 |
throw new Exception( esc_html__( 'Error: Cannot purchase course!.', 'learnpress' ) );
|
427 |
}
|
428 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
429 |
$latest_user_item_id = 0;
|
430 |
|
431 |
$filter = new LP_User_Items_Filter();
|
560 |
|
561 |
// Set status, start_time, end_time of course to enrolled.
|
562 |
$user_course_data->set_status( LP_COURSE_ENROLLED )
|
563 |
+
->set_start_time( current_time( 'mysql', true ) )
|
564 |
+
->set_end_time( '' )
|
565 |
+
->set_graduation( 'in-progress' )
|
566 |
+
->update();
|
567 |
|
568 |
// Remove items' course user learned.
|
569 |
$filter_remove = new LP_User_Items_Filter();
|
651 |
* @author minhpd
|
652 |
* @editor tungnx
|
653 |
* @since 4.1.4
|
654 |
+
* @version 1.0.2
|
655 |
*/
|
656 |
public function continue_course( WP_REST_Request $request ) {
|
657 |
$params = $request->get_params();
|
664 |
$course_id = absint( $params['courseId'] ?? 0 );
|
665 |
$user_id = absint( $params['userId'] ?? 0 );
|
666 |
|
667 |
+
$user = learn_press_get_user( $user_id );
|
668 |
+
$course = learn_press_get_course( $course_id );
|
669 |
+
|
670 |
+
if ( ! $course ) {
|
671 |
+
throw new Exception( __( 'Invalid course', 'learnpress' ) );
|
672 |
+
}
|
673 |
+
|
674 |
$sections_items = $course->get_full_sections_and_items_course();
|
675 |
$total_items = $course->count_items();
|
676 |
|
languages/learnpress-es-co.po
CHANGED
@@ -2670,7 +2670,7 @@ msgid "Do you want to move question \"{{QUESTION_NAME}}\" to trash?"
|
|
2670 |
msgstr "¿Quieres mover la pregunta \"{{QUESTION_NAME}}\" a la papelera?"
|
2671 |
|
2672 |
#: inc/custom-post-types/course.php:643
|
2673 |
-
msgid "No requirement
|
2674 |
msgstr "No requiere registrarse"
|
2675 |
|
2676 |
#: inc/custom-post-types/course.php:86
|
2670 |
msgstr "¿Quieres mover la pregunta \"{{QUESTION_NAME}}\" a la papelera?"
|
2671 |
|
2672 |
#: inc/custom-post-types/course.php:643
|
2673 |
+
msgid "No enroll requirement"
|
2674 |
msgstr "No requiere registrarse"
|
2675 |
|
2676 |
#: inc/custom-post-types/course.php:86
|
languages/learnpress-es.po
CHANGED
@@ -2801,7 +2801,7 @@ msgstr "¿Quieres mover la pregunta «{{QUESTION_NAME}}» a la papelera?"
|
|
2801 |
|
2802 |
#: inc/admin/views/meta-boxes/course/settings.php:256
|
2803 |
#: inc/custom-post-types/course.php:643
|
2804 |
-
msgid "No requirement
|
2805 |
msgstr "Ningún requerimiento para inscribirse"
|
2806 |
|
2807 |
#: inc/custom-post-types/course.php:86
|
2801 |
|
2802 |
#: inc/admin/views/meta-boxes/course/settings.php:256
|
2803 |
#: inc/custom-post-types/course.php:643
|
2804 |
+
msgid "No enroll requirement"
|
2805 |
msgstr "Ningún requerimiento para inscribirse"
|
2806 |
|
2807 |
#: inc/custom-post-types/course.php:86
|
languages/learnpress.pot
CHANGED
@@ -1905,7 +1905,7 @@ msgid "To…"
|
|
1905 |
msgstr ""
|
1906 |
|
1907 |
#: inc/admin/views/meta-boxes/course/settings.php:335
|
1908 |
-
msgid "No requirement
|
1909 |
msgstr ""
|
1910 |
|
1911 |
#: inc/admin/views/meta-boxes/course/settings.php:336
|
1905 |
msgstr ""
|
1906 |
|
1907 |
#: inc/admin/views/meta-boxes/course/settings.php:335
|
1908 |
+
msgid "No enroll requirement"
|
1909 |
msgstr ""
|
1910 |
|
1911 |
#: inc/admin/views/meta-boxes/course/settings.php:336
|
learnpress.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
* Plugin URI: http://thimpress.com/learnpress
|
5 |
* Description: LearnPress is a WordPress complete solution for creating a Learning Management System (LMS). It can help you to create courses, lessons and quizzes.
|
6 |
* Author: ThimPress
|
7 |
-
* Version: 4.1.7
|
8 |
* Author URI: http://thimpress.com
|
9 |
* Requires at least: 5.6
|
10 |
* Tested up to: 6.0
|
@@ -44,6 +44,10 @@ if ( ! class_exists( 'LearnPress' ) ) {
|
|
44 |
* @var int
|
45 |
*/
|
46 |
public $db_version = 4;
|
|
|
|
|
|
|
|
|
47 |
|
48 |
/**
|
49 |
* The single instance of the class
|
@@ -148,6 +152,9 @@ if ( ! class_exists( 'LearnPress' ) ) {
|
|
148 |
// Include files .
|
149 |
$this->includes();
|
150 |
|
|
|
|
|
|
|
151 |
// hooks .
|
152 |
$this->init_hooks();
|
153 |
}
|
@@ -177,7 +184,6 @@ if ( ! class_exists( 'LearnPress' ) ) {
|
|
177 |
'quiz_questions',
|
178 |
'question_answers',
|
179 |
'question_answermeta',
|
180 |
-
'review_logs',
|
181 |
);
|
182 |
|
183 |
foreach ( $tables as $short_name ) {
|
@@ -381,9 +387,6 @@ if ( ! class_exists( 'LearnPress' ) ) {
|
|
381 |
require_once 'inc/rest-api/class-lp-core-api.php';
|
382 |
require_once 'inc/rest-api/class-lp-admin-core-api.php';
|
383 |
|
384 |
-
// include_once 'inc/theme-support/class-theme-support-base.php';
|
385 |
-
// include_once 'inc/class-lp-theme-support.php';
|
386 |
-
|
387 |
/** Jwt */
|
388 |
include_once 'inc/jwt/class-jwt-auth.php';
|
389 |
|
@@ -461,9 +464,8 @@ if ( ! class_exists( 'LearnPress' ) ) {
|
|
461 |
}
|
462 |
|
463 |
add_action( 'wp_loaded', array( $this, 'wp_loaded' ), 20 );
|
464 |
-
add_action( 'after_setup_theme', array( $this, 'setup_theme' ) );
|
465 |
add_action( 'plugins_loaded', array( $this, 'plugin_loaded' ), - 10 );
|
466 |
-
// add_action( 'init', array( $this, 'wp_init' ), 10 );
|
467 |
|
468 |
// Check require version thim-core.
|
469 |
add_action( 'before_thim_core_init', array( $this, 'check_thim_core_version_require' ) );
|
@@ -504,40 +506,6 @@ if ( ! class_exists( 'LearnPress' ) ) {
|
|
504 |
<?php
|
505 |
}
|
506 |
|
507 |
-
/**
|
508 |
-
* Maybe flush rewrite rules
|
509 |
-
*/
|
510 |
-
public function wp_init() {
|
511 |
-
/*if ( LP()->session->flush_rewrite_rules ) {
|
512 |
-
flush_rewrite_rules();
|
513 |
-
unset( LP()->session->flush_rewrite_rules );
|
514 |
-
}*/
|
515 |
-
}
|
516 |
-
|
517 |
-
/**
|
518 |
-
* Get base name of plugin from file.
|
519 |
-
*
|
520 |
-
* @return string
|
521 |
-
*/
|
522 |
-
// private function plugin_basename() {
|
523 |
-
// return learn_press_plugin_basename( __FILE__ );
|
524 |
-
// }
|
525 |
-
|
526 |
-
/**
|
527 |
-
* Magic function to get Learnpress data.
|
528 |
-
*
|
529 |
-
* @param $key
|
530 |
-
*
|
531 |
-
* @return bool|LP_Checkout|LP_Course|LP_Emails|LP_User|LP_User_Guest|mixed
|
532 |
-
* @deprecated since 3.0.0
|
533 |
-
* @editor tungnx
|
534 |
-
* @modify 4.1.3.1 - comment
|
535 |
-
*/
|
536 |
-
/*
|
537 |
-
public function __get( $key ) {
|
538 |
-
return false;
|
539 |
-
}*/
|
540 |
-
|
541 |
/**
|
542 |
* Trigger this function while activating Learnpress.
|
543 |
*
|
@@ -546,7 +514,6 @@ if ( ! class_exists( 'LearnPress' ) ) {
|
|
546 |
*/
|
547 |
public function on_activate() {
|
548 |
LP_Install::instance()->on_activate();
|
549 |
-
// do_action( 'learn-press/activate', $this );
|
550 |
}
|
551 |
|
552 |
/**
|
@@ -613,10 +580,6 @@ if ( ! class_exists( 'LearnPress' ) ) {
|
|
613 |
|
614 |
$this->init();
|
615 |
|
616 |
-
// Todo: tungnx - remove this code after handle ajax on page learn-press-addons
|
617 |
-
// require_once 'inc/background-process/class-lp-background-query-items.php';
|
618 |
-
// require_once 'inc/background-process/class-lp-background-installer.php';
|
619 |
-
|
620 |
require_once 'inc/lp-template-hooks.php';
|
621 |
|
622 |
/**
|
@@ -703,9 +666,6 @@ if ( ! class_exists( 'LearnPress' ) ) {
|
|
703 |
public function init() {
|
704 |
$this->api = new LP_Core_API();
|
705 |
$this->admin_api = new LP_Admin_Core_API();
|
706 |
-
// $this->theme_support = LP_Theme_Support::instance();
|
707 |
-
|
708 |
-
// $this->view_log();
|
709 |
|
710 |
$this->get_session();
|
711 |
|
@@ -882,6 +842,51 @@ if ( ! class_exists( 'LearnPress' ) ) {
|
|
882 |
</div>
|
883 |
<?php
|
884 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
885 |
}
|
886 |
}
|
887 |
|
4 |
* Plugin URI: http://thimpress.com/learnpress
|
5 |
* Description: LearnPress is a WordPress complete solution for creating a Learning Management System (LMS). It can help you to create courses, lessons and quizzes.
|
6 |
* Author: ThimPress
|
7 |
+
* Version: 4.1.7.1
|
8 |
* Author URI: http://thimpress.com
|
9 |
* Requires at least: 5.6
|
10 |
* Tested up to: 6.0
|
44 |
* @var int
|
45 |
*/
|
46 |
public $db_version = 4;
|
47 |
+
/**
|
48 |
+
* @var int Version of mu file on folder mu-plugins
|
49 |
+
*/
|
50 |
+
public $mu_file_version = 2;
|
51 |
|
52 |
/**
|
53 |
* The single instance of the class
|
152 |
// Include files .
|
153 |
$this->includes();
|
154 |
|
155 |
+
// Copy mu plugin.
|
156 |
+
$this->mu_plugin();
|
157 |
+
|
158 |
// hooks .
|
159 |
$this->init_hooks();
|
160 |
}
|
184 |
'quiz_questions',
|
185 |
'question_answers',
|
186 |
'question_answermeta',
|
|
|
187 |
);
|
188 |
|
189 |
foreach ( $tables as $short_name ) {
|
387 |
require_once 'inc/rest-api/class-lp-core-api.php';
|
388 |
require_once 'inc/rest-api/class-lp-admin-core-api.php';
|
389 |
|
|
|
|
|
|
|
390 |
/** Jwt */
|
391 |
include_once 'inc/jwt/class-jwt-auth.php';
|
392 |
|
464 |
}
|
465 |
|
466 |
add_action( 'wp_loaded', array( $this, 'wp_loaded' ), 20 );
|
467 |
+
//add_action( 'after_setup_theme', array( $this, 'setup_theme' ) );
|
468 |
add_action( 'plugins_loaded', array( $this, 'plugin_loaded' ), - 10 );
|
|
|
469 |
|
470 |
// Check require version thim-core.
|
471 |
add_action( 'before_thim_core_init', array( $this, 'check_thim_core_version_require' ) );
|
506 |
<?php
|
507 |
}
|
508 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
509 |
/**
|
510 |
* Trigger this function while activating Learnpress.
|
511 |
*
|
514 |
*/
|
515 |
public function on_activate() {
|
516 |
LP_Install::instance()->on_activate();
|
|
|
517 |
}
|
518 |
|
519 |
/**
|
580 |
|
581 |
$this->init();
|
582 |
|
|
|
|
|
|
|
|
|
583 |
require_once 'inc/lp-template-hooks.php';
|
584 |
|
585 |
/**
|
666 |
public function init() {
|
667 |
$this->api = new LP_Core_API();
|
668 |
$this->admin_api = new LP_Admin_Core_API();
|
|
|
|
|
|
|
669 |
|
670 |
$this->get_session();
|
671 |
|
842 |
</div>
|
843 |
<?php
|
844 |
}
|
845 |
+
|
846 |
+
/**
|
847 |
+
* Copy class-lp-mu-plugin.php to mu_plugins folder
|
848 |
+
*
|
849 |
+
* @return void
|
850 |
+
*/
|
851 |
+
public function mu_plugin() {
|
852 |
+
try {
|
853 |
+
$name = 'class-lp-mu-plugin.php';
|
854 |
+
$can_copy = false;
|
855 |
+
|
856 |
+
// replace the old file
|
857 |
+
$mu_plugin_file = LP_PLUGIN_PATH . '/mu-plugin/' . $name;
|
858 |
+
|
859 |
+
if ( defined( 'WPMU_PLUGIN_DIR' ) ) {
|
860 |
+
$mu_plugins_path = WPMU_PLUGIN_DIR;
|
861 |
+
} else {
|
862 |
+
$mu_plugins_path = WP_CONTENT_DIR . '/' . 'mu-plugins';
|
863 |
+
}
|
864 |
+
|
865 |
+
if ( ! file_exists( $mu_plugins_path ) ) {
|
866 |
+
mkdir( $mu_plugins_path, 0755, true );
|
867 |
+
}
|
868 |
+
|
869 |
+
$mu_plugin_file_path = $mu_plugins_path . '/' . $name;
|
870 |
+
|
871 |
+
// add mu file
|
872 |
+
if ( file_exists( $mu_plugins_path ) ) {
|
873 |
+
if ( file_exists( $mu_plugin_file_path ) ) {
|
874 |
+
if ( LP_MU_Plugin::$version < $this->mu_file_version ) {
|
875 |
+
$can_copy = true;
|
876 |
+
}
|
877 |
+
} else {
|
878 |
+
$can_copy = true;
|
879 |
+
}
|
880 |
+
}
|
881 |
+
|
882 |
+
if ( $can_copy ) {
|
883 |
+
//update_option( 'learnpress_mu_plugin_version', $this->mu_file_version );
|
884 |
+
LP_WP_Filesystem::instance()->copy( $mu_plugin_file, $mu_plugin_file_path );
|
885 |
+
}
|
886 |
+
} catch ( Throwable $e ) {
|
887 |
+
error_log( $e->getMessage() );
|
888 |
+
}
|
889 |
+
}
|
890 |
}
|
891 |
}
|
892 |
|
mu-plugin/class-lp-mu-plugin.php
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class LP_MU_Plugin
|
5 |
+
*
|
6 |
+
* @since 4.1.7.1
|
7 |
+
* @version 1.0.0
|
8 |
+
*/
|
9 |
+
class LP_MU_Plugin {
|
10 |
+
public static $version = 1;
|
11 |
+
|
12 |
+
public static function instance() {
|
13 |
+
static $instance = null;
|
14 |
+
if ( is_null( $instance ) ) {
|
15 |
+
$instance = new self();
|
16 |
+
}
|
17 |
+
|
18 |
+
return $instance;
|
19 |
+
}
|
20 |
+
|
21 |
+
private function __construct() {
|
22 |
+
add_filter( 'option_active_plugins', [ $this, 'load_plugins' ], -1 );
|
23 |
+
}
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Handle list plugins can load in REST API LP
|
27 |
+
* Not handle if called from deactivate_plugins or is_plugin_active function.
|
28 |
+
*
|
29 |
+
* @param $plugins
|
30 |
+
*
|
31 |
+
* @return array|mixed
|
32 |
+
*/
|
33 |
+
public function load_plugins( $plugins_activating ) {
|
34 |
+
try {
|
35 |
+
$url_load_plugins = $this->getPluginsMustLoadInUrl();
|
36 |
+
if ( ! $url_load_plugins ) {
|
37 |
+
return $plugins_activating;
|
38 |
+
}
|
39 |
+
|
40 |
+
// Not handle if call from deactivate_plugins or is_plugin_active function.
|
41 |
+
$methods_called_to = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS );
|
42 |
+
foreach ( $methods_called_to as $method ) {
|
43 |
+
if ( $method['function'] === 'deactivate_plugins' || $method['function'] === 'is_plugin_active' ) {
|
44 |
+
return $plugins_activating;
|
45 |
+
}
|
46 |
+
}
|
47 |
+
|
48 |
+
remove_all_actions( 'setup_theme' );
|
49 |
+
remove_all_actions( 'after_setup_theme' );
|
50 |
+
|
51 |
+
$plugins_load = [];
|
52 |
+
|
53 |
+
foreach ( $url_load_plugins as $plugin => $plugin_dependencies ) {
|
54 |
+
if ( in_array( $plugin, $plugins_activating, true ) ) {
|
55 |
+
$plugins_load[] = $plugin;
|
56 |
+
|
57 |
+
foreach ( $plugin_dependencies as $dependency ) {
|
58 |
+
if ( in_array( $dependency, $plugins_activating, true ) ) {
|
59 |
+
$plugins_load[] = $dependency;
|
60 |
+
}
|
61 |
+
}
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
//error_log( 'plugins_load: ' . print_r( $plugins_load, true ) );
|
66 |
+
|
67 |
+
return $plugins_load;
|
68 |
+
} catch ( Throwable $e ) {
|
69 |
+
error_log( $e->getMessage() );
|
70 |
+
}
|
71 |
+
|
72 |
+
return $plugins_activating;
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Get the current url
|
77 |
+
*
|
78 |
+
* @return string
|
79 |
+
* @since 3.2.6.8
|
80 |
+
* @author tungnx
|
81 |
+
*/
|
82 |
+
public static function getUrlCurrent(): string {
|
83 |
+
$schema = is_ssl() ? 'https://' : 'http://';
|
84 |
+
$http_host = $_SERVER['HTTP_HOST'] ?? '';
|
85 |
+
|
86 |
+
return $schema . $http_host . untrailingslashit( esc_url_raw( $_SERVER['REQUEST_URI'] ?? '' ) );
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Check url request can apply check load plugins.
|
91 |
+
* Format:
|
92 |
+
* ['url' => ['plugin' => ['dependencies']]]
|
93 |
+
*
|
94 |
+
* @return bool|array
|
95 |
+
*/
|
96 |
+
public function getPluginsMustLoadInUrl() {
|
97 |
+
$url_load_plugins = false;
|
98 |
+
$urls_apply = [
|
99 |
+
'wp-json/lp/v1/courses/archive-course' => [
|
100 |
+
'learnpress/learnpress.php' => [],
|
101 |
+
'learnpress-woo-payment/learnpress-woo-payment.php' => [
|
102 |
+
'woocommerce/woocommerce.php',
|
103 |
+
],
|
104 |
+
],
|
105 |
+
'wp-json/lp/v1/profile/course-tab' => [
|
106 |
+
'learnpress/learnpress.php' => [],
|
107 |
+
'learnpress-woo-payment/learnpress-woo-payment.php' => [
|
108 |
+
'woocommerce/woocommerce.php',
|
109 |
+
],
|
110 |
+
],
|
111 |
+
'wp-json/lp/v1/lazy-load/course-curriculum' => [
|
112 |
+
'learnpress/learnpress.php' => [],
|
113 |
+
'learnpress-assignments/learnpress-assignments.php' => [],
|
114 |
+
'learnpress-h5p/learnpress-h5p.php' => [],
|
115 |
+
],
|
116 |
+
'wp-json/lp/v1/lazy-load/course-progress' => [
|
117 |
+
'learnpress/learnpress.php' => [],
|
118 |
+
'learnpress-assignments/learnpress-assignments.php' => [],
|
119 |
+
'learnpress-h5p/learnpress-h5p.php' => [],
|
120 |
+
],
|
121 |
+
'wp-json/lp/v1/lazy-load/items-progress' => [
|
122 |
+
'learnpress/learnpress.php' => [],
|
123 |
+
],
|
124 |
+
'wp-json/lp/v1/profile/statistic' => [
|
125 |
+
'learnpress/learnpress.php' => [],
|
126 |
+
],
|
127 |
+
];
|
128 |
+
|
129 |
+
foreach ( $urls_apply as $url => $plugins_load ) {
|
130 |
+
if ( false !== strpos( self::getUrlCurrent(), $url ) ) {
|
131 |
+
$url_load_plugins = $plugins_load;
|
132 |
+
break;
|
133 |
+
}
|
134 |
+
}
|
135 |
+
|
136 |
+
return $url_load_plugins;
|
137 |
+
}
|
138 |
+
}
|
139 |
+
|
140 |
+
LP_MU_Plugin::instance();
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Tags: elearning, education, course, lms, learning management system
|
|
5 |
Requires at least: 5.6
|
6 |
Tested up to: 6.0
|
7 |
Requires PHP: 7.0
|
8 |
-
Stable tag: 4.1.7
|
9 |
License: GPLv2 or later
|
10 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
@@ -203,6 +203,9 @@ https://www.transifex.com/projects/p/learnpress/
|
|
203 |
|
204 |
== Changelog ==
|
205 |
|
|
|
|
|
|
|
206 |
= 4.1.7 (2022-09-13) =
|
207 |
~ Fixed: IPN paypal.
|
208 |
~ Added: hook 'learn-press/user-item/expiration-time'.
|
5 |
Requires at least: 5.6
|
6 |
Tested up to: 6.0
|
7 |
Requires PHP: 7.0
|
8 |
+
Stable tag: 4.1.7.1
|
9 |
License: GPLv2 or later
|
10 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
203 |
|
204 |
== Changelog ==
|
205 |
|
206 |
+
= 4.1.7.1 (2022-09-16) =
|
207 |
+
~ Fixed: non-LP plugins causing errors.
|
208 |
+
|
209 |
= 4.1.7 (2022-09-13) =
|
210 |
~ Fixed: IPN paypal.
|
211 |
~ Added: hook 'learn-press/user-item/expiration-time'.
|