PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.1.9
Adminify – White Label, Admin Menu Editor, Login Customizer v3.1.9
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Classes / Helper.php

Helper.php in Adminify – White Label, Admin Menu Editor, Login Customizer 3.1.9, at Inc/Classes/Helper.php

365 lines 11.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPAdminify\Inc\Classes;
4
5 // no direct access allowed
6 if (!defined('ABSPATH')) {
7 exit;
8 }
9
10 class Helper
11 {
12
13 // Admin Path
14 public static function jltwp_adminify_admin_path($path)
15 {
16 // Get custom filter path
17 if (has_filter('jltwp_adminify_admin_path')) {
18 return apply_filters('jltwp_adminify_admin_path', $path);
19 }
20
21 // Get plugin path
22 return plugins_url($path, __DIR__);
23 }
24
25 /**
26 * Get the editor/ builder of the given post.
27 *
28 * @param int $post_id ID of the post being checked.
29 * @return string The content editor name.
30 */
31 public static function get_content_editor($post_id)
32 {
33 $content_editor = 'default';
34 $content_editor = apply_filters('udb_content_editor', $content_editor, $post_id);
35
36 return $content_editor;
37 }
38
39 /**
40 * Sanitize Checkbox.
41 *
42 * @param string|bool $checked Customizer option.
43 */
44 public function sanitize_checkbox($checked)
45 {
46 return ((isset($checked) && true === $checked) ? true : false);
47 }
48
49
50
51 /**
52 * Check if Gutenberg Block Editor Page
53 *
54 * WordPress v5+
55 *
56 * @return boolean
57 */
58 public static function is_block_editor_page()
59 {
60 if (function_exists('is_gutenberg_page') && is_gutenberg_page()) {
61 // The Gutenberg plugin is on.
62 return true;
63 }
64
65 if (!function_exists('get_current_screen')) {
66 require_once ABSPATH . '/wp-admin/includes/screen.php';
67 $current_screen = get_current_screen();
68 if (function_exists('get_current_screen')) {
69 if (!is_null($current_screen) && $current_screen->is_block_editor()) {
70 // Gutenberg page on 5+.
71 return true;
72 }
73 }
74 }
75 return false;
76 }
77
78
79 /**
80 * Classic Editor Page
81 *
82 * @return boolean
83 */
84 public static function is_classic_editor_page()
85 {
86 if (function_exists('get_current_screen')) {
87 $current_screen = get_current_screen();
88 if ($current_screen->base == 'post' && empty($current_screen->is_block_editor)) {
89 return true;
90 }
91 }
92 return false;
93 }
94
95 /**
96 * Check if Elementor Page
97 *
98 * @return boolean
99 */
100 public static function is_elementor_editor_page()
101 {
102 return !empty($_GET['elementor-preview']);
103 }
104
105 /**
106 * Image sanitization callback.
107 *
108 * Checks the image's file extension and mime type against a whitelist. If they're allowed,
109 * send back the filename, otherwise, return the setting default.
110 *
111 * - Sanitization: image file extension
112 * - Control: text, WP_Customize_Image_Control
113 *
114 * @see wp_check_filetype() https://developer.wordpress.org/reference/functions/wp_check_filetype/
115 *
116 * @version 1.2.2
117 *
118 * @param string $image Image filename.
119 * @param WP_Customize_Setting $setting Setting instance.
120 *
121 * @return string The image filename if the extension is allowed; otherwise, the setting default.
122 */
123 public static function sanitize_image($image, $setting)
124 {
125
126 /**
127 * Array of valid image file types.
128 *
129 * The array includes image mime types that are included in wp_get_mime_types()
130 */
131 $mimes = array(
132 'jpg|jpeg|jpe' => 'image/jpeg',
133 'gif' => 'image/gif',
134 'png' => 'image/png',
135 'bmp' => 'image/bmp',
136 'tif|tiff' => 'image/tiff',
137 'ico' => 'image/x-icon',
138 );
139
140 // Allowed svg mime type in version 1.2.2.
141 $allowed_mime = get_allowed_mime_types();
142 $svg_mime_check = isset($allowed_mime['svg']) ? true : false;
143
144 if ($svg_mime_check) {
145 $allow_mime = array('svg' => 'image/svg+xml');
146 $mimes = array_merge($mimes, $allow_mime);
147 }
148
149 // Return an array with file extension and mime_type.
150 $file = wp_check_filetype($image, $mimes);
151
152 // If $image has a valid mime_type, return it; otherwise, return the default.
153 return esc_url_raw(($file['ext'] ? $image : $setting->default));
154 }
155
156
157
158 /**
159 * Remove spaces from Plugin Slug
160 */
161 public static function jltwp_adminify_slug_cleanup()
162 {
163 return str_replace('-', '_', strtolower(WP_ADMINIFY_SLUG));
164 }
165
166 /**
167 * Function current_datetime() compability for wp version < 5.3
168 *
169 * @return DateTimeImmutable
170 */
171 public static function jltwp_adminify_current_datetime()
172 {
173 if (function_exists('current_datetime')) {
174 return current_datetime();
175 }
176
177 return new \DateTimeImmutable('now', self::jltwp_adminify_wp_timezone());
178 }
179
180 /**
181 * Function jltwp_adminify_wp_timezone() compability for wp version < 5.3
182 *
183 * @return DateTimeZone
184 */
185 public static function jltwp_adminify_wp_timezone()
186 {
187 if (function_exists('wp_timezone')) {
188 return wp_timezone();
189 }
190
191 return new \DateTimeZone(self::jltwp_adminify_wp_timezone_string());
192 }
193
194 /**
195 * API Endpoint
196 *
197 * @return string
198 */
199 public static function api_endpoint()
200 {
201 $api_endpoint_url = 'https://bo.jeweltheme.com';
202 $api_endpoint = apply_filters('jltwp_adminify_endpoint', $api_endpoint_url);
203
204 return trailingslashit($api_endpoint);
205 }
206
207 /**
208 * CRM Endpoint
209 *
210 * @return string
211 */
212 public static function crm_endpoint()
213 {
214 $crm_endpoint_url = 'https://bo.jeweltheme.com/wp-json/jlt-api/v1/subscribe'; // Endpoint .
215 $crm_endpoint = apply_filters('jltwp_adminify_crm_crm_endpoint', $crm_endpoint_url);
216
217 return trailingslashit($crm_endpoint);
218 }
219
220 /**
221 * CRM Endpoint
222 *
223 * @return string
224 */
225 public static function crm_survey_endpoint()
226 {
227 $crm_feedback_endpoint_url = 'https://bo.jeweltheme.com/wp-json/jlt-api/v1/survey'; // Endpoint .
228 $crm_feedback_endpoint = apply_filters('jltwp_adminify_crm_crm_endpoint', $crm_feedback_endpoint_url);
229
230 return trailingslashit($crm_feedback_endpoint);
231 }
232
233 /**
234 * Function jltwp_adminify_wp_timezone_string() compability for wp version < 5.3
235 *
236 * @return string
237 */
238 public static function jltwp_adminify_wp_timezone_string()
239 {
240 $timezone_string = get_option('timezone_string');
241
242 if ($timezone_string) {
243 return $timezone_string;
244 }
245
246 $offset = (float) get_option('gmt_offset');
247 $hours = (int) $offset;
248 $minutes = ($offset - $hours);
249
250 $sign = ($offset < 0) ? '-' : '+';
251 $abs_hour = abs($hours);
252 $abs_mins = abs($minutes * 60);
253 $tz_offset = sprintf('%s%02d:%02d', $sign, $abs_hour, $abs_mins);
254
255 return $tz_offset;
256 }
257
258 /**
259 * Get Merged Data
260 *
261 * @param [type] $data .
262 * @param string $start_date .
263 * @param string $end_data .
264 *
265 * @author Jewel Theme <support@jeweltheme.com>
266 */
267 public static function get_merged_data($data, $start_date = '', $end_data = '')
268 {
269 $_data = shortcode_atts(
270 array(
271 'image_url' => WP_ADMINIFY_ASSETS_IMAGE . '/promo-image.png',
272 'start_date' => $start_date,
273 'end_date' => $end_data,
274 'counter_time' => '',
275 'is_campaign' => 'false',
276 'button_text' => 'Get Premium',
277 'button_url' => 'https://wpadminify.com/pricing',
278 'btn_color' => '#CC22FF',
279 'notice' => '',
280 'notice_timestamp' => '',
281 ),
282 $data
283 );
284
285 if (empty($_data['image_url'])) {
286 $_data['image_url'] = WP_ADMINIFY_ASSETS_IMAGE . '/promo-image.png';
287 }
288
289 return $_data;
290 }
291
292
293 /**
294 * wp_kses attributes map
295 *
296 * @param array $attrs .
297 *
298 * @author Jewel Theme <support@jeweltheme.com>
299 */
300 public static function wp_kses_atts_map(array $attrs)
301 {
302 return array_fill_keys(array_values($attrs), true);
303 }
304
305 /**
306 * Custom method
307 *
308 * @param [type] $content .
309 *
310 * @author Jewel Theme <support@jeweltheme.com>
311 */
312 public static function wp_kses_custom($content)
313 {
314 $allowed_tags = wp_kses_allowed_html('post');
315
316 $custom_tags = array(
317 'select' => self::wp_kses_atts_map(array('class', 'id', 'style', 'width', 'height', 'title', 'data', 'name', 'autofocus', 'disabled', 'multiple', 'required', 'size')),
318 'input' => self::wp_kses_atts_map(array('class', 'id', 'style', 'width', 'height', 'title', 'data', 'name', 'autofocus', 'disabled', 'required', 'size', 'type', 'checked', 'readonly', 'placeholder', 'value', 'maxlength', 'min', 'max', 'multiple', 'pattern', 'step', 'autocomplete')),
319 'textarea' => self::wp_kses_atts_map(array('class', 'id', 'style', 'width', 'height', 'title', 'data', 'name', 'autofocus', 'disabled', 'required', 'rows', 'cols', 'wrap', 'maxlength')),
320 'option' => self::wp_kses_atts_map(array('class', 'id', 'label', 'disabled', 'label', 'selected', 'value')),
321 'optgroup' => self::wp_kses_atts_map(array('disabled', 'label', 'class', 'id')),
322 'form' => self::wp_kses_atts_map(array('class', 'id', 'data', 'style', 'width', 'height', 'accept-charset', 'action', 'autocomplete', 'enctype', 'method', 'name', 'novalidate', 'rel', 'target')),
323 'svg' => self::wp_kses_atts_map(array('class', 'xmlns', 'viewbox', 'width', 'height', 'fill', 'aria-hidden', 'aria-labelledby', 'role')),
324 'rect' => self::wp_kses_atts_map(array('rx', 'width', 'height', 'fill')),
325 'path' => self::wp_kses_atts_map(array('d', 'fill')),
326 'g' => self::wp_kses_atts_map(array('fill')),
327 'defs' => self::wp_kses_atts_map(array('fill')),
328 'linearGradient' => self::wp_kses_atts_map(array('id', 'x1', 'x2', 'y1', 'y2', 'gradientUnits')),
329 'stop' => self::wp_kses_atts_map(array('stop-color', 'offset', 'stop-opacity')),
330 'style' => self::wp_kses_atts_map(array('type')),
331 'div' => self::wp_kses_atts_map(array('class', 'id', 'style')),
332 'ul' => self::wp_kses_atts_map(array('class', 'id', 'style')),
333 'li' => self::wp_kses_atts_map(array('class', 'id', 'style')),
334 'label' => self::wp_kses_atts_map(array('class', 'for')),
335 'span' => self::wp_kses_atts_map(array('class', 'id', 'style')),
336 'h1' => self::wp_kses_atts_map(array('class', 'id', 'style')),
337 'h2' => self::wp_kses_atts_map(array('class', 'id', 'style')),
338 'h3' => self::wp_kses_atts_map(array('class', 'id', 'style')),
339 'h4' => self::wp_kses_atts_map(array('class', 'id', 'style')),
340 'h5' => self::wp_kses_atts_map(array('class', 'id', 'style')),
341 'h6' => self::wp_kses_atts_map(array('class', 'id', 'style')),
342 'a' => self::wp_kses_atts_map(array('class', 'href', 'target', 'rel')),
343 'p' => self::wp_kses_atts_map(array('class', 'id', 'style', 'data')),
344 'table' => self::wp_kses_atts_map(array('class', 'id', 'style')),
345 'thead' => self::wp_kses_atts_map(array('class', 'id', 'style')),
346 'tbody' => self::wp_kses_atts_map(array('class', 'id', 'style')),
347 'tr' => self::wp_kses_atts_map(array('class', 'id', 'style')),
348 'th' => self::wp_kses_atts_map(array('class', 'id', 'style')),
349 'td' => self::wp_kses_atts_map(array('class', 'id', 'style')),
350 'i' => self::wp_kses_atts_map(array('class', 'id', 'style')),
351 'button' => self::wp_kses_atts_map(array('class', 'id')),
352 'nav' => self::wp_kses_atts_map(array('class', 'id', 'style')),
353 'time' => self::wp_kses_atts_map(array('datetime')),
354 'br' => array(),
355 'strong' => array(),
356 'style' => array(),
357 'img' => self::wp_kses_atts_map(array('class', 'src', 'alt', 'height', 'width', 'srcset', 'id', 'loading')),
358 );
359
360 $allowed_tags = array_merge_recursive($allowed_tags, $custom_tags);
361
362 return wp_kses(stripslashes_deep($content), $allowed_tags);
363 }
364 }
365