*/ class Frontend { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; public $utils; public $settings; public $external_support; public $unique_id; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of the plugin. * @param string $version The version of this plugin. */ public function __construct($plugin_name, $version) { $this->plugin_name = $plugin_name; $this->version = $version; $this->utils = new DarkifyUtils($this); $this->external_support = new DarkifyExternalSupport($this); new DarkifyShortcode($this); if (function_exists('wp_rand')) { $this->unique_id = wp_rand(); } $options = get_option('darkify'); $show_in_menu = isset($options['show_in_menu']) ? $options['show_in_menu'] : ""; $enable_switcher_in_menu = isset($show_in_menu["enable_switch_in_menu"]) ? $show_in_menu["enable_switch_in_menu"] : false; if ($enable_switcher_in_menu) { add_filter('wp_nav_menu_items', array($this, 'darkify_switch_in_menu'), 10, 2); } add_action('wp_enqueue_scripts', array($this, 'darkify_client_enqueue'), 100); add_action('login_enqueue_scripts', array($this, 'darkify_client_enqueue')); add_action('register_enqueue_scripts', array($this, 'darkify_client_enqueue')); add_action('wp_head', array($this, 'darkify_client_header_script'), 1); add_action('login_head', array($this, 'darkify_client_header_script'), 1); add_action('register_head', array($this, 'darkify_client_header_script'), 1); add_action('wp_footer', array($this, 'darkify_client_footer_script')); add_action('login_footer', array($this, 'darkify_client_footer_script')); add_action('register_footer', array($this, 'darkify_client_footer_script')); add_filter('autoptimize_filter_js_exclude', array($this, 'darkify_exclude_js_from_cache_plugins')); } public function darkify_exclude_js_from_cache_plugins($excludes) { $excludes .= ',client_main.js,client_main.min.js'; return $excludes; } function darkify_client_enqueue() { if ($this->darkify_is_dark_mode_allowed()) { $options = get_option('darkify'); $enable_dark_switcher = isset($options['enable_dark_switcher']) ? $options['enable_dark_switcher'] : 'classic'; $min = (apply_filters('darkify_dev_mode', false) || WP_DEBUG) ? '' : '.min'; wp_enqueue_style('darkify-client-main', DARKIFY_DIR_URL . 'src/assets/css/client_main' . $min . '.css', array(), DARKIFY_VERSION); // wp_enqueue_style("theme-{$enable_dark_switcher}", DARKIFY_DIR_URL . 'src/assets/css/switcher/' . $enable_dark_switcher . $min . '.css', array('darkify-client-main'), DARKIFY_VERSION, 'all'); wp_register_style('theme-around', DARKIFY_DIR_URL . 'src/assets/css/switcher/around' . $min . '.css', array('darkify-client-main'), DARKIFY_VERSION, 'all'); wp_register_style('theme-classic', DARKIFY_DIR_URL . 'src/assets/css/switcher/classic' . $min . '.css', array('darkify-client-main'), DARKIFY_VERSION, 'all'); wp_register_style('theme-dark-inner', DARKIFY_DIR_URL . 'src/assets/css/switcher/dark-inner' . $min . '.css', array(), DARKIFY_VERSION, 'all'); wp_register_style('theme-dark-side', DARKIFY_DIR_URL . 'src/assets/css/switcher/dark-side' . $min . '.css', array(), DARKIFY_VERSION, 'all'); wp_register_style('theme-eclipse', DARKIFY_DIR_URL . 'src/assets/css/switcher/eclipse' . $min . '.css', array(), DARKIFY_VERSION, 'all'); wp_register_style('theme-expand', DARKIFY_DIR_URL . 'src/assets/css/switcher/expand' . $min . '.css', array('darkify-client-main'), DARKIFY_VERSION, 'all'); wp_register_style('theme-half-sun', DARKIFY_DIR_URL . 'src/assets/css/switcher/half-sun' . $min . '.css', array(), DARKIFY_VERSION, 'all'); wp_register_style('theme-horizon', DARKIFY_DIR_URL . 'src/assets/css/switcher/horizon' . $min . '.css', array(), DARKIFY_VERSION, 'all'); wp_register_style('theme-inner-moon', DARKIFY_DIR_URL . 'src/assets/css/switcher/inner-moon' . $min . '.css', array(), DARKIFY_VERSION, 'all'); wp_register_style('theme-lightbulb', DARKIFY_DIR_URL . 'src/assets/css/switcher/lightbulb' . $min . '.css', array(), DARKIFY_VERSION, 'all'); wp_register_style('theme-simple', DARKIFY_DIR_URL . 'src/assets/css/switcher/simple' . $min . '.css', array(), DARKIFY_VERSION, 'all'); wp_register_style('theme-orbit', DARKIFY_DIR_URL . 'src/assets/css/switcher/orbit' . $min . '.css', array(), DARKIFY_VERSION, 'all'); wp_register_style('theme-duality', DARKIFY_DIR_URL . 'src/assets/css/switcher/duality' . $min . '.css', array(), DARKIFY_VERSION, 'all'); wp_register_style('theme-dual', DARKIFY_DIR_URL . 'src/assets/css/switcher/dual' . $min . '.css', array(), DARKIFY_VERSION, 'all'); wp_register_style('theme-shift', DARKIFY_DIR_URL . 'src/assets/css/switcher/shift' . $min . '.css', array(), DARKIFY_VERSION, 'all'); wp_register_style('theme-within', DARKIFY_DIR_URL . 'src/assets/css/switcher/within' . $min . '.css', array(), DARKIFY_VERSION, 'all'); wp_enqueue_script('darkify-client-main', DARKIFY_DIR_URL . 'src/assets/js/client_main' . $min . '.js', array('jquery'), DARKIFY_VERSION); } } public function darkify_is_dark_mode_allowed() { $options = get_option('darkify'); /* Disable if Oxygen Builder is Opened */ if (isset($_GET['ct_builder'])) { if ($_GET['ct_builder'] == "true") { if (!isset($_GET['oxygen_iframe'])) { return False; } } } return True; } public function darkify_client_header_script() { if ($this->darkify_is_dark_mode_allowed()) { include_once DarkifyUtils::darkify_locate_template('header_script.php'); } } public function darkify_client_footer_script() { if ($this->darkify_is_dark_mode_allowed()) { include_once DarkifyUtils::darkify_locate_template('footer_script.php'); } } function darkify_switch_in_menu($items, $args) { $options = get_option('darkify'); $show_in_menu = $options['show_in_menu']; $select_menus = isset($show_in_menu['select_menus']) ? $show_in_menu['select_menus'] : []; $last_shortcode = ''; if ($this->darkify_is_dark_mode_allowed() && isset($args->menu->term_id)) { foreach ($select_menus as $select_menu) { $switch_in_menu_location = $select_menu['switch_in_menu_location'] ?? ''; $darkify_menu_shortcode_helper = $select_menu['darkify_menu_shortcode_helper'] ?? ''; $menu_position = isset($select_menu['select_menu_position']) ? $select_menu['select_menu_position'] : 'after'; if ($args->menu->term_id == $switch_in_menu_location) { $last_shortcode = $darkify_menu_shortcode_helper; } } if ($last_shortcode) { $items = ($menu_position == 'before') ? '