Skip to content

Commit

Permalink
= 4.2.7.4 =
Browse files Browse the repository at this point in the history
~ Added: get_i18n_string_plural method.
~ Tweak: save_meta_value_by_key method on PostModel class.
~ Added: get_edit_link on PostModel class.
  • Loading branch information
tungnxt89 committed Nov 27, 2024
1 parent 3324fa1 commit 42f71fb
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 15 deletions.
2 changes: 1 addition & 1 deletion config/course-deliver-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$options = [
'private_1_1' => esc_html__( 'Private 1-1', 'learnpress' ),
'in_person_class' => esc_html__( 'In-person class', 'learnpress' ),
'live_class' => esc_html__( 'Live class', 'learnpress' ),
'live_class' => esc_html__( 'Live class', 'learnpress' ),
];

return apply_filters( 'learn-press/course/deliver-type', $options );
4 changes: 2 additions & 2 deletions inc/Models/CourseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -1244,8 +1244,8 @@ public function clean_caches() {
*/
public static function item_types_support(): array {
$item_types = [
LP_LESSON_CPT => __( 'Lesson', 'learnpress' ),
LP_QUIZ_CPT => __( 'Quiz', 'learnpress' ),
LP_LESSON_CPT,
LP_QUIZ_CPT,
];

return apply_filters( 'learn-press/course/item-types-support', $item_types );
Expand Down
22 changes: 17 additions & 5 deletions inc/Models/PostModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,19 +260,19 @@ public function get_image_url( $size = 'post-thumbnail' ): string {
* Get meta value by key.
*
* @param string $key
* @param mixed $default
* @param mixed $default_value
* @param bool $single
*
* @return false|mixed
*/
public function get_meta_value_by_key( string $key, $default = false, bool $single = true ) {
public function get_meta_value_by_key( string $key, $default_value = false, bool $single = true ) {
if ( $this->meta_data instanceof stdClass && isset( $this->meta_data->{$key} ) ) {
return $this->meta_data->{$key};
}

$value = get_post_meta( $this->ID, $key, $single );
if ( empty( $value ) ) {
$value = $default;
$value = $default_value;
}

$this->meta_data->{$key} = $value;
Expand All @@ -289,6 +289,7 @@ public function get_meta_value_by_key( string $key, $default = false, bool $sing
* @return void
*/
public function save_meta_value_by_key( string $key, $value ) {
$this->meta_data->{$key} = $value;
update_post_meta( $this->ID, $key, $value );
}

Expand Down Expand Up @@ -319,8 +320,8 @@ public function get_categories(): array {
*/
public function get_tags(): array {
// Todo: set cache.
$wpPost = new WP_Post( $this );
$tags = get_the_terms( $wpPost, LP_COURSE_TAXONOMY_TAG );
$wpPost = new WP_Post( $this );
$tags = get_the_terms( $wpPost, LP_COURSE_TAXONOMY_TAG );
if ( ! $tags ) {
$tags = array();
}
Expand Down Expand Up @@ -374,4 +375,15 @@ public function get_the_excerpt(): string {
public function get_the_title(): string {
return get_the_title( $this );
}

/**
* Get edit link of post
*
* @return string|null
* @since 4.2.7.4
* @version 1.0.0
*/
public function get_edit_link() {
return get_edit_post_link( $this->get_id() );
}
}
61 changes: 61 additions & 0 deletions inc/class-lp-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,4 +717,65 @@ public static function get_i18n_of_value( string $value ): string {

return apply_filters( 'learn-press/i18n/value', $i18n, $value );
}

/**
* Get translation string single/plural
*
* @param float $number
* @param string $string_value
* @param bool $include_number
*
* @return string
* @since 4.2.7.4
* @version 1.0.0
*/
public static function get_i18n_string_plural( float $number, string $string_value = '', bool $include_number = true ): string {
switch ( $string_value ) {
case LP_COURSE_CPT:
$plural = sprintf(
_n( 'Course', 'Courses', $number, 'learnpress' ),
$number
);
break;
case LP_LESSON_CPT:
$plural = sprintf(
_n( 'Lesson', 'Lessons', $number, 'learnpress' ),
$number
);
break;
case LP_QUIZ_CPT:
$plural = sprintf(
_n( 'Quiz', 'Quizzes', $number, 'learnpress' ),
$number
);
break;
case LP_QUESTION_CPT:
$plural = sprintf(
_n( 'Question', 'Questions', $number, 'learnpress' ),
$number
);
break;
case 'lp_assignment':
$plural = sprintf(
_n( 'Assignment', 'Assignments', $number, 'learnpress' ),
$number
);
break;
case 'lp_h5p':
$plural = sprintf(
_n( 'H5P', 'H5Ps', $number, 'learnpress' ),
$number
);
break;
default:
$plural = $string_value;
break;
}

if ( $include_number ) {
$plural = sprintf( '%s %s', $number, $plural );
}

return apply_filters( 'learn-press/i18n/plural', $plural, $number, $string_value, $include_number );
}
}
1 change: 1 addition & 0 deletions inc/class-lp-request-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public static function get( $var, $default = false, $type = '', $env = 'request'
* @param string $env
*
* @return int
* @deprecated
*/
public static function get_int( $var, $default = false, $env = 'request' ) {
return self::get( $var, $default, 'int', $env );
Expand Down
25 changes: 18 additions & 7 deletions inc/custom-post-types/course.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,10 @@ public function columns_head( $columns ) {
/**
* Print content for custom column
*
* @param string
* @param int
* @param string $column
* @param int $post_id
*
* @throws Exception
*/
public function columns_content( $column, $post_id = 0 ) {
global $post;
Expand All @@ -451,7 +453,7 @@ public function columns_content( $column, $post_id = 0 ) {
if ( $number_sections ) {
$output = sprintf( _n( '<strong>%d</strong> section', '<strong>%d</strong> sections', $number_sections, 'learnpress' ), $number_sections );
$html_items = array();
$post_types = get_post_types( null, 'objects' );
//$post_types = get_post_types( null, 'objects' );

foreach ( learn_press_get_course_item_types() as $item_type ) {
$count_item = $course->count_items( $item_type );
Expand All @@ -460,10 +462,19 @@ public function columns_content( $column, $post_id = 0 ) {
continue;
}

$post_type_object = $post_types[ $item_type ];
/*$post_type_object = $post_types[ $item_type ];
$singular_name = $post_type_object->labels->singular_name;
$plural_name = $post_type_object->label;
$html_items[] = sprintf( _n( '<strong>%d</strong> ' . $singular_name, '<strong>%d</strong> ' . $plural_name, $count_item, 'learnpress' ), $count_item );
if ( $count_item > 1 || $count_item == 0 ) {
$label_item = $plural_name;
} else {
$label_item = $singular_name;
}*/
$html_items[] = sprintf(
'<strong>%1$d</strong> %2$s',
$count_item,
LP_Helper::get_i18n_string_plural( $count_item, $item_type, false )
);
}

$html_items = apply_filters( 'learn-press/course-count-items', $html_items );
Expand Down Expand Up @@ -603,12 +614,12 @@ protected function save_price( CourseModel &$courseObj ) {
$sale_price = $courseObj->get_sale_price();
if ( (float) $regular_price < 0 ) {
$courseObj->meta_data->{CoursePostModel::META_KEY_REGULAR_PRICE} = '';
$regular_price = $courseObj->get_regular_price();
$regular_price = $courseObj->get_regular_price();
}

if ( $sale_price !== '' && (float) $sale_price > (float) $regular_price ) {
$courseObj->meta_data->{CoursePostModel::META_KEY_SALE_PRICE} = '';
$sale_price = $courseObj->get_sale_price();
$sale_price = $courseObj->get_sale_price();
}

// Save sale regular price and sale price to table postmeta
Expand Down

0 comments on commit 42f71fb

Please sign in to comment.