diff --git a/.github/workflows/wpcs.yml b/.github/workflows/wpcs.yml new file mode 100644 index 00000000..299ec1b0 --- /dev/null +++ b/.github/workflows/wpcs.yml @@ -0,0 +1,28 @@ +name: Wordpress Basic Checks + +on: + push: + branches: + - '**' # matches every branch + - '!master' + +jobs: + phpcs: + name: WPCS + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: WPCS check + uses: 10up/wpcs-action@stable + with: + enable_warnings: false # Enable checking for warnings (-w) + paths: '.' # Paths to check, space separated + excludes: '' # Paths to excludes, space separated + standard: 'WordPress' # Standard to use. Accepts WordPress|WordPress-Core|WordPress-Docs|WordPress-Extra|WordPress-VIP-Go|WordPressVIPMinimum|10up-Default. + standard_repo: '' # Public (git) repository URL of the coding standard + repo_branch: 'master' # Branch of Standard repository + phpcs_bin_path: 'phpcs' # Custom PHPCS bin path + use_local_config: 'true' # Use local config if available + extra_args: '' # Extra arguments passing to the command + only_changed_files: '' # Run the linter only on the changed files. Accepts true|false + only_changed_lines: '' # Run the linter only on the changed lines. Accepts true|false \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f89147d..4e5a6a37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Changelog +##### 6.1.4 +- Fix issues in the input fields. Tested with new WP version + ##### 6.1.2 - Fix possible error when code switch websites and could leave website in a broken state diff --git a/README.md b/README.md index a43bc194..b0fa6f15 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ - Contributors: Mailjet - Tags: email, marketing, signup, newsletter, widget, smtp, woocommerce, contact form 7 - Requires at least: 4.4 -- Tested up to: 6.6.2 -- Stable tag: 6.1.3 +- Tested up to: 6.8.1 +- Stable tag: 6.1.4 - Requires PHP: 7.4 - License: GPLv2 or later - License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -162,6 +162,9 @@ find vendor/ -type d -name ".git" -exec rm -rf {} \; ## Changelog +##### 6.1.4 +- Fix issues in the input fields. Tested with new WP version + ##### 6.1.2 - Fix possible error when code switch websites and could leave website in a broken state diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 00000000..c9c6acb7 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,113 @@ + + + + The Coding standard for the WordPress Coding Standards itself. + + + . + + + */vendor/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/readme.txt b/readme.txt index 29c038bc..655c1009 100644 --- a/readme.txt +++ b/readme.txt @@ -3,8 +3,8 @@ - Contributors: Mailjet - Tags: email, marketing, signup, newsletter, widget, smtp, woocommerce, contact form 7 - Requires at least: 4.4 -- Tested up to: 6.6.2 -- Stable tag: 6.1.3 +- Tested up to: 6.8.1 +- Stable tag: 6.1.4 - Requires PHP: 7.4 - License: GPLv2 or later - License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -152,6 +152,9 @@ find vendor/ -type d -name ".git" -exec rm -rf {} \; == Changelog == += 6.1.4 = +- Fix issues in the input fields. Tested with new WP version + = 6.1.2 = - Fix possible error when code switch websites and could leave website in a broken state diff --git a/src/admin/MailjetAdmin.php b/src/admin/MailjetAdmin.php index daf0c67b..62f7ffc9 100644 --- a/src/admin/MailjetAdmin.php +++ b/src/admin/MailjetAdmin.php @@ -8,12 +8,13 @@ * The admin-specific functionality of the plugin. * Defines the plugin name, version, and two examples hooks for how to * enqueue the admin-specific stylesheet and JavaScript. + * * @package Mailjet * @subpackage Mailjet/admin * @author Your Name */ -class MailjetAdmin -{ +class MailjetAdmin { + /** * The ID of this plugin. * @@ -34,21 +35,19 @@ class MailjetAdmin * Initialize the class and set its properties. * * @since 5.0.0 - * @param string $plugin_name The name of this plugin. - * @param string $version The version of this plugin. + * @param string $plugin_name The name of this plugin. + * @param string $version The version of this plugin. */ - public function __construct($plugin_name, $version) - { + public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; - $this->version = $version; + $this->version = $version; } /** * Register the stylesheets for the admin area. * * @since 5.0.0 */ - public function enqueue_styles() - { + public function enqueue_styles() { /** * This function is provided for demonstration purposes only. * @@ -67,8 +66,7 @@ public function enqueue_styles() * * @since 5.0.0 */ - public function enqueue_scripts() - { + public function enqueue_scripts() { /** * This function is provided for demonstration purposes only. * @@ -80,6 +78,6 @@ public function enqueue_scripts() * between the defined hooks and the functions defined in this * class. */ - wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/mailjet-admin.js', array('jquery'), $this->version, \false); + wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/mailjet-admin.js', array( 'jquery' ), $this->version, \false); } } diff --git a/src/admin/partials/MailjetAdminDisplay.php b/src/admin/partials/MailjetAdminDisplay.php index 077ef92f..05063ece 100644 --- a/src/admin/partials/MailjetAdminDisplay.php +++ b/src/admin/partials/MailjetAdminDisplay.php @@ -15,20 +15,18 @@ * @package Mailjet * @subpackage Mailjet/admin/partials */ -class MailjetAdminDisplay -{ - private static $leftMenuFile = '/settingTemplates/SubscriptionSettingsPartials/leftMenu.php'; +class MailjetAdminDisplay { + + private static $leftMenuFile = '/settingTemplates/SubscriptionSettingsPartials/leftMenu.php'; private static $bottomLinksFile = '/bottomLinks.php'; - public static function getSettingsLeftMenu() - { - $currentPage = !empty($_REQUEST['page']) ? sanitize_text_field($_REQUEST['page']) : null; + public static function getSettingsLeftMenu() { + $currentPage = ! empty($_REQUEST['page']) ? sanitize_text_field($_REQUEST['page']) : null; set_query_var('currentPage', $currentPage); load_template(MAILJET_ADMIN_TAMPLATE_DIR . self::$leftMenuFile); } - public static function renderBottomLinks() - { + public static function renderBottomLinks() { $userGuideLink = Mailjeti18n::getMailjetUserGuideLinkByLocale(); - $supportLink = Mailjeti18n::getMailjetSupportLinkByLocale(); + $supportLink = Mailjeti18n::getMailjetSupportLinkByLocale(); set_query_var('supportLink', $supportLink); set_query_var('userGuideLink', $userGuideLink); load_template(MAILJET_ADMIN_TAMPLATE_DIR . self::$bottomLinksFile); diff --git a/src/front/MailjetPublic.php b/src/front/MailjetPublic.php index f45d99eb..27018d7f 100644 --- a/src/front/MailjetPublic.php +++ b/src/front/MailjetPublic.php @@ -14,8 +14,8 @@ * @subpackage Mailjet/public * @author Your Name */ -class MailjetPublic -{ +class MailjetPublic { + /** * The ID of this plugin. * @@ -36,21 +36,19 @@ class MailjetPublic * Initialize the class and set its properties. * * @since 5.0.0 - * @param string $plugin_name The name of the plugin. - * @param string $version The version of this plugin. + * @param string $plugin_name The name of the plugin. + * @param string $version The version of this plugin. */ - public function __construct($plugin_name, $version) - { + public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; - $this->version = $version; + $this->version = $version; } /** * Register the stylesheets for the public-facing side of the site. * * @since 5.0.0 */ - public function enqueue_styles() - { + public function enqueue_styles() { /** * This function is provided for demonstration purposes only. * @@ -62,15 +60,14 @@ public function enqueue_styles() * between the defined hooks and the functions defined in this * class. */ - // wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/mailjet-public.css', array(), $this->version, 'all' ); + // wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/mailjet-public.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the public-facing side of the site. * * @since 5.0.0 */ - public function enqueue_scripts() - { + public function enqueue_scripts() { /** * This function is provided for demonstration purposes only. * @@ -82,14 +79,14 @@ public function enqueue_scripts() * between the defined hooks and the functions defined in this * class. */ - // wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/mailjet-public.js', array( 'jquery' ), $this->version, false ); + // wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/mailjet-public.js', array( 'jquery' ), $this->version, false ); if (Mailjet::getOption('activate_mailjet_woo_integration') === '1' && Mailjet::getOption('mailjet_woo_abandoned_cart_activate') === '1') { global $wp; $currentUrl = \trim(home_url(add_query_arg(array(), $wp->request)), '/ '); // check current page is wc checkout page if ($currentUrl === \trim(get_permalink(wc_get_page_id('checkout')), '/ ')) { wp_enqueue_script('woocommerce_capture_guest', plugins_url('../front/js/woocommerce_capture_guest.js', __FILE__), '', '', \true); - wp_localize_script('woocommerce_capture_guest', 'woocommerce_capture_guest_params', array('ajax_url' => admin_url('admin-ajax.php'))); + wp_localize_script('woocommerce_capture_guest', 'woocommerce_capture_guest_params', array( 'ajax_url' => admin_url('admin-ajax.php') )); } } } diff --git a/src/includes/Mailjet.php b/src/includes/Mailjet.php index f0aea170..bad54cc8 100644 --- a/src/includes/Mailjet.php +++ b/src/includes/Mailjet.php @@ -22,8 +22,8 @@ * @subpackage Mailjet/includes * @author Your Name */ -class Mailjet -{ +class Mailjet { + /** * The loader that's responsible for maintaining and registering all hooks that power * the plugin. @@ -58,8 +58,7 @@ class Mailjet * * @since 5.0.0 */ - public function __construct() - { + public function __construct() { if (\defined('MAILJET_VERSION')) { $this->version = MAILJET_VERSION; } else { @@ -75,23 +74,22 @@ public function __construct() $this->addMailjetPHPMailer(); $this->registerMailjetWidget(); - add_shortcode('mailjet_form_builder', [$this, 'display_mailjet_form_builder_widget']); + add_shortcode('mailjet_form_builder', array( $this, 'display_mailjet_form_builder_widget' )); } /** - * @param array $attr + * @param array $attr * @param string $tag * @return false|string */ - public static function display_mailjet_form_builder_widget(array $attr = [], string $tag = '') - { - \extract(shortcode_atts(['widget_id' => null], $attr, $tag)); + public static function display_mailjet_form_builder_widget( array $attr = array(), string $tag = '' ) { + \extract(shortcode_atts(array( 'widget_id' => null ), $attr, $tag)); // GET All Mailjet widgets - to find the one that user actually configured with the shortcode - $instance = Mailjet::getOption('mailjet_form_builder_widget_options'); + $instance = self::getOption('mailjet_form_builder_widget_options'); // In case we don't have 'widget_id' attribute in the shortcode defined by user - we use the first widget id from the collection if (empty($widget_id)) { - $widgetIds = []; + $widgetIds = array(); foreach (array_keys($instance) as $key) { if (is_int($key)) { $widgetIds[] = $key; @@ -99,9 +97,13 @@ public static function display_mailjet_form_builder_widget(array $attr = [], str } $widget_id = min($widgetIds); } - ob_start(); - the_widget('MailjetWp\\MailjetPlugin\\WidgetFormBuilder\\WP_Mailjet_FormBuilder_Widget', $instance[(int)$widget_id]); - return ob_get_clean(); + if (isset($instance[ (int) $widget_id ])) { + ob_start(); + the_widget('MailjetWp\\MailjetPlugin\\WidgetFormBuilder\\WP_Mailjet_FormBuilder_Widget', $instance[ (int) $widget_id ]); + return ob_get_clean(); + } + + return false; } /** @@ -120,8 +122,7 @@ public static function display_mailjet_form_builder_widget(array $attr = [], str * @since 5.0.0 * @access private */ - private function load_dependencies() - { + private function load_dependencies() { $this->loader = new MailjetLoader(); } /** @@ -133,8 +134,7 @@ private function load_dependencies() * @since 5.0.0 * @access private */ - private function set_locale() - { + private function set_locale() { $plugin_i18n = new Mailjeti18n(); $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain'); } @@ -145,14 +145,13 @@ private function set_locale() * @since 1.0.0 * @access private */ - private function define_admin_hooks() - { + private function define_admin_hooks() { $plugin_admin = new MailjetAdmin($this->get_plugin_name(), $this->get_version()); $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); $this->loader->add_action('admin_post_user_access_settings_custom_hook', new UserAccessSettings(), 'user_access_post_handler'); $this->loader->add_action('admin_post_integrationsSettings_custom_hook', new IntegrationsSettings(), 'integrations_post_handler'); - if (Mailjet::getOption('activate_mailjet_woo_integration') == '1') { + if (self::getOption('activate_mailjet_woo_integration') == '1') { $this->addWoocommerceActions(); } } @@ -164,8 +163,7 @@ private function define_admin_hooks() * @since 5.0.0 * @access private */ - private function define_public_hooks() - { + private function define_public_hooks() { $plugin_public = new MailjetPublic($this->get_plugin_name(), $this->get_version()); $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles'); $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); @@ -174,8 +172,7 @@ private function define_public_hooks() /** * @return void */ - private function addMailjetMenu(): void - { + private function addMailjetMenu(): void { $plugin_menu = new MailjetMenu(); $this->loader->add_action('admin_menu', $plugin_menu, 'display_menu'); } @@ -183,8 +180,7 @@ private function addMailjetMenu(): void /** * @return void */ - private function addMailjetSettings(): void - { + private function addMailjetSettings(): void { $plugin_settings = new MailjetSettings(); $this->loader->add_action('admin_init', $plugin_settings, 'mailjet_settings_admin_init'); $this->loader->add_action('init', $plugin_settings, 'mailjet_settings_init'); @@ -193,8 +189,7 @@ private function addMailjetSettings(): void /** * @return void */ - private function addMailjetPHPMailer(): void - { + private function addMailjetPHPMailer(): void { $plugin_mails = new MailjetMail(); $this->loader->add_action('phpmailer_init', $plugin_mails, 'phpmailer_init_smtp'); $this->loader->add_action('wp_mail_failed', $plugin_mails, 'wp_mail_failed_cb'); @@ -203,16 +198,14 @@ private function addMailjetPHPMailer(): void /** * @return void */ - private function registerMailjetWidget(): void - { + private function registerMailjetWidget(): void { $this->loader->add_action('widgets_init', $this, 'wp_mailjet_register_widgets'); } /** * @return void */ - public function wp_mailjet_register_widgets() - { + public function wp_mailjet_register_widgets() { $widgetFormBuilder = 'MailjetWp\\MailjetPlugin\\WidgetFormBuilder\\WP_Mailjet_FormBuilder_Widget'; register_widget($widgetFormBuilder); } @@ -221,8 +214,7 @@ public function wp_mailjet_register_widgets() * * @since 5.0.0 */ - public function run(): void - { + public function run(): void { $this->loader->run(); } /** @@ -232,8 +224,7 @@ public function run(): void * @since 1.0.0 * @return string The name of the plugin. */ - public function get_plugin_name(): string - { + public function get_plugin_name(): string { return $this->plugin_name; } /** @@ -242,8 +233,7 @@ public function get_plugin_name(): string * @since 5.0.0 * @return Mailjet_Loader Orchestrates the hooks of the plugin. */ - public function get_loader() - { + public function get_loader() { return $this->loader; } /** @@ -252,33 +242,31 @@ public function get_loader() * @since 5.0.0 * @return string The version number of the plugin. */ - public function get_version(): string - { + public function get_version(): string { return $this->version; } /** * @return void */ - private function addWoocommerceActions(): void - { + private function addWoocommerceActions(): void { $wooCommerceSettings = WooCommerceSettings::getInstance(); if (isset($_POST['action']) && $_POST['action'] === 'order_notification_settings_custom_hook') { $wooCommerceSettings->orders_automation_settings_post(); } $this->loader->add_action('admin_post_abandoned_cart_settings_custom_hook', $wooCommerceSettings, 'abandoned_cart_settings_post'); - if (Mailjet::getOption('mailjet_woo_edata_sync') === '1') { + if (self::getOption('mailjet_woo_edata_sync') === '1') { $this->loader->add_action('woocommerce_order_status_changed', $wooCommerceSettings, 'order_edata_sync', 10, 1); $this->loader->add_action('woocommerce_cheque_process_payment_order_status', $wooCommerceSettings, 'paid_by_cheque_order_edata_sync', 10, 2); } - $activeActions = Mailjet::getOption('mailjet_wc_active_hooks'); - $abandonedCartActiveActions = Mailjet::getOption('mailjet_wc_abandoned_cart_active_hooks'); - if ($activeActions && !empty($activeActions)) { + $activeActions = self::getOption('mailjet_wc_active_hooks'); + $abandonedCartActiveActions = self::getOption('mailjet_wc_abandoned_cart_active_hooks'); + if ($activeActions && ! empty($activeActions)) { foreach ($activeActions as $action) { $this->loader->add_action($action['hook'], $wooCommerceSettings, $action['callable'], 10, 2); } } - if ($abandonedCartActiveActions && !empty($abandonedCartActiveActions)) { + if ($abandonedCartActiveActions && ! empty($abandonedCartActiveActions)) { foreach ($abandonedCartActiveActions as $action) { $this->loader->add_action($action['hook'], $wooCommerceSettings, $action['callable'], 10, 2); } @@ -289,25 +277,23 @@ private function addWoocommerceActions(): void * @param string $key * @return mixed */ - public static function getOption(string $key) - { - if (!is_multisite()) { + public static function getOption( string $key ) { + if ( ! is_multisite()) { return get_option($key); } $mainSiteId = get_main_network_id(); switch_to_blog($mainSiteId); - //If main site has multisite support enabled, we should use the main site options + // If main site has multisite support enabled, we should use the main site options if (get_option('mailjet_multisite_support') === 'on') { $optionValue = get_option($key); restore_current_blog(); return $optionValue; } - //If main site has multisite support disabled, we should use the current site options + // If main site has multisite support disabled, we should use the current site options restore_current_blog(); return get_option($key); } - } diff --git a/src/includes/MailjetActivator.php b/src/includes/MailjetActivator.php index dfd1c57e..4c3007d8 100644 --- a/src/includes/MailjetActivator.php +++ b/src/includes/MailjetActivator.php @@ -8,13 +8,12 @@ * Triggered on mailjet plugin activation * Check if server php version is higher enough */ -class MailjetActivator -{ - public function __construct() - { - add_action('admin_init', array($this, 'check_version')); +class MailjetActivator { + + public function __construct() { + add_action('admin_init', array( $this, 'check_version' )); // Don't run anything else in the plugin, if we're on an incompatible WordPress version - if (!self::compatible_version()) { + if ( ! self::compatible_version()) { return; } } @@ -22,8 +21,7 @@ public function __construct() /** * @return void */ - public function activation_settings(): void - { + public function activation_settings(): void { $adminRole = get_role('administrator'); if ($adminRole) { $adminRole->add_cap(UserAccessSettings::ACCESS_CAP_NAME, \true); @@ -34,12 +32,11 @@ public function activation_settings(): void * The primary sanity check, automatically disable the plugin on activation if it doesn't * meet minimum requirements. */ - public function activation_check(): void - { - if (!self::compatible_version()) { + public function activation_check(): void { + if ( ! self::compatible_version()) { deactivate_plugins(plugin_basename(__FILE__)); $phpVersion = \phpversion(); - $message = \sprintf(esc_html__('Mailjet for WordPress requires PHP 5.5 or later. Your server currently runs on PHP %s. Please upgrade your PHP and activate the plugin again.', 'mailjet-for-wordpress'), $phpVersion); + $message = \sprintf(esc_html__('Mailjet for WordPress requires PHP 5.5 or later. Your server currently runs on PHP %s. Please upgrade your PHP and activate the plugin again.', 'mailjet-for-wordpress'), $phpVersion); wp_die($message); } } @@ -47,12 +44,11 @@ public function activation_check(): void * The backup sanity check, in case the plugin is activated in a weird way, * or the versions change after activation. */ - public function check_version(): void - { - if (!self::compatible_version()) { + public function check_version(): void { + if ( ! self::compatible_version()) { if (is_plugin_active(plugin_basename(__FILE__))) { deactivate_plugins(plugin_basename(__FILE__)); - add_action('admin_notices', array($this, 'disabled_notice')); + add_action('admin_notices', array( $this, 'disabled_notice' )); if (isset($_GET['activate'])) { unset($_GET['activate']); } @@ -60,18 +56,16 @@ public function check_version(): void } } - public function disabled_notice(): void - { + public function disabled_notice(): void { $phpVersion = \phpversion(); - $message = \sprintf(esc_html__('Mailjet for WordPress requires PHP 5.5 or later. Your server currently runs on PHP %s. Please upgrade your PHP and activate the plugin again.', 'mailjet-for-wordpress'), $phpVersion); + $message = \sprintf(esc_html__('Mailjet for WordPress requires PHP 5.5 or later. Your server currently runs on PHP %s. Please upgrade your PHP and activate the plugin again.', 'mailjet-for-wordpress'), $phpVersion); echo '' . $message . ''; } /** * @return bool */ - public static function compatible_version(): bool - { + public static function compatible_version(): bool { $phpVersion = phpversion(); if (version_compare($phpVersion, '7.4', '<')) { return false; diff --git a/src/includes/MailjetApi.php b/src/includes/MailjetApi.php index afd34814..530db397 100644 --- a/src/includes/MailjetApi.php +++ b/src/includes/MailjetApi.php @@ -13,25 +13,25 @@ * Define the internationalization functionality. * Loads and defines the internationalization files for this plugin * so that it is ready for translation. + * * @since 5.0.0 * @package Mailjet * @subpackage Mailjet/includes * @author Your Name */ -class MailjetApi -{ +class MailjetApi { + private static $mjApiClient = null; /** * @return Client|null * @throws Exception */ - public static function getApiClient() - { + public static function getApiClient() { if (self::$mjApiClient instanceof Client) { return self::$mjApiClient; } - $mailjetApikey = Mailjet::getOption('mailjet_apikey'); + $mailjetApikey = Mailjet::getOption('mailjet_apikey'); $mailjetApiSecret = Mailjet::getOption('mailjet_apisecret'); if (empty($mailjetApikey) || empty($mailjetApiSecret)) { @@ -39,7 +39,7 @@ public static function getApiClient() } $mjClient = new Client($mailjetApikey, $mailjetApiSecret); $mjClient->addRequestOption(\CURLOPT_USERAGENT, 'wordpress-' . MAILJET_VERSION); - $mjClient->addRequestOption('headers', ['User-Agent' => 'wordpress-' . MAILJET_VERSION]); + $mjClient->addRequestOption('headers', array( 'User-Agent' => 'wordpress-' . MAILJET_VERSION )); // Add proxy options for guzzle requests - if the Wordpress site is configured to use Proxy if (\defined('WP_PROXY_HOST') && \defined('WP_PROXY_PORT') && \defined('WP_PROXY_USERNAME') && \defined('WP_PROXY_PASSWORD')) { $mjClient->addRequestOption(\CURLOPT_HTTPPROXYTUNNEL, 1); @@ -49,7 +49,7 @@ public static function getApiClient() $mjClient->addRequestOption(\CURLOPT_PROXYUSERPWD, WP_PROXY_USERNAME . ':' . WP_PROXY_PASSWORD); } // We turn of secure protocol for API requests if the wordpress does not support it - if (empty($_SERVER['HTTPS']) || !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'off' || $_SERVER['SERVER_PORT'] != 443) { + if (empty($_SERVER['HTTPS']) || ! empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'off' || $_SERVER['SERVER_PORT'] != 443) { $mjClient->setSecureProtocol(\false); } self::$mjApiClient = $mjClient; @@ -59,16 +59,18 @@ public static function getApiClient() /** * @return array|false */ - public static function getMailjetContactLists() - { + public static function getMailjetContactLists() { try { $mjApiClient = self::getApiClient(); } catch (Exception $e) { return false; } - $filters = ['Limit' => '0', 'Sort' => 'Name ASC']; + $filters = array( + 'Limit' => '0', + 'Sort' => 'Name ASC', + ); try { - $response = $mjApiClient->get(Resources::$Contactslist, ['filters' => $filters]); + $response = $mjApiClient->get(Resources::$Contactslist, array( 'filters' => $filters )); } catch (ConnectException $e) { return \false; } @@ -83,8 +85,7 @@ public static function getMailjetContactLists() * @param $listName * @return false|Response */ - public static function createMailjetContactList($listName) - { + public static function createMailjetContactList( $listName ) { if (empty($listName)) { return \false; } @@ -93,9 +94,9 @@ public static function createMailjetContactList($listName) } catch (Exception $e) { return \false; } - $body = ['Name' => $listName]; + $body = array( 'Name' => $listName ); try { - $response = $mjApiClient->post(Resources::$Contactslist, ['body' => $body]); + $response = $mjApiClient->post(Resources::$Contactslist, array( 'body' => $body )); } catch (ConnectException $e) { return \false; } @@ -106,8 +107,7 @@ public static function createMailjetContactList($listName) * @param $contactListId * @return array|false */ - public static function getContactListByID($contactListId) - { + public static function getContactListByID( $contactListId ) { if (empty($contactListId)) { return false; } @@ -116,9 +116,9 @@ public static function getContactListByID($contactListId) } catch (Exception $e) { return false; } - $filters = ['ID' => $contactListId]; + $filters = array( 'ID' => $contactListId ); try { - $response = $mjApiClient->get(Resources::$Contactslist, ['filters' => $filters]); + $response = $mjApiClient->get(Resources::$Contactslist, array( 'filters' => $filters )); } catch (ConnectException $e) { return false; } @@ -132,8 +132,7 @@ public static function getContactListByID($contactListId) * @param $contactListId * @return array|false */ - public static function getSubscribersFromList($contactListId) - { + public static function getSubscribersFromList( $contactListId ) { if (empty($contactListId)) { return \false; } @@ -142,13 +141,19 @@ public static function getSubscribersFromList($contactListId) } catch (Exception $e) { return \false; } - $limit = 1000; - $dataArray = []; - $offset = 0; + $limit = 1000; + $dataArray = array(); + $offset = 0; do { - $filters = ['ContactsList' => $contactListId, 'Unsub' => \false, 'Offset' => $offset, 'Limit' => $limit, 'Style' => 'Full']; + $filters = array( + 'ContactsList' => $contactListId, + 'Unsub' => \false, + 'Offset' => $offset, + 'Limit' => $limit, + 'Style' => 'Full', + ); try { - $response = $mjApiClient->get(Resources::$Listrecipient, ['filters' => $filters]); + $response = $mjApiClient->get(Resources::$Listrecipient, array( 'filters' => $filters )); } catch (ConnectException $e) { return \false; } @@ -165,16 +170,18 @@ public static function getSubscribersFromList($contactListId) /** * @return array|false */ - public static function getContactProperties() - { + public static function getContactProperties() { try { $mjApiClient = self::getApiClient(); } catch (Exception $e) { return \false; } - $filters = ['limit' => 0, 'Sort' => 'Name ASC']; + $filters = array( + 'limit' => 0, + 'Sort' => 'Name ASC', + ); try { - $response = $mjApiClient->get(Resources::$Contactmetadata, ['filters' => $filters]); + $response = $mjApiClient->get(Resources::$Contactmetadata, array( 'filters' => $filters )); } catch (ConnectException $e) { return \false; } @@ -190,8 +197,7 @@ public static function getContactProperties() * @param string $type * @return array|false */ - public static function createMailjetContactProperty($name, string $type = "str") - { + public static function createMailjetContactProperty( $name, string $type = 'str' ) { if (empty($name)) { return \false; } @@ -200,12 +206,16 @@ public static function createMailjetContactProperty($name, string $type = "str") } catch (Exception $e) { return \false; } - // Name: the name of the custom data field - // DataType: the type of data that is being stored (this can be either a str, int, float or bool) - // NameSpace: this can be either static or historic - $body = ['Datatype' => $type, 'Name' => $name, 'NameSpace' => "static"]; + // Name: the name of the custom data field + // DataType: the type of data that is being stored (this can be either a str, int, float or bool) + // NameSpace: this can be either static or historic + $body = array( + 'Datatype' => $type, + 'Name' => $name, + 'NameSpace' => 'static', + ); try { - $response = $mjApiClient->post(Resources::$Contactmetadata, ['body' => $body]); + $response = $mjApiClient->post(Resources::$Contactmetadata, array( 'body' => $body )); } catch (ConnectException $e) { return \false; } @@ -219,8 +229,7 @@ public static function createMailjetContactProperty($name, string $type = "str") /** * @return array|false */ - public static function getMailjetSegments() - { + public static function getMailjetSegments() { try { $mjApiClient = self::getApiClient(); } catch (Exception $e) { @@ -241,11 +250,10 @@ public static function getMailjetSegments() /** * @param $name * @param $expression - * @param string $description + * @param string $description * @return array|false */ - public static function createMailjetSegment($name, $expression, string $description = '') - { + public static function createMailjetSegment( $name, $expression, string $description = '' ) { if (empty($name) || empty($expression)) { return \false; } @@ -254,9 +262,13 @@ public static function createMailjetSegment($name, $expression, string $descript } catch (Exception $e) { return \false; } - $body = ['Description' => $description, 'Expression' => $expression, 'Name' => $name]; + $body = array( + 'Description' => $description, + 'Expression' => $expression, + 'Name' => $name, + ); try { - $response = $mjApiClient->post(Resources::$Contactfilter, ['body' => $body]); + $response = $mjApiClient->post(Resources::$Contactfilter, array( 'body' => $body )); } catch (ConnectException $e) { return \false; } @@ -270,16 +282,18 @@ public static function createMailjetSegment($name, $expression, string $descript /** * @return array|bool */ - public static function getMailjetSenders() - { + public static function getMailjetSenders() { try { $mjApiClient = self::getApiClient(); } catch (Exception $e) { return false; } - $filters = ['Limit' => '0', 'Sort' => 'ID DESC']; + $filters = array( + 'Limit' => '0', + 'Sort' => 'ID DESC', + ); try { - $response = $mjApiClient->get(Resources::$Sender, ['filters' => $filters]); + $response = $mjApiClient->get(Resources::$Sender, array( 'filters' => $filters )); } catch (ConnectException $e) { return false; } @@ -293,8 +307,7 @@ public static function getMailjetSenders() /** * @return bool */ - public static function isValidAPICredentials(): bool - { + public static function isValidAPICredentials(): bool { try { $mjApiClient = self::getApiClient(); if ($mjApiClient === null) { @@ -303,9 +316,9 @@ public static function isValidAPICredentials(): bool } catch (Exception $e) { return false; } - $filters = ['Limit' => '1']; + $filters = array( 'Limit' => '1' ); try { - $response = $mjApiClient->get(Resources::$Contactmetadata, ['filters' => $filters]); + $response = $mjApiClient->get(Resources::$Contactmetadata, array( 'filters' => $filters )); } catch (ConnectException $e) { return false; } catch (RequestException $exception) { @@ -320,21 +333,30 @@ public static function isValidAPICredentials(): bool /** * Add or Remove a contact to a Mailjet contact list - It can process many or single contact at once + * * @param $contactListId - int - ID of the contact list to sync contacts * @param $contacts - array('Email' => ContactEmail, 'Name' => ContactName, 'Properties' => array(propertyName1 => propertyValue1, ...)); - * @param string $action - 'addforce', 'adnoforce', 'remove' + * @param string $action - 'addforce', 'adnoforce', 'remove' * @return array|bool */ - public static function syncMailjetContacts($contactListId, $contacts, $action = 'addforce') - { + public static function syncMailjetContacts( $contactListId, $contacts, $action = 'addforce' ) { try { $mjApiClient = self::getApiClient(); } catch (Exception $e) { return \false; } - $body = ['Action' => $action, 'Contacts' => $contacts]; + $body = array( + 'Action' => $action, + 'Contacts' => $contacts, + ); try { - $response = $mjApiClient->post(Resources::$ContactslistManagemanycontacts, ['id' => $contactListId, 'body' => $body]); + $response = $mjApiClient->post( + Resources::$ContactslistManagemanycontacts, + array( + 'id' => $contactListId, + 'body' => $body, + ) + ); } catch (ConnectException $e) { return \false; } @@ -348,8 +370,7 @@ public static function syncMailjetContacts($contactListId, $contacts, $action = /** * Add a contact to a Mailjet contact list */ - public static function syncMailjetContact($contactListId, $contact, $action = 'addforce') - { + public static function syncMailjetContact( $contactListId, $contact, $action = 'addforce' ) { try { $mjApiClient = self::getApiClient(); } catch (Exception $e) { @@ -359,9 +380,20 @@ public static function syncMailjetContact($contactListId, $contact, $action = 'a if (isset($contact['Properties'])) { $name = $contact['Properties']['firstname'] ?? ''; } - $body = ['Name' => $name, 'Action' => $action, 'Email' => $contact['Email'], 'Properties' => $contact['Properties'] ?? []]; - try { - $response = $mjApiClient->post(Resources::$ContactslistManagecontact, ['id' => $contactListId, 'body' => $body]); + $body = array( + 'Name' => $name, + 'Action' => $action, + 'Email' => $contact['Email'], + 'Properties' => $contact['Properties'] ?? array(), + ); + try { + $response = $mjApiClient->post( + Resources::$ContactslistManagecontact, + array( + 'id' => $contactListId, + 'body' => $body, + ) + ); } catch (ConnectException $e) { return \false; } @@ -374,30 +406,33 @@ public static function syncMailjetContact($contactListId, $contact, $action = 'a /** * Return TRUE if a contact already subscribed to the list and FALSE if it is not, or is added to the list but Unsubscribed + * * @param $email * @param $listId - * @param bool $getContactId + * @param bool $getContactId * @return bool */ - public static function checkContactSubscribedToList($email, $listId, $getContactId = \false) - { - $exists = \false; + public static function checkContactSubscribedToList( $email, $listId, $getContactId = \false ) { + $exists = \false; $existsAndSubscribed = \false; try { $mjApiClient = self::getApiClient(); } catch (Exception $e) { return \false; } - $filters = ['ContactEmail' => $email, 'ContactsList' => $listId]; + $filters = array( + 'ContactEmail' => $email, + 'ContactsList' => $listId, + ); try { - $response = $mjApiClient->get(Resources::$Listrecipient, ['filters' => $filters]); + $response = $mjApiClient->get(Resources::$Listrecipient, array( 'filters' => $filters )); } catch (ConnectException $e) { return \false; } if ($response->success() && $response->getCount() > 0) { - $data = $response->getData(); + $data = $response->getData(); $exists = true; - if (isset($data[0]['IsUnsubscribed']) && !$data[0]['IsUnsubscribed']) { + if (isset($data[0]['IsUnsubscribed']) && ! $data[0]['IsUnsubscribed']) { $existsAndSubscribed = \true; } if ($getContactId && $exists && $existsAndSubscribed) { @@ -410,12 +445,14 @@ public static function checkContactSubscribedToList($email, $listId, $getContact /** * @throws Exception */ - public static function isContactInList($email, $listId, $getContactId = \false) - { + public static function isContactInList( $email, $listId, $getContactId = \false ) { $mjApiClient = self::getApiClient(); - $filters = ['ContactEmail' => $email, 'ContactsList' => $listId]; - $response = $mjApiClient->get(Resources::$Listrecipient, ['filters' => $filters]); - if (!$response->success() || $response->getCount() <= 0) { + $filters = array( + 'ContactEmail' => $email, + 'ContactsList' => $listId, + ); + $response = $mjApiClient->get(Resources::$Listrecipient, array( 'filters' => $filters )); + if ( ! $response->success() || $response->getCount() <= 0) { return \false; } $data = $response->getData(); @@ -428,29 +465,27 @@ public static function isContactInList($email, $listId, $getContactId = \false) /** * @throws Exception */ - public static function updateContactData($contactEmail, $data) - { + public static function updateContactData( $contactEmail, $data ) { $mjApiClient = self::getApiClient(); - $body = ['Data' => $data ?? []]; - return $mjApiClient->put(['contactdata', $contactEmail], ['body' => $body]); + $body = array( 'Data' => $data ?? array() ); + return $mjApiClient->put(array( 'contactdata', $contactEmail ), array( 'body' => $body )); } /** * @return false|string */ - public static function getProfileName() - { + public static function getProfileName() { try { $mjApiClient = self::getApiClient(); } catch (Exception $e) { return \false; } try { - $response = $mjApiClient->get(Resources::$Myprofile, []); + $response = $mjApiClient->get(Resources::$Myprofile, array()); } catch (ConnectException $e) { return \false; } - $name = ""; + $name = ''; if ($response->success() && $response->getCount() > 0) { $data = $response->getData(); if (isset($data[0]['Firstname']) && isset($data[0]['Lastname'])) { @@ -464,15 +499,14 @@ public static function getProfileName() * @param $templateName * @return false|mixed */ - public static function getTemplateByName($templateName) - { + public static function getTemplateByName( $templateName ) { try { $mjApiClient = self::getApiClient(); } catch (Exception $e) { return false; } try { - $response = $mjApiClient->get(Resources::$Template, ['id' => 'apikey|' . $templateName]); + $response = $mjApiClient->get(Resources::$Template, array( 'id' => 'apikey|' . $templateName )); } catch (ConnectException $e) { return false; } @@ -487,15 +521,14 @@ public static function getTemplateByName($templateName) * @param $id * @return false|mixed */ - public static function getTemplateDetails($id) - { + public static function getTemplateDetails( $id ) { try { $mjApiClient = self::getApiClient(); } catch (Exception $e) { return \false; } try { - $response = $mjApiClient->get(Resources::$TemplateDetailcontent, ['id' => $id]); + $response = $mjApiClient->get(Resources::$TemplateDetailcontent, array( 'id' => $id )); } catch (ConnectException $e) { return \false; } @@ -510,8 +543,7 @@ public static function getTemplateDetails($id) * @param array $arguments * @return false|mixed */ - public static function createTemplate(array $arguments) - { + public static function createTemplate( array $arguments ) { try { $mjApiClient = self::getApiClient(); } catch (Exception $e) { @@ -537,8 +569,7 @@ public static function createTemplate(array $arguments) * @param array $content * @return array|false */ - public static function createTemplateContent(array $content) - { + public static function createTemplateContent( array $content ) { try { $mjApiClient = self::getApiClient(); } catch (Exception $e) { @@ -559,17 +590,16 @@ public static function createTemplateContent(array $content) * @param $content * @return array|false */ - public static function sendEmail($content) - { + public static function sendEmail( $content ) { try { $mjApiClient = self::getApiClient(); } catch (Exception $e) { return \false; } - $body = ['Messages' => [$content]]; + $body = array( 'Messages' => array( $content ) ); try { - $response = $mjApiClient->post(Resources::$Email, ['body' => $body], ['version' => 'v3.1']); + $response = $mjApiClient->post(Resources::$Email, array( 'body' => $body ), array( 'version' => 'v3.1' )); } catch (ConnectException $e) { return \false; } diff --git a/src/includes/MailjetDeactivator.php b/src/includes/MailjetDeactivator.php index 6b433c3d..6a5e30d3 100644 --- a/src/includes/MailjetDeactivator.php +++ b/src/includes/MailjetDeactivator.php @@ -11,13 +11,12 @@ * @package Mailjet * @subpackage Mailjet/includes */ -class MailjetDeactivator -{ +class MailjetDeactivator { + /** * @return void */ - public function deactivate() - { + public function deactivate() { $timestamp = wp_next_scheduled('bl_cron_hook'); wp_unschedule_event($timestamp, 'bl_cron_hook'); update_option('mailjet_woo_abandoned_cart_activate', 0); diff --git a/src/includes/MailjetLoader.php b/src/includes/MailjetLoader.php index f80f8b39..6d86749d 100644 --- a/src/includes/MailjetLoader.php +++ b/src/includes/MailjetLoader.php @@ -13,8 +13,8 @@ * @subpackage Mailjet/includes * @author Your Name */ -class MailjetLoader -{ +class MailjetLoader { + /** * The array of actions registered with WordPress. * @@ -36,37 +36,34 @@ class MailjetLoader * * @since 5.0.0 */ - public function __construct() - { - $this->actions = []; - $this->filters = []; + public function __construct() { + $this->actions = array(); + $this->filters = array(); } /** * Add a new action to the collection to be registered with WordPress. * * @since 5.0.0 - * @param string $hook The name of the WordPress action that is being registered. - * @param object $component A reference to the instance of the object on which the action is defined. - * @param string $callback The name of the function definition on the $component. - * @param int $priority Optional. The priority at which the function should be fired. Default is 10. - * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. + * @param string $hook The name of the WordPress action that is being registered. + * @param object $component A reference to the instance of the object on which the action is defined. + * @param string $callback The name of the function definition on the $component. + * @param int $priority Optional. The priority at which the function should be fired. Default is 10. + * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. */ - public function add_action($hook, $component, $callback, $priority = 10, $accepted_args = 1) - { + public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { $this->actions = $this->add($this->actions, $hook, $component, $callback, $priority, $accepted_args); } /** * Add a new filter to the collection to be registered with WordPress. * * @since 5.0.0 - * @param string $hook The name of the WordPress filter that is being registered. - * @param object $component A reference to the instance of the object on which the filter is defined. - * @param string $callback The name of the function definition on the $component. - * @param int $priority Optional. The priority at which the function should be fired. Default is 10. - * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1 + * @param string $hook The name of the WordPress filter that is being registered. + * @param object $component A reference to the instance of the object on which the filter is defined. + * @param string $callback The name of the function definition on the $component. + * @param int $priority Optional. The priority at which the function should be fired. Default is 10. + * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1 */ - public function add_filter($hook, $component, $callback, $priority = 10, $accepted_args = 1) - { + public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { $this->filters = $this->add($this->filters, $hook, $component, $callback, $priority, $accepted_args); } /** @@ -75,17 +72,22 @@ public function add_filter($hook, $component, $callback, $priority = 10, $accept * * @since 5.0.0 * @access private - * @param array $hooks The collection of hooks that is being registered (that is, actions or filters). - * @param string $hook The name of the WordPress filter that is being registered. - * @param object $component A reference to the instance of the object on which the filter is defined. - * @param string $callback The name of the function definition on the $component. - * @param int $priority The priority at which the function should be fired. - * @param int $accepted_args The number of arguments that should be passed to the $callback. + * @param array $hooks The collection of hooks that is being registered (that is, actions or filters). + * @param string $hook The name of the WordPress filter that is being registered. + * @param object $component A reference to the instance of the object on which the filter is defined. + * @param string $callback The name of the function definition on the $component. + * @param int $priority The priority at which the function should be fired. + * @param int $accepted_args The number of arguments that should be passed to the $callback. * @return array The collection of actions and filters registered with WordPress. */ - private function add($hooks, $hook, $component, $callback, $priority, $accepted_args) - { - $hooks[] = ['hook' => $hook, 'component' => $component, 'callback' => $callback, 'priority' => $priority, 'accepted_args' => $accepted_args]; + private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { + $hooks[] = array( + 'hook' => $hook, + 'component' => $component, + 'callback' => $callback, + 'priority' => $priority, + 'accepted_args' => $accepted_args, + ); return $hooks; } /** @@ -93,13 +95,12 @@ private function add($hooks, $hook, $component, $callback, $priority, $accepted_ * * @since 5.0.0 */ - public function run() - { + public function run() { foreach ($this->filters as $hook) { - add_filter($hook['hook'], [$hook['component'], $hook['callback']], $hook['priority'], $hook['accepted_args']); + add_filter($hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args']); } foreach ($this->actions as $hook) { - add_action($hook['hook'], [$hook['component'], $hook['callback']], $hook['priority'], $hook['accepted_args']); + add_action($hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args']); } } } diff --git a/src/includes/MailjetLogger.php b/src/includes/MailjetLogger.php index 1a509d1c..38213595 100644 --- a/src/includes/MailjetLogger.php +++ b/src/includes/MailjetLogger.php @@ -4,66 +4,58 @@ use MailjetWp\Analog\Analog; -class MailjetLogger -{ - public static function log($message, $level = null) - { +class MailjetLogger { + + public static function log( $message, $level = null ) { $mailjetActivateLogger = Mailjet::getOption('mailjet_activate_logger'); if (empty($mailjetActivateLogger) || $mailjetActivateLogger != 1) { return ''; } return Analog::log($message, $level); } - public static function urgent($message) - { + public static function urgent( $message ) { $mailjetActivateLogger = Mailjet::getOption('mailjet_activate_logger'); if (empty($mailjetActivateLogger) || $mailjetActivateLogger != 1) { return ''; } return Analog::urgent($message); } - public static function alert($message) - { + public static function alert( $message ) { $mailjetActivateLogger = Mailjet::getOption('mailjet_activate_logger'); if (empty($mailjetActivateLogger) || $mailjetActivateLogger != 1) { return ''; } return Analog::alert($message); } - public static function error($message) - { + public static function error( $message ) { $mailjetActivateLogger = Mailjet::getOption('mailjet_activate_logger'); if (empty($mailjetActivateLogger) || $mailjetActivateLogger != 1) { return ''; } return Analog::error($message); } - public static function warning($message) - { + public static function warning( $message ) { $mailjetActivateLogger = Mailjet::getOption('mailjet_activate_logger'); if (empty($mailjetActivateLogger) || $mailjetActivateLogger != 1) { return ''; } return Analog::warning($message); } - public static function notice($message) - { + public static function notice( $message ) { $mailjetActivateLogger = Mailjet::getOption('mailjet_activate_logger'); if (empty($mailjetActivateLogger) || $mailjetActivateLogger != 1) { return ''; } return Analog::notice($message); } - public static function info($message) - { + public static function info( $message ) { $mailjetActivateLogger = Mailjet::getOption('mailjet_activate_logger'); if (empty($mailjetActivateLogger) || $mailjetActivateLogger != 1) { return ''; } return Analog::info($message); } - public static function debug($message) - { + public static function debug( $message ) { $mailjetActivateLogger = Mailjet::getOption('mailjet_activate_logger'); if (empty($mailjetActivateLogger) || $mailjetActivateLogger != 1) { return ''; diff --git a/src/includes/MailjetMail.php b/src/includes/MailjetMail.php index efec0465..c2c957c5 100644 --- a/src/includes/MailjetMail.php +++ b/src/includes/MailjetMail.php @@ -13,12 +13,11 @@ * @subpackage Mailjet/includes * @author Your Name */ -class MailjetMail -{ - public const MJ_HOST = 'in-v3.mailjet.com'; +class MailjetMail { + + public const MJ_HOST = 'in-v3.mailjet.com'; public const MJ_MAILER = 'X-Mailer:WP-Mailjet/0.1'; - public function __construct() - { + public function __construct() { if (\version_compare(get_bloginfo('version'), '5.5-alpha', '<')) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; require_once ABSPATH . WPINC . '/class-smtp.php'; @@ -27,36 +26,33 @@ public function __construct() require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php'; } } - public function phpmailer_init_smtp($phpmailer) - { - if (!Mailjet::getOption('mailjet_enabled') || 0 === (int)Mailjet::getOption('mailjet_enabled')) { + public function phpmailer_init_smtp( $phpmailer ) { + if ( ! Mailjet::getOption('mailjet_enabled') || 0 === (int) Mailjet::getOption('mailjet_enabled')) { return; } - $phpmailer->Mailer = 'smtp'; + $phpmailer->Mailer = 'smtp'; $phpmailer->SMTPSecure = Mailjet::getOption('mailjet_ssl'); - $phpmailer->Host = self::MJ_HOST; - $phpmailer->Port = Mailjet::getOption('mailjet_port'); - $phpmailer->SMTPAuth = \TRUE; - $phpmailer->Username = Mailjet::getOption('mailjet_apikey'); - $phpmailer->Password = Mailjet::getOption('mailjet_apisecret'); - $from_email = Mailjet::getOption('mailjet_from_email') ? Mailjet::getOption('mailjet_from_email') : Mailjet::getOption('admin_email'); - $phpmailer->From = $from_email; - $phpmailer->Sender = $from_email; - $phpmailer->FromName = Mailjet::getOption('mailjet_from_name') ? Mailjet::getOption('mailjet_from_name') : get_bloginfo('name'); + $phpmailer->Host = self::MJ_HOST; + $phpmailer->Port = Mailjet::getOption('mailjet_port'); + $phpmailer->SMTPAuth = \TRUE; + $phpmailer->Username = Mailjet::getOption('mailjet_apikey'); + $phpmailer->Password = Mailjet::getOption('mailjet_apisecret'); + $from_email = Mailjet::getOption('mailjet_from_email') ? Mailjet::getOption('mailjet_from_email') : Mailjet::getOption('admin_email'); + $phpmailer->From = $from_email; + $phpmailer->Sender = $from_email; + $phpmailer->FromName = Mailjet::getOption('mailjet_from_name') ? Mailjet::getOption('mailjet_from_name') : get_bloginfo('name'); $phpmailer->AddCustomHeader(self::MJ_MAILER); } - public function wp_mail_failed_cb($wpError) - { - add_action('admin_notices', array($this, 'wp_mail_failed_admin_notice')); - if (!Mailjet::getOption('mailjet_enabled')) { + public function wp_mail_failed_cb( $wpError ) { + add_action('admin_notices', array( $this, 'wp_mail_failed_admin_notice' )); + if ( ! Mailjet::getOption('mailjet_enabled')) { return \false; } if (\function_exists('MailjetWp\\add_settings_error')) { add_settings_error('mailjet_messages', 'mailjet_message', 'ERROR - ' . $wpError->get_error_message(), 'error'); } } - public function wp_mail_failed_admin_notice() - { + public function wp_mail_failed_admin_notice() { global $pagenow; if ($pagenow === 'index.php') { $user = wp_get_current_user(); @@ -65,29 +61,25 @@ public function wp_mail_failed_admin_notice() } } } - public static function sendTestEmail() - { - $testSent = \false; + public static function sendTestEmail() { + $testSent = \false; $mailjetTestAddress = Mailjet::getOption('mailjet_test_address'); if (empty($mailjetTestAddress)) { return $testSent; } // Send a test mail - add_filter('wp_mail_content_type', ['MailjetWp\\MailjetPlugin\\Includes\\MailjetMail', 'set_html_content_type']); + add_filter('wp_mail_content_type', array( 'MailjetWp\\MailjetPlugin\\Includes\\MailjetMail', 'set_html_content_type' )); $subject = __('Your test mail from Mailjet', 'mailjet-for-wordpress'); $message = \sprintf(__('Your Mailjet configuration is ok!
Site URL: %s
SSL: %s
Port: %s', 'mailjet-for-wordpress'), get_home_url(), Mailjet::getOption('mailjet_ssl') ? 'On' : 'Off', Mailjet::getOption('mailjet_port')); return wp_mail(Mailjet::getOption('mailjet_test_address'), $subject, $message); } - public static function set_html_content_type() - { + public static function set_html_content_type() { return 'text/html'; } - public function wp_sender_email($original_email_address) - { + public function wp_sender_email( $original_email_address ) { return Mailjet::getOption('mailjet_from_email'); } - public function wp_sender_name($original_email_from) - { + public function wp_sender_name( $original_email_from ) { return Mailjet::getOption('mailjet_from_name'); } } diff --git a/src/includes/MailjetMenu.php b/src/includes/MailjetMenu.php index 584fb781..34768c0b 100644 --- a/src/includes/MailjetMenu.php +++ b/src/includes/MailjetMenu.php @@ -22,41 +22,42 @@ * Maintain a list of all hooks that are registered throughout * the plugin, and register them with the WordPress API. Call the * run function to execute the list of actions and filters. + * * @package Mailjet * @subpackage Mailjet/includes * @author Your Name */ -class MailjetMenu -{ +class MailjetMenu { + /** * Register the filters and actions with WordPress. + * * @since 5.0.0 */ - public function display_menu() - { + public function display_menu() { if (current_user_can(UserAccessSettings::ACCESS_CAP_NAME)) { - add_menu_page(__('Connect your Mailjet account to get started', 'mailjet-for-wordpress'), 'Mailjet', 'read', 'mailjet_settings_page', [new InitialSettings(), 'mailjet_initial_settings_page_html'], plugin_dir_url(__DIR__) . 'admin/images/mj_logo_small.png'); + add_menu_page(__('Connect your Mailjet account to get started', 'mailjet-for-wordpress'), 'Mailjet', 'read', 'mailjet_settings_page', array( new InitialSettings(), 'mailjet_initial_settings_page_html' ), plugin_dir_url(__DIR__) . 'admin/images/mj_logo_small.png'); if (\function_exists('add_submenu_page')) { - add_submenu_page('', __('Manage your Mailjet lists', 'mailjet-for-wordpress'), __('Lists', 'mailjet-for-wordpress'), 'read', 'mailjet_settings_contacts_menu', [$this, 'show_contacts_page']); - add_submenu_page('', __('Manage your Mailjet campaigns', 'mailjet-for-wordpress'), __('Campaigns', 'mailjet-for-wordpress'), 'read', 'mailjet_settings_campaigns_menu', [$this, 'show_campaigns_page']); - add_submenu_page('', __('View your Mailjet statistics', 'mailjet-for-wordpress'), __('Statistics', 'mailjet-for-wordpress'), 'read', 'mailjet_settings_stats_menu', [$this, 'show_stats_page']); - add_submenu_page('', __('View your Mailjet template', 'mailjet-for-wordpress'), __('Template', 'mailjet-for-wordpress'), 'read', 'mailjet_template', [$this, 'show_template_page']); + add_submenu_page('', __('Manage your Mailjet lists', 'mailjet-for-wordpress'), __('Lists', 'mailjet-for-wordpress'), 'read', 'mailjet_settings_contacts_menu', array( $this, 'show_contacts_page' )); + add_submenu_page('', __('Manage your Mailjet campaigns', 'mailjet-for-wordpress'), __('Campaigns', 'mailjet-for-wordpress'), 'read', 'mailjet_settings_campaigns_menu', array( $this, 'show_campaigns_page' )); + add_submenu_page('', __('View your Mailjet statistics', 'mailjet-for-wordpress'), __('Statistics', 'mailjet-for-wordpress'), 'read', 'mailjet_settings_stats_menu', array( $this, 'show_stats_page' )); + add_submenu_page('', __('View your Mailjet template', 'mailjet-for-wordpress'), __('Template', 'mailjet-for-wordpress'), 'read', 'mailjet_template', array( $this, 'show_template_page' )); // Initial configuration pages - add_submenu_page('', __('Configure your lists.', 'mailjet-for-wordpress'), null, 'read', 'mailjet_initial_contact_lists_page', [new InitialContactListsSettings(), 'mailjet_initial_contact_lists_page_html']); + add_submenu_page('', __('Configure your lists.', 'mailjet-for-wordpress'), null, 'read', 'mailjet_initial_contact_lists_page', array( new InitialContactListsSettings(), 'mailjet_initial_contact_lists_page_html' )); // All Setup page - add_submenu_page('', __('You\'re all set up!', 'mailjet-for-wordpress'), null, 'read', 'mailjet_allsetup_page', [new AllSetup(), 'mailjet_allsetup_page_html']); + add_submenu_page('', __('You\'re all set up!', 'mailjet-for-wordpress'), null, 'read', 'mailjet_allsetup_page', array( new AllSetup(), 'mailjet_allsetup_page_html' )); // Dashboard page - add_submenu_page('', __('Welcome to the Mailjet plugin for WordPress', 'mailjet-for-wordpress'), null, 'read', 'mailjet_dashboard_page', [new Dashboard(), 'mailjet_dashboard_page_html']); + add_submenu_page('', __('Welcome to the Mailjet plugin for WordPress', 'mailjet-for-wordpress'), null, 'read', 'mailjet_dashboard_page', array( new Dashboard(), 'mailjet_dashboard_page_html' )); // Order Notification page - add_submenu_page('', __('Welcome to the Mailjet plugin for WordPress', 'mailjet-for-wordpress'), null, 'read', 'mailjet_order_notifications_page', [new OrderNotificationsSettings(), 'mailjet_order_notifications_settings_page_html']); + add_submenu_page('', __('Welcome to the Mailjet plugin for WordPress', 'mailjet-for-wordpress'), null, 'read', 'mailjet_order_notifications_page', array( new OrderNotificationsSettings(), 'mailjet_order_notifications_settings_page_html' )); // Abandoned Cart page - add_submenu_page('', __('Welcome to the Mailjet plugin for WordPress', 'mailjet-for-wordpress'), null, 'read', 'mailjet_abandoned_cart_page', [new AbandonedCartSettings(), 'mailjet_abandoned_cart_settings_page_html']); + add_submenu_page('', __('Welcome to the Mailjet plugin for WordPress', 'mailjet-for-wordpress'), null, 'read', 'mailjet_abandoned_cart_page', array( new AbandonedCartSettings(), 'mailjet_abandoned_cart_settings_page_html' )); // Settings pages - add_submenu_page('', __('Connect your Mailjet account', 'mailjet-for-wordpress'), null, 'read', 'mailjet_connect_account_page', [new ConnectAccountSettings(), 'mailjet_connect_account_page_html']); - add_submenu_page('', __('Sending settings', 'mailjet-for-wordpress'), null, 'read', 'mailjet_sending_settings_page', [new EnableSendingSettings(), 'mailjet_sending_settings_page_html']); - add_submenu_page('', __('Subscription options', 'mailjet-for-wordpress'), null, 'read', 'mailjet_subscription_options_page', [SubscriptionOptionsSettings::getInstance(), 'mailjet_subscription_options_page_html']); - add_submenu_page('', __('User access', 'mailjet-for-wordpress'), null, 'read', 'mailjet_user_access_page', [new UserAccessSettings(), 'mailjet_user_access_page_html']); - add_submenu_page('', __('Integrations', 'mailjet-for-wordpress'), null, 'read', 'mailjet_integrations_page', [new IntegrationsSettings(), 'mailjet_integrations_page_html']); + add_submenu_page('', __('Connect your Mailjet account', 'mailjet-for-wordpress'), null, 'read', 'mailjet_connect_account_page', array( new ConnectAccountSettings(), 'mailjet_connect_account_page_html' )); + add_submenu_page('', __('Sending settings', 'mailjet-for-wordpress'), null, 'read', 'mailjet_sending_settings_page', array( new EnableSendingSettings(), 'mailjet_sending_settings_page_html' )); + add_submenu_page('', __('Subscription options', 'mailjet-for-wordpress'), null, 'read', 'mailjet_subscription_options_page', array( SubscriptionOptionsSettings::getInstance(), 'mailjet_subscription_options_page_html' )); + add_submenu_page('', __('User access', 'mailjet-for-wordpress'), null, 'read', 'mailjet_user_access_page', array( new UserAccessSettings(), 'mailjet_user_access_page_html' )); + add_submenu_page('', __('Integrations', 'mailjet-for-wordpress'), null, 'read', 'mailjet_integrations_page', array( new IntegrationsSettings(), 'mailjet_integrations_page_html' )); // Add old initial page to fix settings link after update } } else { @@ -64,8 +65,7 @@ public function display_menu() } } - public function wp_mailjet_options_top() - { + public function wp_mailjet_options_top() { // Redirect to current initial page MailjetSettings::redirectJs(admin_url('/admin.php?page=mailjet_settings_page&from=plugins')); } @@ -74,56 +74,56 @@ public function wp_mailjet_options_top() * @return MailjetIframe * @throws MailjetException */ - private function getMailjetIframe(): MailjetIframe - { - $mailjetApikey = Mailjet::getOption('mailjet_apikey'); + private function getMailjetIframe(): MailjetIframe { + $mailjetApikey = Mailjet::getOption('mailjet_apikey'); $mailjetApiSecret = Mailjet::getOption('mailjet_apisecret'); - $mailjetIframe = new MailjetIframe($mailjetApikey, $mailjetApiSecret, \false); - $mailjetIframe->setCallback('')->setTokenExpiration(600)->setLocale($this->get_locale())->setTokenAccess(['campaigns', 'contacts', 'stats', 'transactional'])->turnDocumentationProperties(MailjetIframe::OFF)->turnNewContactListCreation(MailjetIframe::ON)->turnMenu(MailjetIframe::ON)->turnFooter(MailjetIframe::ON)->turnBar(MailjetIframe::ON)->turnCreateCampaignButton(MailjetIframe::ON)->turnSendingPolicy(MailjetIframe::ON); + $mailjetIframe = new MailjetIframe($mailjetApikey, $mailjetApiSecret, \false); + $mailjetIframe->setCallback('')->setTokenExpiration(600)->setLocale($this->get_locale())->setTokenAccess(array( 'campaigns', 'contacts', 'stats', 'transactional' ))->turnDocumentationProperties(MailjetIframe::OFF)->turnNewContactListCreation(MailjetIframe::ON)->turnMenu(MailjetIframe::ON)->turnFooter(MailjetIframe::ON)->turnBar(MailjetIframe::ON)->turnCreateCampaignButton(MailjetIframe::ON)->turnSendingPolicy(MailjetIframe::ON); return $mailjetIframe; } /** * This method returns the current locale of the wordpress' user */ - private function get_locale() - { + private function get_locale() { $locale = get_locale(); - if (\in_array($locale, ['de_DE', 'de_DE_formal'])) { + if (\in_array($locale, array( 'de_DE', 'de_DE_formal' ))) { $locale = 'de_DE'; } - if (!\in_array($locale, ['fr_FR', 'en_US', 'en_GB', 'en_EU', 'de_DE', 'es_ES', 'it_IT'])) { + if ( ! \in_array($locale, array( 'fr_FR', 'en_US', 'en_GB', 'en_EU', 'de_DE', 'es_ES', 'it_IT' ))) { $locale = 'en_US'; } return $locale; } - public function show_campaigns_page() - { + public function show_campaigns_page() { echo '
'; try { $mailjetIframe = $this->getMailjetIframe(); $mailjetIframe->setInitialPage(MailjetIframe::PAGE_CAMPAIGNS); echo '
- Mailjet Logo + Mailjet Logo
'; - echo wp_kses($mailjetIframe->getHtml(), [ - 'iframe' => [ - 'align' => true, - 'width' => true, - 'height' => true, - 'frameborder' => true, - 'name' => true, - 'src' => true, - 'id' => true, - 'class' => true, - 'style' => true, - 'scrolling' => true, - 'marginwidth' => true, - 'marginheight' => true, - ], - ]); + echo wp_kses( + $mailjetIframe->getHtml(), + array( + 'iframe' => array( + 'align' => true, + 'width' => true, + 'height' => true, + 'frameborder' => true, + 'name' => true, + 'src' => true, + 'id' => true, + 'class' => true, + 'style' => true, + 'scrolling' => true, + 'marginwidth' => true, + 'marginheight' => true, + ), + ) + ); echo '
'; } catch (MailjetException $e) { MailjetLogger::error('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ ' . $e->getMessage() . ' ]'); @@ -136,25 +136,27 @@ public function show_campaigns_page() echo '
'; } - public function show_stats_page() - { + public function show_stats_page() { echo '
'; try { $mailjetIframe = $this->getMailjetIframe(); $mailjetIframe->setInitialPage(MailjetIframe::PAGE_STATS); echo '
- Mailjet Logo + Mailjet Logo
'; - echo wp_kses($mailjetIframe->getHtml(), [ - 'iframe' => [ - 'src' => true, - 'height' => true, - 'width' => true, - 'frameborder' => true, - 'allowfullscreen' => true, - ], - ]); + echo wp_kses( + $mailjetIframe->getHtml(), + array( + 'iframe' => array( + 'src' => true, + 'height' => true, + 'width' => true, + 'frameborder' => true, + 'allowfullscreen' => true, + ), + ) + ); echo '
'; } catch (MailjetException $e) { MailjetLogger::error('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ ' . $e->getMessage() . ' ]'); @@ -167,25 +169,27 @@ public function show_stats_page() echo '
'; } - public function show_contacts_page() - { + public function show_contacts_page() { echo '
'; try { $mailjetIframe = $this->getMailjetIframe(); $mailjetIframe->setInitialPage(MailjetIframe::PAGE_CONTACTS); echo '
- Mailjet Logo + Mailjet Logo
'; - echo wp_kses($mailjetIframe->getHtml(), [ - 'iframe' => [ - 'src' => true, - 'height' => true, - 'width' => true, - 'frameborder' => true, - 'allowfullscreen' => true, - ], - ]); + echo wp_kses( + $mailjetIframe->getHtml(), + array( + 'iframe' => array( + 'src' => true, + 'height' => true, + 'width' => true, + 'frameborder' => true, + 'allowfullscreen' => true, + ), + ) + ); echo '
'; } catch (MailjetException $e) { MailjetLogger::error('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ ' . $e->getMessage() . ' ]'); @@ -198,11 +202,10 @@ public function show_contacts_page() echo '
'; } - 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() ?>
Mailjet Logo
@@ -119,36 +134,50 @@ public function mailjet_abandoned_cart_settings_page_html() ?>
-
" method="post" id="abandoned-cart-form"> + ?> + " method="post" id="abandoned-cart-form">
-

