class-thwcfd.php
115 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The file that defines the core plugin class. |
| 4 | * |
| 5 | * @link https://themehigh.com |
| 6 | * @since 1.5.0 |
| 7 | * |
| 8 | * @package woo-checkout-field-editor-pro |
| 9 | * @subpackage woo-checkout-field-editor-pro/includes |
| 10 | */ |
| 11 | if(!defined('WPINC')){ die; } |
| 12 | |
| 13 | if(!class_exists('THWCFD')): |
| 14 | |
| 15 | class THWCFD { |
| 16 | protected $plugin_name; |
| 17 | protected $version; |
| 18 | const TEXT_DOMAIN = 'woo-checkout-field-editor-pro'; |
| 19 | |
| 20 | public function __construct() { |
| 21 | if(defined( 'THWCFD_VERSION')){ |
| 22 | $this->version = THWCFD_VERSION; |
| 23 | } else { |
| 24 | $this->version = '1.0.0'; |
| 25 | } |
| 26 | $this->plugin_name = 'woo-checkout-field-editor-pro'; |
| 27 | |
| 28 | $this->load_dependencies(); |
| 29 | $this->set_locale(); |
| 30 | $this->define_admin_hooks(); |
| 31 | $this->define_public_hooks(); |
| 32 | |
| 33 | add_action('init', array($this, 'init')); |
| 34 | } |
| 35 | |
| 36 | private function load_dependencies() { |
| 37 | if(!function_exists('is_plugin_active')){ |
| 38 | include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 39 | } |
| 40 | |
| 41 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-thwcfd-autoloader.php'; |
| 42 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-thwcfd-admin.php'; |
| 43 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-thwcfd-public-checkout.php'; |
| 44 | |
| 45 | // require_once THWCFD_PATH . 'classes/class-thwcfd-utils.php'; |
| 46 | // require_once THWCFD_PATH . 'classes/class-thwcfd-settings.php'; |
| 47 | // require_once THWCFD_PATH . 'classes/class-thwcfd-settings-general.php'; |
| 48 | // require_once THWCFD_PATH . 'classes/class-thwcfd-settings-advanced.php'; |
| 49 | // require_once THWCFD_PATH . 'classes/class-thwcfd-checkout.php'; |
| 50 | } |
| 51 | |
| 52 | private function set_locale() { |
| 53 | add_action('plugins_loaded', array($this, 'load_plugin_textdomain')); |
| 54 | } |
| 55 | |
| 56 | public function load_plugin_textdomain(){ |
| 57 | $locale = apply_filters('plugin_locale', get_locale(), self::TEXT_DOMAIN); |
| 58 | |
| 59 | load_textdomain(self::TEXT_DOMAIN, WP_LANG_DIR.'/woo-checkout-field-editor-pro/'.self::TEXT_DOMAIN.'-'.$locale.'.mo'); |
| 60 | load_plugin_textdomain(self::TEXT_DOMAIN, false, dirname(THWCFD_BASE_NAME) . '/languages/'); |
| 61 | } |
| 62 | |
| 63 | private function define_admin_hooks() { |
| 64 | $plugin_admin = new THWCFD_Admin( $this->get_plugin_name(), $this->get_version() ); |
| 65 | |
| 66 | add_action('admin_enqueue_scripts', array($plugin_admin, 'enqueue_styles_and_scripts')); |
| 67 | add_action('admin_menu', array($plugin_admin, 'admin_menu')); |
| 68 | add_filter('woocommerce_screen_ids', array($plugin_admin, 'add_screen_id')); |
| 69 | add_filter('plugin_action_links_'.THWCFD_BASE_NAME, array($plugin_admin, 'plugin_action_links')); |
| 70 | //add_filter('plugin_row_meta', array($plugin_admin, 'plugin_row_meta'), 10, 2); |
| 71 | add_action('wp_ajax_dismiss_thwcfd_review_request_notice', array($plugin_admin, 'dismiss_thwcfd_review_request_notice')); |
| 72 | add_action('wp_ajax_skip_thwcfd_review_request_notice', array($plugin_admin, 'skip_thwcfd_review_request_notice')); |
| 73 | |
| 74 | $general_settings = new THWCFD_Admin_Settings_General(); |
| 75 | add_action('after_setup_theme', array($general_settings, 'define_admin_hooks')); |
| 76 | } |
| 77 | |
| 78 | private function define_public_hooks() { |
| 79 | //if(!is_admin() || (defined( 'DOING_AJAX' ) && DOING_AJAX)){ |
| 80 | $plugin_checkout = new THWCFD_Public_Checkout( $this->get_plugin_name(), $this->get_version() ); |
| 81 | add_action('wp_enqueue_scripts', array($plugin_checkout, 'enqueue_styles_and_scripts')); |
| 82 | add_action('after_setup_theme', array($plugin_checkout, 'define_public_hooks')); |
| 83 | //} |
| 84 | } |
| 85 | |
| 86 | public function init(){ |
| 87 | $this->define_constants(); |
| 88 | } |
| 89 | |
| 90 | private function define_constants(){ |
| 91 | !defined('THWCFD_ASSETS_URL_ADMIN') && define('THWCFD_ASSETS_URL_ADMIN', THWCFD_URL . 'admin/assets/'); |
| 92 | !defined('THWCFD_ASSETS_URL_PUBLIC') && define('THWCFD_ASSETS_URL_PUBLIC', THWCFD_URL . 'public/assets/'); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * The name of the plugin used to uniquely identify it within the context of |
| 97 | * WordPress and to define internationalization functionality. |
| 98 | * |
| 99 | * @return string The name of the plugin. |
| 100 | */ |
| 101 | public function get_plugin_name() { |
| 102 | return $this->plugin_name; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Retrieve the version number of the plugin. |
| 107 | * |
| 108 | * @return string The version number of the plugin. |
| 109 | */ |
| 110 | public function get_version() { |
| 111 | return $this->version; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | endif; |