Add notice when someone is using a newsletter shortcode

[MAILPOET-3333]
This commit is contained in:
Pavel Dohnal
2020-12-02 13:57:53 +01:00
committed by Veljko V
parent 06dca19738
commit 3af2ffbbb4
2 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,61 @@
<?php
namespace MailPoet\Util\Notices;
use MailPoet\Util\Helpers;
use MailPoet\WP\Functions as WPFunctions;
use MailPoet\WP\Notice;
/**
* This can be removed after 2021-08-01
*/
class DeprecatedShortcodeNotice {
const DISMISS_NOTICE_TIMEOUT_SECONDS = 15552000; // 6 months
const OPTION_NAME = 'dismissed-deprecated-shortcode-notice';
public function init($shouldDisplay) {
if ($shouldDisplay && $this->isUsingDeprecatedShortcode()) {
return $this->display();
}
return null;
}
public function isUsingDeprecatedShortcode() {
global $wp_filter;// phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
$hook = 'mailpoet_newsletter_shortcode';
if (empty($wp_filter[$hook])) return false;// phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
$callbacks = $wp_filter[$hook];// phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
if (empty($callbacks->callbacks) || !is_array($callbacks->callbacks)) return false;
foreach ($callbacks->callbacks as $callbackByPriority) {
if (empty($callbackByPriority) || !is_array($callbackByPriority)) continue;
foreach ($callbackByPriority as $callback) {
if (!is_array($callback)) return true;// this is not our callback
if (empty($callback['function']) || !is_array($callback['function'])) return true; // not our callback
if (isset($callback['function'][1]) && $callback['function'][1] === 'handleOrderTotalShortcode') continue;
if (isset($callback['function'][1]) && $callback['function'][1] === 'handleOrderDateShortcode') continue;
return true;
}
}
}
public function display() {
$errorString = __('MailPoet recently changed how custom email shortcodes work, you may need to update your custom shortcodes.', 'mailpoet');
$getInTouchString = __('[link]See the documentation for necessary changes[/link]', 'mailpoet');
$error = Helpers::replaceLinkTags($errorString, 'https://kb.mailpoet.com/article/160-create-a-custom-shortcode', [
'target' => '_blank',
'data-beacon-article' => '581f6faac697914aa838044f',
]);
$error .= '<br><br>' . Helpers::replaceLinkTags($getInTouchString, 'https://www.mailpoet.com/let-us-handle-your-php-upgrade/', [
'target' => '_blank',
'class' => 'mailpoet-button mailpoet-button-small',
]);
$extraClasses = 'mailpoet-dismissible-notice is-dismissible';
return Notice::displayWarning($error, $extraClasses, self::OPTION_NAME);
}
public function disable() {
WPFunctions::get()->setTransient(self::OPTION_NAME, true, self::DISMISS_NOTICE_TIMEOUT_SECONDS);
}
}

View File

@ -32,6 +32,9 @@ class PermanentNotices {
/** @var HeadersAlreadySentNotice */ /** @var HeadersAlreadySentNotice */
private $headersAlreadySentNotice; private $headersAlreadySentNotice;
/** @var DeprecatedShortcodeNotice */
private $deprecatedShortcodeNotice;
public function __construct(WPFunctions $wp) { public function __construct(WPFunctions $wp) {
$this->wp = $wp; $this->wp = $wp;
$this->phpVersionWarnings = new PHPVersionWarnings(); $this->phpVersionWarnings = new PHPVersionWarnings();
@ -41,6 +44,7 @@ class PermanentNotices {
$this->inactiveSubscribersNotice = new InactiveSubscribersNotice(SettingsController::getInstance(), $wp); $this->inactiveSubscribersNotice = new InactiveSubscribersNotice(SettingsController::getInstance(), $wp);
$this->blackFridayNotice = new BlackFridayNotice(); $this->blackFridayNotice = new BlackFridayNotice();
$this->headersAlreadySentNotice = new HeadersAlreadySentNotice(SettingsController::getInstance(), $wp); $this->headersAlreadySentNotice = new HeadersAlreadySentNotice(SettingsController::getInstance(), $wp);
$this->deprecatedShortcodeNotice = new DeprecatedShortcodeNotice();
} }
public function init() { public function init() {
@ -75,6 +79,9 @@ class PermanentNotices {
$this->headersAlreadySentNotice->init( $this->headersAlreadySentNotice->init(
Menu::isOnMailPoetAdminPage($excludeWizard) Menu::isOnMailPoetAdminPage($excludeWizard)
); );
$this->deprecatedShortcodeNotice->init(
Menu::isOnMailPoetAdminPage($excludeWizard)
);
} }
public function ajaxDismissNoticeHandler() { public function ajaxDismissNoticeHandler() {
@ -95,6 +102,9 @@ class PermanentNotices {
case (InactiveSubscribersNotice::OPTION_NAME): case (InactiveSubscribersNotice::OPTION_NAME):
$this->inactiveSubscribersNotice->disable(); $this->inactiveSubscribersNotice->disable();
break; break;
case (DeprecatedShortcodeNotice::OPTION_NAME):
$this->deprecatedShortcodeNotice->disable();
break;
} }
} }
} }