+

-

+ ?> + +

+ +

- + ?> +
-

+

- + ?> +

-->
@@ -158,40 +187,60 @@ public function mailjet_abandoned_cart_settings_page_html() ?>
-
> - + ?> + " />

- > + + > + +

- > + + > + + - + ?> + ">
; - timeScaleSelect.value = + ; + timeScaleSelect.value = + ; + ?> + ; } } diff --git a/src/includes/SettingsPages/AllSetup.php b/src/includes/SettingsPages/AllSetup.php index 25999fcb..04e12a2b 100644 --- a/src/includes/SettingsPages/AllSetup.php +++ b/src/includes/SettingsPages/AllSetup.php @@ -16,82 +16,113 @@ * @subpackage Mailjet/includes * @author Your Name */ -class AllSetup -{ +class AllSetup { + /** * top level menu: * callback functions */ - public function mailjet_allsetup_page_html() - { + public function mailjet_allsetup_page_html() { // check user capabilities - if (!current_user_can('manage_options')) { + if ( ! current_user_can('manage_options')) { MailjetLogger::error('[ Mailjet ] [ ' . __METHOD__ . ' ] [ Line #' . __LINE__ . ' ] [ Current user don\'t have \\`manage_options\\` permission ]'); return; } ?>
-
Mailjet Logo
+
Mailjet Logo
- -

--> + + +

+

-

+ +

+

+ ?> +

- -
+ " /> +
+
-

+

+

+

-
+ ?> + ">
- -
+ " /> +
+
-

+

+

+

-
+ ?> + ">
- -
+ " /> +
+
-

+

+

+

-
+ ?> + ">
Go to your Mailjet Plugin Homepage', 'mailjet-for-wordpress'), "admin.php?page=mailjet_dashboard_page"); + \printf(__('or Go to your Mailjet Plugin Homepage', 'mailjet-for-wordpress'), 'admin.php?page=mailjet_dashboard_page'); ?>
diff --git a/src/includes/SettingsPages/CommentAuthorsSettings.php b/src/includes/SettingsPages/CommentAuthorsSettings.php index 1e2f8bef..7a83a7bb 100644 --- a/src/includes/SettingsPages/CommentAuthorsSettings.php +++ b/src/includes/SettingsPages/CommentAuthorsSettings.php @@ -18,22 +18,21 @@ * @subpackage Mailjet/includes * @author Your Name */ -class CommentAuthorsSettings -{ +class CommentAuthorsSettings { + /** * @return void */ - public function mailjet_show_extra_comment_fields() - { - $commentAuthorsListId = (int)Mailjet::getOption('mailjet_comment_authors_list'); - if ((int)Mailjet::getOption('activate_mailjet_comment_authors_sync') === 1 && $commentAuthorsListId > 0) { + public function mailjet_show_extra_comment_fields() { + $commentAuthorsListId = (int) Mailjet::getOption('mailjet_comment_authors_list'); + if ( (int) Mailjet::getOption('activate_mailjet_comment_authors_sync') === 1 && $commentAuthorsListId > 0) { $user = wp_get_current_user(); // Display the checkbox for NOT-logged in or unsubscribed users - if (empty($user->data->user_email) || !MailjetApi::checkContactSubscribedToList($user->data->user_email, $commentAuthorsListId)) { + if (empty($user->data->user_email) || ! MailjetApi::checkContactSubscribedToList($user->data->user_email, $commentAuthorsListId)) { ?>