Skip to content

Commit

Permalink
Merge pull request #89 from stellarwp/bugfix/missing-filter
Browse files Browse the repository at this point in the history
Add expired message filter
  • Loading branch information
kadencewp authored Dec 4, 2024
2 parents ac42ee4 + bb787f2 commit 301a5d4
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 9 deletions.
77 changes: 69 additions & 8 deletions src/Uplink/Messages/Expired_Key.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,81 @@
<?php

namespace StellarWP\Uplink\Messages;
use StellarWP\Uplink\Config;

class Expired_Key extends Message_Abstract {
/**
* @inheritDoc
*/
public function get(): string {
$message = '<div class="notice notice-warning"><p>';
$message .= __( 'Your license is expired', '%TEXTDOMAIN%' );
$message .= '<a href="https://evnt.is/195y" target="_blank" class="button button-primary">' .
__( 'Renew Your License Now', '%TEXTDOMAIN%' ) .
'<span class="screen-reader-text">' .
__( ' (opens in a new window)', '%TEXTDOMAIN%' ) .
'</span></a>';
$message .= '</p> </div>';
// TEC only default link for backwards compatibility.
$default_link = in_array(
Config::get_hook_prefix(),
[
'the-events-calendar',
'events-calendar-pro',
'event-tickets',
'event-tickets-plus',
'tribe-filterbar',
'events-virtual',
'events-community',
'events-community-tickets',
'event-aggregator',
'events-elasticsearch',
'image-widget-plus',
'advanced-post-manager',
'tribe-eventbrite',
'event-automator',
'tec-seating',
],
true ) ? 'https://evnt.is/195y' : '';

$message_link = apply_filters( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/messages/expired_key_link', $default_link );
$renew_label = __( 'Renew Your License Now', '%TEXTDOMAIN%' );
$opens_in_new_window = __( '(opens in a new window)', '%TEXTDOMAIN%' );
$notice_text = __( 'Your license is expired', '%TEXTDOMAIN%' );

if ( ! empty( $message_link ) ) {
$message_content = sprintf(
'<p>%s <a href="%s" target="_blank" class="button button-primary">%s <span class="screen-reader-text">%s</span></a></p>',
esc_html( $notice_text ),
esc_url( $message_link ),
esc_html( $renew_label ),
esc_html( $opens_in_new_window )
);
} else {
$message_content = sprintf(
'<p>%s</p>',
esc_html( $notice_text )
);
}

$message_content = apply_filters( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/messages/expired_key', $message_content );

$allowed_html = [
'a' => [
'href' => [],
'title' => [],
'target' => [],
'class' => []
],
'br' => [],
'em' => [],
'strong' => [],
'div' => [
'class' => []
],
'p' => [
'class' => []
],
'span' => [
'class' => []
],
];

$message = '<div class="notice notice-warning">';
$message .= wp_kses( $message_content, $allowed_html );
$message .= '</div>';

return $message;
}
Expand Down
13 changes: 12 additions & 1 deletion tests/wpunit/Admin/NoticeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use StellarWP\Uplink\Admin\Notice;
use StellarWP\Uplink\Tests\UplinkTestCase;
use StellarWP\Uplink\Config;

class NoticeTest extends UplinkTestCase {

Expand All @@ -19,7 +20,17 @@ public function test_it_should_display_notice() {
$notice = new Notice();
$notice->add_notice( Notice::EXPIRED_KEY, 'uplink' );

$this->expectOutputString( '<div class="notice notice-warning"><p>Your license is expired<a href="https://evnt.is/195y" target="_blank" class="button button-primary">Renew Your License Now<span class="screen-reader-text"> (opens in a new window)</span></a></p> </div>' );
$this->expectOutputString( '<div class="notice notice-warning"><p>Your license is expired</p></div>' );

$notice->setup_notices();
}

public function test_it_should_display_notice_with_link() {
Config::set_hook_prefix( 'events-calendar-pro' );
$notice = new Notice();
$notice->add_notice( Notice::EXPIRED_KEY, 'uplink' );

$this->expectOutputString( '<div class="notice notice-warning"><p>Your license is expired <a href="https://evnt.is/195y" target="_blank" class="button button-primary">Renew Your License Now <span class="screen-reader-text">(opens in a new window)</span></a></p></div>' );

$notice->setup_notices();
}
Expand Down

0 comments on commit 301a5d4

Please sign in to comment.