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

Feature: Re-engaging customers. #6821

Merged
merged 27 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
20ad6a4
Add Sensei Pro updater fallback
renatho Mar 31, 2023
7fbd3c1
Fix class PHPDoc
renatho Mar 31, 2023
cd77c88
Add changelog styles
renatho Mar 31, 2023
b864245
Add update disclaimer for invalid license
renatho Apr 3, 2023
8394c57
Mark method as internal
renatho Apr 3, 2023
13d7921
Fix wrong variable
renatho Apr 4, 2023
c304eb8
Add licensing API filter to sensei lms
renatho Apr 4, 2023
e511e22
Add changelog
renatho Apr 4, 2023
1bec450
Merge pull request #6728 from Automattic/add/sensei-pro-updater-fallback
renatho Apr 5, 2023
99c6562
Merge pull request #6748 from Automattic/add/invalid-license-update-d…
renatho Apr 5, 2023
d7a48e2
Add condition for notices to happen in a specific date range
jom Apr 6, 2023
a29679d
Improve support for partial date ranges
jom Apr 6, 2023
5300189
Add a changelog for date range condition
jom Apr 6, 2023
873181b
Merge branch 'trunk' into feature/reengaging-customers
fjorgemota Apr 10, 2023
b362f2f
Return early if date condition fails
jom Apr 11, 2023
4ecbd17
Merge pull request #6775 from Automattic/add/notice-date-condition
jom Apr 12, 2023
55f6e2a
Switch level class to be consistent with other classes
jom Apr 17, 2023
e5a9440
Default to the info level
jom Apr 17, 2023
3ad66d6
Update naming for notice level CSS classes
jom Apr 17, 2023
cb9cede
Update with 'trunk'.
aaronfc Apr 18, 2023
551a2a5
Add support for passing the screens condition on the get_base_plugin_…
fjorgemota Apr 19, 2023
32b167e
Include update notice on all sensei pages
fjorgemota Apr 19, 2023
a834625
Merge branch 'feature/reengaging-customers' into update/notice-level
jom May 2, 2023
bc20410
Merge pull request #6816 from Automattic/update/notice-level
jom May 2, 2023
f9ef501
Merge pull request #6824 from Automattic/change/show-update-notice-on…
fjorgemota May 2, 2023
aed7137
Update with `trunk`.
aaronfc May 2, 2023
f13e2b6
Update with `trunk`.
aaronfc May 4, 2023
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
8 changes: 4 additions & 4 deletions assets/css/admin-notices.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ $sensei-notice-icon-width: 30px;
position: static;
}

