| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Another Mailchimp Widget |
| 4 |
* Plugin URI: https://motopress.com/products/another-mailchimp-widget/ |
| 5 |
* Description: Simple Mailchimp subscription form to your lists and groups. |
| 6 |
* Author: MotoPress |
| 7 |
* Version: 2.1.0 |
| 8 |
* Author URI: https://motopress.com/ |
| 9 |
* License: GPL2 |
| 10 |
* Text Domain: another-mailchimp-widget |
| 11 |
* Domain Path: /languages |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! defined( 'AN_MC_PLUGIN_VERSION' ) ) { |
| 15 |
define( 'AN_MC_PLUGIN_VERSION', '2.1.0' ); |
| 16 |
} |
| 17 |
|
| 18 |
if ( ! defined( 'AN_MC_PLUGIN_FILE' ) ) { |
| 19 |
define( 'AN_MC_PLUGIN_FILE', __FILE__ ); |
| 20 |
} |
| 21 |
|
| 22 |
register_activation_hook( __FILE__, array( Another_mailChimp_widget::get_instance(), 'on_activation' ) ); |
| 23 |
add_action( 'plugins_loaded', array( 'Another_mailChimp_widget', 'get_instance' ) ); |
| 24 |
|
| 25 |
/** |
| 26 |
* Class Another_mailChimp_widget |
| 27 |
*/ |
| 28 |
class Another_mailChimp_widget { |
| 29 |
|
| 30 |
protected static $instance; |
| 31 |
|
| 32 |
/** |
| 33 |
* Another_mailChimp_widget constructor. |
| 34 |
*/ |
| 35 |
public function __construct() { |
| 36 |
|
| 37 |
spl_autoload_register( array( $this, 'buffered_autoloader' ) ); |
| 38 |
|
| 39 |
$this->include_all(); |
| 40 |
$this->init(); |
| 41 |
|
| 42 |
if ( ! defined( 'AN_MC_TEMPLATE_PATH' ) ) { |
| 43 |
define( 'AN_MC_TEMPLATE_PATH', $this->template_path() ); |
| 44 |
} |
| 45 |
if ( ! defined( 'AN_MC_PLUGIN_URL' ) ) { |
| 46 |
define( 'AN_MC_PLUGIN_URL', $this->get_plugin_url() ); |
| 47 |
} |
| 48 |
if ( ! defined( 'AN_MC_TEMPLATES_PATH' ) ) { |
| 49 |
define( 'AN_MC_TEMPLATES_PATH', $this::get_plugin_dir() . 'templates/' ); |
| 50 |
} |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Include classes into plugin |
| 56 |
*/ |
| 57 |
public function include_all() { |
| 58 |
|
| 59 |
$plugin_dir = $this::get_plugin_dir(); |
| 60 |
|
| 61 |
include $plugin_dir . 'classes/class-view.php'; |
| 62 |
|
| 63 |
include $plugin_dir . 'functions/functions.php'; |
| 64 |
|
| 65 |
include $plugin_dir . 'lib/an_mc_plugin.class.php'; |
| 66 |
|
| 67 |
include_once $plugin_dir . 'shortcodes/registrator.php'; |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Get plugin dir |
| 73 |
* @return string |
| 74 |
*/ |
| 75 |
public static function get_plugin_dir() { |
| 76 |
if ( ! defined( 'AN_MC_PLUGIN_PATH' ) ) { |
| 77 |
|
| 78 |
$file = Another_mailChimp_widget::get_plugin_file(); |
| 79 |
$path = trailingslashit( plugin_dir_path( $file ) ); |
| 80 |
|
| 81 |
define( 'AN_MC_PLUGIN_PATH', $path ); |
| 82 |
} else { |
| 83 |
$path = AN_MC_PLUGIN_PATH; |
| 84 |
} |
| 85 |
|
| 86 |
return $path; |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Get plugin File |
| 91 |
* |
| 92 |
* @return string |
| 93 |
*/ |
| 94 |
public static function get_plugin_file() { |
| 95 |
global $wp_version, $network_plugin; |
| 96 |
|
| 97 |
if ( version_compare( $wp_version, '3.9', '<' ) && isset( $network_plugin ) ) { |
| 98 |
$pluginFile = $network_plugin; |
| 99 |
} else { |
| 100 |
$pluginFile = __FILE__; |
| 101 |
} |
| 102 |
|
| 103 |
return $pluginFile; |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* init plugin data |
| 108 |
*/ |
| 109 |
public function init() { |
| 110 |
spl_autoload_register( array( $this, 'buffered_autoloader' ) ); |
| 111 |
AN_MC_Plugin::get_instance()->init_action(); |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Get the template path. |
| 116 |
* |
| 117 |
* @return string |
| 118 |
*/ |
| 119 |
public function template_path() { |
| 120 |
return apply_filters( 'an_mc_template_path', 'another-mailchimp-widget/' ); |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Get plugin URL |
| 125 |
*/ |
| 126 |
public function get_plugin_url() { |
| 127 |
$path = plugins_url( plugin_basename( __DIR__ ) ); |
| 128 |
|
| 129 |
return trailingslashit( $path ); |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* @return Another_mailChimp_widget |
| 134 |
*/ |
| 135 |
public static function get_instance() { |
| 136 |
if ( null === self::$instance ) { |
| 137 |
self::$instance = new self(); |
| 138 |
} |
| 139 |
|
| 140 |
return self::$instance; |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* On activation |
| 145 |
*/ |
| 146 |
public function on_activation() { |
| 147 |
AN_MC_Plugin::get_instance()->set_up_options(); |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* On deactivation |
| 152 |
*/ |
| 153 |
public function on_deactivation() { |
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* on uninstall |
| 158 |
*/ |
| 159 |
public function on_uninstall() { |
| 160 |
} |
| 161 |
|
| 162 |
/** |
| 163 |
* |
| 164 |
* Autoloader |
| 165 |
* |
| 166 |
* @param $class |
| 167 |
* |
| 168 |
* @return string |
| 169 |
*/ |
| 170 |
public function buffered_autoloader( $class ) { |
| 171 |
try { |
| 172 |
set_include_path( get_include_path() . PATH_SEPARATOR . realpath( $this::get_plugin_dir() . '/lib/' ) ); |
| 173 |
spl_autoload( $class, '.class.php' ); |
| 174 |
ini_restore('include_path'); |
| 175 |
} catch ( Exception $e ) { |
| 176 |
$message = $e->getMessage(); |
| 177 |
|
| 178 |
return $message; |
| 179 |
} |
| 180 |
} |
| 181 |
} |