# darkify/1.3.0/src/Frontend/Frontend.php

Darkify – Dark Mode &amp; Night Mode for Website &amp; Admin (Dark Theme Included), version 1.3.0. 216 lines.

- Page: https://pluginprobe.com/plugins/darkify/1.3.0/code/src/Frontend/Frontend.php
- Raw: https://pluginprobe.com/plugins/darkify/1.3.0/raw/src/Frontend/Frontend.php
- Modified: 2025-03-21T01:44:12+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/darkify/1.3.0/code/src/Frontend/Frontend.php#L10-L20`.

```php
<?php

namespace ThemeAtelier\Darkify\Frontend;

use ThemeAtelier\Darkify\Helpers\DarkifyExternalSupport;
use ThemeAtelier\Darkify\Helpers\DarkifyUtils;
use ThemeAtelier\Darkify\Helpers\Helpers;

/**
 * The public-facing functionality of the plugin.
 *
 * @link       https://themeatelier.net
 * @since      1.0.0
 *
 * @package    Darkify
 * @subpackage Darkify/public
 */

/**
 * The public-facing functionality of the plugin.
 *
 * Defines the plugin name, version, and two examples hooks for how to
 * enqueue the public-facing stylesheet and JavaScript.
 *
 * @package    Darkify
 * @subpackage Darkify/public
 * @author     ThemeAtelier <themeatelierbd@gmail.com>
 */
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'));
        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'));
    }


    public function darkify_client_enqueue()
    {
        if ($this->darkify_is_dark_mode_allowed()) {
            $options = get_option('darkify');
            $enable_dark_switcher = $options['enable_dark_switcher'];
            $enable_time = $options['enable_time'];

            $enable_default_dark_mode = $options['enable_default_dark_mode'];
            $enable_time = $options['enable_time'];
            $enable_time_based_dark = isset($enable_time['enable_time_based_dark']) ? $enable_time['enable_time_based_dark'] : "";
            $time_based_dark_start = isset($enable_time['time_based_dark_start']['from']) ? $enable_time['time_based_dark_start']['from'] : "";
            $time_based_dark_stop =  isset($enable_time['time_based_dark_start']['to'])  ?  $enable_time['time_based_dark_start']['to'] : "";
            $grayscale =  $options['brightness'];
            $enable_low_image_brightness =  isset($grayscale['enable_low_image_brightness']) ? $grayscale['enable_low_image_brightness'] : "";
            $low_image_brightness_label =  isset($grayscale['low_image_brightness_label']) ? $grayscale['low_image_brightness_label'] : "";
            $grayscale =  isset($options['grayscale']);
            $enable_image_grayscale =  isset($grayscale['enable_image_grayscale']) ? $grayscale['enable_image_grayscale'] : "";
            $image_grayscale_label =  isset($grayscale['image_grayscale_label']) ? $grayscale['image_grayscale_label'] : "";
            $disallowed_low_grayscale_images =  isset($grayscale['disallowed_low_grayscale_images']) ? $grayscale['disallowed_low_grayscale_images'] : "";
            $darken_background =  isset($options['darken_background']);
            $enable_low_image_darken =  isset($darken_background['enable_low_image_darken']) ? $darken_background['enable_low_image_darken'] : "";
            $low_image_darken_label =  isset($darken_background['low_image_darken_label']) ? $darken_background['low_image_darken_label'] : "";
            $video_brightness =  isset($options['video_brightness']);
            $enable_low_video_brightness =  isset($video_brightness['enable_low_video_brightness']) ? $video_brightness['enable_low_video_brightness'] : "";
            $low_video_brightness_label =  isset($video_brightness['low_video_brightness_label']) ? $video_brightness['low_video_brightness_label'] : "";
            $video_grayscale =  isset($options['video_grayscale']);
            $enable_video_grayscale =  isset($video_grayscale['enable_video_grayscale']) ? $video_grayscale['enable_video_grayscale'] : "";



            wp_enqueue_style("theme-{$enable_dark_switcher}", DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/$enable_dark_switcher.css", array(), DARKIFY_VERSION, 'all');
            wp_register_style('theme-around',  DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/around.css", array(), DARKIFY_VERSION, 'all');
            wp_register_style('theme-classic',  DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/classic.css", array(), DARKIFY_VERSION, 'all');
            wp_register_style('theme-dark-inner',  DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/dark-inner.css", array(), DARKIFY_VERSION, 'all');
            wp_register_style('theme-dark-side',  DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/dark-side.css", array(), DARKIFY_VERSION, 'all');
            wp_register_style('theme-eclipse',  DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/eclipse.css", array(), DARKIFY_VERSION, 'all');
            wp_register_style('theme-expand',  DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/expand.css", array(), DARKIFY_VERSION, 'all');
            wp_register_style('theme-half-sun',  DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/half-sun.css", array(), DARKIFY_VERSION, 'all');
            wp_register_style('theme-horizon',  DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/horizon.css", array(), DARKIFY_VERSION, 'all');
            wp_register_style('theme-inner-moon',  DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/inner-moon.css", array(), DARKIFY_VERSION, 'all');
            wp_register_style('theme-lightbulb',  DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/lightbulb.css", array(), DARKIFY_VERSION, 'all');
            wp_register_style('theme-simple',  DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/simple.css", array(), DARKIFY_VERSION, 'all');
            wp_register_style('theme-within',  DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/within.css", array(), DARKIFY_VERSION, 'all');
            wp_enqueue_style('darkify-client-main', DARKIFY_DIR_URL . 'src/assets/css/client_main.css', array(), DARKIFY_VERSION);
            wp_enqueue_style('ico-font', DARKIFY_DIR_URL . 'src/assets/css/icofont.css', array(), DARKIFY_VERSION);
            wp_enqueue_script('darkify-client-main', DARKIFY_DIR_URL . 'src/assets/js/client_main.js', array('jquery'), DARKIFY_VERSION);

            $darkify_data = array(
                'darkify_switch_unique_id' => $this->unique_id,
                'darkify_is_this_admin_panel' => is_admin() ? "1" : "0",
                'darkify_enable_default_dark_mode' => $enable_default_dark_mode,
                'darkify_enable_os_aware' => $options["enable_os_aware"],
                'darkify_enable_keyboard_shortcut' => $options["enable_keyboard_shortcut"],
                'darkify_enable_time_based_dark' => $enable_time_based_dark,
                'darkify_time_based_dark_start' => $time_based_dark_start ? $time_based_dark_start : "19:00",
                'darkify_time_based_dark_stop' => $time_based_dark_stop ? $time_based_dark_stop : "07:00",
                'darkify_alternative_dark_mode_switch' => $options["alternative_dark_mode_switcher"],
                'darkify_enable_low_image_brightness' => $enable_low_image_brightness,
                'darkify_image_brightness_to' => $low_image_brightness_label,
                'darkify_enable_image_grayscale' => $enable_image_grayscale,
                'darkify_image_grayscale_to' => $image_grayscale_label,
                'darkify_disallowed_grayscale_images' => $disallowed_low_grayscale_images,
                'darkify_enable_bg_image_darken' => $enable_low_image_darken,
                'darkify_bg_image_darken_to' => $low_image_darken_label,
                'darkify_enable_invert_inline_svg' => $options["enable_invert_inline_svg"],
                'darkify_enable_low_video_brightness' => $enable_low_video_brightness,
                'darkify_video_brightness_to' => $low_video_brightness_label,
                'darkify_enable_video_grayscale' => $enable_video_grayscale,
                // Add more variables as needed...
            );
            wp_localize_script('darkify-client-main', 'darkify_data', $darkify_data);
        }
    }
    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 Helpers::darkify_locate_template('header_script.php');
        }
    }

    public function darkify_client_footer_script()
    {
        if ($this->darkify_is_dark_mode_allowed()) {
            include_once Helpers::darkify_locate_template('footer_script.php');
        }
    }

    public function darkify_switch_in_menu($items, $args)
    {
        $options = get_option('darkify');
        $show_in_menu = $options['show_in_menu'];
        $switch_in_menu_location = $show_in_menu['switch_in_menu_location'];
        $darkify_menu_shortcode_helper = $show_in_menu['darkify_menu_shortcode_helper'];

        if ($this->darkify_is_dark_mode_allowed()) {
            if (isset($args->menu->term_id)) {
                if ($args->menu->term_id == $switch_in_menu_location) {
                    $items .=  '<li class="menu-item">' . do_shortcode($darkify_menu_shortcode_helper) . '</li>';
                }
            }
        }
        return $items;
    }
}

```
