define_constants(); $this->includes(); $this->init_hooks(); } /** * Define Constants. */ private function define_constants() { $this->define( 'NOTIFIER_VERSION', '2.1.3' ); $this->define( 'NOTIFIER_NAME', 'notifier' ); $this->define( 'NOTIFIER_PREFIX', 'notifier_' ); $this->define( 'NOTIFIER_URL', trailingslashit( plugins_url( '', dirname(__FILE__) ) ) ); $this->define( 'NOTIFIER_APP_API_URL', 'https://app.wanotifier.com/api/v1/' ); } /** * Define constant if not already set. * * @param string $name Constant name. * @param string|bool $value Constant value. */ private function define( $name, $value ) { if ( ! defined( $name ) ) { define( $name, $value ); } } /** * Main Notifier Instance. * * @return Notifier instance. */ public static function get_instance() { if ( is_null( self::$_instance ) ) { self::$_instance = new self(); } return self::$_instance; } /** * Include required core files used in admin and on the frontend. */ private function includes() { // Functions require_once NOTIFIER_PATH . 'includes/functions/functions-notifier-helpers.php'; require_once NOTIFIER_PATH . 'includes/functions/functions-notifier-meta-box-fields.php'; // Classes require_once NOTIFIER_PATH . 'includes/classes/class-notifier-admin-notices.php'; require_once NOTIFIER_PATH . 'includes/classes/class-notifier-dashboard.php'; require_once NOTIFIER_PATH . 'includes/classes/class-notifier-notification-merge-tags.php'; require_once NOTIFIER_PATH . 'includes/classes/class-notifier-notification-triggers.php'; require_once NOTIFIER_PATH . 'includes/classes/class-notifier-settings.php'; require_once NOTIFIER_PATH . 'includes/classes/class-notifier-frontend.php'; } /** * Hook into actions and filters. */ private function init_hooks() { register_activation_hook ( NOTIFIER_FILE, array( $this, 'install') ); add_action( 'after_setup_theme', array( 'Notifier_Admin_Notices', 'init' ) ); add_action( 'after_setup_theme', array( 'Notifier_Dashboard', 'init' ) ); add_action( 'after_setup_theme', array( 'Notifier_Notification_Merge_Tags', 'init' ) ); add_action( 'after_setup_theme', array( 'Notifier_Notification_Triggers', 'init' ) ); add_action( 'after_setup_theme', array( 'Notifier_Settings', 'init' ) ); add_action( 'after_setup_theme', array( 'Notifier_Frontend', 'init' ) ); add_action( 'admin_enqueue_scripts', array( $this , 'admin_scripts') ); add_action( 'wp_enqueue_scripts', array( $this , 'frontend_scripts') ); add_action( 'in_admin_header', array( $this , 'embed_page_header' ) ); add_action( 'after_setup_theme', array( $this, 'maybe_include_integrations' ) ); } /** * Setup during plugin activation */ public function install() { } /** * Check if plugin's page */ public static function is_notifier_page() { $current_screen = get_current_screen(); if ( strpos($current_screen->id, NOTIFIER_NAME) !== false) { return true; } return false; } /** * Add admin scripts and styles */ public function admin_scripts () { if (!self::is_notifier_page()) { return; } // Select2 wp_enqueue_script( NOTIFIER_NAME . '-select2-js', NOTIFIER_URL . 'assets/js/select2.min.js', array('jquery'), NOTIFIER_VERSION, true ); // Admin JS file wp_enqueue_script( NOTIFIER_NAME . '-admin-js', NOTIFIER_URL . 'assets/js/admin.js', array('jquery'), NOTIFIER_VERSION, true ); wp_localize_script( NOTIFIER_NAME . '-admin-js', 'notifierObj', apply_filters( 'notifier_js_variables', array('ajaxurl' => admin_url( 'admin-ajax.php' ) ) ) ); // Styles wp_enqueue_style( NOTIFIER_NAME . '-admin-css', NOTIFIER_URL . 'assets/css/admin.css', null, NOTIFIER_VERSION ); } /** * Add frontend scripts and styles */ public function frontend_scripts () { if('yes' === get_option('notifier_ctc_enable')){ // Styles wp_enqueue_style( NOTIFIER_NAME . '-frontend-css', NOTIFIER_URL . 'assets/css/frontend.css', null, NOTIFIER_VERSION ); } } /** * Set up a div for the header embed to render into. * The initial contents here are meant as a place loader for when the PHP page initialy loads. */ public static function embed_page_header() { if (!self::is_notifier_page()) { return; } $current_screen = get_current_screen(); $cpt = ( '' !== $current_screen->post_type) ? $current_screen->post_type : ''; $tax = ( '' !== $current_screen->taxonomy) ? $current_screen->taxonomy : ''; ?>