| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: AcyMailing |
| 4 |
* Description: Manage your contact lists and send newsletters from your site. |
| 5 |
* Author: AcyMailing Newsletter Team |
| 6 |
* Author URI: https://www.acymailing.com |
| 7 |
* License: GPLv3 |
| 8 |
* Version: 11.0.5 |
| 9 |
* Text Domain: acymailing |
| 10 |
* Requires at least: 5.8 |
| 11 |
* Requires PHP: 7.4 |
| 12 |
*/ |
| 13 |
|
| 14 |
use AcyMailing\WpInit\Activation; |
| 15 |
use AcyMailing\WpInit\Addons; |
| 16 |
use AcyMailing\WpInit\Beaver; |
| 17 |
use AcyMailing\WpInit\Cron; |
| 18 |
use AcyMailing\WpInit\Data; |
| 19 |
use AcyMailing\WpInit\Deactivate; |
| 20 |
use AcyMailing\WpInit\Elementor; |
| 21 |
use AcyMailing\WpInit\Forms; |
| 22 |
use AcyMailing\WpInit\Gutenberg; |
| 23 |
use AcyMailing\WpInit\Menu; |
| 24 |
use AcyMailing\WpInit\Message; |
| 25 |
use AcyMailing\WpInit\Oauth; |
| 26 |
use AcyMailing\WpInit\OverrideEmail; |
| 27 |
use AcyMailing\WpInit\Router; |
| 28 |
use AcyMailing\WpInit\Security; |
| 29 |
use AcyMailing\WpInit\UserSync; |
| 30 |
use AcyMailing\WpInit\WpRocket; |
| 31 |
|
| 32 |
defined('ABSPATH') || die('Restricted Access'); |
| 33 |
|
| 34 |
class acymailingLoader |
| 35 |
{ |
| 36 |
public function __construct() |
| 37 |
{ |
| 38 |
// Install Acy DB and sample data on first activation (not on installation because of FTP install) |
| 39 |
register_activation_hook(__DIR__.'/'.basename(__FILE__), [$this, 'activation']); |
| 40 |
add_action('wp_initialize_site', [$this, 'subsiteCreation'], 101); |
| 41 |
|
| 42 |
// Prevent bad plugins from loading on AcyMailing pages |
| 43 |
add_action('plugins_loaded', [$this, 'protectAcyMailingPages'], 5); |
| 44 |
|
| 45 |
// Init widgets. According to the WP doc widgets_init should be loaded after init, but it isn't |
| 46 |
add_action('widgets_init', [$this, 'initWidgets']); |
| 47 |
|
| 48 |
// Init AcyMailing |
| 49 |
add_action('init', [$this, 'initAcyMailing'], 0); |
| 50 |
|
| 51 |
add_filter('wpml_show_admin_language_switcher', [$this, 'disableWpml']); |
| 52 |
} |
| 53 |
|
| 54 |
public function subsiteCreation(): void |
| 55 |
{ |
| 56 |
if (is_plugin_active_for_network(basename(__DIR__).'/'.basename(__FILE__))) { |
| 57 |
$this->activation(); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
public function activation(): void |
| 62 |
{ |
| 63 |
// Load Acy library |
| 64 |
$helperFile = __DIR__.DIRECTORY_SEPARATOR.'back'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'init.php'; |
| 65 |
if (file_exists($helperFile) && include_once $helperFile) { |
| 66 |
$activation = new Activation(); |
| 67 |
$activation->install(); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
public function protectAcyMailingPages() |
| 72 |
{ |
| 73 |
if (!$this->isCurrentlyOnAcyPage()) { |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
// Prevent plugins from breaking AcyMailing pages (mainly JS scripts loaded without the WP way) |
| 78 |
remove_action('plugins_loaded', 'mailchimp_on_all_plugins_loaded', 12); |
| 79 |
remove_action('plugins_loaded', '_imagify_init'); |
| 80 |
remove_action('plugins_loaded', 'plugins_loaded_wps_hide_login_plugin'); |
| 81 |
remove_action('plugins_loaded', ['WPAS_Gas', 'get_instance'], 11); |
| 82 |
remove_action('plugins_loaded', 'woosb_init', 12); |
| 83 |
} |
| 84 |
|
| 85 |
public function disableWpml(): bool |
| 86 |
{ |
| 87 |
if (!$this->isCurrentlyOnAcyPage() || !$this->loadAcyMailingLibrary()) { |
| 88 |
return true; |
| 89 |
} |
| 90 |
|
| 91 |
$config = acym_config(); |
| 92 |
|
| 93 |
return intval($config->get('multilingual')) !== 1; |
| 94 |
} |
| 95 |
|
| 96 |
public function initWidgets() |
| 97 |
{ |
| 98 |
$ds = DIRECTORY_SEPARATOR; |
| 99 |
include_once __DIR__.$ds.'widgets'.$ds.'archive'.$ds.'widget.php'; |
| 100 |
include_once __DIR__.$ds.'widgets'.$ds.'profile'.$ds.'widget.php'; |
| 101 |
include_once __DIR__.$ds.'widgets'.$ds.'subscriptionform'.$ds.'widget.php'; |
| 102 |
|
| 103 |
register_widget('acym_archive_widget'); |
| 104 |
register_widget('acym_profile_widget'); |
| 105 |
register_widget('acym_subscriptionform_widget'); |
| 106 |
} |
| 107 |
|
| 108 |
private function loadAcyMailingLibrary() |
| 109 |
{ |
| 110 |
$helperFile = __DIR__.DIRECTORY_SEPARATOR.'back'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'init.php'; |
| 111 |
|
| 112 |
return file_exists($helperFile) && include_once $helperFile; |
| 113 |
} |
| 114 |
|
| 115 |
public function initAcyMailing() |
| 116 |
{ |
| 117 |
if (!$this->loadAcyMailingLibrary()) { |
| 118 |
return; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
$router = new Router(); |
| 124 |
new Menu($router); |
| 125 |
new UserSync(); |
| 126 |
new Message(); |
| 127 |
new Elementor(); |
| 128 |
new Beaver(); |
| 129 |
new WpRocket(); |
| 130 |
new Addons(); |
| 131 |
new Forms(); |
| 132 |
new OverrideEmail(); |
| 133 |
new Cron(); |
| 134 |
new Gutenberg(); |
| 135 |
new Security(); |
| 136 |
new Deactivate(); |
| 137 |
new Oauth(); |
| 138 |
new Data(); |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
private function isCurrentlyOnAcyPage(): bool |
| 143 |
{ |
| 144 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Make sure we're on an AcyMailing page. |
| 145 |
$page = isset($_REQUEST['page']) ? sanitize_text_field(wp_unslash($_REQUEST['page'])) : ''; |
| 146 |
|
| 147 |
return !empty($page) && strpos($page, 'acymailing_') !== false; |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
new acymailingLoader(); |
| 152 |
|