Skip to content

Commit

Permalink
Merge pull request #2730 from gocodebox/dev
Browse files Browse the repository at this point in the history
Release 7.7.5
  • Loading branch information
brianhogg authored Aug 15, 2024
2 parents dafbfb9 + 42bad79 commit 4739f86
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 82 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
LifterLMS Changelog
===================

v7.7.5 - 2024-08-15
-------------------

##### Bug Fixes

+ Show video tiles for courses on the Dashboard and My Courses pages when enabled. [#2728](https://github.com/gocodebox/lifterlms/issues/2728)

##### Updated Templates

+ [templates/myaccount/dashboard-section.php](https://github.com/gocodebox/lifterlms/blob/7.7.5/templates/myaccount/dashboard-section.php)


v7.7.4 - 2024-08-13
-------------------

##### Bug Fixes

+ Reverts changes to restricting pages by membership functionality to avoid conflicts with certain themes and plugins. [#2714](https://github.com/gocodebox/lifterlms/issues/2714)


v7.7.3 - 2024-08-12
-------------------

Expand Down
6 changes: 5 additions & 1 deletion class-lifterlms.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class LifterLMS {
*
* @var string
*/
public $version = '7.7.3';
public $version = '7.7.5';

/**
* LLMS_Assets instance
Expand Down Expand Up @@ -174,6 +174,9 @@ private function define_constants() {
'decoding' => true,
'disabled' => true,
'required' => true,
'allowfullscreen' => true,
'allow' => true,
'frameborder' => true,
'class' => true,
'type' => true,
'id' => true,
Expand Down Expand Up @@ -292,6 +295,7 @@ private function define_constants() {
'kbd' => $allowed_atts,
'q' => $allowed_atts,
's' => $allowed_atts,
'iframe' => $allowed_atts,
'header' => $allowed_atts,
'footer' => $allowed_atts,
'strike' => $allowed_atts,
Expand Down
87 changes: 29 additions & 58 deletions includes/class.llms.template.loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,79 +323,50 @@ public function restricted_by_lesson_prerequisite( $info ) {
*
* @since 3.0.0
* @since 3.37.10 Added Flag to print notices when landing on the redirected page.
* @since 7.7.0 Added support for multiple memberships warning.
*
* @param array $info Array of restriction info from `llms_page_restricted()`.
* @return void
*/
public function restricted_by_membership( $info ) {

$membership_ids = $info['restriction_id'];
$membership_id = $info['restriction_id'];

// Do nothing if we don't have a membership id.
if ( ! empty( $membership_ids ) && ( is_array( $membership_ids ) || is_numeric( $membership_ids ) ) ) {
if ( ! empty( $membership_id ) && is_numeric( $membership_id ) ) {

// Instantiate the membership.
$membership = new LLMS_Membership( $membership_id );

$msg = '';
$redirect = '';

// Check if we're dealing with an array or a numeric for single membership restriction.
if ( ( is_array( $membership_ids ) && 1 === count( $membership_ids ) ) || is_numeric( $membership_ids ) ) {

// Get the membership.
$membership = new LLMS_Membership( is_array( $membership_ids ) ? $membership_ids[0] : $membership_ids );

if ( 'yes' === $membership->get( 'restriction_add_notice' ) ) {
if ( 'yes' === $membership->get( 'restriction_add_notice' ) ) {

$msg = $membership->get( 'restriction_notice' );
$msg = $membership->get( 'restriction_notice' );

}

// Get the redirect based on the redirect type (if set).
switch ( $membership->get( 'restriction_redirect_type' ) ) {

case 'custom':
$redirect = $membership->get( 'redirect_custom_url' );
break;

case 'membership':
$redirect = get_permalink( $membership->get( 'id' ) );
break;

case 'page':
$redirect = get_permalink( $membership->get( 'redirect_page_id' ) );
// Make sure to print notices in wp pages.
$redirect = empty( $msg ) ? $redirect : add_query_arg(
array(
'llms_print_notices' => 1,
),
$redirect
);
break;
}
} else {
}

$restricted_memberships = '';
$count = 0;
$length = count( $membership_ids );
// Get the redirect based on the redirect type (if set).
switch ( $membership->get( 'restriction_redirect_type' ) ) {

foreach ( $membership_ids as $membership_id ) {
case 'custom':
$redirect = $membership->get( 'redirect_custom_url' );
break;

$restricted_memberships .= do_shortcode( '[lifterlms_membership_link id="' . $membership_id . '"]' );
++$count;
case 'membership':
$redirect = get_permalink( $membership->get( 'id' ) );
break;

// Adding `, ` or ` or ` depending on the number of memberships.
if ( $count < $length - 1 ) {
$restricted_memberships .= ', ';
} elseif ( $count === $length - 1 ) {
$restricted_memberships .= __( ' or ', 'lifterlms' );
}
}

// Translators: %s = Membership links.
$msg = sprintf(
esc_html__( 'You must belong to one of the following memberships to access this content: %s', 'lifterlms' ),
wp_kses_post( $restricted_memberships )
);
case 'page':
$redirect = get_permalink( $membership->get( 'redirect_page_id' ) );
// Make sure to print notices in wp pages.
$redirect = empty( $msg ) ? $redirect : add_query_arg(
array(
'llms_print_notices' => 1,
),
$redirect
);
break;

}

Expand Down Expand Up @@ -713,7 +684,6 @@ public function maybe_prepare_post_content_restriction() {
* @since 3.41.1
* @since 4.0.0 Don't pass by reference because it's unnecessary.
* @since 4.10.1 Fixed incorrect position of `true` in `in_array()`.
* @since 7.7.0 Added support for restricted membership IDs array.
*
* @param WP_Post $post Post Object.
* @param WP_Query $query Query object.
Expand Down Expand Up @@ -761,8 +731,9 @@ public function maybe_restrict_post_content( $post, $query ) {

$membership_id = $page_restricted['restriction_id'];

if ( ! empty( $membership_id ) && ( is_array( $membership_id ) || is_numeric( $membership_id ) ) ) {
$membership = new LLMS_Membership( is_array( $membership_id ) ? $membership_id[0] : $membership_id );
if ( ! empty( $membership_id ) && is_numeric( $membership_id ) ) {

$membership = new LLMS_Membership( $membership_id );

if ( 'yes' === $membership->get( 'restriction_add_notice' ) ) {
$msg = $membership->get( 'restriction_notice' );
Expand Down
45 changes: 30 additions & 15 deletions includes/functions/llms.functions.access.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,11 @@ function llms_is_post_restricted_by_time_period( $post_id, $user_id = null ) {
* @since 3.0.0
* @since 3.16.14 Unknown.
* @since 3.37.10 Call `in_array()` with strict comparison.
* @since 7.7.0 Added support for multiple membership restrictions.D
*
* @param int $post_id WP_Post ID.
* @param int|null $user_id Optional. WP User ID (will use get_current_user_id() if none supplied). Default `null`.
* @return bool|array Array of WP_Post IDs of the memberships that restrict the post.
* False if no restrictions found.
* @return bool|int WP_Post ID of the membership if a restriction is found.
* False if no restrictions found.
*/
function llms_is_post_restricted_by_membership( $post_id, $user_id = null ) {

Expand All @@ -530,24 +529,40 @@ function llms_is_post_restricted_by_membership( $post_id, $user_id = null ) {

if ( 'yes' === $restricted && $memberships && is_array( $memberships ) ) {

$restriction_ids = array();
$student = llms_get_student( $user_id );
// if no user, return the first membership from the array as the restriction id.
if ( ! $user_id ) {

foreach ( $memberships as $mid ) {
if ( ! is_numeric( $mid ) || absint( $mid ) === 0 ) {
continue;
}
$restriction_id = array_shift( $memberships );

} else {

$student = llms_get_student( $user_id );
if ( ! $student ) {

$restriction_id = array_shift( $memberships );

} else {

// reverse so to ensure that if user is in none of the memberships,
// they'd encounter the same restriction settings as a visitor.
$memberships = array_reverse( $memberships );

// loop through the memberships.
foreach ( $memberships as $mid ) {

$restriction_ids[] = absint( $mid );
// set this as the restriction id.
$restriction_id = $mid;

// once we find the student has access break the loop,
// this will be the restriction that the template loader will check against later.
if ( $student && $student->is_enrolled( $mid ) ) {
break;
// once we find the student has access break the loop,
// this will be the restriction that the template loader will check against later.
if ( $student->is_enrolled( $mid ) ) {
break;
}
}
}
}

return $restriction_ids;
return absint( $restriction_id );

}

Expand Down
2 changes: 1 addition & 1 deletion lifterlms.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Plugin Name: LifterLMS
* Plugin URI: https://lifterlms.com/
* Description: Complete e-learning platform to sell online courses, protect lessons, offer memberships, and quiz students. WP Learning Management System.
* Version: 7.7.3
* Version: 7.7.5
* Author: LifterLMS
* Author URI: https://lifterlms.com/
* Text Domain: lifterlms
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lifterlms",
"version": "7.7.3",
"version": "7.7.5",
"description": "LifterLMS by codeBOX",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion templates/myaccount/dashboard-section.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<?php do_action( 'lifterlms_before_' . $action ); ?>

<?php echo wp_kses_post( $content ); ?>
<?php echo wp_kses( $content, LLMS_ALLOWED_HTML_FORM_FIELDS ); ?>

<?php if ( $more ) : ?>
<footer class="llms-sd-section-footer">
Expand Down
8 changes: 5 additions & 3 deletions tests/phpunit/unit-tests/class-llms-test-functions-access.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ public function test_llms_is_post_restricted_by_membership() {

update_post_meta( $post_id, '_llms_restricted_levels', $memberships );
update_post_meta( $post_id, '_llms_is_restricted', 'yes' );
$this->assertEquals( $memberships, llms_is_post_restricted_by_membership( $post_id ) );
$this->assertEquals( $memberships, llms_is_post_restricted_by_membership( $post_id, $uid ) );

$this->assertEquals( $memberships[0], llms_is_post_restricted_by_membership( $post_id ) );
$this->assertEquals( $memberships[0], llms_is_post_restricted_by_membership( $post_id, $uid ) );

$out = llms_is_post_restricted_by_membership( $post_id );
$in = llms_is_post_restricted_by_membership( $post_id, $uid );

$student->enroll( $memberships[1] );
$this->assertEquals( $memberships, llms_is_post_restricted_by_membership( $post_id, $uid ) );
$this->assertEquals( $memberships[1], llms_is_post_restricted_by_membership( $post_id, $uid ) );

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public function test_has_student() {
*/
public function test_get_students() {

$this->markTestSkipped( 'This tests fails randomly.' );

$instructor = $this->factory->instructor->create_and_get();
$student_1 = $this->factory->student->create_and_get();
$student_2 = $this->factory->student->create_and_get();
Expand Down

0 comments on commit 4739f86

Please sign in to comment.