Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use options instead of transients for saving the notice delay #2768

Merged
merged 6 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changelogs/fix_use-options-for-notice-delay.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
significance: patch
type: fixed
links:
- "#2767"
entry: Using a more reliable method of keeping LifterLMS notices dismissed.
13 changes: 8 additions & 5 deletions includes/admin/class.llms.admin.notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ public static function add_output_actions() {
public static function add_notice( $notice_id, $html_or_options = '', $options = array() ) {

// Don't add the notice if we've already dismissed or delayed it.
if ( get_transient( 'llms_admin_notice_' . $notice_id . '_delay' ) ) {
if ( get_transient( 'llms_admin_notice_' . $notice_id . '_delay' ) ||
( is_numeric( get_option( 'llms_admin_notice_' . $notice_id . '_delay' ) ) &&
time() < get_option( 'llms_admin_notice_' . $notice_id . '_delay' )
) ) {
return;
}

Expand Down Expand Up @@ -136,15 +139,15 @@ public static function delete_notice( $notice_id, $trigger = 'delete' ) {
$notice = self::get_notice( $notice_id );
delete_option( 'llms_admin_notice_' . $notice_id );
if ( $notice ) {
$delay = 0;
if ( 'remind' === $trigger && $notice['remindable'] ) {
$delay = isset( $notice['remind_in_days'] ) ? $notice['remind_in_days'] : 0;
} elseif ( 'hide' === $trigger && $notice['dismissible'] ) {
}
if ( 'hide' === $trigger && $notice['dismissible'] ) {
$delay = isset( $notice['dismiss_for_days'] ) ? $notice['dismiss_for_days'] : 7;
} else {
$delay = 0;
}
if ( $delay ) {
set_transient( 'llms_admin_notice_' . $notice_id . '_delay', 'yes', DAY_IN_SECONDS * $delay );
update_option( 'llms_admin_notice_' . $notice_id . '_delay', time() + ( DAY_IN_SECONDS * $delay ) );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function test_delete_notice_remind() {
LLMS_Admin_Notices::delete_notice( 'test-remind', 'remind' );

$this->assertEquals( array(), LLMS_Admin_Notices::get_notice( 'test-remind' ) );
$this->assertEquals( 'yes', get_transient( 'llms_admin_notice_test-remind_delay' ) );
$this->assertTrue( is_numeric( get_option( 'llms_admin_notice_test-remind_delay' ) ) && time() < get_option( 'llms_admin_notice_test-remind_delay' ) );
$this->assertSame( 1, did_action( 'lifterlms_remind_test-remind_notice' ) );


Expand Down Expand Up @@ -263,7 +263,7 @@ public function test_delete_notice_dismiss() {
LLMS_Admin_Notices::delete_notice( 'test-dismiss', 'hide' );

$this->assertEquals( array(), LLMS_Admin_Notices::get_notice( 'test-dismiss' ) );
$this->assertEquals( 'yes', get_transient( 'llms_admin_notice_test-dismiss_delay' ) );
$this->assertTrue( is_numeric( get_option( 'llms_admin_notice_test-dismiss_delay' ) ) && time() < get_option( 'llms_admin_notice_test-dismiss_delay' ) );
$this->assertSame( 1, did_action( 'lifterlms_hide_test-dismiss_notice' ) );

}
Expand Down
Loading