Skip to content

Commit

Permalink
Merge pull request #372 from mailjet/DE-1311-wp-mailjet-multisite-usa…
Browse files Browse the repository at this point in the history
…ge-with-the-plugin

Multisite support. In Progress
  • Loading branch information
oleksandr-mykhailenko authored Sep 8, 2024
2 parents d24b48e + b183c2d commit 4401dd9
Show file tree
Hide file tree
Showing 26 changed files with 247 additions and 188 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

##### 6.1
- Added support Multisite settings across all sites. Now, you can use plugin settings from the main site on all your subdomains.

##### 6.0.1
* Removed old widget filter function `mailjet_subscription_widget_email_params`. It was deprecated and unsupported since we have Form Builder widget

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- Tags: email, marketing, signup, newsletter, widget, smtp, woocommerce, contact form 7
- Requires at least: 4.4
- Tested up to: 6.6.1
- Stable tag: 6.0.1
- Stable tag: 6.1
- Requires PHP: 7.4
- License: GPLv2 or later
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -162,6 +162,9 @@ find vendor/ -type d -name ".git" -exec rm -rf {} \;

## Changelog

##### 6.1
- Added support Multisite settings across all sites. Now, you can use plugin settings from the main site on all your subdomains.

##### 6.0.1
* Removed old widget filter function `mailjet_subscription_widget_email_params`. It was deprecated and unsupported since we have Form Builder widget

Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- Tags: email, marketing, signup, newsletter, widget, smtp, woocommerce, contact form 7
- Requires at least: 4.4
- Tested up to: 6.6.1
- Stable tag: 6.0.1
- Stable tag: 6.1
- Requires PHP: 7.4
- License: GPLv2 or later
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down
3 changes: 3 additions & 0 deletions src/admin/css/mailjet-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@
border-radius: 3px;
box-shadow: none;
}
.mj-pluginPage .form-table td .text-muted {
color: #888;
}

.mailjet_row input[type="checkbox"]:disabled {
background-color: #dddddd;
Expand Down
2 changes: 1 addition & 1 deletion src/front/MailjetPublic.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function enqueue_scripts()
* class.
*/
// wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/mailjet-public.js', array( 'jquery' ), $this->version, false );
if (get_option('activate_mailjet_woo_integration') === '1' && get_option('mailjet_woo_abandoned_cart_activate') === '1') {
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
Expand Down
36 changes: 30 additions & 6 deletions src/includes/Mailjet.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct()
if (\defined('MAILJET_VERSION')) {
$this->version = MAILJET_VERSION;
} else {
$this->version = '6.0.1';
$this->version = '6.1';
}
$this->plugin_name = 'mailjet';
$this->load_dependencies();
Expand All @@ -87,7 +87,7 @@ public static function display_mailjet_form_builder_widget(array $attr = [], str
{
\extract(shortcode_atts(['widget_id' => null], $attr, $tag));
// GET All Mailjet widgets - to find the one that user actually configured with the shortcode
$instance = get_option('mailjet_form_builder_widget_options');
$instance = Mailjet::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)) {
Expand Down Expand Up @@ -152,7 +152,7 @@ private function define_admin_hooks()
$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 (get_option('activate_mailjet_woo_integration') == '1') {
if (Mailjet::getOption('activate_mailjet_woo_integration') == '1') {
$this->addWoocommerceActions();
}
}
Expand Down Expand Up @@ -267,12 +267,12 @@ private function addWoocommerceActions(): void
$wooCommerceSettings->orders_automation_settings_post();
}
$this->loader->add_action('admin_post_abandoned_cart_settings_custom_hook', $wooCommerceSettings, 'abandoned_cart_settings_post');
if (get_option('mailjet_woo_edata_sync') === '1') {
if (Mailjet::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 = get_option('mailjet_wc_active_hooks');
$abandonedCartActiveActions = get_option('mailjet_wc_abandoned_cart_active_hooks');
$activeActions = Mailjet::getOption('mailjet_wc_active_hooks');
$abandonedCartActiveActions = Mailjet::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);
Expand All @@ -284,4 +284,28 @@ private function addWoocommerceActions(): void
}
}
}

/**
* @param string $key
* @return mixed
*/
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 (get_option('mailjet_multisite_support') === 'on') {
return get_option($key);
}
//If main site has multisite support disabled, we should use the current site options
restore_current_blog();

return get_option($key);
}

}
5 changes: 3 additions & 2 deletions src/includes/MailjetApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public static function getApiClient()
if (self::$mjApiClient instanceof Client) {
return self::$mjApiClient;
}
$mailjetApikey = get_option('mailjet_apikey');
$mailjetApiSecret = get_option('mailjet_apisecret');
$mailjetApikey = Mailjet::getOption('mailjet_apikey');
$mailjetApiSecret = Mailjet::getOption('mailjet_apisecret');

