Skip to content

Commit

Permalink
merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tungnxt89 committed Jul 27, 2024
2 parents b1be47c + 6365090 commit 9ec3666
Show file tree
Hide file tree
Showing 19 changed files with 322 additions and 214 deletions.
24 changes: 24 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
= 4.2.6.8.2 (2024-06-28) =
~ Added: function retrieve_password_message override message reset password.
~ Fixed: security.
~ Fixed: style login/register for Divi theme.
~ Fixed: responsive curriculum.

= 4.2.6.8.1 (2024-06-03) =
~ Fixed: security.
~ Fixed: query by status on list LP Orders.
~ Fixed: minor bugs.
~ Added: translate text grid, list.

= 4.2.6.8 (2024-05-27) =
~ Fixed: error create answers question.
~ Fixed: minor bugs.

= 4.2.6.7 (2024-05-20) =
~ Fixed: security.
~ Fixed: error conflict with CookieYes plugin.
~ Fixed: sale course price with config timezone of WordPress.
~ Optimize: style.
~ Remove Font Awesome and replace it with Font LearnPress.
~ Tweak: query search LP Order.

= 4.2.6.6 (2024-05-09) =
~ Fixed: security.
~ Fixed: delete user item when remove order item.
Expand Down
19 changes: 19 additions & 0 deletions inc/Helpers/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,24 @@ public static function combine_components( array $elms = [] ): string {

return $html;
}

/**
* Print message
*
* @param string $message
* @param string $status
*
* @return void
* @since 4.2.6.9.3
* @version 1.0.0
*/
public static function print_message( string $message, string $status = 'success' ) {
$customer_message = [
'content' => $message,
'status' => $status
];

Template::instance()->get_frontend_template( 'global/lp-message.php', compact( 'customer_message' ) );
}
}

