PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.3.0
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.3.0
2.1.3 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 All 57 releases
darkify / src / Admin / Framework / Classes / abstract.class.php

abstract.class.php in Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) 1.3.0, at src/Admin/Framework/Classes/abstract.class.php

199 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use ThemeAtelier\Darkify\Admin\Framework\Classes\Darkify;
4
5 if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
6 /**
7 *
8 * Abstract Class
9 *
10 * @since 1.0.0
11 * @version 1.0.0
12 *
13 */
14 if ( ! class_exists( 'DarkifyAbstract' ) ) {
15 abstract class DarkifyAbstract {
16
17 public $abstract = '';
18 public $output_css = '';
19
20 public function __construct() {
21
22 // Collect output css and typography
23 if ( ! empty( $this->args['output_css'] ) || ! empty( $this->args['enqueue_webfont'] ) ) {
24 add_action( 'wp_enqueue_scripts', array( $this, 'collect_output_css_and_typography' ), 10 );
25 Darkify::$css = apply_filters( "darkify_{$this->unique}_output_css", Darkify::$css, $this );
26 }
27
28 }
29
30 public function collect_output_css_and_typography() {
31 $this->recursive_output_css( $this->pre_fields );
32 }
33
34 public function recursive_output_css( $fields = array(), $combine_field = array() ) {
35
36 if ( ! empty( $fields ) ) {
37
38 foreach ( $fields as $field ) {
39
40 $field_id = ( ! empty( $field['id'] ) ) ? $field['id'] : '';
41 $field_type = ( ! empty( $field['type'] ) ) ? $field['type'] : '';
42 $field_output = ( ! empty( $field['output'] ) ) ? $field['output'] : '';
43 $field_check = ( $field_type === 'typography' || $field_output ) ? true : false;
44 $field_class = 'DarkifyField_' . $field_type;
45
46 if ( $field_type && $field_id ) {
47
48
49 if( $field_type === 'fieldset' ) {
50 if ( ! empty( $field['fields'] ) ) {
51 $this->recursive_output_css( $field['fields'], $field );
52 }
53 }
54
55 if( $field_type === 'accordion' ) {
56 if ( ! empty( $field['accordions'] ) ) {
57 foreach ( $field['accordions'] as $accordion ) {
58 $this->recursive_output_css( $accordion['fields'], $field );
59 }
60 }
61 }
62
63 if( $field_type === 'tabbed' ) {
64 if ( ! empty( $field['tabs'] ) ) {
65 foreach ( $field['tabs'] as $accordion ) {
66 $this->recursive_output_css( $accordion['fields'], $field );
67 }
68 }
69 }
70
71 if ( class_exists( $field_class ) ) {
72
73 if ( method_exists( $field_class, 'output' ) || method_exists( $field_class, 'enqueue_google_fonts' ) ) {
74
75 $field_value = '';
76
77 if ( $field_check && ( $this->abstract === 'options' || $this->abstract === 'customize' ) ) {
78
79 if( ! empty( $combine_field ) ) {
80
81 $field_value = ( isset( $this->options[$combine_field['id']][$field_id] ) ) ? $this->options[$combine_field['id']][$field_id] : '';
82
83 } else {
84
85 $field_value = ( isset( $this->options[$field_id] ) ) ? $this->options[$field_id] : '';
86
87 }
88
89 } else if ( $field_check && ( $this->abstract === 'metabox' && is_singular() || $this->abstract === 'taxonomy' && is_archive() ) ) {
90
91 if( ! empty( $combine_field ) ) {
92
93 $meta_value = $this->get_meta_value( $combine_field );
94 $field_value = ( isset( $meta_value[$field_id] ) ) ? $meta_value[$field_id] : '';
95
96 } else {
97
98 $meta_value = $this->get_meta_value( $field );
99 $field_value = ( isset( $meta_value ) ) ? $meta_value : '';
100
101 }
102
103 }
104
105 $instance = new $field_class( $field, $field_value, $this->unique, 'wp/enqueue', $this );
106
107 // typography enqueue and embed google web fonts
108 if ( $field_type === 'typography' && $this->args['enqueue_webfont'] && ! empty( $field_value['font-family'] ) ) {
109
110 $method = ( ! empty( $this->args['async_webfont'] ) ) ? 'async' : 'enqueue';
111
112 $instance->enqueue_google_fonts( $method );
113
114 }
115
116 // output css
117 if ( $field_output && $this->args['output_css'] ) {
118 Darkify::$css .= $instance->output();
119 }
120
121 unset( $instance );
122
123 }
124
125 }
126
127 }
128
129 }
130
131 }
132
133 }
134
135 public function pre_tabs( $sections ) {
136
137 $count = 100;
138 $result = array();
139 $parents = array();
140
141 foreach ( $sections as $key => $section ) {
142 if ( ! empty( $section['parent'] ) ) {
143 $section['priority'] = ( isset( $section['priority'] ) ) ? $section['priority'] : $count;
144 $parents[$section['parent']][] = $section;
145 unset( $sections[$key] );
146 }
147 $count++;
148 }
149
150 foreach ( $sections as $key => $section ) {
151 $section['priority'] = ( isset( $section['priority'] ) ) ? $section['priority'] : $count;
152 if ( ! empty( $section['id'] ) && ! empty( $parents[$section['id']] ) ) {
153 $section['subs'] = wp_list_sort( $parents[$section['id']], array( 'priority' => 'ASC' ), 'ASC', true );
154 }
155 $result[] = $section;
156 $count++;
157 }
158
159 return wp_list_sort( $result, array( 'priority' => 'ASC' ), 'ASC', true );
160
161 }
162
163 public function pre_sections( $sections ) {
164
165 $result = array();
166
167 foreach ( $this->pre_tabs( $sections ) as $section ) {
168 if ( ! empty( $section['subs'] ) ) {
169 foreach ( $section['subs'] as $sub ) {
170 $sub['ptitle'] = ( ! empty( $section['title'] ) ) ? $section['title'] : '';
171 $result[] = $sub;
172 }
173 }
174 if ( empty( $section['subs'] ) ) {
175 $result[] = $section;
176 }
177 }
178
179 return $result;
180 }
181
182 public function pre_fields( $sections ) {
183
184 $result = array();
185
186 foreach ( $sections as $key => $section ) {
187 if ( ! empty( $section['fields'] ) ) {
188 foreach ( $section['fields'] as $field ) {
189 $result[] = $field;
190 }
191 }
192 }
193
194 return $result;
195 }
196
197 }
198 }
199