PluginProbe
Selection Lite / 1.12
Selection Lite v1.12
trunk 1.0 1.1 1.10 1.11 1.12 1.14 1.15 1.16 1.17 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9
selection-lite / src / Merkulove / Unity / ReporterTheme.php

ReporterTheme.php in Selection Lite 1.12, at src/Merkulove/Unity/ReporterTheme.php

340 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Selection Lite
4 * Carefully selected Elementor addons bundle, for building the most awesome websites
5 *
6 * @encoding UTF-8
7 * @version 1.12
8 * @copyright (C) 2018-2024 Merkulove ( https://merkulov.design/ ). All rights reserved.
9 * @license GPLv3
10 * @contributors merkulove, vladcherviakov, phoenixmkua, podolianochka, viktorialev01
11 * @support help@merkulov.design
12 **/
13
14 namespace Merkulove\SelectionLite\Unity;
15
16 /** Exit if accessed directly. */
17 if ( ! defined( 'ABSPATH' ) ) {
18 header( 'Status: 403 Forbidden' );
19 header( 'HTTP/1.1 403 Forbidden' );
20 exit;
21 }
22
23 /**
24 * Unity theme report.
25 * System report handler class responsible for generating a report for the theme.
26 *
27 * @since 1.0
28 **/
29 final class ReporterTheme {
30
31 /**
32 * The one true ReporterTheme.
33 *
34 * @var ReporterTheme
35 **/
36 private static $instance;
37
38 /**
39 * Theme.
40 *
41 * Holds the sites theme object.
42 *
43 * @since 1.0
44 * @access private
45 *
46 * @var \WP_Theme WordPress theme object.
47 **/
48 private $theme = null;
49
50 /**
51 * Get theme reporter title.
52 *
53 * Retrieve theme reporter title.
54 *
55 * @since 1.0
56 * @access public
57 *
58 * @return string Reporter title.
59 **/
60 public function get_title() {
61 return 'Theme';
62 }
63
64 /**
65 * Get theme report fields.
66 *
67 * Retrieve the required fields for the theme report.
68 *
69 * @since 1.0
70 * @access public
71 *
72 * @return array Required report fields with field ID and field label.
73 **/
74 public function get_fields() {
75 $fields = [
76 'name' => 'Name',
77 'version' => 'Version',
78 'author' => 'Author',
79 'is_child_theme' => 'Child Theme',
80 ];
81
82 if ( $this->get_parent_theme() ) {
83 $parent_fields = [
84 'parent_name' => 'Parent Theme Name',
85 'parent_version' => 'Parent Theme Version',
86 'parent_author' => 'Parent Theme Author',
87 ];
88 $fields = array_merge( $fields, $parent_fields );
89 }
90
91 return $fields;
92 }
93
94 /**
95 * Get theme.
96 *
97 * Retrieve the theme.
98 *
99 * @since 1.0
100 * @access protected
101 *
102 * @return \WP_Theme WordPress theme object.
103 **/
104 protected function _get_theme() {
105 if ( is_null( $this->theme ) ) {
106 $this->theme = wp_get_theme();
107 }
108 return $this->theme;
109 }
110
111 /**
112 * Get parent theme.
113 *
114 * Retrieve the parent theme.
115 *
116 * @since 1.0
117 * @access protected
118 *
119 * @return \WP_Theme|false WordPress theme object, or false if the current theme is not a child theme.
120 **/
121 protected function get_parent_theme() {
122 return $this->_get_theme()->parent();
123 }
124
125 /**
126 * Get theme name.
127 *
128 * Retrieve the theme name.
129 *
130 * @since 1.0
131 * @access public
132 *
133 * @return array {
134 * Report data.
135 *
136 * @type string $value The theme name.
137 * }
138 **/
139 public function get_name() {
140 return [
141 'value' => $this->_get_theme()->get( 'Name' ),
142 ];
143 }
144
145 /**
146 * Get theme author.
147 *
148 * Retrieve the theme author.
149 *
150 * @since 1.0
151 * @access public
152 *
153 * @return array {
154 * Report data.
155 *
156 * @type string $value The theme author.
157 * }
158 **/
159 public function get_author() {
160 return [
161 'value' => $this->_get_theme()->get( 'Author' ),
162 ];
163 }
164
165 /**
166 * Get theme version.
167 *
168 * Retrieve the theme version.
169 *
170 * @since 1.0
171 * @access public
172 *
173 * @return array {
174 * Report data.
175 *
176 * @type string $value The theme version.
177 * }
178 **/
179 public function get_version() {
180 return [
181 'value' => $this->_get_theme()->get( 'Version' ),
182 ];
183 }
184
185 /**
186 * Is the theme is a child theme.
187 *
188 * Whether the theme is a child theme.
189 *
190 * @since 1.0
191 * @access public
192 *
193 * @return array {
194 * Report data.
195 *
196 * @type string $value Yes if the theme is a child theme, No otherwise.
197 * @type string $recommendation Theme source code modification recommendation.
198 * }
199 **/
200 public function get_is_child_theme() {
201 $is_child_theme = is_child_theme();
202
203 $result = [
204 'value' => $is_child_theme ? 'Yes' : 'No',
205 ];
206
207 if ( ! $is_child_theme ) {
208 $result['recommendation'] = sprintf(
209 /* translators: %s: Codex URL */
210 _x( 'If you want to modify the source code of your theme, we recommend using a <a href="%s">child theme</a>.', 'System Info', 'selection-lite' ),
211 'https://codex.wordpress.org/Child_Themes'
212 );
213 }
214
215 return $result;
216 }
217
218 /**
219 * Get parent theme version.
220 *
221 * Retrieve the parent theme version.
222 *
223 * @since 1.0
224 * @access public
225 *
226 * @return array {
227 * Report data.
228 *
229 * @type string $value The parent theme version.
230 * }
231 **/
232 public function get_parent_version() {
233 return [
234 'value' => $this->get_parent_theme()->get( 'Version' ),
235 ];
236 }
237
238 /**
239 * Get parent theme author.
240 *
241 * Retrieve the parent theme author.
242 *
243 * @since 1.0
244 * @access public
245 *
246 * @return array {
247 * Report data.
248 *
249 * @type string $value The parent theme author.
250 * }
251 **/
252 public function get_parent_author() {
253 return [
254 'value' => $this->get_parent_theme()->get( 'Author' ),
255 ];
256 }
257
258 /**
259 * Get parent theme name.
260 *
261 * Retrieve the parent theme name.
262 *
263 * @since 1.0
264 * @access public
265 *
266 * @return array {
267 * Report data.
268 *
269 * @type string $value The parent theme name.
270 * }
271 **/
272 public function get_parent_name() {
273 return [
274 'value' => $this->get_parent_theme()->get( 'Name' ),
275 ];
276 }
277
278 /**
279 * Get report.
280 * Retrieve the report with all it's containing fields.
281 *
282 * @since 1.0
283 * @access public
284 *
285 * @return array {
286 * Report fields.
287 *
288 * @type string $name Field name.
289 * @type string $label Field label.
290 * }
291 **/
292 public function get_report() {
293
294 $result = [];
295
296 foreach ( $this->get_fields() as $field_name => $field_label ) {
297
298 $method = 'get_' . $field_name;
299
300 $reporter_field = [
301 'name' => $field_name,
302 'label' => $field_label,
303 ];
304
305
306
307 /** @noinspection SlowArrayOperationsInLoopInspection */
308 $reporter_field = array_merge( $reporter_field, $this->$method() );
309
310 $result[ $field_name ] = $reporter_field;
311
312 }
313
314 return $result;
315
316 }
317
318 /**
319 * Main ReporterTheme Instance.
320 *
321 * Insures that only one instance of ReporterTheme exists in memory at any one time.
322 *
323 * @static
324 * @since 1.0
325 * @return ReporterTheme
326 **/
327 public static function get_instance() {
328
329 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) {
330
331 self::$instance = new self;
332
333 }
334
335 return self::$instance;
336
337 }
338
339 }
340