&.sensei-notice-error {
&--error {
border-left-color: $notice-error;
}

&.sensei-notice-warning {
&--warning {
border-left-color: $notice-warning;
}

&.sensei-notice-info {
&--info {
border-left-color: $notice-info;
}

&.sensei-notice-success {
&--success {
border-left-color: $notice-success;
}
}
8 changes: 8 additions & 0 deletions assets/css/senseilms-licensing.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#section-changelog {
h2 {
clear: none;
}
h3 {
margin: 0;
}
}
2 changes: 1 addition & 1 deletion assets/home/notices.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const NoticeInfoLink = ( { infoLink } ) => {
const Notice = ( { noticeId, notice, dismissNonce } ) => {
let noticeClass = '';
if ( !! notice.level ) {
noticeClass = 'sensei-notice-' + notice.level;
noticeClass = 'sensei-notice--' + notice.level;
}

const isDismissible = notice.dismissible && dismissNonce;
Expand Down
4 changes: 4 additions & 0 deletions changelog/add-invalid-license-update-disclaimer
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Add disclamer with the reason that Sensei Pro can't be updated when license is not active
4 changes: 4 additions & 0 deletions changelog/add-notice-condition-date-range
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Ability to set conditions on admin notices based on a date range
63 changes: 56 additions & 7 deletions includes/admin/class-sensei-admin-notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ protected function get_notices( $max_age = null ) {
$transient_key = implode( '_', [ 'sensei_notices', Sensei()->version, determine_locale() ] );
$data = get_transient( $transient_key );
$notices = false;

// If the data is too old, fetch it again.
if ( $max_age && is_array( $data ) ) {
$age = time() - ( $data['_fetched'] ?? 0 );
Expand Down Expand Up @@ -236,20 +235,18 @@ private function add_admin_notice( $notice_id, $notice ) {
$notice['actions'] = [];
}

$notice_class = '';
if ( ! empty( $notice['style'] ) ) {
$notice_class = 'sensei-notice-' . $notice['style'];
}
$notice_classes = [];
$notice_classes[] = 'sensei-notice--' . $notice['level'];

$is_dismissible = $notice['dismissible'];
$notice_wrapper_extra = '';
if ( $is_dismissible ) {
wp_enqueue_script( 'sensei-dismiss-notices' );
$notice_class .= ' is-dismissible';
$notice_classes[] = 'is-dismissible';
$notice_wrapper_extra = sprintf( ' data-dismiss-action="sensei_dismiss_notice" data-dismiss-notice="%1$s" data-dismiss-nonce="%2$s"', esc_attr( $notice_id ), esc_attr( wp_create_nonce( self::DISMISS_NOTICE_NONCE_ACTION ) ) );
}
?>
<div class="notice sensei-notice <?php echo esc_attr( $notice_class ); ?>"
<div class="notice sensei-notice <?php echo esc_attr( implode( ' ', $notice_classes ) ); ?>"
<?php
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped above.
echo $notice_wrapper_extra;
Expand Down Expand Up @@ -413,6 +410,18 @@ private function check_notice_conditions( $notice, $screen_id = null ) {
break 2;
}
break;

case 'date_range':
if ( ! isset( $condition['start_date'] ) && ! isset( $condition['end_date'] ) ) {
break;
}

if ( ! $this->condition_check_date_range( $condition['start_date'] ?? null, $condition['end_date'] ?? null ) ) {
$can_see_notice = false;
break 2;
}

break;
}
}

Expand Down Expand Up @@ -506,6 +515,8 @@ private function condition_check_screen( array $allowed_screens, $screen_id = nu
/**
* Check an "installed since" condition
*
* @since 4.10.0
*
* @param int|string $installed_since Time to check the installation time for.
*
* @return bool
Expand All @@ -521,6 +532,39 @@ private function condition_installed_since( $installed_since ) : bool {
return $installed_at <= $installed_since;
}

/**
* Check a date range condition.
*
* @since $$next-version$$
*
* @param ?string $start_date_str Start date.
* @param ?string $end_date_str End date.
*
* @return bool
*/
private function condition_check_date_range( ?string $start_date_str, ?string $end_date_str ) : bool {
$now = new DateTime();

// Defaults to WP timezone, but can be overridden by passing string that includes timezone.
$start_date = $start_date_str ? date_create( $start_date_str, wp_timezone() ) : null;
$end_date = $end_date_str ? date_create( $end_date_str, wp_timezone() ) : null;

// If the passed date strings are invalid, don't show the notice.
if ( false === $start_date || false === $end_date ) {
return false;
}

if ( $start_date && $now < $start_date ) {
return false;
}

if ( $end_date && $now > $end_date ) {
return false;
}

return true;
}

/**
* Check a plugin condition.
*
Expand Down Expand Up @@ -616,6 +660,11 @@ private function normalize_notice( $notice ) {
];
}

$notice_levels = [ 'error', 'warning', 'success', 'info' ];
if ( ! isset( $notice['level'] ) || ! in_array( $notice['level'], $notice_levels, true ) ) {
$notice['level'] = 'info';
}

if ( ! isset( $notice['dismissible'] ) ) {
$notice['dismissible'] = true;
}
Expand Down
Loading