Skip to content
Merged
7 changes: 6 additions & 1 deletion assets/src/css/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ to ensure proper responsiveness and avoid layout issues.
}
}

/* Seasonal offer notice (Halloween 2026), shown on the Dashboard and Media Library. */
/* Seasonal offer notice (Halloween and Black Friday 2026), shown on the Dashboard and Media Library. */
.rtgodam-offer-notice {
position: relative;
display: flex;
Expand All @@ -1214,6 +1214,11 @@ to ensure proper responsiveness and avoid layout issues.
border-left-color: #5d31ff;
overflow: hidden;

// No drawing on the left: the text needs the usual notice padding instead.
&--no-art {
padding-left: 16px;
}

&__art {
flex: none;
width: 92px;
Expand Down
152 changes: 102 additions & 50 deletions inc/classes/class-offer-notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
/**
* Seasonal offer notice shown in wp-admin to free and trial sites.
*
* The current campaign is the Halloween 2026 offer: 50% off the first payment
* with the code SPOOKY50, through November 9. The message names the
* integrations the site already uses, so a LifterLMS site reads about course
* videos and a WooCommerce store about shoppable video.
* Each campaign has fixed dates, a code and its own dismissal: the Halloween
* 2026 offer (SPOOKY50, through November 9) and the Black Friday and Cyber Monday
* 2026 offer (BFCM2026, November 13 to December 3). Nothing shows between or after them. The
* message names the integrations the site already uses, so a LifterLMS site
* reads about course videos and a WooCommerce store about shoppable video.
*
* @package GoDAM
* @since 2.5.2
Expand All @@ -23,27 +24,43 @@
class Offer_Notice {

/**
* Option that stores the dismissal for this campaign only.
* The campaigns, in date order.
*
* A new key per campaign, so a site that dismissed an earlier offer still sees this one.
* `start` and `end` are the first and last moment the notice shows, in the site's time zone,
* matching the offer on godam.io. Each campaign has its own dismiss option, so a site that
* dismissed an earlier offer still sees the next one. `path` is the godam.io page the Claim
* button opens, and `utm` its tracking (`utm_content` is added per placement and message).
*
* @var string
*/
const DISMISS_OPTION = 'rtgodam_offer_halloween_2026_dismissed';

/**
* Last moment the notice shows, in the site's time zone. Matches the offer on godam.io.
*
* @var string
*/
const END_TIME = '2026-11-09 23:59:59';

/**
* Offer code.
* @since n.e.x.t

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@since n.e.x.t. This is the only n.e.x.t in the repo, and I couldn't find a release step that replaces it, so it would ship as-is. Since this is aimed at 2.8.1, could both tags (here and on get_campaign()) be @since 2.8.1?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in de5d688. Both tags, on CAMPAIGNS and get_campaign(), are now @since 2.8.1.

*
* @var string
* @var array
*/
const CODE = 'SPOOKY50';
const CAMPAIGNS = array(
'halloween-2026' => array(
'start' => '2026-10-01 00:00:00', // Before 2.5.2 shipped it: the notice showed from install.
'end' => '2026-11-09 23:59:59',
'code' => 'SPOOKY50',
'dismiss_option' => 'rtgodam_offer_halloween_2026_dismissed',
'path' => '/pricing/',
'utm' => array(
'utm_campaign' => 'halloween-2026',
'utm_source' => '', // The site's host, filled in at render.
Comment thread
subodhr258 marked this conversation as resolved.
Resolved
'utm_medium' => 'plugin',
),
),
'bfcm-2026' => array(
'start' => '2026-11-13 00:00:00',
'end' => '2026-12-03 23:59:59',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time zone of the campaign window. start and end are read in each site's own time zone, so BFCM2026 shows over a different absolute window on each site. A site set to Pacific/Pago_Pago (UTC-11) keeps showing the notice, and "Ends December 3 at 11:59 p.m.", until December 4 10:59 UTC. A UTC+14 site starts on November 12 at 10:00 UTC.

If the code on Central expires at one fixed moment, some admins will copy a code that no longer works. Could we confirm how Central expires BFCM2026, and if it is a fixed zone, pin start/end to that zone (for example a timezone key per campaign) instead of wp_timezone()?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Central expiry needs a buffer.

'code' => 'BFCM2026',
'dismiss_option' => 'rtgodam_offer_bfcm_2026_dismissed',
'path' => '/pricing/',
'utm' => array(
'utm_source' => 'godam-plugin',
'utm_medium' => 'admin-notice',
'utm_campaign' => 'bfcm2026',
),
),
);

/**
* AJAX action and nonce action for dismissing the notice.
Expand All @@ -70,19 +87,34 @@ public static function should_show( $now = null, $user_data = null ) {
return false;
}

if ( get_option( self::DISMISS_OPTION, false ) ) {
$campaign = self::get_campaign( $now );
if ( ! $campaign || get_option( self::CAMPAIGNS[ $campaign ]['dismiss_option'], false ) ) {
return false;
}

return self::is_free_or_trial_site( $user_data );
}

/**
* The campaign running at the given moment, in the site's time zone.
*
* @since n.e.x.t
*
* @param \DateTimeInterface|null $now The moment to check, now when null. Tests pass a fixed time.
*
* @return string|null A key of CAMPAIGNS, or null between and after campaigns.
*/
public static function get_campaign( $now = null ) {
$timezone = wp_timezone();
$now = $now ? $now : new \DateTime( 'now', $timezone );
$end_time = new \DateTime( self::END_TIME, $timezone );

if ( $now > $end_time ) {
return false;
foreach ( self::CAMPAIGNS as $key => $campaign ) {
if ( $now >= new \DateTime( $campaign['start'], $timezone ) && $now <= new \DateTime( $campaign['end'], $timezone ) ) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeated work. get_campaign() builds two DateTime objects per campaign on every call. One Dashboard load runs it three times: free_plan_admin_notice() calls should_show(), then render() calls should_show() and get_campaign(). Each should_show() also reads rtgodam_get_user_data(). It is small now, but grows with each campaign. render() could call get_campaign() once and pass the result on, or the result could be cached in a static for the request. Optional.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, small. With one campaign, a Dashboard load builds two DateTime pairs three times. render() can call get_campaign() once and pass it on; follow-up with the next offer, no code change in this PR.

return $key;
}
}

return self::is_free_or_trial_site( $user_data );
return null;
}

/**
Expand Down Expand Up @@ -229,25 +261,28 @@ public static function get_message( $integrations ) {
* @return void
*/
public static function render( $placement, $now = null, $user_data = null ) {
// Read the clock once, so a campaign that ends mid-request cannot pass should_show() and then be gone.
$now = $now ? $now : new \DateTime( 'now', wp_timezone() );

if ( ! self::should_show( $now, $user_data ) ) {
return;
}

$campaign_key = self::get_campaign( $now );
$campaign = self::CAMPAIGNS[ $campaign_key ];
$is_halloween = 'halloween-2026' === $campaign_key;
Comment thread
subodhr258 marked this conversation as resolved.
Resolved
$integrations = self::get_active_integrations();
$message = self::get_message( $integrations );
$chips = array_slice( array_unique( array_column( $integrations, 'name' ) ), 0, 3 );
$host = wp_parse_url( home_url(), PHP_URL_HOST );
$claim_url = add_query_arg(
array(
'utm_campaign' => 'halloween-2026',
'utm_source' => $host,
'utm_medium' => 'plugin',
'utm_content' => $placement . '-' . $message['key'],
),
RTGODAM_IO_API_BASE . '/pricing/'
);
$utm = $campaign['utm'];
if ( '' === $utm['utm_source'] ) {
$utm['utm_source'] = wp_parse_url( home_url(), PHP_URL_HOST );
}
$utm['utm_content'] = $placement . '-' . $message['key'];
$claim_url = add_query_arg( $utm, RTGODAM_IO_API_BASE . $campaign['path'] );
?>
<div class="notice rtgodam-offer-notice" data-nonce="<?php echo esc_attr( wp_create_nonce( self::DISMISS_ACTION ) ); ?>">
<div class="notice rtgodam-offer-notice<?php echo $is_halloween ? '' : ' rtgodam-offer-notice--no-art'; ?>" data-nonce="<?php echo esc_attr( wp_create_nonce( self::DISMISS_ACTION ) ); ?>">
<?php if ( $is_halloween ) : ?>
<svg class="rtgodam-offer-notice__art" viewBox="0 0 92 104" width="92" height="104" aria-hidden="true" focusable="false">
<g stroke="#b9aee8" stroke-width="1" fill="none">
<path d="M0 0 L80 0"/><path d="M0 0 L70 40"/><path d="M0 0 L40 72"/><path d="M0 0 L0 90"/>
Expand All @@ -258,23 +293,29 @@ public static function render( $placement, $now = null, $user_data = null ) {
<g stroke="#2b1a66" stroke-width="1.5" fill="none" stroke-linecap="round"><path d="M57 65 l-7 -5 M56 70 l-8 0 M57 75 l-7 6 M67 65 l7 -5 M68 70 l8 0 M67 75 l7 6"/></g>
<circle cx="60.5" cy="59" r="1" fill="#fff"/><circle cx="63.5" cy="59" r="1" fill="#fff"/>
</svg>
<?php endif; ?>
<div class="rtgodam-offer-notice__body">
<p class="rtgodam-offer-notice__eyebrow">
<?php esc_html_e( 'Halloween offer', 'godam' ); ?>
<?php if ( $is_halloween ) : ?>
<?php esc_html_e( 'Halloween offer', 'godam' ); ?>
<svg class="rtgodam-offer-notice__pumpkin" viewBox="0 0 24 24" width="18" height="18" aria-hidden="true" focusable="false">
<path d="M12 6c-1-2 0-4 2-4" stroke="#5d31ff" stroke-width="1.6" fill="none" stroke-linecap="round"/>
<ellipse cx="7.5" cy="14" rx="5" ry="7" fill="#7a57ff"/><ellipse cx="16.5" cy="14" rx="5" ry="7" fill="#7a57ff"/><ellipse cx="12" cy="14" rx="4" ry="7.5" fill="#5d31ff"/>
<path d="M8 12l2-2 1 2zM13 12l2-2 1 2zM8 16q4 3 8 0l-1.5 1-1.2-.8-1.3 1-1.3-1-1.2.8z" fill="#fff"/>
</svg>
<?php else : ?>
<?php esc_html_e( 'Black Friday and Cyber Monday offer', 'godam' ); ?>
<?php endif; ?>
</p>
<p class="rtgodam-offer-notice__title">
<?php
$title = $is_halloween
/* translators: %s: the discount, shown in the accent colour, for example "Get 50% off". */
? esc_html__( 'No tricks, just treats: %s GoDAM!', 'godam' )
/* translators: %s: the discount, shown in the accent colour, for example "Get 50% off". */
: esc_html__( 'Black Friday and Cyber Monday deal: %s GoDAM', 'godam' );
echo wp_kses(
sprintf(
/* translators: %s: the discount, shown in the accent colour, for example "Get 50% off". */
esc_html__( 'No tricks, just treats: %s GoDAM!', 'godam' ),
'<span>' . esc_html__( 'Get 50% off', 'godam' ) . '</span>'
),
sprintf( $title, '<span>' . esc_html__( 'Get 50% off', 'godam' ) . '</span>' ),
array( 'span' => array() )
);
?>
Expand All @@ -299,20 +340,26 @@ public static function render( $placement, $now = null, $user_data = null ) {
</a>
<?php
/* translators: %s: offer code. */
$copy_label = sprintf( __( 'Copy the code %s', 'godam' ), self::CODE );
$copy_label = sprintf( __( 'Copy the code %s', 'godam' ), $campaign['code'] );
?>
<span class="rtgodam-offer-notice__code-group">
<span class="rtgodam-offer-notice__code-label"><?php esc_html_e( 'Code', 'godam' ); ?></span>
<button type="button" class="rtgodam-offer-notice__copy" data-code="<?php echo esc_attr( self::CODE ); ?>" data-copied="<?php esc_attr_e( 'Copied', 'godam' ); ?>" aria-label="<?php echo esc_attr( $copy_label ); ?>">
<span class="rtgodam-offer-notice__copy-text"><?php echo esc_html( self::CODE ); ?></span>
<button type="button" class="rtgodam-offer-notice__copy" data-code="<?php echo esc_attr( $campaign['code'] ); ?>" data-copied="<?php esc_attr_e( 'Copied', 'godam' ); ?>" aria-label="<?php echo esc_attr( $copy_label ); ?>">
<span class="rtgodam-offer-notice__copy-text"><?php echo esc_html( $campaign['code'] ); ?></span>
<svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true" focusable="false"><rect x="8" y="8" width="12" height="12" rx="2" fill="none" stroke="currentColor" stroke-width="1.8"/><path d="M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2" fill="none" stroke="currentColor" stroke-width="1.8"/></svg>
</button>
</span>
<span class="screen-reader-text rtgodam-offer-notice__status" role="status" aria-live="polite" data-message="<?php esc_attr_e( 'Code copied', 'godam' ); ?>"></span>
</p>
<p class="rtgodam-offer-notice__ends">
<span class="dashicons dashicons-calendar-alt" aria-hidden="true"></span>
<?php esc_html_e( 'Through November 9. Don\'t let this treat disappear!', 'godam' ); ?>
<?php
if ( $is_halloween ) {
esc_html_e( 'Through November 9. Don\'t let this treat disappear!', 'godam' );
} else {
esc_html_e( 'Ends December 3 at 11:59 p.m. 50% off your first month or year on any plan.', 'godam' );
Comment thread
subodhr258 marked this conversation as resolved.
Resolved
}
?>
</p>
</div>
<button type="button" class="notice-dismiss rtgodam-offer-notice__dismiss"><span class="screen-reader-text"><?php esc_html_e( 'Dismiss this offer', 'godam' ); ?></span></button>
Expand All @@ -321,20 +368,25 @@ public static function render( $placement, $now = null, $user_data = null ) {
}

/**
* Save the dismissal for the whole site.
* Save the dismissal of the running campaign for the whole site.
*
* @since 2.5.2
*
* @param \DateTimeInterface|null $now The moment to check, now when empty. Tests pass a fixed time.
*
* @return void
*/
public static function dismiss() {
public static function dismiss( $now = null ) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dismiss uses the clock, not the notice shown. dismiss() picks the campaign from the server time when the click arrives. If an admin loads the Dashboard at December 3, 23:59:50 and clicks the close button at December 4, 00:00:05, the call returns success but writes no option. With back-to-back campaigns, a stale notice dismissed after the switch would hide the new campaign, which the admin never saw.

Rendering data-campaign="<key>" on the notice, sending it with the AJAX call and checking it against CAMPAIGNS would tie the dismissal to what the admin actually closed. Not urgent for 2026, since there is a gap between the two campaigns.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid. A close click that lands after the end returns success and writes nothing, and with back-to-back campaigns a stale notice could hide the next one. Sending the campaign key with the AJAX call ties the dismissal to the notice shown. Black Friday is the only campaign and there is a gap before the next, so it is a follow-up for after 2.8.1; no code change in this PR.

check_ajax_referer( self::DISMISS_ACTION, 'nonce' );

if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array( 'message' => __( 'You are not allowed to dismiss this offer.', 'godam' ) ), 403 );
}

update_option( self::DISMISS_OPTION, time(), false );
$campaign = self::get_campaign( $now instanceof \DateTimeInterface ? $now : null );
if ( $campaign ) {
update_option( self::CAMPAIGNS[ $campaign ]['dismiss_option'], time(), false );
}

wp_send_json_success();
}
Expand Down
Loading
Loading