PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 2.0.2
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v2.0.2
2.1.2 2.1.1 2.1.0 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 trunk 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 All 56 releases
darkify / src / Frontend / DarkifyShortcode.php

DarkifyShortcode.php in Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) 2.0.2, at src/Frontend/DarkifyShortcode.php

100 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ThemeAtelier\Darkify\Frontend;
4
5 use ThemeAtelier\Darkify\Includes\Darkify;
6
7 // If this file is called directly, abort.
8 if (!defined('WPINC')) {
9 die;
10 }
11
12 if (!class_exists('DarkifyShortcode')) {
13 class DarkifyShortcode
14 {
15
16 public $base_client;
17
18 public function __construct($base_client)
19 {
20 $this->base_client = $base_client;
21
22 add_shortcode('darkify', array($this, 'darkify_shortcode_parser'));
23 }
24
25 public function darkify_shortcode_parser($atts, $content = null)
26 {
27 $options = get_option('darkify');
28
29 // Background
30 $switch_background = isset($options['switch_background']) ? $options['switch_background'] : [];
31 $switch_light_mode_bg = !empty($switch_background) ? $switch_background['switch_light_mode_bg'] : '#121116';
32 $switch_dark_mode_bg = !empty($switch_background) ? $switch_background['switch_dark_mode_bg'] : '#ffffff';
33
34 // Border
35 $switch_border = isset($options['switch_border']) ? $options['switch_border'] : [];
36 $switch_border_all = !empty($switch_border['all']) ? $switch_border['all'] : "0px";
37 $switch_border_light_color = !empty($switch_border['color']) ? $switch_border['color'] : "#ffffff";
38 $switch_border_dark_color = !empty($switch_border['color3']) ? $switch_border['color3'] : "#121116";
39 $switch_border_radius = !empty($switch_border['radius']) ? $switch_border['radius'] . 'px' : "7px";
40
41 // Color
42 $switch_icon_color = isset($options['switch_icon_color']) ? $options['switch_icon_color'] : [];
43 $switch_light_mode_color = !empty($switch_icon_color) ? $switch_icon_color['switch_light_mode_color'] : '#ffffff';
44 $switch_dark_mode_color = !empty($switch_icon_color) ? $switch_icon_color['switch_dark_mode_color'] : '#121116';
45
46 $atts = shortcode_atts(array(
47 'switch' => '1',
48 'switch_size' => '100',
49 'light_mode_bg' => $switch_light_mode_bg,
50 'dark_mode_bg' => $switch_dark_mode_bg,
51 'border' => $switch_border_all,
52 'border_light_color' => $switch_border_light_color,
53 'border_dark_color' => $switch_border_dark_color,
54 'border_radius' => $switch_border_radius,
55 'light_mode_color' => $switch_light_mode_color,
56 'dark_mode_color' => $switch_dark_mode_color,
57 ), $atts);
58
59 return $this->darkify_client_view_maker($atts);
60 }
61 public function darkify_client_view_maker($atts)
62 {
63 if (function_exists('wp_rand')) {
64 $unique_id = wp_rand() . "_shortcode";
65 }
66 $switch_styles = $this->base_client->utils->generateSwitchStylesForShortcode($atts);
67 ob_start();
68
69 if (sizeof($switch_styles) > 0) { ?>
70 <style type="text/css">
71 #darkify_switch_<?php echo esc_attr($unique_id); ?> {
72 <?php foreach ($switch_styles as $key => $value) { ?><?php echo esc_attr($key); ?>: <?php echo esc_attr($value); ?>;
73 <?php } ?>
74 }
75 </style>
76 <?php }
77
78 $switcher_number = $atts['switch'];
79
80 $switcher_number = $atts['switch'];
81 if ($switcher_number === '1') {
82 $switcher_number = 'classic';
83 } elseif ($switcher_number === '2') {
84 $switcher_number = 'expand';
85 } elseif ($switcher_number === '3') {
86 $switcher_number = 'inner-moon';
87 } elseif ($switcher_number === '4') {
88 $switcher_number = 'within';
89 } elseif ($switcher_number === '5') {
90 $switcher_number = 'orbit';
91 }
92 $switch_size = $atts['switch_size'] / 100;
93 // switcher_wrapper() escapes each dynamic value internally, so its
94 // returned markup is safe to print as-is.
95 echo Darkify::switcher_wrapper('shortcode', $unique_id, $switcher_number, $switch_size); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
96 return ob_get_clean();
97 }
98 }
99 }
100