| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: EmailOctopus |
| 4 |
* Plugin URI: https://emailoctopus.com |
| 5 |
* Description: Email marketing widget; easily add subscribers to an EmailOctopus list. Fully customisable. |
| 6 |
* Version: 2.2.0 |
| 7 |
* Author: EmailOctopus |
| 8 |
* Author URI: https://emailoctopus.com |
| 9 |
* Text Domain: emailoctopus |
| 10 |
* License: GPL-2.0+ |
| 11 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 12 |
* Domain Path: /languages |
| 13 |
*/ |
| 14 |
|
| 15 |
// Exit if accessed directly. |
| 16 |
if (!defined('ABSPATH')) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
// If the user does not have a sufficient version of PHP, exit. |
| 21 |
if (version_compare(PHP_VERSION, '5.6.0', '<')) { |
| 22 |
/** |
| 23 |
* Add admin message about old version of PHP. |
| 24 |
* |
| 25 |
* Prints an update nag when site uses PHP version prior to 5.6. |
| 26 |
* |
| 27 |
* @TODO: Once plugin requires WP 5.2+, switch to built-in function validate_plugin_requirements(). |
| 28 |
*/ |
| 29 |
function emailoctopus_upgrade_notice() |
| 30 |
{ |
| 31 |
// Only to administrators. |
| 32 |
if (!current_user_can('activate_plugins')){ |
| 33 |
return; |
| 34 |
} |
| 35 |
$error_message = sprintf( |
| 36 |
/* translators: 1: Current PHP version, 2: Required PHP version. */ |
| 37 |
__('<strong>Error:</strong> Current PHP version (%1$s) does not meet minimum requirements for EmailOctopus. The plugin requires PHP %2$s.', 'emailoctopus'), |
| 38 |
phpversion(), |
| 39 |
'5.6' |
| 40 |
); |
| 41 |
$php_update_message = sprintf( |
| 42 |
/* translators: %s: URL to Update PHP page. */ |
| 43 |
__('<a href="%s">Learn more about updating PHP</a>.', 'emailoctopus'), |
| 44 |
esc_url(_x('https://wordpress.org/support/update-php/', 'localized PHP upgrade information page', 'emailoctopus')) |
| 45 |
); |
| 46 |
printf('<div class="error"><p>%s</p><p>%s</p></div>', $error_message, $php_update_message); |
| 47 |
} |
| 48 |
add_action('all_admin_notices', 'emailoctopus_upgrade_notice'); |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
use EmailOctopus\Admin\Admin_Container as Admin; |
| 53 |
use EmailOctopus\Frontend\Frontend_Container as Frontend; |
| 54 |
|
| 55 |
if (!class_exists('EmailOctopus')) : |
| 56 |
|
| 57 |
/** |
| 58 |
* Main plugin class. |
| 59 |
*/ |
| 60 |
final class EmailOctopus |
| 61 |
{ |
| 62 |
private static $instance = null; |
| 63 |
private $slug = 'emailoctopus'; |
| 64 |
private $url = ''; |
| 65 |
private $file = __FILE__; |
| 66 |
|
| 67 |
/** |
| 68 |
* Holds admin container class instance. |
| 69 |
* |
| 70 |
* @var \EmailOctopus\Admin\Admin_Container |
| 71 |
*/ |
| 72 |
public $admin; |
| 73 |
|
| 74 |
/** |
| 75 |
* Holds frontend container class instance. |
| 76 |
* |
| 77 |
* @var \EmailOctopus\Frontend\Frontend_Container |
| 78 |
*/ |
| 79 |
public $public; |
| 80 |
|
| 81 |
/** |
| 82 |
* Class constructor. |
| 83 |
* |
| 84 |
* Set up internationalization, auto-loader, and plugin initialization. |
| 85 |
*/ |
| 86 |
private function __construct() |
| 87 |
{ |
| 88 |
// Init internationalization. |
| 89 |
load_plugin_textdomain('emailoctopus', false, dirname(plugin_basename(__FILE__)) . '/languages/'); |
| 90 |
|
| 91 |
// Load the plugin. |
| 92 |
add_action('init', [$this, 'init'], 0); |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Retrieve a class instance. |
| 97 |
* |
| 98 |
* @return EmailOctopus Instance of the class. |
| 99 |
*/ |
| 100 |
public static function get_instance() |
| 101 |
{ |
| 102 |
if (!isset(self::$instance) && !(self::$instance instanceof EmailOctopus)) { |
| 103 |
self::$instance = new self(); |
| 104 |
self::$instance->setup_constants(); |
| 105 |
self::$instance->require_global(); |
| 106 |
} |
| 107 |
|
| 108 |
return self::$instance; |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Loads all global files into scope. |
| 113 |
*/ |
| 114 |
public function require_global() |
| 115 |
{ |
| 116 |
require_once trailingslashit(EMAILOCTOPUS_DIR) . 'Functions/common.php'; |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Setup environmental constants for EmailOctopus. |
| 121 |
* |
| 122 |
* @return void |
| 123 |
*/ |
| 124 |
public function setup_constants() |
| 125 |
{ |
| 126 |
$this->define('EMAILOCTOPUS_VERSION', '2.2.0'); |
| 127 |
$this->define('EMAILOCTOPUS_URL', $this->url); |
| 128 |
$this->define('EMAILOCTOPUS_SLUG', $this->slug); |
| 129 |
$this->define('EMAILOCTOPUS_FILE', $this->file); |
| 130 |
$this->define('EMAILOCTOPUS_DIR', plugin_dir_path(__FILE__)); |
| 131 |
$this->define('EMAILOCTOPUS_URL', plugin_dir_url(__FILE__)); |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Replaces mb_substr. |
| 136 |
* |
| 137 |
* @static |
| 138 |
* |
| 139 |
* @param string $string The string. |
| 140 |
* @param int $offset The offset. |
| 141 |
* @param int $length The length. |
| 142 |
* |
| 143 |
* @return string |
| 144 |
*/ |
| 145 |
public static function mb_substr($string, $offset, $length) |
| 146 |
{ |
| 147 |
$arr = preg_split('//u', $string); |
| 148 |
$slice = array_slice($arr, $offset + 1, $length); |
| 149 |
|
| 150 |
return implode('', $slice); |
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
* Autoload function. |
| 155 |
* |
| 156 |
* @static |
| 157 |
* |
| 158 |
* @param mixed $class The class. |
| 159 |
* |
| 160 |
* @return void |
| 161 |
*/ |
| 162 |
public static function autoload($class) |
| 163 |
{ |
| 164 |
// Prepare variables. |
| 165 |
$prefix = 'EmailOctopus'; |
| 166 |
$base_dir = __DIR__ . '/'; |
| 167 |
$length = mb_strlen($prefix); |
| 168 |
|
| 169 |
// If the class is not using the namespace prefix, return. |
| 170 |
if (0 !== strncmp($prefix, $class, $length)) { |
| 171 |
return; |
| 172 |
} |
| 173 |
|
| 174 |
// Prepare classes to be autoloaded. |
| 175 |
$relative_class = self::mb_substr($class, 0, strlen($class)); |
| 176 |
$relative_class = str_replace('EmailOctopus\\', '', $relative_class); |
| 177 |
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; |
| 178 |
|
| 179 |
// If the file exists, load it. |
| 180 |
if (file_exists($file)) { |
| 181 |
require $file; |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
/** |
| 186 |
* Loads the plugin into WordPress. |
| 187 |
*/ |
| 188 |
public function init() |
| 189 |
{ |
| 190 |
// Kick off the frontend. |
| 191 |
$this->public = new Frontend(); |
| 192 |
|
| 193 |
// Load admin only components. |
| 194 |
if (is_admin()) { |
| 195 |
// Kick off the Admin. |
| 196 |
$this->admin = new Admin(); |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
/** |
| 201 |
* Helper Method to define constants. |
| 202 |
* |
| 203 |
* @param string $name The name. |
| 204 |
* @param mixed $value The value. |
| 205 |
* |
| 206 |
* @return void |
| 207 |
*/ |
| 208 |
public function define($name, $value) |
| 209 |
{ |
| 210 |
if (!defined($name)) { |
| 211 |
define($name, $value); |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
spl_autoload_register('EmailOctopus::autoload'); |
| 217 |
|
| 218 |
/** |
| 219 |
* Init function. |
| 220 |
* |
| 221 |
* @return EmailOctopus |
| 222 |
*/ |
| 223 |
function emailoctopus_start() |
| 224 |
{ |
| 225 |
return EmailOctopus::get_instance(); |
| 226 |
} |
| 227 |
|
| 228 |
add_action('plugins_loaded', 'emailoctopus_start'); |
| 229 |
|
| 230 |
endif; |
| 231 |
|