40 changes: 20 additions & 20 deletions inc/Models/CourseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,7 @@ public function has_sale_price(): bool {
* @return mixed
*/
public function get_sale_start() {
$key = CoursePostModel::META_KEY_SALE_START;
if ( $this->meta_data && isset( $this->meta_data->{$key} ) ) {
return $this->meta_data->{$key};
}

$coursePost = new CoursePostModel( $this );
$sale_start = $coursePost->get_meta_value_by_key( $key, false );
$this->meta_data->{$key} = $sale_start;

return $this->meta_data->{$key};
return $this->get_meta_value_by_key( CoursePostModel::META_KEY_SALE_START );
}

/**
Expand All @@ -321,16 +312,7 @@ public function get_sale_start() {
* @return mixed
*/
public function get_sale_end() {
$key = CoursePostModel::META_KEY_SALE_END;
if ( $this->meta_data && isset( $this->meta_data->{$key} ) ) {
return $this->meta_data->{$key};
}

$coursePost = new CoursePostModel( $this );
$sale_end = $coursePost->get_meta_value_by_key( $key, false );
$this->meta_data->{$key} = $sale_end;

return $this->meta_data->{$key};
return $this->get_meta_value_by_key( CoursePostModel::META_KEY_SALE_END );
}

/**
Expand Down Expand Up @@ -575,6 +557,24 @@ public function get_permalink(): string {
return $this->permalink;
}

/**
* Get value option No enroll requirement
*
* @return mixed
*/
public function get_no_enroll_requirement() {
return $this->get_meta_value_by_key( CoursePostModel::META_KEY_NO_REQUIRED_ENROLL, 'no' );
}

/**
* Get value option No enroll requirement
*
* @return bool
*/
public function has_no_enroll_requirement(): bool {
return $this->get_no_enroll_requirement() === 'yes';
}

public function get_meta_value_by_key( string $key, $default = false ) {
if ( ! empty( $this->meta_data ) && isset( $this->meta_data->{$key} ) ) {
$value = $this->meta_data->{$key};
Expand Down
1 change: 1 addition & 0 deletions inc/Models/CoursePostModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class CoursePostModel extends PostModel {
const META_KEY_FEATURED_REVIEW = '_lp_featured_review';
const META_KEY_EXTERNAL_LINK_BY_COURSE = '_lp_external_link_buy_course';
const META_KEY_IS_SALE = '_lp_course_is_sale';
const META_KEY_NO_REQUIRED_ENROLL = '_lp_no_required_enroll';

/**
* Get the price of course.
Expand Down
2 changes: 1 addition & 1 deletion inc/admin/class-lp-install-sample-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ protected function create_course( $name = '' ) {
if ( $course_id ) {
$metas = array(
'_lp_duration' => '10 week',
'_lp_max_students' => '1000',
'_lp_max_students' => '0',
'_lp_students' => '0',
'_lp_retake_count' => '0',
'_lp_featured' => 'no',
Expand Down
4 changes: 2 additions & 2 deletions inc/admin/editor/class-lp-admin-editor-course.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ public function update_section( $args = array() ) {
'section_name' => $section['title'],
'section_description' => $section['description'],
'section_order' => $section['order'],
'section_course_id' => $section['course_id'],
'section_course_id' => $this->course->get_id(),
);

$this->result = $this->section_curd->update( $data );

return true;
return $this->result;
}

/**
Expand Down
88 changes: 56 additions & 32 deletions inc/admin/views/meta-boxes/order/details.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<h3 class="order-data-number"><?php echo sprintf( __( 'Order %s', 'learnpress' ), $order->get_order_number() ); ?></h3>
<div class="order-data-field payment-method-title">
<?php
if ( $order->is_manual() ) {
printf( '<strong>%s</strong>', __( 'Created manually', 'learnpress' ) );
}
if ( $method_title && $user_ip ) {
printf( 'Pay via <strong>%s</strong> at <strong>%s</strong>', $method_title, $user_ip );
} elseif ( $method_title ) {
Expand Down Expand Up @@ -93,7 +96,7 @@
<div class="order-users">
<label><?php esc_html_e( 'Customers:', 'learnpress' ); ?></label>
<?php
if ( LP_ORDER_PENDING === $order->get_status() ) {
if ( LP_ORDER_PENDING === $order->get_status() && $order->is_manual() ) {
$data_struct = [
'urlApi' => get_rest_url( null, 'lp/v1/admin/tools/search-user' ),
'dataType' => 'users',
Expand Down Expand Up @@ -133,29 +136,48 @@
<div class="advanced-list">
<div class="ts-control">
<?php
if ( ! is_array( $user_ids ) ) {
$user_ids = (array) $user_ids;
}

foreach ( $user_ids as $user_id ) {
$user = learn_press_get_user( $user_id );
if ( ! $user ) {
continue;
}
if ( ! $order->is_manual() && $order->is_guest() ) {
printf(
'<li data-id="%1$s"><div class="item" data-ts-item="">%2$s</div><input type="hidden" name="order-customer[]" value="%1$s"></li>',
$user_id,
sprintf( '%s (#%d) - %s', $user->get_display_name(), $user->get_id(), $user->get_email() )
'<li>
<div class="item">%s</div>
</li>',
sprintf( '%s (%s)', $order->get_checkout_email(), __( 'Guest', 'learnpress' ) )
);
} elseif ( $order->is_manual() && $order->is_guest() ) {
printf(
'<li>
<div class="item">%s</div>
</li>',
__( 'No customer', 'learnpress' )
);
} else {
if ( ! is_array( $user_ids ) ) {
$user_ids = (array) $user_ids;
}

foreach ( $user_ids as $user_id ) {
$user = learn_press_get_user( $user_id );
if ( ! $user ) {
continue;
}
printf(
'<li>
<div class="item" data-ts-item="">%s</div>
</li>',
sprintf( '%s (#%d) - %s', $user->get_display_name(), $user->get_id(), $user->get_email() )
);
}
}
?>
</div>
</div>
<?php
printf(
'<p class="description">%s</p>',
esc_html__( 'In order to change the order user, please change the order status to "Pending".', 'learnpress' )
);
if ( $order->is_manual() ) {
printf(
'<p class="description">%s</p>',
esc_html__( 'In order to change the order user, please change the order status to "Pending".', 'learnpress' )
);
}
}
?>
</div>
Expand Down Expand Up @@ -232,21 +254,23 @@
<td colspan="2"></td>
<td colspan="2" style="border-bottom: 1px dashed #DDD;"></td>
</tr>
<tr>
<td class="align-right" colspan="4" style="border-top: 1px solid #DDD;">
<?php if ( 'pending' === $order->get_status() ) { ?>
<button class="button" type="button" id="learn-press-add-order-item">
<?php esc_html_e( 'Add item(s)', 'learnpress' ); ?>
</button>
<?php
} else {
echo '<p class="description">';
esc_html_e( 'In order to change the order item, please change the order status to \'Pending\'.', 'learnpress' );
echo '</p>';
}
?>
</td>
</tr>
<?php if ( $order->is_manual() ) { ?>
<tr>
<td class="align-right" colspan="4" style="border-top: 1px solid #DDD;">
<?php if ( 'pending' === $order->get_status() ) { ?>
<button class="button" type="button" id="learn-press-add-order-item">
<?php esc_html_e( 'Add item(s)', 'learnpress' ); ?>
</button>
<?php
} else {
echo '<p class="description">';
esc_html_e( 'In order to change the order item, please change the order status to \'Pending\'.', 'learnpress' );
echo '</p>';
}
?>
</td>
</tr>
<?php } ?>
</tfoot>
</table>
</div>
Expand Down
8 changes: 5 additions & 3 deletions inc/admin/views/meta-boxes/order/order-item.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* @author Nhamdv <4.0.0>
* @version 4.0.1
*/

/**
* @var LP_Order $order
*/
if ( ! isset( $item ) || ! isset( $order ) ) {
return;
}
Expand All @@ -14,8 +16,8 @@
<?php if ( ! empty( $item['course_id'] ) ) { ?>
<tr class="order-item-row" data-item_id="<?php echo esc_attr( $item['id'] ); ?>" data-id="<?php echo esc_attr( $item['course_id'] ); ?>" data-remove_nonce="<?php echo wp_create_nonce( 'remove_order_item' ); ?>">
<td class="column-name">
<?php if ( 'manual' === $order->get_created_via() ) : ?>
<a class="remove-order-item" href="">
<?php if ( $order->is_manual() ) : ?>
<a class="remove-order-item learn-press-tooltip" href="" data-tooltip="<?php esc_attr_e( 'Delete item', 'learnpress' ); ?>">
<span class="dashicons dashicons-no-alt"></span>
</a>
<?php endif; ?>
Expand Down
2 changes: 2 additions & 0 deletions inc/class-lp-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected function __construct() {
if ( ! is_admin() ) {
return;
}
$time_limit_default = ini_get('max_execution_time');
@set_time_limit( 0 );
// From LP v4.2.2 temporary run create table thim_cache.
// After a long time, will remove this code. Only run create table when activate plugin LP.
Expand All @@ -58,6 +59,7 @@ protected function __construct() {
if ( ! LP_Settings::is_created_tb_material_files() ) {
$this->create_table_learnpress_files();
}
@set_time_limit( $time_limit_default );
}

/**
Expand Down
6 changes: 3 additions & 3 deletions inc/custom-post-types/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ public function save_post( int $post_id, WP_Post $post = null, bool $is_update =

$created_via = $order->get_created_via();
if ( empty( $created_via ) ) {
$created_via = 'manual';
$order->set_created_via( 'manual' );
$created_via = LP_ORDER_CREATED_VIA_MANUAL;
$order->set_created_via( $created_via );
}

if ( isset( $_POST['order-customer'] ) && $created_via === 'manual' ) {
if ( isset( $_POST['order-customer'] ) && $order->is_manual() ) {
$user_id = LP_Request::get_param( 'order-customer' );
$order->set_user_id( $user_id );
}
Expand Down
15 changes: 12 additions & 3 deletions inc/emails/types/class-lp-email-type-enrolled-course.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
/**
* Prevent loading this file directly
*/

use LearnPress\Models\UserItems\UserCourseModel;

defined( 'ABSPATH' ) || exit();

class LP_Email_Type_Enrolled_Course extends LP_Email {
Expand Down Expand Up @@ -78,10 +81,16 @@ final function check_and_set( array $params ): bool {
return false;
}

$user_course_status = $user->get_course_status( $course_id );
$filter = new LP_User_Items_Filter();
$filter->user_id = $user_id;
$filter->item_id = $course_id;
$filter->item_type = LP_COURSE_CPT;
$filter->ref_type = LP_ORDER_CPT;
$filter->ref_id = $order_id;
$userCourse = UserCourseModel::get_user_item_model_from_db( $filter );

if ( LP_COURSE_ENROLLED != $user_course_status ) {
error_log( 'User did not enrolled course ' . __CLASS__ );
if ( LP_COURSE_ENROLLED != $userCourse->status ) {
throw new Exception( 'User not enrolled course' );
}

$this->_order = new LP_Order( $order_id );
Expand Down
3 changes: 3 additions & 0 deletions inc/lp-constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
const LP_ORDER_CANCELLED_DB = 'lp-cancelled';
const LP_ORDER_FAILED_DB = 'lp-failed';

// LP Order type create via.
const LP_ORDER_CREATED_VIA_MANUAL = 'manual';

// Graduation user item course
const LP_COURSE_GRADUATION_IN_PROGRESS = 'in-progress';
const LP_COURSE_GRADUATION_PASSED = 'passed';
Expand Down
2 changes: 1 addition & 1 deletion inc/order/class-lp-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ public function is_completed(): bool {
* @version 1.0.0
*/
public function is_manual(): bool {
return $this->get_created_via() === 'manual';
return $this->get_created_via() === LP_ORDER_CREATED_VIA_MANUAL;
}

/**
Expand Down
Loading

0 comments on commit 9ec3666

Please sign in to comment.