| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: EmailKit. Email Builder |
| 5 |
* Plugin URI: https://wpmet.com/plugin/emailkit/ |
| 6 |
* Description: EmailKit is the most-complete drag-and-drop Email template builder. |
| 7 |
* Author: wpmet |
| 8 |
* Version: 1.0.0 |
| 9 |
* Text Domain: emailkit |
| 10 |
* License: GPLv3 |
| 11 |
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt |
| 12 |
*/ |
| 13 |
if (!defined('ABSPATH')) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
require_once __DIR__ . '/vendor/autoload.php'; |
| 18 |
|
| 19 |
/** |
| 20 |
* The main plugin class |
| 21 |
*/ |
| 22 |
final class EmailKit |
| 23 |
{ |
| 24 |
|
| 25 |
/** |
| 26 |
* Plugin version |
| 27 |
* |
| 28 |
* @var string |
| 29 |
*/ |
| 30 |
|
| 31 |
/** |
| 32 |
* Class constructor |
| 33 |
*/ |
| 34 |
private function __construct() |
| 35 |
{ |
| 36 |
$this->define_constants(); |
| 37 |
register_activation_hook(__FILE__, [$this, 'activate']); |
| 38 |
|
| 39 |
add_action('plugins_loaded', [$this, 'init_plugin']); |
| 40 |
add_action('admin_head', [$this, 'emailkit_header_script_data']); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Initializes a singleton instance |
| 45 |
* |
| 46 |
* @return \EmailKit |
| 47 |
*/ |
| 48 |
public static function init() |
| 49 |
{ |
| 50 |
|
| 51 |
static $instance = false; |
| 52 |
|
| 53 |
if (!$instance) { |
| 54 |
$instance = new self(); |
| 55 |
} |
| 56 |
|
| 57 |
return $instance; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
/** |
| 62 |
* Define the required plugin constants |
| 63 |
* |
| 64 |
* @return void |
| 65 |
*/ |
| 66 |
public function define_constants() |
| 67 |
{ |
| 68 |
define('EMAILKIT_VERSION', '1.0.0'); |
| 69 |
define('EMAILKIT_TEXTDOMAIN', 'emailkit'); |
| 70 |
define('EMAILKIT_FILE', __FILE__); |
| 71 |
define('EMAILKIT_PATH', __DIR__); |
| 72 |
define('EMAILKIT_URL', trailingslashit(plugin_dir_url(EMAILKIT_FILE))); |
| 73 |
define('EMAILKIT_ASSETS', EMAILKIT_URL . '/assets'); |
| 74 |
define('EMAILKIT_DIR', trailingslashit(plugin_dir_path(__FILE__))); |
| 75 |
define('EMAILKIT_CONFIG', []); |
| 76 |
} |
| 77 |
|
| 78 |
public function emailkit_header_script_data() |
| 79 |
{ |
| 80 |
$_nonce = wp_create_nonce('wp_rest'); |
| 81 |
$config = [ |
| 82 |
'version' => EMAILKIT_VERSION, |
| 83 |
'restNonce' => esc_attr($_nonce), |
| 84 |
'siteUrl' => esc_url(get_site_url()), |
| 85 |
'assetsUrl' => esc_url(EMAILKIT_URL . 'assets/'), |
| 86 |
'baseApi' => esc_url(get_rest_url(null, 'emailkit/v1/')), |
| 87 |
'baseUrl' => esc_url(EMAILKIT_URL), |
| 88 |
'post_id' => esc_attr(get_the_id()), |
| 89 |
]; |
| 90 |
|
| 91 |
update_option('emailkit_config', $config); |
| 92 |
|
| 93 |
?> |
| 94 |
<script> |
| 95 |
window.emailKit = window.emailKit ?? {}; |
| 96 |
window.emailKit.config = <?php echo wp_json_encode($config); ?>; |
| 97 |
</script> |
| 98 |
<?php |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Initialize the plugin |
| 103 |
* |
| 104 |
* @return void |
| 105 |
*/ |
| 106 |
public function init_plugin() |
| 107 |
{ |
| 108 |
new EmailKit\Admin(); |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Do stuff upon plugin activation |
| 113 |
*/ |
| 114 |
public function activate() |
| 115 |
{ |
| 116 |
/** |
| 117 |
* Save plugin installation time. |
| 118 |
*/ |
| 119 |
|
| 120 |
$installed = get_option('emailkit_installed'); |
| 121 |
if (!$installed) { |
| 122 |
update_option('emailkit_installed', time()); |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Update plugin version. |
| 127 |
* |
| 128 |
* @param string $option |
| 129 |
*/ |
| 130 |
update_option('emailkit_version', EMAILKIT_VERSION); |
| 131 |
} |
| 132 |
} |
| 133 |
/**. |
| 134 |
* Initializes the main plugin |
| 135 |
* |
| 136 |
* @return \EmailKit |
| 137 |
*/ |
| 138 |
|
| 139 |
|
| 140 |
EmailKit::init(); |
| 141 |
|