Do not call hooks on repeated getAutomaticEmails calls (e.g. in editor) [MAILPOET-2433]
This commit is contained in:
@@ -10,6 +10,9 @@ class AutomaticEmails {
|
|||||||
|
|
||||||
private $wp;
|
private $wp;
|
||||||
|
|
||||||
|
/** @var array|null */
|
||||||
|
private $automaticEmails;
|
||||||
|
|
||||||
public $availableGroups = [
|
public $availableGroups = [
|
||||||
'WooCommerce',
|
'WooCommerce',
|
||||||
];
|
];
|
||||||
@@ -45,6 +48,10 @@ class AutomaticEmails {
|
|||||||
public function getAutomaticEmails() {
|
public function getAutomaticEmails() {
|
||||||
global $wp_filter; // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
|
global $wp_filter; // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
|
||||||
|
|
||||||
|
if ($this->automaticEmails) {
|
||||||
|
return $this->automaticEmails;
|
||||||
|
}
|
||||||
|
|
||||||
// phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
|
// phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
|
||||||
$registeredGroups = preg_grep('!^' . self::FILTER_PREFIX . '(.*?)$!', array_keys($wp_filter));
|
$registeredGroups = preg_grep('!^' . self::FILTER_PREFIX . '(.*?)$!', array_keys($wp_filter));
|
||||||
|
|
||||||
@@ -66,6 +73,8 @@ class AutomaticEmails {
|
|||||||
$automaticEmails[$automaticEmail['slug']] = $automaticEmail;
|
$automaticEmails[$automaticEmail['slug']] = $automaticEmail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->automaticEmails = $automaticEmails;
|
||||||
|
|
||||||
return $automaticEmails;
|
return $automaticEmails;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,6 +145,8 @@ class AutomaticEmails {
|
|||||||
array_map(function($group) use($self) {
|
array_map(function($group) use($self) {
|
||||||
$self->wp->removeAllFilters($group);
|
$self->wp->removeAllFilters($group);
|
||||||
}, $registeredGroups);
|
}, $registeredGroups);
|
||||||
|
|
||||||
|
$this->automaticEmails = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function displayGroupWarning($group) {
|
private function displayGroupWarning($group) {
|
||||||
|
@@ -344,6 +344,7 @@ class Initializer {
|
|||||||
public function setupAutomaticEmails() {
|
public function setupAutomaticEmails() {
|
||||||
$automaticEmails = new AutomaticEmails();
|
$automaticEmails = new AutomaticEmails();
|
||||||
$automaticEmails->init();
|
$automaticEmails->init();
|
||||||
|
$automaticEmails->getAutomaticEmails();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setupWoocommerceTransactionalEmails() {
|
private function setupWoocommerceTransactionalEmails() {
|
||||||
|
Reference in New Issue
Block a user