# darkify/1.4.7/src/Frontend/DarkifyShortcode.php

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

- Page: https://pluginprobe.com/plugins/darkify/1.4.7/code/src/Frontend/DarkifyShortcode.php
- Raw: https://pluginprobe.com/plugins/darkify/1.4.7/raw/src/Frontend/DarkifyShortcode.php
- Modified: 2025-08-30T08:46:40+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.4.7/code/src/Frontend/DarkifyShortcode.php#L10-L20`.

```php
<?php

namespace ThemeAtelier\Darkify\Frontend;

// If this file is called directly, abort.
if (!defined('WPINC')) {
    die;
}

if (!class_exists('DarkifyShortcode')) {
    class DarkifyShortcode
    {

        public $base_client;

        public function __construct($base_client)
        {
            $this->base_client = $base_client;

            add_shortcode('darkify', array($this, 'darkify_shortcode_parser'));
        }

        public function darkify_shortcode_parser($atts, $content = null)
        {
            $options = get_option('darkify');

            // Background
            $switch_background = isset($options['switch_background']) ? $options['switch_background'] : [];
            $switch_light_mode_bg = !empty($switch_background) ? $switch_background['switch_light_mode_bg'] : '#121116';
            $switch_dark_mode_bg = !empty($switch_background) ? $switch_background['switch_dark_mode_bg'] : '#ffffff';

            // Border
            $switch_border = isset($options['switch_border']) ? $options['switch_border'] : [];
            $switch_border_all = !empty($switch_border['all']) ? $switch_border['all'] : "0px";
            $switch_border_light_color = !empty($switch_border['color']) ? $switch_border['color'] : "#ffffff";
            $switch_border_dark_color = !empty($switch_border['color3']) ? $switch_border['color3'] : "#121116";
            $switch_border_radius = !empty($switch_border['radius']) ? $switch_border['radius'] . 'px' : "7px";

            // Color
            $switch_icon_color = isset($options['switch_icon_color']) ? $options['switch_icon_color'] : [];
            $switch_light_mode_color = !empty($switch_icon_color) ? $switch_icon_color['switch_light_mode_color'] : '#ffffff';
            $switch_dark_mode_color = !empty($switch_icon_color) ? $switch_icon_color['switch_dark_mode_color'] : '#121116';

            $switch_icon_size = isset($options["switch_icon_size"]) ? $options["switch_icon_size"] : [];
            $switch_icon_size_width = !empty($switch_icon_size['width']) ? $switch_icon_size['width'] . "px" : '40px';

            $switch_width_height = isset($options['switch_width_height']) ? $options['switch_width_height'] : [];
            $switch_width = !empty($switch_width_height['width']) ? $switch_width_height['width'] . "px" : '60px';
            $switch_height = !empty($switch_width_height['height']) ? $switch_width_height['height'] . "px" : '60px';

            $atts = shortcode_atts(array(
                'switch' => '1',
                'light_mode_bg' =>  $switch_light_mode_bg,
                'dark_mode_bg' => $switch_dark_mode_bg,
                'width' => $switch_width,
                'height' => $switch_height,
                'border' =>  $switch_border_all,
                'border_light_color' => $switch_border_light_color,
                'border_dark_color' => $switch_border_dark_color,
                'border_radius' => $switch_border_radius,
                'light_mode_color' =>  $switch_light_mode_color,
                'dark_mode_color' => $switch_dark_mode_color,
                'icon_size' => $switch_icon_size_width,
            ), $atts);

            return $this->darkify_client_view_maker($atts);
        }
        public function darkify_client_view_maker($atts)
        {
            if (function_exists('wp_rand')) {
                $unique_id = wp_rand() . "_shortcode";
            }
            $switch_styles = $this->base_client->utils->generateSwitchStylesForShortcode($atts);
            ob_start();

            if (sizeof($switch_styles) > 0) { ?>
                <style type="text/css">
                    #darkify_switch_<?php echo esc_attr($unique_id); ?> {
                        <?php foreach ($switch_styles as $key => $value) { ?><?php echo esc_attr($key); ?>: <?php echo esc_attr($value); ?>;
                        <?php } ?>
                    }
                </style>
                <?php }

            $switcher_number = $atts['switch'];

            switch ($switcher_number) {
                case '1':
                    wp_enqueue_style('theme-classic');
                ?>
                    <div id="darkify_switch_<?php echo esc_attr($unique_id); ?>" onclick="darkify_switch_trigger()" class="darkify_switch darkify_switch_style" style="position: relative;">
                        <div class="theme-toggle">
                            <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" stroke-linecap="round" class="theme-toggle__classic" viewBox="0 0 32 32">
                                <clipPath id="theme-toggle__classic__cutout">
                                    <path d="M0-5h30a1 1 0 0 0 9 13v24H0Z" />
                                </clipPath>
                                <g clip-path="url(#theme-toggle__classic__cutout)">
                                    <circle cx="16" cy="16" r="9.34" />
                                    <g stroke="currentColor" stroke-width="1.5">
                                        <path d="M16 5.5v-4" />
                                        <path d="M16 30.5v-4" />
                                        <path d="M1.5 16h4" />
                                        <path d="M26.5 16h4" />
                                        <path d="m23.4 8.6 2.8-2.8" />
                                        <path d="m5.7 26.3 2.9-2.9" />
                                        <path d="m5.8 5.8 2.8 2.8" />
                                        <path d="m23.4 23.4 2.9 2.9" />
                                    </g>
                                </g>
                            </svg>
                        </div>
                    </div>
                <?php
                    break;
                case '2':
                    wp_enqueue_style('theme-expand');
                ?>
                    <div id="darkify_switch_<?php echo esc_attr($unique_id); ?>" onclick="darkify_switch_trigger()" class="darkify_switch darkify_switch_style">
                        <div class="theme-toggle">
                            <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="0px" height="0px" fill="currentColor" class="theme-toggle__expand" viewBox="0 0 32 32">
                                <clipPath id="theme-toggle__expand__cutout">
                                    <path d="M0-11h25a1 1 0 0017 13v30H0Z" />
                                </clipPath>
                                <g clip-path="url(#theme-toggle__expand__cutout)">
                                    <circle cx="16" cy="16" r="8.4" />
                                    <path d="M18.3 3.2c0 1.3-1 2.3-2.3 2.3s-2.3-1-2.3-2.3S14.7.9 16 .9s2.3 1 2.3 2.3zm-4.6 25.6c0-1.3 1-2.3 2.3-2.3s2.3 1 2.3 2.3-1 2.3-2.3 2.3-2.3-1-2.3-2.3zm15.1-10.5c-1.3 0-2.3-1-2.3-2.3s1-2.3 2.3-2.3 2.3 1 2.3 2.3-1 2.3-2.3 2.3zM3.2 13.7c1.3 0 2.3 1 2.3 2.3s-1 2.3-2.3 2.3S.9 17.3.9 16s1-2.3 2.3-2.3zm5.8-7C9 7.9 7.9 9 6.7 9S4.4 8 4.4 6.7s1-2.3 2.3-2.3S9 5.4 9 6.7zm16.3 21c-1.3 0-2.3-1-2.3-2.3s1-2.3 2.3-2.3 2.3 1 2.3 2.3-1 2.3-2.3 2.3zm2.4-21c0 1.3-1 2.3-2.3 2.3S23 7.9 23 6.7s1-2.3 2.3-2.3 2.4 1 2.4 2.3zM6.7 23C8 23 9 24 9 25.3s-1 2.3-2.3 2.3-2.3-1-2.3-2.3 1-2.3 2.3-2.3z" />
                                </g>
                            </svg>
                        </div>
                    </div>


                <?php break;
                case '3':
                    wp_enqueue_style('theme-inner-moon');
                ?>
                    <div id="darkify_switch_<?php echo esc_attr($unique_id); ?>" onclick="darkify_switch_trigger()" class="darkify_switch darkify_switch_style">
                        <div class="theme-toggle">
                            <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="0px" height="0px" fill="currentColor" class="theme-toggle__inner-moon" viewBox="0 0 32 32">
                                <path d="M27.5 11.5v-7h-7L16 0l-4.5 4.5h-7v7L0 16l4.5 4.5v7h7L16 32l4.5-4.5h7v-7L32 16l-4.5-4.5zM16 25.4a9.39 9.39 0 1 1 0-18.8 9.39 9.39 0 1 1 0 18.8z" />
                                <circle cx="16" cy="16" r="8.1" />
                            </svg>
                        </div>

                    </div>
                <?php
                    break;
                case '4':
                    wp_enqueue_style('theme-within');
                ?>
                    <div id="darkify_switch_<?php echo esc_attr($unique_id); ?>" onclick="darkify_switch_trigger()" class="darkify_switch darkify_switch_style">
                        <div class="theme-toggle">
                            <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" class="theme-toggle__within" height="1em" width="1em" viewBox="0 0 32 32" fill="currentColor">
                                <clipPath id="theme-toggle__within__clip">
                                    <path d="M0 0h32v32h-32ZM6 16A1 1 0 0026 16 1 1 0 006 16" />
                                </clipPath>
                                <g clip-path="url(#theme-toggle__within__clip)">
                                    <path d="M30.7 21.3 27.1 16l3.7-5.3c.4-.5.1-1.3-.6-1.4l-6.3-1.1-1.1-6.3c-.1-.6-.8-.9-1.4-.6L16 5l-5.4-3.7c-.5-.4-1.3-.1-1.4.6l-1 6.3-6.4 1.1c-.6.1-.9.9-.6 1.3L4.9 16l-3.7 5.3c-.4.5-.1 1.3.6 1.4l6.3 1.1 1.1 6.3c.1.6.8.9 1.4.6l5.3-3.7 5.3 3.7c.5.4 1.3.1 1.4-.6l1.1-6.3 6.3-1.1c.8-.1 1.1-.8.7-1.4zM16 25.1c-5.1 0-9.1-4.1-9.1-9.1 0-5.1 4.1-9.1 9.1-9.1s9.1 4.1 9.1 9.1c0 5.1-4 9.1-9.1 9.1z" />
                                </g>
                                <path class="theme-toggle__within__circle" d="M16 7.7c-4.6 0-8.2 3.7-8.2 8.2s3.6 8.4 8.2 8.4 8.2-3.7 8.2-8.2-3.6-8.4-8.2-8.4zm0 14.4c-3.4 0-6.1-2.9-6.1-6.2s2.7-6.1 6.1-6.1c3.4 0 6.1 2.9 6.1 6.2s-2.7 6.1-6.1 6.1z" />
                                <path class="theme-toggle__within__inner" d="M16 9.5c-3.6 0-6.4 2.9-6.4 6.4s2.8 6.5 6.4 6.5 6.4-2.9 6.4-6.4-2.8-6.5-6.4-6.5z" />
                            </svg>
                        </div>

                    </div>
                <?php break;
                default:
                    wp_enqueue_style('theme-classic');
                ?>
                    <div id="darkify_switch_<?php echo esc_attr($unique_id); ?>" onclick="darkify_switch_trigger()" class="darkify_switch darkify_switch_style" style="position: relative;">
                        <div class="theme-toggle">
                            <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="0px" height="0px" fill="currentColor" stroke-linecap="round" class="theme-toggle__classic" viewBox="0 0 32 32">
                                <clipPath id="theme-toggle__classic__cutout">
                                    <path d="M0-5h30a1 1 0 0 0 9 13v24H0Z" />
                                </clipPath>
                                <g clip-path="url(#theme-toggle__classic__cutout)">
                                    <circle cx="16" cy="16" r="9.34" />
                                    <g stroke="currentColor" stroke-width="1.5">
                                        <path d="M16 5.5v-4" />
                                        <path d="M16 30.5v-4" />
                                        <path d="M1.5 16h4" />
                                        <path d="M26.5 16h4" />
                                        <path d="m23.4 8.6 2.8-2.8" />
                                        <path d="m5.7 26.3 2.9-2.9" />
                                        <path d="m5.8 5.8 2.8 2.8" />
                                        <path d="m23.4 23.4 2.9 2.9" />
                                    </g>
                                </g>
                            </svg>
                        </div>
                    </div>
<?php
            }
            return ob_get_clean();
        }
    }
}

```
