diff --git a/assets/js/src/date.js b/assets/js/src/date.js index 12ba06c449..ae6debd5b8 100644 --- a/assets/js/src/date.js +++ b/assets/js/src/date.js @@ -119,14 +119,14 @@ define('date', let outputFormat = ''; - Object.keys(replacements).forEach(function (key) { - if (format.contains(key)) { + Object.keys(replacements).forEach(function(key) { + if (format.indexOf(key) !== -1) { format = format.replace(key, '%'+key); } }); outputFormat = format; Object.keys(replacements).forEach(function(key) { - if (outputFormat.contains('%'+key)) { + if (outputFormat.indexOf('%'+key) !== -1) { outputFormat = outputFormat.replace('%'+key, replacements[key]); } }); diff --git a/lib/Config/Initializer.php b/lib/Config/Initializer.php index 279419217d..70df7063c0 100644 --- a/lib/Config/Initializer.php +++ b/lib/Config/Initializer.php @@ -33,7 +33,6 @@ class Initializer { $this->setupRenderer(); $this->setupLocalizer(); $this->setupMenu(); - $this->setupRouter(); $this->setupPermissions(); $this->setupPublicAPI(); $this->setupAnalytics(); @@ -49,6 +48,7 @@ class Initializer { } function onInit() { + $this->setupRouter(); $this->setupPages(); $this->runQueueSupervisor(); } diff --git a/lib/Models/Subscriber.php b/lib/Models/Subscriber.php index 2d1f55c1d9..9c47a7e318 100644 --- a/lib/Models/Subscriber.php +++ b/lib/Models/Subscriber.php @@ -146,7 +146,7 @@ class Subscriber extends Model { ) ); - // convert subsdriber to array + // convert subscriber to array $subscriber = $this->asArray(); // set from @@ -163,14 +163,13 @@ class Subscriber extends Model { ) ? $signup_confirmation['reply_to'] : false; - // send email - $mailer = new Mailer( - false, - $from, - $reply_to - ); - return $mailer->send($email, $subscriber); + try { + $mailer = new Mailer(false, $from, $reply_to); + return $mailer->send($email, $subscriber); + } catch(\Exception $e) { + return false; + } } return false; } diff --git a/lib/Router/Router.php b/lib/Router/Router.php index 3549080802..b6bed9f8e3 100644 --- a/lib/Router/Router.php +++ b/lib/Router/Router.php @@ -15,12 +15,26 @@ class Router { ); add_action( 'wp_ajax_mailpoet', - array($this, 'setup') + array($this, 'setupAdmin') + ); + add_action( + 'wp_ajax_nopriv_mailpoet', + array($this, 'setupPublic') ); } - function setup() { - $this->securityCheck(); + function setupAdmin() { + $this->verifyToken(); + $this->checkPermissions(); + return $this->processRoute(); + } + + function setupPublic() { + $this->verifyToken(); + return $this->processRoute(); + } + + function processRoute() { $class = ucfirst($_POST['endpoint']); $endpoint = __NAMESPACE__ . "\\" . $class; $method = $_POST['method']; @@ -43,8 +57,11 @@ class Router { echo $global; } - function securityCheck() { + function checkPermissions() { if(!current_user_can('manage_options')) { die(); } + } + + function verifyToken() { if(!wp_verify_nonce($_POST['token'], 'mailpoet_token')) { die(); } } }