Skip to content

Commit

Permalink
= 4.2.0 =
Browse files Browse the repository at this point in the history
~ Handle set message when complete lesson.
  • Loading branch information
tungnxt89 committed Dec 20, 2022
1 parent b41c11a commit 4cbed85
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
22 changes: 15 additions & 7 deletions inc/class-lp-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ public static function complete_lesson() {
);

try {
$nonce = LP_Helper::sanitize_params_submitted( $_POST['complete-lesson-nonce'] ?? '' );
$lesson_id = LP_Helper::sanitize_params_submitted( $_POST['id'] ?? 0 );
$course_id = LP_Helper::sanitize_params_submitted( $_POST['course_id'] ?? 0 );
$nonce = LP_Request::get_param( 'complete-lesson-nonce' );
$lesson_id = LP_Request::get_param( 'id', 0, 'int' );
$course_id = LP_Request::get_param( 'course_id', 0, 'int' );

if ( ! wp_verify_nonce( $nonce, 'lesson-complete' ) ) {
throw new Exception( __( 'Error! Invalid lesson or failed security check.', 'learnpress' ) );
Expand Down Expand Up @@ -222,15 +222,23 @@ public static function complete_lesson() {
$response['redirect'] = $course->get_item_link( $next );
}

learn_press_add_message( sprintf( __( 'Congrats! You have completed "%s".', 'learnpress' ), $item->get_title() ) );
$message_data = [
'status' => 'success',
'content' => sprintf( __( 'Congrats! You have completed "%s".', 'learnpress' ), $item->get_title() ),
];
learn_press_set_message( $message_data );
$response['result'] = 'success';
} else {
learn_press_add_message( $result->get_error_message(), 'error' );
throw new Exception( $result->get_error_message() );
}

$response = apply_filters( 'learn-press/user-completed-lesson-result', $response, $lesson_id, $course_id, $user->get_id() );
} catch ( Exception $ex ) {
learn_press_add_message( $ex->getMessage(), 'error' );
} catch ( Throwable $e ) {
$message_data = [
'status' => 'error',
'content' => $e->getMessage(),
];
learn_press_set_message( $message_data );
}

//learn_press_maybe_send_json( $response );
Expand Down
6 changes: 3 additions & 3 deletions inc/lp-template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,16 +728,16 @@ function learn_press_session_message_id() {
* @deprecated 4.2.0
*/
function _learn_press_print_messages() {
_deprecated_function( __FUNCTION__, '4.2.0' );
//_deprecated_function( __FUNCTION__, '4.2.0' );
$item = LP_Global::course_item();
if ( ( 'learn_press_before_main_content' == current_action() ) && $item ) {
return;
}
learn_press_print_messages( true );
}

add_action( 'learn_press_before_main_content', '_learn_press_print_messages', 50 );
add_action( 'learn-press/before-course-item-content', '_learn_press_print_messages', 50 );
//add_action( 'learn_press_before_main_content', '_learn_press_print_messages', 50 );
add_action( 'learn-press/before-course-item-content', 'learn_press_show_message', 50 );

if ( ! function_exists( 'learn_press_page_title' ) ) {

Expand Down
10 changes: 5 additions & 5 deletions languages/learnpress.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# This file is distributed under the same license as the LearnPress plugin.
msgid ""
msgstr ""
"Project-Id-Version: LearnPress 4.2.0-beta-11\n"
"Project-Id-Version: LearnPress 4.2.0-beta-12\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/learnpress\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2022-12-19T12:28:42+03:00\n"
"POT-Creation-Date: 2022-12-20T05:18:43+03:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.7.1\n"
"X-Domain: learnpress\n"
Expand Down Expand Up @@ -338,7 +338,7 @@ msgstr ""
#: config/settings/permalink.php:123
#: inc/admin/sub-menus/class-lp-submenu-settings.php:18
#: inc/user/class-lp-profile.php:276
#: learnpress.php:484
#: learnpress.php:480
msgid "Settings"
msgstr ""

Expand Down Expand Up @@ -1498,7 +1498,7 @@ msgid "Reset Password"
msgstr ""

#: inc/admin/sub-menus/class-lp-submenu-addons.php:14
#: learnpress.php:486
#: learnpress.php:482
msgid "Add-ons"
msgstr ""

Expand Down Expand Up @@ -6942,7 +6942,7 @@ msgstr ""
msgid "Recent Courses"
msgstr ""

#: learnpress.php:485
#: learnpress.php:481
msgid "Documentation"
msgstr ""

Expand Down

0 comments on commit 4cbed85

Please sign in to comment.