'1.1.6', 'plugin_name' => '9MAIL - WP Email Templates Designer', 'slug' => 'em-tmpl', 'assets_slug' => 'em-tmpl-', 'file' => __FILE__, 'basename' => plugin_basename( __FILE__ ), 'plugin_dir' => plugin_dir_path( __FILE__ ), 'dist_url' => plugins_url( 'assets/dist/', __FILE__ ), 'libs_url' => plugins_url( 'assets/libs/', __FILE__ ), 'img_url' => plugins_url( 'assets/img/', __FILE__ ), ] ); require_once EMTMPL_CONST['plugin_dir'] . 'autoload.php'; if ( ! class_exists( 'WP_Email_Templates_Designer' ) ) { class WP_Email_Templates_Designer { public function __construct() { add_action( 'plugins_loaded', [ $this, 'init' ], 20 ); register_activation_hook( __FILE__, array( $this, 'emtmpl_activate' ) ); } public function init() { if ( class_exists( '\EmTmpl\EMTMPL_Email_Templates_Designer' ) ) { return; } if ( ! class_exists( 'VillaTheme_Require_Environment' ) ) { include_once EMTMPL_CONST['plugin_dir'] . 'support/support.php'; } $environment = new \VillaTheme_Require_Environment( [ 'plugin_name' => EMTMPL_CONST['plugin_name'], 'php_version' => '7.4', 'wp_version' => '6.2', ] ); if ( $environment->has_error() ) { return; } add_filter( 'plugin_action_links_' . EMTMPL_CONST['basename'], [ $this, 'setting_link' ] ); add_action( 'init', [ $this, 'load_text_domain' ] ); $this->load_classes(); } public function load_text_domain() { $domain = '9mail-wp-email-templates-designer'; $locale = determine_locale(); $locale = apply_filters( 'plugin_locale', $locale, $domain ); $basename = dirname( EMTMPL_CONST['basename'] ); unload_textdomain( $domain, true ); load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $domain . '-' . $locale . '.mo' ); load_textdomain( $domain, EMTMPL_CONST['plugin_dir'] . 'languages/' . $domain . '-' . $locale . '.mo' ); load_plugin_textdomain( $domain, false, $basename . '/languages' ); } public function load_classes() { require_once EMTMPL_CONST['plugin_dir'] . 'inc/functions.php'; require_once EMTMPL_CONST['plugin_dir'] . 'support/support.php'; Enqueue::instance(); Email_Builder::instance(); Email_Trigger::instance(); $this->includes(); if ( is_admin() && ! wp_doing_ajax() ) { $this->support(); } } protected function includes() { $files = array( EMTMPL_CONST['plugin_dir'] . 'plugins' => [ 'class_prefix' => 'EMTMPL_Plugins_', 'file_name' => [ 'itsec.php', ] ], ); foreach ( $files as $path => $items ) { if ( empty( $items['file_name'] ) || ! is_array( $items['file_name'] ) ) { continue; } $class_prefix = $items['class_prefix'] ?? ''; foreach ( $items['file_name'] as $file_name ) { $file = $path . '/' . $file_name; if ( ! file_exists( $file ) ) { continue; } require_once $file; $ext_file = pathinfo( $file ); $class_name = $ext_file['filename'] ?? ''; if ( $class_prefix ) { $class_name = preg_replace( '/\W/i', '_', $class_prefix . ucfirst( $class_name ) ); } if ( $class_name && class_exists( $class_name ) ) { new $class_name; } } } } public function support() { if ( class_exists( 'VillaTheme_Support' ) ) { new \VillaTheme_Support( array( 'support' => 'https://wordpress.org/support/plugin/9mail-wp-email-templates-designer/', 'docs' => 'https://docs.villatheme.com/?item=9mail', 'review' => 'https://wordpress.org/support/plugin/9mail-wp-email-templates-designer/reviews/?rate=5#rate-response', 'pro_url' => 'https://villatheme.com/extensions/9mail-wordpress-email-templates-designer/', 'css' => EMTMPL_CONST['dist_url'], 'image' => EMTMPL_CONST['img_url'], 'slug' => '9mail-wp-email-templates-designer', 'menu_slug' => 'edit.php?post_type=wp_email_tmpl', 'version' => EMTMPL_CONST['version'], 'survey_url' => 'https://script.google.com/macros/s/AKfycbxCadAI0khct5tqhGMvp1kGqVOtHH05iwOqrbPyJcjGWiQiKv-64FL7-VpWbO0bPUU7/exec' ) ); } } public function emtmpl_activate() { $check_exist = get_posts( [ 'post_type' => 'wp_email_tmpl', 'numberposts' => 1 ] ); if ( empty( $check_exist ) ) { $default_subject = Email_Samples::default_subject(); $templates = Email_Samples::sample_templates(); $site_title = get_option( 'blogname' ); foreach ( $templates as $key => $template ) { // PHP 8.0+: avoid undefined array key warning when subject map lacks $key. $subject = isset( $default_subject[ $key ] ) ? (string) $default_subject[ $key ] : ''; $args = [ 'post_title' => $subject !== '' ? str_replace( '{site_title}', $site_title, $subject ) : '', 'post_status' => 'publish', 'post_type' => 'wp_email_tmpl', ]; $post_id = wp_insert_post( $args ); $template = $template['basic']['data']; $template = str_replace( '\\', '\\\\', $template ); update_post_meta( $post_id, 'emtmpl_settings_type', $key ); update_post_meta( $post_id, 'emtmpl_email_structure', $template ); } } } public function setting_link( $links ) { return array_merge( [ sprintf( "%2s", esc_url( admin_url( 'edit.php?post_type=wp_email_tmpl' ) ), esc_html__( 'Settings', '9mail-wp-email-templates-designer' ) ) ], $links ); } } new WP_Email_Templates_Designer(); }