Skip to content

Commit

Permalink
Merge pull request #6821 from Automattic/feature/reengaging-customers
Browse files Browse the repository at this point in the history
Feature: Re-engaging customers.
  • Loading branch information
aaronfc committed May 5, 2023
2 parents e03b821 + f13e2b6 commit 3ed9696
Show file tree
Hide file tree
Showing 13 changed files with 571 additions and 24 deletions.
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

0 comments on commit 3ed9696

Please sign in to comment.