';
}
- public function show_template_page()
- {
+ public function show_template_page() {
try {
$mailjetIframe = $this->getMailjetIframe();
- $templateId = sanitize_text_field($_GET['id'] ?? '');
+ $templateId = sanitize_text_field($_GET['id'] ?? '');
if (isset($templateId)) {
$mailjetIframe->setInitialPage(MailjetIframe::PAGE_EDIT_TEMPLATE, $templateId);
} else {
diff --git a/src/includes/MailjetSettings.php b/src/includes/MailjetSettings.php
index b0b79cce..59a9762e 100644
--- a/src/includes/MailjetSettings.php
+++ b/src/includes/MailjetSettings.php
@@ -19,14 +19,13 @@
* @subpackage Mailjet/includes
* @author Your Name
*/
-class MailjetSettings
-{
+class MailjetSettings {
+
/**
* custom option and settings
* IMPORTANT - add each setting here, in order to be processed by the WP Settings API
*/
- public function mailjet_settings_admin_init()
- {
+ public function mailjet_settings_admin_init() {
// register a new settings for Mailjet pages
register_setting('mailjet_initial_settings_page', 'mailjet_apikey');
register_setting('mailjet_initial_settings_page', 'mailjet_apisecret');
@@ -82,16 +81,15 @@ public function mailjet_settings_admin_init()
/**
* @return void
*/
- public function mailjet_settings_init()
- {
+ public function mailjet_settings_init() {
MailjetLogger::info('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Settings Init Start]');
$this->addMailjetActions();
$this->addSubscriptionConfirmations();
- $currentPage = !empty($_REQUEST['page']) ? sanitize_text_field($_REQUEST['page']) : null;
- $fromPage = !empty($_REQUEST['from']) ? sanitize_text_field($_REQUEST['from']) : null;
- if (\in_array($currentPage, array('mailjet_allsetup_page', 'mailjet_dashboard_page', 'mailjet_user_access_page', 'mailjet_integrations_page', 'mailjet_subscription_options_page', 'mailjet_sending_settings_page', 'mailjet_connect_account_page', 'mailjet_initial_contact_lists_page', 'mailjet_settings_page'))) {
+ $currentPage = ! empty($_REQUEST['page']) ? sanitize_text_field($_REQUEST['page']) : null;
+ $fromPage = ! empty($_REQUEST['from']) ? sanitize_text_field($_REQUEST['from']) : null;
+ if (\in_array($currentPage, array( 'mailjet_allsetup_page', 'mailjet_dashboard_page', 'mailjet_user_access_page', 'mailjet_integrations_page', 'mailjet_subscription_options_page', 'mailjet_sending_settings_page', 'mailjet_connect_account_page', 'mailjet_initial_contact_lists_page', 'mailjet_settings_page' ))) {
$apiCredentialsOk = Mailjet::getOption('api_credentials_ok');
- if (!($fromPage === 'plugins') && !empty($apiCredentialsOk) && '1' != $apiCredentialsOk) {
+ if ( ! ($fromPage === 'plugins') && ! empty($apiCredentialsOk) && '1' != $apiCredentialsOk) {
self::redirectJs(admin_url('/admin.php?page=mailjet_settings_page'));
}
}
@@ -100,73 +98,72 @@ public function mailjet_settings_init()
/**
* Adding a Mailjet logic and functionality to some WP actions - for example - inserting checkboxes for subscription
*/
- private function addMailjetActions()
- {
+ private function addMailjetActions() {
$activate_mailjet_sync = Mailjet::getOption('activate_mailjet_sync');
- $mailjet_sync_list = Mailjet::getOption('mailjet_sync_list');
+ $mailjet_sync_list = Mailjet::getOption('mailjet_sync_list');
MailjetLogger::info('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Adding some custom mailjet logic to WP actions - Start ]');
- if (!empty($activate_mailjet_sync) && !empty($mailjet_sync_list)) {
+ if ( ! empty($activate_mailjet_sync) && ! empty($mailjet_sync_list)) {
$subscriptionOptionsSettings = SubscriptionOptionsSettings::getInstance();
// Check after login if the user is subscribed to the contact list
- add_action('wp_login', [$subscriptionOptionsSettings, 'checkUserSubscription'], 10, 2);
+ add_action('wp_login', array( $subscriptionOptionsSettings, 'checkUserSubscription' ), 10, 2);
// When user is viewing another users profile page (not their own).
- add_action('edit_user_profile', [$subscriptionOptionsSettings, 'mailjet_show_extra_profile_fields']);
+ add_action('edit_user_profile', array( $subscriptionOptionsSettings, 'mailjet_show_extra_profile_fields' ));
// - If you want to apply your hook to ALL profile pages (including the current user) then you also need to use this one.
- add_action('show_user_profile', [$subscriptionOptionsSettings, 'mailjet_show_extra_profile_fields']);
+ add_action('show_user_profile', array( $subscriptionOptionsSettings, 'mailjet_show_extra_profile_fields' ));
// Runs just before the end of the new user registration form.
if (Mailjet::getOption('activate_mailjet_woo_integration') === '1') {
- add_action('woocommerce_edit_account_form', [$subscriptionOptionsSettings, 'mailjet_show_extra_profile_fields']);
+ add_action('woocommerce_edit_account_form', array( $subscriptionOptionsSettings, 'mailjet_show_extra_profile_fields' ));
}
// Runs just before the end of the new user registration form.
- add_action('register_form', [$subscriptionOptionsSettings, 'mailjet_show_extra_profile_fields']);
+ add_action('register_form', array( $subscriptionOptionsSettings, 'mailjet_show_extra_profile_fields' ));
// Runs near the end of the "Add New" user screen.
- add_action('user_new_form', [$subscriptionOptionsSettings, 'mailjet_show_extra_profile_fields']);
+ add_action('user_new_form', array( $subscriptionOptionsSettings, 'mailjet_show_extra_profile_fields' ));
// Runs when a user's profile is updated. Action function argument: user ID.
- add_action('profile_update', [$subscriptionOptionsSettings, 'mailjet_save_extra_profile_fields']);
+ add_action('profile_update', array( $subscriptionOptionsSettings, 'mailjet_save_extra_profile_fields' ));
// Runs immediately after the new user is added to the database.
- add_action('user_register', [$subscriptionOptionsSettings, 'mailjet_register_user']);
+ add_action('user_register', array( $subscriptionOptionsSettings, 'mailjet_register_user' ));
}
/* Add custom field to comment form and process it on form submit */
$activate_mailjet_comment_authors_sync = (int) Mailjet::getOption('activate_mailjet_comment_authors_sync');
- $mailjet_comment_authors_list = (int) Mailjet::getOption('mailjet_comment_authors_list');
+ $mailjet_comment_authors_list = (int) Mailjet::getOption('mailjet_comment_authors_list');
if ($activate_mailjet_comment_authors_sync === 1 && $mailjet_comment_authors_list > 1) {
$commentAuthorsSettings = new CommentAuthorsSettings();
if (null !== wp_get_current_user() && wp_get_current_user()->exists()) {
- add_action('comment_form', array($commentAuthorsSettings, 'mailjet_show_extra_comment_fields'));
+ add_action('comment_form', array( $commentAuthorsSettings, 'mailjet_show_extra_comment_fields' ));
} else {
- add_action('comment_form_after_fields', array($commentAuthorsSettings, 'mailjet_show_extra_comment_fields'));
+ add_action('comment_form_after_fields', array( $commentAuthorsSettings, 'mailjet_show_extra_comment_fields' ));
}
- add_action('wp_insert_comment', array($commentAuthorsSettings, 'mailjet_subscribe_comment_author'));
+ add_action('wp_insert_comment', array( $commentAuthorsSettings, 'mailjet_subscribe_comment_author' ));
MailjetLogger::info('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Comment Authors Sync active - added custom actions to sync them ]');
}
/* Add custom field to WooCommerce checkout form and process it on form submit */
$activate_mailjet_woo_integration = Mailjet::getOption('activate_mailjet_woo_integration');
- $activate_mailjet_sync = Mailjet::getOption('activate_mailjet_sync');
- if ((int) $activate_mailjet_woo_integration === 1 && (int) $activate_mailjet_sync === 1) {
+ $activate_mailjet_sync = Mailjet::getOption('activate_mailjet_sync');
+ if ( (int) $activate_mailjet_woo_integration === 1 && (int) $activate_mailjet_sync === 1) {
$wooCommerceSettings = WooCommerceSettings::getInstance();
// Add the checkbox
- add_action('woocommerce_after_checkout_billing_form', array($wooCommerceSettings, 'mailjet_show_extra_woo_fields'), 10, 2);
- add_action('woocommerce_register_form', array($wooCommerceSettings, 'add_account_newsletter_checkbox_field'), 10, 2);
+ add_action('woocommerce_after_checkout_billing_form', array( $wooCommerceSettings, 'mailjet_show_extra_woo_fields' ), 10, 2);
+ add_action('woocommerce_register_form', array( $wooCommerceSettings, 'add_account_newsletter_checkbox_field' ), 10, 2);
// Process the checkbox on submit
- add_action('woocommerce_register_post', array($wooCommerceSettings, 'mailjet_subscribe_woo_register'), 10, 2);
- add_action('woocommerce_checkout_create_order', array($wooCommerceSettings, 'mailjet_subscribe_woo'), 10, 2);
- add_action('wp_ajax_nopriv_mj_ajax_subscribe', array($wooCommerceSettings, 'subscribeViaAjax'));
- add_action('wp_ajax_mj_ajax_subscribe', array($wooCommerceSettings, 'subscribeViaAjax'));
+ add_action('woocommerce_register_post', array( $wooCommerceSettings, 'mailjet_subscribe_woo_register' ), 10, 2);
+ add_action('woocommerce_checkout_create_order', array( $wooCommerceSettings, 'mailjet_subscribe_woo' ), 10, 2);
+ add_action('wp_ajax_nopriv_mj_ajax_subscribe', array( $wooCommerceSettings, 'subscribeViaAjax' ));
+ add_action('wp_ajax_mj_ajax_subscribe', array( $wooCommerceSettings, 'subscribeViaAjax' ));
// Add filter for changing "Thank you" text on order processed page
- add_filter('woocommerce_thankyou_order_received_text', array($wooCommerceSettings, 'woo_change_order_received_text'), 10, 2);
+ add_filter('woocommerce_thankyou_order_received_text', array( $wooCommerceSettings, 'woo_change_order_received_text' ), 10, 2);
MailjetLogger::info('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Comment Authors Sync active - added custom actions to sync them ]');
}
$isContactFormActivated = Mailjet::getOption('activate_mailjet_cf7_integration');
- $cfList = Mailjet::getOption('mailjet_cf7_list');
+ $cfList = Mailjet::getOption('mailjet_cf7_list');
if ($isContactFormActivated && $cfList) {
$this->activateCf7Url($cfList);
}
// Add a Link to Mailjet settings page next to the activate/deactivate links in WP Plugins page
- add_filter('plugin_action_links', array($this, 'mailjet_settings_link'), 10, 2);
- $currentPage = !empty($_REQUEST['page']) ? sanitize_text_field($_REQUEST['page']) : null;
- if (\in_array($currentPage, array('mailjet_initial_contact_lists_page', 'mailjet_sending_settings_page', 'mailjet_subscription_options_page'))) {
- if (!MailjetApi::isValidAPICredentials()) {
- add_action('admin_notices', array($this, 'apiCredentialsInvalid'));
+ add_filter('plugin_action_links', array( $this, 'mailjet_settings_link' ), 10, 2);
+ $currentPage = ! empty($_REQUEST['page']) ? sanitize_text_field($_REQUEST['page']) : null;
+ if (\in_array($currentPage, array( 'mailjet_initial_contact_lists_page', 'mailjet_sending_settings_page', 'mailjet_subscription_options_page' ))) {
+ if ( ! MailjetApi::isValidAPICredentials()) {
+ add_action('admin_notices', array( $this, 'apiCredentialsInvalid' ));
}
}
MailjetLogger::info('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Adding some custom mailjet logic to WP actions - End ]');
@@ -177,28 +174,33 @@ private function addMailjetActions()
* @return false|void
* @throws Exception
*/
- private function activateCf7Url($contactListId)
- {
- $locale = Mailjeti18n::getLocale();
- $technicalIssue = Mailjeti18n::getTranslationsFromFile($locale, 'A technical issue has prevented your subscription. Please try again later.');
+ private function activateCf7Url( $contactListId ) {
+ $locale = Mailjeti18n::getLocale();
+ $technicalIssue = Mailjeti18n::getTranslationsFromFile($locale, 'A technical issue has prevented your subscription. Please try again later.');
$contactForm7Settings = new ContactForm7Settings();
- add_action('wpcf7_mail_sent', array($contactForm7Settings, 'sendConfirmationEmail'), 10, 2);
- if (!empty($_GET['cf7list']) && sanitize_text_field($_GET['cf7list']) === $contactListId) {
+ add_action('wpcf7_mail_sent', array( $contactForm7Settings, 'sendConfirmationEmail' ), 10, 2);
+ if ( ! empty($_GET['cf7list']) && sanitize_text_field($_GET['cf7list']) === $contactListId) {
if (empty($_GET['email'])) {
echo esc_attr($technicalIssue);
MailjetLogger::error('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Subscription failed ]');
die;
}
- $email = sanitize_email($_GET['email']);
- $name = sanitize_text_field($_GET['prop']);
- $params = \http_build_query(array('cf7list' => $contactListId, 'email' => $email, 'prop' => $name));
- if (\sha1($params . MailjetSettings::getCryptoHash()) !== sanitize_text_field($_GET['token'])) {
+ $email = sanitize_email($_GET['email']);
+ $name = sanitize_text_field($_GET['prop']);
+ $params = \http_build_query(
+ array(
+ 'cf7list' => $contactListId,
+ 'email' => $email,
+ 'prop' => $name,
+ )
+ );
+ if (\sha1($params . self::getCryptoHash()) !== sanitize_text_field($_GET['token'])) {
return \false;
}
// Hardcode this in order to pass the check inside `$this->>subsctiptionConfirmationAdminNoticeSuccess()`
- $_GET['subscribe'] = 1;
- $contact = array();
- $contact['Email'] = $email;
+ $_GET['subscribe'] = 1;
+ $contact = array();
+ $contact['Email'] = $email;
$contact['Properties']['name'] = $name;
MailjetApi::createMailjetContactProperty('name');
$syncSingleContactEmailToMailjetList = MailjetApi::syncMailjetContact($contactListId, $contact);
@@ -213,25 +215,23 @@ private function activateCf7Url($contactListId)
/**
* Add admin notice saying that current API credentials are not valid
*/
- public function apiCredentialsInvalid()
- {
+ public function apiCredentialsInvalid() {
add_settings_error('mailjet_messages', 'mailjet_message', __('Your Mailjet API credentials are invalid or not yet configured. Please check and configure them to proceed further.', 'mailjet-for-wordpress'), 'error');
}
/**
* Adding a Mailjet logic and functionality to some WP actions - for example - inserting checkboxes for subscription
*/
- public function addSubscriptionConfirmations()
- {
+ public function addSubscriptionConfirmations() {
MailjetLogger::info('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Handling subscription confirmations - Start ]');
- $subscribeParam = isset($_GET['subscribe']) ? sanitize_text_field($_GET['subscribe']) : '';
+ $subscribeParam = isset($_GET['subscribe']) ? sanitize_text_field($_GET['subscribe']) : '';
$subscriptionEmail = isset($_GET['user_email']) ? sanitize_email($_GET['user_email']) : '';
/* Add custom field to comment form and process it on form submit */
$activate_mailjet_comment_authors_sync = Mailjet::getOption('activate_mailjet_comment_authors_sync');
- $mailjet_comment_authors_list = Mailjet::getOption('mailjet_comment_authors_list');
- if (!empty($activate_mailjet_comment_authors_sync) && !empty($mailjet_comment_authors_list) && !empty($_GET['mj_sub_comment_author_token'])) {
+ $mailjet_comment_authors_list = Mailjet::getOption('mailjet_comment_authors_list');
+ if ( ! empty($activate_mailjet_comment_authors_sync) && ! empty($mailjet_comment_authors_list) && ! empty($_GET['mj_sub_comment_author_token'])) {
// Verify the token from the confirmation email link and subscribe the comment author to the Mailjet contacts list
$mj_sub_comment_author_token = sanitize_text_field($_GET['mj_sub_comment_author_token']);
- $tokenCheck = \sha1($subscribeParam . \str_ireplace(' ', '+', $subscriptionEmail) . self::getCryptoHash());
+ $tokenCheck = \sha1($subscribeParam . \str_ireplace(' ', '+', $subscriptionEmail) . self::getCryptoHash());
if ($mj_sub_comment_author_token === $tokenCheck) {
$commentAuthorsSettings = new CommentAuthorsSettings();
MailjetLogger::info('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Subscribe/Unsubscribe Comment Author To List ]');
@@ -246,12 +246,12 @@ public function addSubscriptionConfirmations()
}
/* Add custom field to WooCommerce checkout form and process it on form submit */
$activate_mailjet_woo_integration = Mailjet::getOption('activate_mailjet_woo_integration');
- if (!empty($activate_mailjet_woo_integration) && !empty($_GET['mj_sub_woo_token'])) {
+ if ( ! empty($activate_mailjet_woo_integration) && ! empty($_GET['mj_sub_woo_token'])) {
// Verify the token from the confirmation email link and subscribe the comment author to the Mailjet contacts list
$mj_sub_woo_token = sanitize_text_field($_GET['mj_sub_woo_token']);
- $firstName = sanitize_text_field($_GET['first_name']);
- $lastName = sanitize_text_field($_GET['last_name']);
- $tokenCheck = \sha1($subscribeParam . \str_ireplace(' ', '+', $subscriptionEmail) . $firstName . $lastName . self::getCryptoHash());
+ $firstName = sanitize_text_field($_GET['first_name']);
+ $lastName = sanitize_text_field($_GET['last_name']);
+ $tokenCheck = \sha1($subscribeParam . \str_ireplace(' ', '+', $subscriptionEmail) . $firstName . $lastName . self::getCryptoHash());
if ($mj_sub_woo_token === $tokenCheck) {
$wooCommerceSettings = WooCommerceSettings::getInstance();
MailjetLogger::info('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Subscribe/Unsubscribe WooCommerce user To List ]');
@@ -268,20 +268,19 @@ public function addSubscriptionConfirmations()
/**
* Display settings link on plugins page
*
- * @param array $links
+ * @param array $links
* @param string $file
* @return array
*/
- public function mailjet_settings_link($links, $file)
- {
- if ($file != plugin_basename(dirname(__FILE__, 3)) . '/wp-mailjet.php') {
+ public function mailjet_settings_link( $links, $file ) {
+ if ($file != plugin_basename(dirname(__DIR__, 2)) . '/wp-mailjet.php') {
return $links;
}
- $mailjetApikey = Mailjet::getOption('mailjet_apikey');
+ $mailjetApikey = Mailjet::getOption('mailjet_apikey');
$mailjetApiSecret = Mailjet::getOption('mailjet_apisecret');
$pluginLink = 'admin.php?page=mailjet_settings_page';
- if (!$mailjetApikey || !$mailjetApiSecret) {
+ if ( ! $mailjetApikey || ! $mailjetApiSecret) {
$pluginLink .= '&from=plugins';
}
@@ -293,48 +292,43 @@ public function mailjet_settings_link($links, $file)
/**
* @return void
*/
- public function subsctiptionConfirmationAdminNoticeSuccess()
- {
- if ((int) sanitize_text_field($_GET['subscribe']) > 0) {
- $locale = Mailjeti18n::getLocaleByPll();
+ public function subsctiptionConfirmationAdminNoticeSuccess() {
+ if ( (int) sanitize_text_field($_GET['subscribe']) > 0) {
+ $locale = Mailjeti18n::getLocaleByPll();
$newsletterRegistration = Mailjeti18n::getTranslationsFromFile($locale, 'Newsletter Registration');
- $congratsSubscribed = Mailjeti18n::getTranslationsFromFile($locale, 'Congratulations, you have successfully subscribed!');
+ $congratsSubscribed = Mailjeti18n::getTranslationsFromFile($locale, 'Congratulations, you have successfully subscribed!');
wp_enqueue_style('ubuntu-google-font', 'http://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700');
$tankyouPageTemplate = apply_filters('mailjet_thank_you_page_template', plugin_dir_path(__FILE__) . '..' . \DIRECTORY_SEPARATOR . 'templates' . \DIRECTORY_SEPARATOR . 'thankyou.php');
// Default page is selected
include $tankyouPageTemplate;
- // echo '
' . __('You have been successfully subscribed to a Mailjet contact list', 'mailjet-for-wordpress') . '
';
+ // echo '
' . __('You have been successfully subscribed to a Mailjet contact list', 'mailjet-for-wordpress') . '
';
} else {
echo '
' . 'You have been successfully unsubscribed from a Mailjet contact list' . '
';
}
die;
- //We die here to not continue loading rest of the WP home page
+ // We die here to not continue loading rest of the WP home page
}
/**
* @return void
*/
- public function subsctiptionConfirmationAdminNoticeFailed()
- {
+ public function subsctiptionConfirmationAdminNoticeFailed() {
echo '
' . __('Something went wrong with adding a contact to Mailjet contact list', 'mailjet-for-wordpress') . '
';
die;
- //We die here to not continue loading rest of the WP home page
+ // We die here to not continue loading rest of the WP home page
}
/**
* Automatically redirect to the next step - we use javascript to prevent the WP issue when using `wp_redirect` method and headers already sent
*
* @param $urlToRedirect
*/
- public static function redirectJs($urlToRedirect)
- {
+ public static function redirectJs( $urlToRedirect ) {
if (empty($urlToRedirect)) {
return;
}
?>
');
@@ -345,8 +339,7 @@ public static function redirectJs($urlToRedirect)
* @return false|mixed|null
* @throws \Exception
*/
- public static function getCryptoHash()
- {
+ public static function getCryptoHash() {
$hash = Mailjet::getOption('crypto_hash');
if (empty($hash)) {
try {
diff --git a/src/includes/MailjetUpdate.php b/src/includes/MailjetUpdate.php
index 6d0d813f..4a553104 100644
--- a/src/includes/MailjetUpdate.php
+++ b/src/includes/MailjetUpdate.php
@@ -2,11 +2,10 @@
namespace MailjetWp\MailjetPlugin\Includes;
-class MailjetUpdate
-{
- public static function updateToV5()
- {
- $apikey = Mailjet::getOption('mailjet_apikey');
+class MailjetUpdate {
+
+ public static function updateToV5() {
+ $apikey = Mailjet::getOption('mailjet_apikey');
$apisecret = Mailjet::getOption('mailjet_apisecret');
// Check if transition from v4 to v5 is already done
if ($apikey != false && $apisecret != false) {
@@ -38,13 +37,12 @@ public static function updateToV5()
$authorSync = $commentAuthorsListId > 0 ? 1 : '';
add_option('activate_mailjet_comment_authors_sync', $authorSync);
// Delete unused options
- $deleteOptions = array('mailjet_username', 'mailjet_password', 'mailjet_initial_sync_list_id', 'mailjet_comment_authors_list_id', 'mailjet_initial_sync_last_date', 'mailjet_comment_authors_list_date', 'mailjet_auto_subscribe_list_id', 'mailjet_user_api_version');
+ $deleteOptions = array( 'mailjet_username', 'mailjet_password', 'mailjet_initial_sync_list_id', 'mailjet_comment_authors_list_id', 'mailjet_initial_sync_last_date', 'mailjet_comment_authors_list_date', 'mailjet_auto_subscribe_list_id', 'mailjet_user_api_version' );
foreach ($deleteOptions as $option) {
delete_option($option);
}
}
- public static function updateToV5_2()
- {
+ public static function updateToV5_2() {
$activateMailjetWooSync = Mailjet::getOption('activate_mailjet_woo_sync');
if (empty($activateMailjetWooSync)) {
return;
@@ -53,10 +51,9 @@ public static function updateToV5_2()
add_option('mailjet_woo_register_checkbox', $activateMailjetWooSync);
delete_option('activate_mailjet_woo_sync');
}
- public static function updateToV5_2_1()
- {
+ public static function updateToV5_2_1() {
$pluginVersion = Mailjet::getOption('mailjet_plugin_version');
- if (!empty($pluginVersion)) {
+ if ( ! empty($pluginVersion)) {
return;
}
add_option('mailjet_plugin_version', '5.2.17');
diff --git a/src/includes/Mailjeti18n.php b/src/includes/Mailjeti18n.php
index 469550ce..30a9aa7f 100644
--- a/src/includes/Mailjeti18n.php
+++ b/src/includes/Mailjeti18n.php
@@ -13,18 +13,23 @@
* @subpackage Mailjet/includes
* @author Your Name
*/
-class Mailjeti18n
-{
- public static $supportedLocales = array('English' => 'en_US', 'French' => 'fr_FR', 'German' => 'de_DE', 'Spanish' => 'es_ES', 'Italian' => 'it_IT');
- const DEFAULT_LANGUAGE_DIR = MAILJET_PLUGIN_DIR . 'languages' . \DIRECTORY_SEPARATOR;
- const CUSTOM_LANGUAGE_DIR = WP_CONTENT_DIR . \DIRECTORY_SEPARATOR . 'languages' . \DIRECTORY_SEPARATOR . 'plugins' . \DIRECTORY_SEPARATOR;
+class Mailjeti18n {
+
+ public static $supportedLocales = array(
+ 'English' => 'en_US',
+ 'French' => 'fr_FR',
+ 'German' => 'de_DE',
+ 'Spanish' => 'es_ES',
+ 'Italian' => 'it_IT',
+ );
+ const DEFAULT_LANGUAGE_DIR = MAILJET_PLUGIN_DIR . 'languages' . \DIRECTORY_SEPARATOR;
+ const CUSTOM_LANGUAGE_DIR = WP_CONTENT_DIR . \DIRECTORY_SEPARATOR . 'languages' . \DIRECTORY_SEPARATOR . 'plugins' . \DIRECTORY_SEPARATOR;
/**
* Load the plugin text domain for translation.
*
* @since 5.0.0
*/
- public function load_plugin_textdomain()
- {
+ public function load_plugin_textdomain() {
load_plugin_textdomain('mailjet-for-wordpress', \false, self::DEFAULT_LANGUAGE_DIR);
MailjetLogger::info('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ \'mailjet\' text domain loaded ]');
}
@@ -32,11 +37,10 @@ public function load_plugin_textdomain()
* Provide array with translations in a format [key => message] and a locale to trnaslate to
*
* @param string $locale
- * @param array $translations
+ * @param array $translations
* @return bool true - if succesfully updated or added translations | false - if something went wrong and translations were not updated
*/
- public static function updateTranslationsInFile($locale = 'en_US', array $translations = array())
- {
+ public static function updateTranslationsInFile( $locale = 'en_US', array $translations = array() ) {
if (empty($locale) || empty($translations)) {
MailjetLogger::error('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Empty Locale or Translation messages provided ] ');
return \false;
@@ -49,11 +53,11 @@ public static function updateTranslationsInFile($locale = 'en_US', array $transl
MailjetLogger::info('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Translations PO file loaded ] - ' . $filePo);
// Parse a po file
$fileHandler = new \MailjetWp\Sepia\PoParser\SourceHandler\FileSystem($filePo);
- $poParser = new \MailjetWp\Sepia\PoParser\Parser($fileHandler);
- $catalog = $poParser->parse();
+ $poParser = new \MailjetWp\Sepia\PoParser\Parser($fileHandler);
+ $catalog = $poParser->parse();
foreach ($translations as $keyToTranslate => $textToTranslate) {
$entry = $catalog->getEntry($keyToTranslate);
- if (!empty($entry)) {
+ if ( ! empty($entry)) {
$catalog->removeEntry($keyToTranslate);
}
$catalog->addEntry(new \MailjetWp\Sepia\PoParser\Catalog\Entry($keyToTranslate, $textToTranslate));
@@ -64,17 +68,16 @@ public static function updateTranslationsInFile($locale = 'en_US', array $transl
MailjetLogger::info('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Translations PO and MO file updated ]');
return \true;
}
- public static function getTranslationsFromFile($locale, $msgId)
- {
+ public static function getTranslationsFromFile( $locale, $msgId ) {
$filePo = self::getTranslationFile('mailjet-for-wordpress-' . $locale . '.po');
if ($filePo === \false) {
return $msgId;
}
MailjetLogger::info('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Translations PO file loaded ] - ' . $filePo);
$fileHandler = new \MailjetWp\Sepia\PoParser\SourceHandler\FileSystem($filePo);
- $poParser = new \MailjetWp\Sepia\PoParser\Parser($fileHandler);
- $catalog = $poParser->parse();
- $entry = $catalog->getEntry($msgId);
+ $poParser = new \MailjetWp\Sepia\PoParser\Parser($fileHandler);
+ $catalog = $poParser->parse();
+ $entry = $catalog->getEntry($msgId);
if (empty($entry)) {
return $msgId;
}
@@ -82,27 +85,26 @@ public static function getTranslationsFromFile($locale, $msgId)
}
/**
* Get locale, if it is not supported the default en_US is returned
+ *
* @return string
*/
- public static function getLocale()
- {
+ public static function getLocale() {
$locale = get_locale();
// de_DE_formal consider as de_DE
- if (\in_array($locale, array('de_DE', 'de_DE_formal'))) {
+ if (\in_array($locale, array( 'de_DE', 'de_DE_formal' ))) {
$locale = 'de_DE';
}
// Use en_US as main if locale is some en
- if (\in_array($locale, array('en_US', 'en_EN', 'en_GB'))) {
+ if (\in_array($locale, array( 'en_US', 'en_EN', 'en_GB' ))) {
$locale = 'en_US';
}
// Use en_US if locale is not supported
- if (!\in_array($locale, \array_values(self::getSupportedLocales()))) {
+ if ( ! \in_array($locale, \array_values(self::getSupportedLocales()))) {
$locale = 'en_US';
}
return $locale;
}
- public static function getSupportedLocales()
- {
+ public static function getSupportedLocales() {
$customLocales = self::getAllSupportedLanguages();
if (empty($customLocales)) {
return self::$supportedLocales;
@@ -114,33 +116,31 @@ public static function getSupportedLocales()
}
/**
* Get user language via locale, if the language is not supported returns the default en_US
+ *
* @return string
*/
- public static function getCurrentUserLanguage($forceLocale = null)
- {
- $locale = $forceLocale ?: self::getLocale();
+ public static function getCurrentUserLanguage( $forceLocale = null ) {
+ $locale = $forceLocale ?: self::getLocale();
$languages = \array_flip(self::getSupportedLocales());
- if (!isset($languages[$locale])) {
+ if ( ! isset($languages[ $locale ])) {
// return English if the language is not supported
$locale = 'en_US';
}
- return $languages[$locale];
+ return $languages[ $locale ];
}
- public static function getMailjetSupportLinkByLocale()
- {
- $locale = self::getLocale();
+ public static function getMailjetSupportLinkByLocale() {
+ $locale = self::getLocale();
$supportedLocales = \array_flip(self::getSupportedLocales());
- if (!isset($supportedLocales[$locale])) {
+ if ( ! isset($supportedLocales[ $locale ])) {
// return English if the language is not supported
$locale = 'en_US';
}
- return "https://app.mailjet.com/support?lc=" . $locale;
+ return 'https://app.mailjet.com/support?lc=' . $locale;
}
/**
* Get user locale depends on polylang cookie
*/
- public static function getLocaleByPll()
- {
+ public static function getLocaleByPll() {
if (empty($_COOKIE['pll_language'])) {
// The user language is not changed via polylang
return self::getLocale();
@@ -168,11 +168,10 @@ public static function getLocaleByPll()
}
return $locale;
}
- public static function getMailjetUserGuideLinkByLocale()
- {
- $locale = self::getLocale();
+ public static function getMailjetUserGuideLinkByLocale() {
+ $locale = self::getLocale();
$supportedLocales = \array_flip(self::getSupportedLocales());
- if (!isset($supportedLocales[$locale])) {
+ if ( ! isset($supportedLocales[ $locale ])) {
// return English if the language is not supported
$locale = 'en_US';
}
@@ -194,11 +193,10 @@ public static function getMailjetUserGuideLinkByLocale()
}
return $link;
}
- private static function getAllSupportedLanguages()
- {
- $customLanguages = [];
+ private static function getAllSupportedLanguages() {
+ $customLanguages = array();
$customLanguagesDir = ABSPATH . 'wp-content/languages/plugins';
- if (!\file_exists($customLanguagesDir)) {
+ if ( ! \file_exists($customLanguagesDir)) {
return $customLanguages;
}
$dir = new \DirectoryIterator($customLanguagesDir);
@@ -207,16 +205,15 @@ private static function getAllSupportedLanguages()
continue;
}
$fileBasename = $fileInfo->getBasename('.' . $fileInfo->getExtension());
- if (!\file_exists($customLanguagesDir . \DIRECTORY_SEPARATOR . $fileBasename . '.mo') || !\file_exists($customLanguagesDir . \DIRECTORY_SEPARATOR . $fileBasename . '.po')) {
+ if ( ! \file_exists($customLanguagesDir . \DIRECTORY_SEPARATOR . $fileBasename . '.mo') || ! \file_exists($customLanguagesDir . \DIRECTORY_SEPARATOR . $fileBasename . '.po')) {
continue;
}
- $languageCode = \str_replace('mailjet-for-wordpress-', '', $fileBasename);
- $customLanguages[$languageCode] = $languageCode;
+ $languageCode = \str_replace('mailjet-for-wordpress-', '', $fileBasename);
+ $customLanguages[ $languageCode ] = $languageCode;
}
return $customLanguages;
}
- private static function getTranslationFile($filename)
- {
+ private static function getTranslationFile( $filename ) {
$customFIleInfo = new \SplFileInfo(self::CUSTOM_LANGUAGE_DIR . $filename);
if ($customFIleInfo->isFile() && $customFIleInfo->isWritable()) {
return $customFIleInfo->getRealPath();
diff --git a/src/includes/SettingsPages/AbandonedCartSettings.php b/src/includes/SettingsPages/AbandonedCartSettings.php
index c9526ee2..b5b2f3d9 100644
--- a/src/includes/SettingsPages/AbandonedCartSettings.php
+++ b/src/includes/SettingsPages/AbandonedCartSettings.php
@@ -8,31 +8,30 @@
use MailjetWp\MailjetPlugin\Includes\MailjetLogger;
use MailjetWp\MailjetPlugin\Includes\MailjetSettings;
-class AbandonedCartSettings
-{
+class AbandonedCartSettings {
+
/**
* @return void
*/
- public function mailjet_abandoned_cart_settings_page_html()
- {
- $nonce = wp_create_nonce('mailjet_abandoned_cart_settings_page_html');
+ public function mailjet_abandoned_cart_settings_page_html() {
+ $nonce = wp_create_nonce('mailjet_abandoned_cart_settings_page_html');
$isAbandonedCartActivated = Mailjet::getOption('mailjet_woo_abandoned_cart_activate') === '1';
- $sendingTime = Mailjet::getOption('mailjet_woo_abandoned_cart_sending_time');
+ $sendingTime = Mailjet::getOption('mailjet_woo_abandoned_cart_sending_time');
// time in seconds
$sendingTimeScaleInMinutes = $sendingTime <= 3600;
// scale in minutes if time <= 1h (60 * 60)
- $sendingTimeScaled = $sendingTimeScaleInMinutes ? $sendingTime / 60 : $sendingTime / 3600;
+ $sendingTimeScaled = $sendingTimeScaleInMinutes ? $sendingTime / 60 : $sendingTime / 3600;
$abandonedCartTemplate = WooCommerceSettings::getWooTemplate('mailjet_woocommerce_abandoned_cart');
- if (!$abandonedCartTemplate) {
+ if ( ! $abandonedCartTemplate) {
$wooCommerceSettings = WooCommerceSettings::getInstance();
- $templates = $wooCommerceSettings->createTemplates(\true, \false);
+ $templates = $wooCommerceSettings->createTemplates(\true, \false);
if ($templates) {
$abandonedCartTemplate = $templates['mailjet_woocommerce_abandoned_cart'];
}
}
$postUpdateMsg = Mailjet::getOption('mailjet_post_update_message');
- $wasActivated = \false;
- if (\is_array($postUpdateMsg) && !\is_null($postUpdateMsg['mjACWasActivated'])) {
+ $wasActivated = \false;
+ if (\is_array($postUpdateMsg) && ! \is_null($postUpdateMsg['mjACWasActivated'])) {
$wasActivated = Mailjet::getOption('mailjet_post_update_message')['mjACWasActivated'];
if ($wasActivated) {
update_option('mailjet_post_update_message', '');
@@ -47,23 +46,29 @@ public function mailjet_abandoned_cart_settings_page_html()
-
+
+ ?>
+
-
+
+ ?>
+
@@ -76,26 +81,34 @@ public function mailjet_abandoned_cart_settings_page_html()
-
+
+ ?>
+
-
+
+ ?>
+
@@ -104,9 +117,11 @@ public function mailjet_abandoned_cart_settings_page_html()
?>
@@ -119,36 +134,50 @@ public function mailjet_abandoned_cart_settings_page_html()
?>