PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.0.1.6
Adminify – White Label, Admin Menu Editor, Login Customizer v4.0.1.6
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 / utils.php

utils.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.0.1.6, at Inc/utils.php

1,192 lines 38.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;
4
5 use ReturnTypeWillChange;
6 use WPAdminify\Inc\Classes\Helper;
7 // no direct access allowed
8 if (!defined('ABSPATH')) {
9 exit;
10 }
11
12 class Utils
13 {
14 public $post_types = '';
15
16 /**
17 * Check if the Module is Enable/Disable
18 *
19 * @param [type] $value
20 *
21 * @return void
22 */
23 public static function check_modules($value)
24 {
25 if (empty($value)) {
26 return;
27 } else {
28 return true;
29 }
30 }
31
32 /**
33 * Check given value empty or not
34 *
35 * @param [type] $value
36 *
37 * @return void
38 */
39 public static function check_is_empty($value, $default = '')
40 {
41 $value = !empty(esc_attr($value)) ? $value : $default;
42 return $value;
43 }
44
45
46 /**
47 * Check hidden for rules or not
48 *
49 * @param [type] $value
50 *
51 * @return bool
52 */
53 public static function restricted_for($disabled_for)
54 {
55 if (empty($disabled_for)) {
56 return false;
57 }
58
59 if (!function_exists('wp_get_current_user')) {
60 include ABSPATH . 'wp-includes/pluggable.php';
61 }
62
63 $restrict_for = array();
64
65 if (!is_array($disabled_for)) {
66 $restrict_for[] = $disabled_for;
67 } else {
68 $restrict_for = $disabled_for;
69 }
70
71
72 $current_user = wp_get_current_user();
73 $current_name = $current_user->display_name;
74 $current_roles = $current_user->roles;
75 // $all_roles = wp_roles()->get_names();
76
77 if (in_array($current_name, $restrict_for)) {
78 return true;
79 }
80
81 if (in_array('Super Admin', $restrict_for) || in_array('administrator', $restrict_for)) {
82 return true;
83 }
84
85 // Super Admin for Multisite
86 if (is_super_admin() && is_multisite()) {
87 if (in_array('Super Admin', $restrict_for) || in_array('administrator', $restrict_for)) {
88 return true;
89 } else {
90 return false;
91 }
92 }
93
94 $formattedroles = [];
95
96 foreach ($restrict_for as $item) {
97 $item = is_string($item) ? strtolower($item) : $item;
98 $item = is_string($item) ? str_replace(' ', '_', $item) : $item;
99 array_push($formattedroles, $item);
100 }
101
102 foreach ($current_roles as $role) {
103 // $role_name = $all_roles[$role];
104 if (in_array($role, $restrict_for)) {
105 return true;
106 }
107 }
108 }
109
110
111 /**
112 * Check Site wide plugin settings
113 */
114 public static function is_site_wide($plugin)
115 {
116 if (!is_multisite()) {
117 return false;
118 }
119
120 $plugins = get_site_option('active_sitewide_plugins');
121 if (isset($plugins[$plugin])) {
122 return true;
123 }
124
125 return false;
126 }
127
128 /**
129 * Get All Taxonomies
130 *
131 * @return void
132 */
133 public static function get_all_taxonomies()
134 {
135 $taxonomies = get_taxonomies(
136 [
137 'show_ui' => true,
138 ],
139 'objects'
140 );
141 $taxonomy_names = [];
142 foreach ($taxonomies as $taxonomy) {
143 if ($taxonomy->name == 'post_format') {
144 continue;
145 }
146 $taxonomy_names[$taxonomy->name] = $taxonomy->label;
147 }
148 return $taxonomy_names;
149 }
150
151 /**
152 * Restricts for role / user
153 */
154
155 public static function restrict_for($disabled_for)
156 {
157 if (!is_array($disabled_for)) {
158 return false;
159 }
160
161 require_once ABSPATH . '/wp-includes/pluggable.php';
162
163 if (!function_exists('wp_get_current_user')) {
164 return false;
165 }
166 $current_user = wp_get_current_user();
167 $current_name = $current_user->display_name;
168 $current_roles = $current_user->roles;
169
170 $formattedroles = [];
171
172 foreach ($disabled_for as $item) {
173 $item = strtolower($item);
174 $item = str_replace(' ', '_', $item);
175 array_push($formattedroles, $item);
176 }
177
178 if (in_array($current_name, $disabled_for)) {
179 return true;
180 }
181
182 foreach ($current_roles as $role) {
183 if (in_array($role, $formattedroles)) {
184 return true;
185 }
186 }
187 }
188
189
190 // Get Taxonomies
191 public static function get_taxonomies()
192 {
193 $args = [
194 'public' => true,
195 'show_ui' => true,
196 ];
197 $output = 'objects';
198 $taxonomies = get_taxonomies($args, $output);
199 $taxonomies = $taxonomies;
200 return $taxonomies;
201 }
202
203 // Get Post Types
204 public static function get_post_types()
205 {
206 $args = [
207 'public' => true,
208 'show_ui' => true,
209 ];
210 $output = 'objects';
211 $post_types = get_post_types($args, $output);
212 $post_types = $post_types;
213 return $post_types;
214 }
215
216 // Get Post Meta
217 public static function post_meta($meta_key)
218 {
219 $meta_key = get_post_meta(get_the_ID(), $meta_key, true);
220 return $meta_key;
221 }
222
223
224 // verfiy current page id
225 public static function jltwp_adminify_currentpage_id($id)
226 {
227 if (!function_exists('get_current_screen')) {
228 return true;
229 }
230
231 $screen = get_current_screen();
232 return is_object($screen) && $screen->id == $id;
233 }
234
235 /**
236 * Get Current Admin Page Title
237 *
238 * @param string $title
239 *
240 * @return void
241 */
242 public static function admin_page_title($title = '')
243 {
244 $title = isset($title) && !empty($title) ? $title : WP_ADMINIFY;
245 echo esc_html($title);
246
247 if (is_multisite()) {
248 $text = ' | ' . esc_html__('Current Blog ID', 'adminify') . ': ' . get_current_blog_id(); ?>
249 <?php echo self::wp_kses_custom(self::admin_page_subtitle($text)); ?>
250 <?php } ?>
251 <?php
252 }
253
254 /**
255 * Get Current Admin Subtitle
256 */
257
258 public static function admin_page_subtitle($text)
259 {
260 ?>
261 <span style="color:#8b959e;" <?php
262 if (is_rtl()) {
263 echo ' dir="rtl"';
264 }
265 ?>>
266 <?php echo esc_html($text); ?>
267 </span>
268
269 <?php
270 }
271
272 public static function convert_name_to_class($name)
273 {
274 $class = str_replace([' ', ',', '.', '"', "'", '/', '\\', '+', '=', ')', '(', '*', '&', '^', '%', '$', '#', '@', '!', '~', '`', '<', '>', '?', '[', ']', '{', '}', '|', ':'], '', $name);
275 return $class;
276 }
277
278 public static function jltwp_adminify_class_cleanup($string)
279 {
280 // Lower case everything
281 $string = strtolower($string);
282 // Make alphanumeric (removes all other characters)
283 $string = preg_replace('/[^a-z0-9_\s-]/', '', $string);
284 // Clean up multiple dashes or whitespaces
285 $string = preg_replace('/[\s-]+/', ' ', $string);
286 // Convert whitespaces and underscore to dash
287 $string = preg_replace('/[\s_]/', '-', $string);
288 return $string;
289 }
290
291 public static function sanitize_id($url)
292 {
293 $url = preg_replace('/^customize.php\?return=.*$/', 'customize', $url);
294 $url = preg_replace('/(&|&amp;|&#038;)?_wpnonce=([^&]+)/', '', $url);
295 return str_replace(['.php', '.', '/', '?', '='], ['', '_', '_', '_', '_'], $url);
296 }
297
298 /**
299 * Strip tags and it's content from the given string.
300 *
301 * @link https://stackoverflow.com/questions/14684077/remove-all-html-tags-from-php-string/#answer-39320168
302 *
303 * @param string $text The string being stripped.
304 * @return string The stripped string.
305 */
306 public static function strip_tags_content($text)
307 {
308 $cleanup = preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text);
309 $cleanup = wp_strip_all_tags($cleanup);
310 $cleanup = trim($cleanup);
311
312 return $cleanup;
313 }
314
315 /**
316 * String to ID
317 * Remove Space replace with underscore and lowercase
318 *
319 * @param void
320 *
321 * @return string
322 */
323 public static function string_to_id($string)
324 {
325 $string_replace = str_replace(' ', '_', $string);
326 $formatted_string = strtolower($string_replace);
327 return $formatted_string;
328 }
329
330 /**
331 * ID to String
332 * Remove Space replace with underscore and lowercase
333 *
334 * @param void
335 *
336 * @return string
337 */
338 public static function id_to_string($string)
339 {
340 $string_replace = str_replace('_', ' ', $string);
341 $formatted_string = ucwords($string_replace);
342 return $formatted_string;
343 }
344
345 /**
346 * Check is Plugin Active
347 *
348 * @param [type] $plugin_path
349 *
350 * @return boolean
351 */
352 public static function is_plugin_active( $plugin_path )
353 {
354 include_once ABSPATH . 'wp-admin/includes/plugin.php';
355 return is_plugin_active( $plugin_path );
356 }
357
358 /**
359 * Check if Block Editor Page
360 *
361 * @return boolean
362 */
363 public static function is_block_editor_page() {
364 if (function_exists('get_current_screen')) {
365 $current_screen = get_current_screen();
366 if (!empty($current_screen->is_block_editor)) {
367 return true;
368 }
369 }
370 return false;
371 }
372
373 /**
374 * Check is Plugin Active
375 *
376 * @param [type] $plugin_path
377 *
378 * @return boolean
379 */
380 public static function is_plugin_installed_and_active($plugin_path)
381 {
382 // Check if the plugin is active
383 if (is_plugin_active($plugin_path)) {
384 return true; // Plugin is both installed and active
385 } else {
386 return false; // Plugin is either not installed or not active
387 }
388 }
389
390 public static function is_plugin_installed($plugin_slug, $plugin_file)
391 {
392 $installed_plugins = get_plugins();
393 return isset($installed_plugins[$plugin_file]);
394 }
395
396 public static function jltwp_adminify_notification_bar()
397 {
398 $plugin_slug = 'adminify-notification-bar';
399 $plugin_file = 'adminify-notification-bar/adminify-notification-bar.php';
400 $addons_page_url = network_admin_url('admin.php?page=wp-adminify-settings-addons');
401
402 // $addons_download_link = jltwp_adminify()->_get_latest_download_local_url(14434);
403
404 $html = '';
405 if (self::is_plugin_installed($plugin_slug, $plugin_file)) {
406 if (!current_user_can('install_plugins')) {
407 return;
408 }
409
410 if (!self::is_plugin_active($plugin_file)) {
411 $activation_url = wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=all&amp;paged=1&amp;s', 'activate-plugin_' . $plugin_file);
412 $html .= '<a class="wp-adminify-addons-download addon-active" href="' . $activation_url . '" ><span class="pr-1">' . esc_html__('Activate', 'adminify') . '</span><i class="dashicons dashicons-yes-alt"></i></a>';
413 }
414 } else {
415 // $install_url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $plugin_slug), 'install-plugin_' . $plugin_slug);
416 $html = '<a class="wp-adminify-addons-download addon-download" href="' . $addons_page_url . '"><span class="wp-adminify-addons-download-text">' . esc_html__('Download', 'adminify') . '</span><i class="dashicons dashicons-download"></i></a>';
417
418 activate_plugin($plugin_file);
419 }
420
421 $html_content = '<div class="adminify-title">
422 <h4>' . esc_html__('Notification Bar', 'adminify') . '</h4>
423 <div class="adminify-subtitle-text">' . esc_html__('Cookie Notice, Promotional Bar on frontend', 'adminify') . '</div>
424 </div>
425 <div class="adminify-fieldset">
426 <div class="adminify--addons" style="width: 100px;">
427 ' . wp_kses_post($html) . '
428 </div>
429 </div>
430 <div class="clear"></div>';
431
432 echo wp_kses_post($html_content);
433 }
434
435
436 /**
437 * User Defined Settings
438 */
439
440 public static function get_user_preference($key)
441 {
442 $userid = get_current_user_id();
443 $current = get_user_meta($userid, '_wpadminify_preferences', true);
444 $value = false;
445
446 if (is_array($current)) {
447 if (isset($current[$key])) {
448 $value = $current[$key];
449 }
450 }
451
452 return $value;
453 }
454
455 /**
456 * Sanitises and strips tags of input from ajax
457 *
458 * @since 1.0.0
459 * @variables $values = item to clean (array or string)
460 */
461 public static function clean_ajax_input($values)
462 {
463 if (is_array($values)) {
464 foreach ($values as $index => $in) {
465 if (is_array($in)) {
466 $values[$index] = self::clean_ajax_input($in);
467 } else {
468 $values[$index] = strip_tags($in);
469 }
470 }
471 } else {
472 $values = strip_tags($values);
473 }
474
475 return $values;
476 }
477
478 /**
479 * Check Ajax Error Messages
480 *
481 * @param [type] $message
482 *
483 * @return void
484 */
485 public static function ajax_error_message($message)
486 {
487 $returndata = [];
488 $returndata['error'] = true;
489 $returndata['error_message'] = $message;
490 return json_encode($returndata);
491 }
492
493 /**
494 * Get All Updates
495 * Themes, Plugins, Core etc
496 *
497 * @return void
498 */
499 public static function get_all_updates()
500 {
501 $allupdates = [];
502 $allupdates['total'] = 0;
503 $allupdates['wordpress'] = 0;
504 $allupdates['theme'] = 0;
505 $allupdates['plugin'] = 0;
506
507 if (!is_admin()) {
508 return $allupdates;
509 }
510
511 if (!current_user_can('install_plugins')) {
512 return $allupdates;
513 }
514 $updatesTotal = 0;
515 if (is_super_admin() && is_admin()) {
516 $pluginUpdates = get_plugin_updates();
517 $themeUpdates = get_theme_updates();
518 $wpUpdates = get_core_updates();
519
520 if (isset($wpUpdates[0])) {
521 $wpversion = $wpUpdates[0]->version;
522 global $wp_version;
523
524 if ($wpversion > $wp_version) {
525 $wpUpdates = 1;
526 } else {
527 $wpUpdates = 0;
528 }
529 } else {
530 $wpUpdates = 0;
531 }
532
533 $updatesTotal = count($pluginUpdates) + count($themeUpdates) + $wpUpdates;
534
535 $allupdates['total'] = $updatesTotal;
536 $allupdates['wordpress'] = $wpUpdates;
537 $allupdates['theme'] = $themeUpdates;
538 $allupdates['plugin'] = $pluginUpdates;
539 }
540 return $allupdates;
541 }
542
543 public static function adminfiy_help_urls($module_name = '', $docs = '', $youtube = '', $facebook_grp = '', $support = '')
544 {
545 $help_content = '';
546
547 // Modules
548 if (empty($module_name)) {
549 $module_name = '';
550 } else {
551 $module_name = $module_name;
552 }
553
554 $help_content_urls = '';
555
556 // Docs
557 if (!empty($docs)) {
558 $help_content_urls .= '<a class="adminify-tag adminify-tag-purple adminify-docs-url" href="' . esc_url( $docs ) . '" target="_blank"> ' . self::docs_icon() . ' Docs</a>';
559 }
560
561 // youtube
562 if (!empty($youtube)) {
563 $help_content_urls .= '<a class="adminify-tag adminify-tag-danger adminify-video-url" href="' . esc_url( $youtube ) . '" target="_blank">' . self::video_tutorials_icon() . ' Video Tutorial</a>';
564 }
565
566 // facebook_grp
567 if (!empty($facebook_grp)) {
568 $help_content_urls .= '<a class="adminify-tag adminify-tag-primary adminify-fbgroup-url" href="' . esc_url($facebook_grp) . '" target="_blank">' . self::fbgroup_icon() . ' Facebook Group</a>';
569 }
570
571 // Support
572 if ( !empty($support)) {
573 $help_content_urls .= '<a class="adminify-tag adminify-tag-secondary adminify-support-url" href="' . esc_url($support) . '" target="_blank">' . self::support_icon() . ' Support</a>';
574 }
575
576 $help_content = sprintf( __('%1$s <div class="adminify-helps">%2$s</div>', 'adminify' ), $module_name, $help_content_urls );
577 return $help_content;
578 }
579
580 /**
581 * Upgrade Pro Icon
582 *
583 * @return void
584 */
585 public static function jltwp_adminify_upgrade_pro_icon()
586 {
587 return '<svg class="adminify-pro-notice-icon is-pulled-left mr-2" width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
588 <path fill-rule="evenodd" clip-rule="evenodd" d="M21.8233 0.18318C21.8541 0.215042 21.8753 0.255055 21.8843 0.298527C22.5767 3.32046 20.085 9.8239 16.4731 13.4209C15.8343 14.064 15.1407 14.6502 14.4002 15.1727C14.4955 16.2787 14.411 17.3846 13.9985 18.3318C12.8302 21.0043 9.75855 21.7824 8.44197 21.9937C8.36979 22.0059 8.29577 22.0012 8.22571 21.9799C8.15566 21.9587 8.09147 21.9215 8.03819 21.8713C7.9849 21.821 7.94397 21.7591 7.9186 21.6904C7.89323 21.6217 7.88411 21.548 7.89196 21.4751L8.36241 17.189C8.04096 17.1858 7.71987 17.1663 7.40039 17.1305C7.17735 17.1087 6.96893 17.0096 6.81109 16.8503L5.15076 15.1924C4.99146 15.0346 4.89242 14.8259 4.87084 14.6026C4.83497 14.281 4.81547 13.9578 4.8124 13.6343L0.524795 14.1076C0.451994 14.1156 0.378341 14.1065 0.309629 14.0811C0.240917 14.0558 0.17902 14.0148 0.128806 13.9615C0.0785915 13.9081 0.0414297 13.8438 0.0202432 13.7736C-0.000943262 13.7035 -0.0055768 13.6293 0.00670721 13.5571C0.223273 12.2368 1.00065 9.16771 3.67065 7.99148C4.61695 7.57859 5.72728 7.4965 6.83761 7.59481C7.35968 6.85546 7.94513 6.16306 8.58733 5.52547C12.1879 1.92304 18.8337 -0.585245 21.7099 0.118627C21.7531 0.128924 21.7924 0.151317 21.8233 0.18318ZM12.224 7.92186C12.3151 8.37957 12.5397 8.79996 12.8695 9.12986C13.0882 9.34908 13.348 9.52298 13.6339 9.64164C13.9198 9.7603 14.2263 9.82137 14.5358 9.82137C14.8453 9.82137 15.1517 9.7603 15.4377 9.64164C15.7236 9.52298 15.9833 9.34908 16.202 9.12986C16.5318 8.79996 16.7565 8.37957 16.8475 7.92186C16.9386 7.46415 16.892 6.98968 16.7137 6.55848C16.5353 6.12727 16.2332 5.7587 15.8455 5.49939C15.4578 5.24007 15.002 5.10166 14.5358 5.10166C14.0695 5.10166 13.6137 5.24007 13.226 5.49939C12.8384 5.7587 12.5362 6.12727 12.3579 6.55848C12.1795 6.98968 12.1329 7.46415 12.224 7.92186ZM5.47798 18.5161C5.99754 18.4262 6.4292 18.321 6.69831 18.0511C6.83974 17.9032 7.0897 18.0256 7.07153 18.2311C6.99299 18.8853 6.69667 19.4941 6.23032 19.9593C5.07579 21.1158 0.785726 21.225 0.785726 21.225C0.785726 21.225 0.894746 16.9334 2.04927 15.7768C2.51439 15.3115 3.12167 15.0153 3.77443 14.9353C3.81912 14.9292 3.86459 14.9374 3.90439 14.9586C3.94419 14.9799 3.97629 15.0131 3.99613 15.0537C4.01597 15.0942 4.02255 15.14 4.01493 15.1845C4.00731 15.229 3.98588 15.2699 3.95368 15.3015C3.80635 15.449 3.56965 16.0767 3.48961 16.5245C3.27991 17.7056 4.31069 18.7152 5.47798 18.5161Z" fill="#000"/>
589 </svg>';
590 }
591
592
593 // Upgrade to Pro Notice
594 public static function adminify_upgrade_pro_img_notice( $image ){
595 return '<div class="adminify-pro-notice"><img src="' . esc_url_raw($image ) . '" /></div>';
596 }
597
598 // Upgrade to Pro Notice Class
599 public static function upgrade_pro_class($classname = '')
600 {
601 if(empty($classname)){
602 // return ' adminify-depend-visible adminify-depend-on adminify-pro-notice ';
603 return ' adminify-pro-feature adminify-pro-notice';
604 } else {
605 echo esc_attr($classname);
606 }
607 }
608
609 // Upgrade to Pro Notice
610 public static function adminify_upgrade_pro($custom_message = '', $style='')
611 {
612
613 if (empty($custom_message)) {
614 $pro_content = sprintf(__('<strong>(Upgrade to Pro)</strong>', 'adminify'));
615 } else {
616 $pro_content = $custom_message;
617 }
618
619 if($style === 'inline'){
620 return '<strong style="font-size:16px;">' . $pro_content . '</strong>';
621 }
622
623 $upgrade_notice_msg = sprintf(
624 __('<div class="adminify-pro-notice adminify-missing-addons"> %1$s %2$s </div>', 'adminify'),
625 self::jltwp_adminify_upgrade_pro_icon(),
626 self::wp_kses_custom($pro_content)
627 );
628 return self::wp_kses_custom($upgrade_notice_msg);
629 }
630
631
632
633 /**
634 * Documentation SVG Icon
635 */
636 public static function docs_icon()
637 {
638 return '<svg class="is-pulled-left mr-1 width="9" height="12" viewBox="0 0 9 12" fill="none" xmlns="http://www.w3.org/2000/svg">
639 <path d="M5.25 3.1875V0H0.5625C0.250781 0 0 0.250781 0 0.5625V11.4375C0 11.7492 0.250781 12 0.5625 12H8.4375C8.74922 12 9 11.7492 9 11.4375V3.75H5.8125C5.50313 3.75 5.25 3.49687 5.25 3.1875ZM6.75 8.71875C6.75 8.87344 6.62344 9 6.46875 9H2.53125C2.37656 9 2.25 8.87344 2.25 8.71875V8.53125C2.25 8.37656 2.37656 8.25 2.53125 8.25H6.46875C6.62344 8.25 6.75 8.37656 6.75 8.53125V8.71875ZM6.75 7.21875C6.75 7.37344 6.62344 7.5 6.46875 7.5H2.53125C2.37656 7.5 2.25 7.37344 2.25 7.21875V7.03125C2.25 6.87656 2.37656 6.75 2.53125 6.75H6.46875C6.62344 6.75 6.75 6.87656 6.75 7.03125V7.21875ZM6.75 5.53125V5.71875C6.75 5.87344 6.62344 6 6.46875 6H2.53125C2.37656 6 2.25 5.87344 2.25 5.71875V5.53125C2.25 5.37656 2.37656 5.25 2.53125 5.25H6.46875C6.62344 5.25 6.75 5.37656 6.75 5.53125ZM9 2.85703V3H6V0H6.14297C6.29297 0 6.43594 0.0585938 6.54141 0.164062L8.83594 2.46094C8.94141 2.56641 9 2.70938 9 2.85703Z" fill="#0347FF"/>
640 </svg>';
641 }
642 /**
643 * Video Tutorials SVG Icon
644 */
645 public static function video_tutorials_icon()
646 {
647 return '<svg class="is-pulled-left mr-1 width="8" height="10" viewBox="0 0 8 10" fill="none" xmlns="http://www.w3.org/2000/svg">
648 <path d="M7.5 4.13399C8.16667 4.51889 8.16667 5.48114 7.5 5.86604L1.5 9.33014C0.833334 9.71504 0 9.23392 0 8.46412V1.53592C0 0.766115 0.833333 0.28499 1.5 0.66989L7.5 4.13399Z" fill="#C30052"/>
649 </svg>';
650 }
651
652 /**
653 * Facebook Group SVG Icon
654 */
655 public static function fbgroup_icon()
656 {
657 return '<svg class="is-pulled-left mr-1 width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
658 <path d="M1.82594 0C0.814448 0 0 0.814448 0 1.82594V8.17405C0 9.18554 0.814448 9.99999 1.82594 9.99999H5.26656V6.09062H4.23281V4.68312H5.26656V3.48062C5.26656 2.53587 5.87735 1.66844 7.28437 1.66844C7.85404 1.66844 8.2753 1.72313 8.2753 1.72313L8.24217 3.0375C8.24217 3.0375 7.81254 3.03344 7.34374 3.03344C6.83635 3.03344 6.75499 3.26722 6.75499 3.65532V4.68313H8.28248L8.21592 6.09063H6.75499V10H8.17404C9.18553 10 9.99998 9.18555 9.99998 8.17406V1.82595C9.99998 0.814458 9.18553 9.99998e-06 8.17404 9.99998e-06H1.82593L1.82594 0Z" fill="#3B5998"/>
659 </svg>';
660 }
661
662 /**
663 * Support SVG Icon
664 */
665 public static function support_icon()
666 {
667 return '<svg class="is-pulled-left mr-1 width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
668 <path fill-rule="evenodd" clip-rule="evenodd" d="M10 5C10 6.32608 9.47322 7.59785 8.53553 8.53553C7.59785 9.47322 6.32608 10 5 10C3.67392 10 2.40215 9.47322 1.46447 8.53553C0.526784 7.59785 0 6.32608 0 5C0 3.67392 0.526784 2.40215 1.46447 1.46447C2.40215 0.526784 3.67392 0 5 0C6.32608 0 7.59785 0.526784 8.53553 1.46447C9.47322 2.40215 10 3.67392 10 5ZM8.75 5C8.75 5.62063 8.59937 6.20563 8.3325 6.72125L7.38 5.76813C7.52262 5.32668 7.5395 4.85425 7.42875 4.40375L8.405 3.4275C8.62625 3.90563 8.75 4.4375 8.75 5ZM5.52187 7.44563L6.50938 8.43312C6.03375 8.64254 5.51968 8.75046 5 8.75C4.45699 8.75068 3.92036 8.63294 3.4275 8.405L4.40375 7.42875C4.77042 7.5186 5.15266 7.52437 5.52187 7.44563ZM2.59875 5.69812C2.47576 5.27463 2.46692 4.82614 2.57313 4.39812L2.52313 4.44812L1.56687 3.49C1.35738 3.96582 1.24945 4.48011 1.25 5C1.25 5.59625 1.38937 6.16 1.63687 6.66062L2.59938 5.69812H2.59875ZM3.27875 1.66687C3.81076 1.39189 4.40112 1.24891 5 1.25C5.59625 1.25 6.16 1.38937 6.66062 1.63687L5.69812 2.59938C5.21829 2.45961 4.70759 2.46679 4.23187 2.62L3.27875 1.6675V1.66687ZM6.25 5C6.25 5.33152 6.1183 5.64946 5.88388 5.88388C5.64946 6.1183 5.33152 6.25 5 6.25C4.66848 6.25 4.35054 6.1183 4.11612 5.88388C3.8817 5.64946 3.75 5.33152 3.75 5C3.75 4.66848 3.8817 4.35054 4.11612 4.11612C4.35054 3.8817 4.66848 3.75 5 3.75C5.33152 3.75 5.64946 3.8817 5.88388 4.11612C6.1183 4.35054 6.25 4.66848 6.25 5Z" fill="#4E4B66"/>
669 </svg>';
670 }
671
672 /* White Label Upgrade Pro */
673 public static function jltwp_adminify_white_label_upgrade()
674 {
675 ?>
676 <div class="wp-adminify-white-label-notice-content">
677 <div class="wp-adminify-white-label-notice-logo">
678 <img src="<?php echo esc_url(WP_ADMINIFY_ASSETS_IMAGE) . 'logos/logo-text-light.svg'; ?>" alt="<?php echo esc_attr(WP_ADMINIFY); ?>">
679 </div>
680 <h2>
681 <?php echo sprintf(__('Upgrade <span>Pro</span> for White Labeling', 'adminify')); ?>
682 </h2>
683 <p>
684 <?php
685 echo sprintf(__('<strong>%1$s</strong> can be completely re-branded with your own brand Logo, Name and Author Details. Your clients will never know what tools you are using to build their website and will think that this is your own tool set. White-labeling works as long as your license is active. ', 'adminify'), esc_html(WP_ADMINIFY));
686 ?>
687 <br>
688 <em><?php esc_html_e('Note: Agency or Higher Plans Only', 'adminify'); ?></em>
689 </p>
690 <a class="wp-adminify-btn wp-adminify-get-pro" href="<?php echo esc_url('https://wpadminify.com/pricing/'); ?>" target="_blank">
691 <?php esc_html_e('Upgrade Now', 'adminify'); ?>
692 </a>
693 </div>
694 <?php
695 }
696
697
698 public static function get_widget_template_options()
699 {
700 $type = 'widget';
701 $page_templates = self::jltwp_adminify_get_page_templates($type);
702
703 $options[-1] = __('Select', 'adminify');
704
705 if (count($page_templates)) {
706 foreach ($page_templates as $id => $name) {
707 $options[$id] = $name;
708 }
709 } else {
710 $options['no_template'] = __('No saved templates found!', 'adminify');
711 }
712
713 return $options;
714 }
715
716 public static function get_section_template_options()
717 {
718 $type = 'section';
719 $page_templates = self::jltwp_adminify_get_page_templates($type);
720
721 $options[-1] = __('Select', 'adminify');
722
723 if (count($page_templates)) {
724 foreach ($page_templates as $id => $name) {
725 $options[$id] = $name;
726 }
727 } else {
728 $options['no_template'] = __('No saved templates found!', 'adminify');
729 }
730
731 return $options;
732 }
733
734 public static function get_page_template_options()
735 {
736 $type = 'page';
737 $page_templates = self::jltwp_adminify_get_page_templates($type);
738
739 $options[-1] = __('Select', 'adminify');
740
741 if (count($page_templates)) {
742 foreach ($page_templates as $id => $name) {
743 $options[$id] = $name;
744 }
745 } else {
746 $options['no_template'] = __('No saved templates found!', 'adminify');
747 }
748
749 return $options;
750 }
751
752 public static function get_theme_presets($theme = null)
753 {
754
755 $common_var = [
756 '--adminify-menu-vertical-padding' => '10px',
757 '--adminify-menu-horizontal-padding' => '8px',
758 '--adminify-menu-wrapper-padding-top' => '16px',
759 '--adminify-menu-wrapper-padding-right' => '8px',
760 '--adminify-menu-wrapper-padding-bottom' => '16px',
761 '--adminify-menu-wrapper-padding-left' => '8px',
762 '--adminify-submenu-vertical-padding' => '4px',
763 '--adminify-submenu-wrapper-padding-top' => '8px',
764 '--adminify-submenu-wrapper-padding-right' => '0px',
765 '--adminify-submenu-wrapper-padding-bottom' => '8px',
766 '--adminify-submenu-wrapper-padding-left' => '28px',
767 // '--adminify-menu-text-align' => 'left',
768 // '--adminify-menu-text-transform' => '',
769 // '--adminify-menu-text-decoration' => 'none',
770 '--adminify-menu-font-size' => '13px',
771 '--adminify-menu-line-height' => '20px',
772 '--adminify-menu-letter-spacing' => '',
773 '--adminify-menu-width' => '260px'
774 ];
775
776 $presets = [
777
778 // Base/ Default Preset
779 'preset1' => [
780 '--adminify-preset-background' => '#F9F9F9',
781 '--adminify-primary' => '#3a3ae9',
782 // '--adminify-text-color' => '#ffffff',
783 '--adminify-menu-border' => '#dedee7',
784 '--adminify-menu-bg' => '#ffffff',
785 '--adminify-menu-hover-bg' => '#3a3ae9',
786 '--adminify-menu-text-color' => '#48455f',
787 '--adminify-menu-text-hover-color' => '#ffffff',
788 '--adminify-menu-active-bg' => '#3a3ae9',
789 '--adminify-menu-active-color' => '#ffffff',
790 '--adminify-submenu-wrapper-bg' => '#ffffff',
791 '--adminify-submenu-hover-bg' => 'transparent',
792 '--adminify-submenu-text-color' => '#48455f',
793 '--adminify-submenu-text-hover-color' => '#3a3ae9',
794 '--adminify-submenu-active-bg' => 'transparent',
795 '--adminify-submenu-active-color' => '#3a3ae9',
796 '--adminify-notif-bg-color' => '#3a3ae9',
797 '--adminify-notif-color' => '#ffffff',
798 ],
799
800 'preset2' => [
801 '--adminify-preset-background' => '#F9F9F9',
802 '--adminify-primary' => '#0347FF',
803 '--adminify-notif-bg-color' => '#FF1C69',
804 // '--adminify-text-color' => '#ffffff',
805 '--adminify-menu-border' => '#404052',
806 '--adminify-menu-bg' => '#14142B',
807 '--adminify-menu-hover-bg' => '#0347FF',
808 '--adminify-menu-text-color' => '#ffffff',
809 '--adminify-menu-text-hover-color' => '#ffffff',
810 '--adminify-menu-active-bg' => '#0347FF',
811 '--adminify-menu-active-color' => '#ffffff',
812 '--adminify-submenu-wrapper-bg' => '#14142B',
813 '--adminify-submenu-hover-bg' => 'transparent',
814 '--adminify-submenu-text-color' => '#ffffff',
815 '--adminify-submenu-text-hover-color' => '#0347FF',
816 '--adminify-submenu-active-bg' => 'transparent',
817 '--adminify-submenu-active-color' => '#0347FF',
818 '--adminify-notif-bg-color' => '#0347FF',
819 '--adminify-notif-color' => '#ffffff',
820 ],
821 ];
822
823 $pro_presets = apply_filters('adminify_settings/color_presets', $common_var);
824
825 if( !empty(array_key_exists('preset3', $pro_presets)) ) {
826 $presets = array_merge($presets, $pro_presets);
827 }
828
829 // Merge $common_var variable with every preset
830 foreach ($presets as $key => $value) {
831 $presets[$key] = array_merge($value, $common_var);
832 }
833
834 // return all presets
835 if (is_null($theme)) {
836 return $presets;
837 }
838
839 // return specific preset
840 if (array_key_exists($theme, $presets)) {
841 return $presets[$theme];
842 }
843
844 // specific preset not found
845 return [];
846 }
847
848 public static function jltwp_adminify_get_page_templates($type = '')
849 {
850 $args = [
851 'post_type' => 'elementor_library',
852 'posts_per_page' => -1,
853 ];
854
855 if ($type) {
856 $args['tax_query'] = [
857 [
858 'taxonomy' => 'elementor_library_type',
859 'field' => 'slug',
860 'terms' => $type,
861 ],
862 ];
863 }
864
865 $page_templates = get_posts($args);
866
867 $options = [];
868
869 if (!empty($page_templates) && !is_wp_error($page_templates)) {
870 foreach ($page_templates as $post) {
871 $options[$post->ID] = $post->post_title;
872 }
873 }
874 return $options;
875 }
876
877 public static function assets_ext($ext)
878 {
879 if (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) {
880 return $ext;
881 }
882 return '.min' . $ext;
883 }
884
885 public static function wp_kses_atts_map(array $attrs)
886 {
887 return array_fill_keys(array_values($attrs), true);
888 }
889
890 public static function wp_kses_custom($content)
891 {
892 $allowed_tags = wp_kses_allowed_html('post');
893
894 $custom_tags = [
895 'select' => self::wp_kses_atts_map(['class', 'id', 'style', 'width', 'height', 'title', 'data', 'name', 'autofocus', 'disabled', 'multiple', 'required', 'size']),
896 'input' => self::wp_kses_atts_map(['class', 'id', 'style', 'width', 'height', 'title', 'data', 'name', 'autofocus', 'disabled', 'required', 'size', 'type', 'checked', 'readonly', 'placeholder', 'value', 'maxlength', 'min', 'max', 'multiple', 'pattern', 'step', 'autocomplete']),
897 'textarea' => self::wp_kses_atts_map(['class', 'id', 'style', 'width', 'height', 'title', 'data', 'name', 'autofocus', 'disabled', 'required', 'rows', 'cols', 'wrap', 'maxlength']),
898 'option' => self::wp_kses_atts_map(['class', 'id', 'label', 'disabled', 'label', 'selected', 'value']),
899 'optgroup' => self::wp_kses_atts_map(['disabled', 'label', 'class', 'id']),
900 'form' => self::wp_kses_atts_map(['class', 'id', 'data', 'style', 'width', 'height', 'accept-charset', 'action', 'autocomplete', 'enctype', 'method', 'name', 'novalidate', 'rel', 'target']),
901 'svg' => self::wp_kses_atts_map(['class', 'xmlns', 'viewbox', 'width', 'height', 'fill', 'aria-hidden', 'aria-labelledby', 'role']),
902 'rect' => self::wp_kses_atts_map(['rx', 'width', 'height', 'fill']),
903 'path' => self::wp_kses_atts_map(['d', 'fill']),
904 'g' => self::wp_kses_atts_map(['fill']),
905 'defs' => self::wp_kses_atts_map(['fill']),
906 'linearGradient' => self::wp_kses_atts_map(['id', 'x1', 'x2', 'y1', 'y2', 'gradientUnits']),
907 'stop' => self::wp_kses_atts_map(['stop-color', 'offset', 'stop-opacity']),
908 'style' => self::wp_kses_atts_map(['type']),
909 'div' => self::wp_kses_atts_map(['class', 'id', 'style']),
910 'ul' => self::wp_kses_atts_map(['class', 'id', 'style']),
911 'li' => self::wp_kses_atts_map(['class', 'id', 'style']),
912 'label' => self::wp_kses_atts_map(['class', 'for']),
913 'span' => self::wp_kses_atts_map(['class', 'id', 'style']),
914 'h1' => self::wp_kses_atts_map(['class', 'id', 'style']),
915 'h2' => self::wp_kses_atts_map(['class', 'id', 'style']),
916 'h3' => self::wp_kses_atts_map(['class', 'id', 'style']),
917 'h4' => self::wp_kses_atts_map(['class', 'id', 'style']),
918 'h5' => self::wp_kses_atts_map(['class', 'id', 'style']),
919 'h6' => self::wp_kses_atts_map(['class', 'id', 'style']),
920 'a' => self::wp_kses_atts_map(['class', 'href', 'target', 'rel']),
921 'p' => self::wp_kses_atts_map(['class', 'id', 'style', 'data']),
922 'table' => self::wp_kses_atts_map(['class', 'id', 'style']),
923 'thead' => self::wp_kses_atts_map(['class', 'id', 'style']),
924 'tbody' => self::wp_kses_atts_map(['class', 'id', 'style']),
925 'tr' => self::wp_kses_atts_map(['class', 'id', 'style']),
926 'th' => self::wp_kses_atts_map(['class', 'id', 'style']),
927 'td' => self::wp_kses_atts_map(['class', 'id', 'style']),
928 'i' => self::wp_kses_atts_map(['class', 'id', 'style']),
929 'button' => self::wp_kses_atts_map(['class', 'id']),
930 'nav' => self::wp_kses_atts_map(['class', 'id', 'style']),
931 'time' => self::wp_kses_atts_map(['datetime']),
932 'br' => [],
933 'strong' => [],
934 'style' => [],
935 'img' => self::wp_kses_atts_map(['class', 'src', 'alt', 'height', 'width', 'srcset', 'id', 'loading']),
936 ];
937
938 $allowed_tags = array_merge_recursive($allowed_tags, $custom_tags);
939
940 return wp_kses(stripslashes_deep($content), $allowed_tags);
941 }
942
943
944 /**
945 * Missing Addon/Plugin Notice
946 *
947 * @param [type] $args
948 *
949 * @return void
950 */
951 public static function missing_plugin_notice( $plugin_name = '' )
952 {
953 /* translators: %s: Plugin Name */
954 $missing_plugin_notice = sprintf(
955 __('<strong>"%1$s"</strong> plugin is not Activated! Please install and activate <strong>%1$s</strong> Plugin <p> <a class="adminify-missing-addons" href="%2$s">%3$s</a></p>', 'adminify'),
956 esc_html($plugin_name),
957 admin_url('admin.php?page=wp-adminify-addons-plugins'),
958 __('Install Now', 'adminify')
959 );
960 return '<div class="adminify-missing-addons">' . self::jltwp_adminify_upgrade_pro_icon() . self::wp_kses_custom( $missing_plugin_notice ) . '</div>';
961 }
962
963
964 /**
965 * Update Existing Data to New Options data
966 *
967 * @param [type] $get_option_value
968 * @param [type] $update_option_value
969 * @param [type] $option_name
970 *
971 * @return void
972 */
973 public static function update_options($get_option_value, $option_name)
974 {
975
976 // Retrieve the current option value
977 $current_value = get_option($option_name);
978 // $current_value = self::$option_data;
979 // Initialize the current value if it's empty
980 if (empty($current_value)) {
981 $current_value = [];
982 }
983 // If $get_option_value is provided, use it to update the current value
984 if (!empty($get_option_value)) {
985 // Ensure current value is an array before merging
986 if (!is_array($current_value)) {
987 $current_value = [];
988 }
989 // Merge the provided value into the current value
990 $current_value = array_merge($current_value, $get_option_value);
991 }
992 // Update the specific key within the option with the new value
993 // $current_value[$option_key] = $update_option_value;
994
995 // Update the option with the new value
996 update_option($option_name, $current_value);
997 // Optionally, return the updated value
998 return get_option($option_name);
999 }
1000
1001
1002 /**
1003 * Replace Array Keys
1004 *
1005 * @return void
1006 */
1007 public static function replace_keys($sourceArray, $newArray){
1008 $new_value = [];
1009 foreach ($newArray as $key => $value) {
1010 if (!array_key_exists($key, $sourceArray)) {
1011 return $sourceArray;
1012 }
1013 $new_value[$value] = $sourceArray[$key];
1014 unset($sourceArray[$key]);
1015 }
1016 return array_merge($sourceArray, $new_value);
1017 }
1018
1019
1020 /**
1021 * Move Array Keys
1022 *
1023 * @return void
1024 */
1025 public static function move_keys(&$sourceArray, $keysToMove)
1026 {
1027 $destinationArray = [];
1028 foreach ($keysToMove as $key) {
1029 if (array_key_exists($key, $sourceArray)) {
1030 $destinationArray[$key] = $sourceArray[$key];
1031 unset($sourceArray[$key]);
1032 }
1033 }
1034 return $destinationArray;
1035 }
1036
1037
1038 /**
1039 * Remove unnecessary keys.
1040 *
1041 * @param string $option_name The name of the option.
1042 * @param array $keys_to_remove An array of keys to remove.
1043 */
1044 public static function removeKeys($sourceArray, $keysToRemove)
1045 {
1046 foreach ($keysToRemove as $key) {
1047 if (array_key_exists($key, $sourceArray)) {
1048 unset($sourceArray[$key]);
1049 }
1050 }
1051 return $sourceArray;
1052 }
1053
1054
1055
1056 /**
1057 * Move Nested Keys
1058 *
1059 * @return void
1060 */
1061 public static function moveNestedKeys(&$sourceArray, $moveInstructions) {
1062 $destinationArray = [];
1063 foreach ($moveInstructions as $sourcePath => $destPath) {
1064 $sourcePathArray = explode('.', $sourcePath);
1065 $destPathArray = explode('.', $destPath);
1066 $sourceValue = self::getNestedValue($sourceArray, $sourcePathArray);
1067 if ($sourceValue !== null) {
1068 self::setNestedValue($destinationArray, $destPathArray, $sourceValue);
1069 self::unsetNestedValue($sourceArray, $sourcePathArray);
1070 }
1071 }
1072
1073 return array_merge_recursive($sourceArray, $destinationArray);
1074 }
1075
1076 public static function getNestedValue(&$array, $pathArray) {
1077 $value = &$array;
1078 foreach ($pathArray as $key) {
1079 if (is_array($value) && array_key_exists($key, $value)) {
1080 $value = &$value[$key];
1081 } else {
1082 return null;
1083 }
1084 }
1085 return $value;
1086 }
1087
1088 public static function setNestedValue(&$array, $pathArray, $value) {
1089 $temp = &$array;
1090 foreach ($pathArray as $key) {
1091 if (!isset($temp[$key])) {
1092 $temp[$key] = [];
1093 }
1094 $temp = &$temp[$key];
1095 }
1096 $temp = $value;
1097 }
1098
1099 public static function unsetNestedValue(&$array, $pathArray) {
1100 $temp = &$array;
1101 foreach ($pathArray as $key) {
1102 if (isset($temp[$key])) {
1103 if (count($pathArray) === 1) {
1104 unset($temp[$key]);
1105 } else {
1106 self::unsetNestedValue($temp[$key], array_slice($pathArray, 1));
1107 }
1108 return;
1109 }
1110 }
1111 }
1112
1113
1114
1115 /**
1116 *
1117 * Checkbox Method
1118 */
1119 public static function checkboxes(&$old_db, $checkbox_keys) {
1120 $result = [];
1121 $parentKey = "";
1122 $childKey = "";
1123
1124 $thirdStep = [];
1125
1126 foreach ($checkbox_keys as $key => $value) {
1127
1128 $sourceArray = explode(".", $value);
1129
1130 foreach ($sourceArray as $x => $element) {
1131 if (!array_key_exists($element, $result) && $x === 0) {
1132 $parentKey = $element;
1133 if (count($sourceArray) === 3) {
1134 $result[$element] = [];
1135 } else {
1136 $result[$element] = [];
1137 }
1138 }
1139
1140
1141 if ($x === 1 && !empty($old_db[$key])) {
1142 $childKey = $element;
1143 if (count($sourceArray) === 3) {
1144 $result[$parentKey][$element] = [];
1145 } else {
1146 $result[$parentKey][] = $element;
1147 }
1148 } elseif ($x === 1 && empty($old_db[$key]) && count($sourceArray) === 3) {
1149 $childKey = $element;
1150 if (!array_key_exists($element, $result[$parentKey])) {
1151 $result[$parentKey][$element] = [];
1152 }
1153 }
1154
1155 if ($x === 2 && !empty($old_db[$key]) && count($sourceArray) === 3) {
1156 $thirdStep[] = $element;
1157 $result[$parentKey][$childKey] = $thirdStep;
1158 }
1159 }
1160 }
1161
1162 return array_merge_recursive($old_db, $result);
1163 }
1164
1165 public static function adminify_upgrade_pro_class($inline_badge=false){
1166 if(!empty($inline_badge)){
1167 return '<span class="adminify-pro-checkbox adminify-pro-badge adminify-pro-notice">Pro</span>';
1168 }
1169 return '<span class="adminify-pro-checkbox">' . self::jltwp_adminify_upgrade_pro_icon() . ' <strong>(Upgrade to Pro)</strong>' . '</span>';
1170 }
1171
1172 public static function adminify_upgrade_pro_badge($badge_text = 'Pro'){
1173 if(!empty($badge_text)){
1174 return '<span class="adminify-pro-badge">' . $badge_text . '</span>';
1175 }
1176 }
1177
1178 /*
1179 * Compares the version of WordPress running to the $version specified.
1180 * Usage: Utils::check_wp_version('>=', '4.0')
1181 version_compare( $wp_version, '4.3', '>=' )
1182 * @param string $operator
1183 * @param string $version
1184 * @returns boolean
1185 */
1186 public static function check_wp_version( $operator = '>', $version = '6.6' ) {
1187 global $wp_version;
1188 return version_compare( $wp_version, $version, $operator );
1189 }
1190
1191 }
1192