if (empty($mailjetApikey) || empty($mailjetApiSecret)) {
throw new Exception('Missing Mailjet API credentials');
}
Expand Down
16 changes: 8 additions & 8 deletions src/includes/MailjetLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,63 @@ class MailjetLogger
{
public static function log($message, $level = null)
{
$mailjetActivateLogger = get_option('mailjet_activate_logger');
$mailjetActivateLogger = Mailjet::getOption('mailjet_activate_logger');
if (empty($mailjetActivateLogger) || $mailjetActivateLogger != 1) {
return '';
}
return Analog::log($message, $level);
}
public static function urgent($message)
{
$mailjetActivateLogger = get_option('mailjet_activate_logger');
$mailjetActivateLogger = Mailjet::getOption('mailjet_activate_logger');
if (empty($mailjetActivateLogger) || $mailjetActivateLogger != 1) {
return '';
}
return Analog::urgent($message);
}
public static function alert($message)
{
$mailjetActivateLogger = get_option('mailjet_activate_logger');
$mailjetActivateLogger = Mailjet::getOption('mailjet_activate_logger');
if (empty($mailjetActivateLogger) || $mailjetActivateLogger != 1) {
return '';
}
return Analog::alert($message);
}
public static function error($message)
{
$mailjetActivateLogger = get_option('mailjet_activate_logger');
$mailjetActivateLogger = Mailjet::getOption('mailjet_activate_logger');
if (empty($mailjetActivateLogger) || $mailjetActivateLogger != 1) {
return '';
}
return Analog::error($message);
}
public static function warning($message)
{
$mailjetActivateLogger = get_option('mailjet_activate_logger');
$mailjetActivateLogger = Mailjet::getOption('mailjet_activate_logger');
if (empty($mailjetActivateLogger) || $mailjetActivateLogger != 1) {
return '';
}
return Analog::warning($message);
}
public static function notice($message)
{
$mailjetActivateLogger = get_option('mailjet_activate_logger');
$mailjetActivateLogger = Mailjet::getOption('mailjet_activate_logger');
if (empty($mailjetActivateLogger) || $mailjetActivateLogger != 1) {
return '';
}
return Analog::notice($message);
}
public static function info($message)
{
$mailjetActivateLogger = get_option('mailjet_activate_logger');
$mailjetActivateLogger = Mailjet::getOption('mailjet_activate_logger');
if (empty($mailjetActivateLogger) || $mailjetActivateLogger != 1) {
return '';
}
return Analog::info($message);
}
public static function debug($message)
{
$mailjetActivateLogger = get_option('mailjet_activate_logger');
$mailjetActivateLogger = Mailjet::getOption('mailjet_activate_logger');
if (empty($mailjetActivateLogger) || $mailjetActivateLogger != 1) {
return '';
}
Expand Down
26 changes: 13 additions & 13 deletions src/includes/MailjetMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ public function __construct()
}
public function phpmailer_init_smtp($phpmailer)
{
if (!get_option('mailjet_enabled') || 0 === (int)get_option('mailjet_enabled')) {
if (!Mailjet::getOption('mailjet_enabled') || 0 === (int)Mailjet::getOption('mailjet_enabled')) {
return;
}
$phpmailer->Mailer = 'smtp';
$phpmailer->SMTPSecure = get_option('mailjet_ssl');
$phpmailer->SMTPSecure = Mailjet::getOption('mailjet_ssl');
$phpmailer->Host = self::MJ_HOST;
$phpmailer->Port = get_option('mailjet_port');
$phpmailer->Port = Mailjet::getOption('mailjet_port');
$phpmailer->SMTPAuth = \TRUE;
$phpmailer->Username = get_option('mailjet_apikey');
$phpmailer->Password = get_option('mailjet_apisecret');
$from_email = get_option('mailjet_from_email') ? get_option('mailjet_from_email') : get_option('admin_email');
$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 = get_option('mailjet_from_name') ? get_option('mailjet_from_name') : get_bloginfo('name');
$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 (!get_option('mailjet_enabled')) {
if (!Mailjet::getOption('mailjet_enabled')) {
return \false;
}
if (\function_exists('MailjetWp\\add_settings_error')) {
Expand All @@ -68,26 +68,26 @@ public function wp_mail_failed_admin_notice()
public static function sendTestEmail()
{
$testSent = \false;
$mailjetTestAddress = get_option('mailjet_test_address');
$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']);
$subject = __('Your test mail from Mailjet', 'mailjet-for-wordpress');
$message = \sprintf(__('Your Mailjet configuration is ok! <br /> Site URL: %s <br /> SSL: %s <br /> Port: %s', 'mailjet-for-wordpress'), get_home_url(), get_option('mailjet_ssl') ? 'On' : 'Off', get_option('mailjet_port'));
return wp_mail(get_option('mailjet_test_address'), $subject, $message);
$message = \sprintf(__('Your Mailjet configuration is ok! <br /> Site URL: %s <br /> SSL: %s <br /> 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()
{
return 'text/html';
}
public function wp_sender_email($original_email_address)
{
return get_option('mailjet_from_email');
return Mailjet::getOption('mailjet_from_email');
}
public function wp_sender_name($original_email_from)
{
return get_option('mailjet_from_name');
return Mailjet::getOption('mailjet_from_name');
}
}
4 changes: 2 additions & 2 deletions src/includes/MailjetMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public function wp_mailjet_options_top()
*/
private function getMailjetIframe(): MailjetIframe
{
$mailjetApikey = get_option('mailjet_apikey');
$mailjetApiSecret = get_option('mailjet_apisecret');
$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);
return $mailjetIframe;
Expand Down
Loading

0 comments on commit 4401dd9

Please sign in to comment.