PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.1
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-utility.php

class-mainwp-utility.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.1, at class/class-mainwp-utility.php

1,623 lines 48.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Utility Helper.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 // phpcs:disable WordPress.DB.RestrictedFunctions, WordPress.WP.AlternativeFunctions, WordPress.PHP.NoSilencedErrors, Generic.Metrics.CyclomaticComplexity -- Using cURL functions.
11
12 /**
13 * Class MainWP_Utility
14 *
15 * @package MainWP\Dashboard
16 */
17 class MainWP_Utility { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
18
19 /**
20 * Yoast SEO is enabled return true else return null.
21 *
22 * @static
23 * @var boolean $enabled_wp_seo If Yoast SEO is enabled return true else return null.
24 */
25 public static $enabled_wp_seo = null;
26
27 /**
28 * Private static variable.
29 *
30 * @static
31 *
32 * @var mixed Default null
33 */
34 public static $last_deactivated_alerts = null;
35
36 /**
37 * Private static variable to hold the single instance of the class.
38 *
39 * @static
40 *
41 * @var mixed Default null
42 */
43 private static $instance = null;
44
45 /**
46 * Store the disabled php functions.
47 *
48 * @static
49 * @var string $disabled_functions disabled php functions.
50 */
51 public static $disabled_functions = null;
52
53 /**
54 * Method get_class_name()
55 *
56 * Get Class Name.
57 *
58 * @return object __CLASS__
59 */
60 public static function get_class_name() {
61 return __CLASS__;
62 }
63
64 /**
65 * Method instance()
66 *
67 * Create public static instance.
68 *
69 * @static
70 * @return MainWP_Utility
71 */
72 public static function instance() {
73 if ( null === static::$instance ) {
74 static::$instance = new self();
75 }
76
77 return static::$instance;
78 }
79
80 /**
81 * Method starts_with()
82 *
83 * Start of Stack Trace.
84 *
85 * @param mixed $haystack The full stack.
86 * @param mixed $needle The function that is throwing the error.
87 *
88 * @return mixed Needle in the Haystack.
89 */
90 public static function starts_with( $haystack, $needle ) {
91 return ! strncmp( $haystack, $needle, strlen( $needle ) );
92 }
93
94 /**
95 * Method ends_with()
96 *
97 * End of Stack Trace.
98 *
99 * @param mixed $haystack Haystack parameter.
100 * @param mixed $needle Needle parameter.
101 *
102 * @return boolean
103 */
104 public static function ends_with( $haystack, $needle ) {
105 $length = strlen( $needle );
106 if ( 0 === $length ) {
107 return true;
108 }
109
110 return substr( $haystack, - $length ) === $needle;
111 }
112
113 /**
114 * Method get_nice_url()
115 *
116 * Grab url.
117 *
118 * @param string $pUrl Website URL.
119 * @param bool $showHttp Show HTTP.
120 *
121 * @return string $url.
122 */
123 public static function get_nice_url( $pUrl, $showHttp = false ) {
124 $url = $pUrl;
125
126 if ( static::starts_with( $url, 'http://' ) ) {
127 if ( ! $showHttp ) {
128 $url = substr( $url, 7 );
129 }
130 } elseif ( static::starts_with( $pUrl, 'https://' ) ) {
131 if ( ! $showHttp ) {
132 $url = substr( $url, 8 );
133 }
134 } elseif ( $showHttp ) {
135 $url = 'http://' . $url;
136 }
137
138 if ( static::ends_with( $url, '/' ) ) {
139 if ( ! $showHttp ) {
140 $url = substr( $url, 0, strlen( $url ) - 1 );
141 }
142 } else {
143 $url = $url . '/';
144 }
145
146 return $url;
147 }
148
149 /**
150 * Method is_domain_valid()
151 *
152 * Check $url against FILTER_VALIDATE_URL.
153 *
154 * @param mixed $url Domain to check.
155 *
156 * @return boolean True|False.
157 */
158 public static function is_domain_valid( $url ) {
159 return filter_var( $url, FILTER_VALIDATE_URL );
160 }
161
162 /**
163 * Method ctype_digit()
164 *
165 * Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise.
166 *
167 * @param mixed $str String to check.
168 *
169 * @return boolean Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise.
170 */
171 public static function ctype_digit( $str ) {
172 return ( is_string( $str ) || is_int( $str ) || is_float( $str ) ) && preg_match( '/^\d+\z/', $str );
173 }
174
175 /**
176 * Method sortmulti()
177 *
178 * Sort the given array, Acending, Decending or by Natural Order.
179 *
180 * @param mixed $arr Array to sort.
181 * @param mixed $index Index of array.
182 * @param mixed $order Acending or Decending order.
183 * @param bool $natsort Sort an array using a "natural order" algorithm. Default: false.
184 * @param bool $case_sensitive If case sensitive return true else return false. Default: false.
185 *
186 * @return array $sorted Return the sorted array.
187 */
188 public static function sortmulti( $arr, $index, $order, $natsort = false, $case_sensitive = false ) { // phpcs:ignore -- NOSONAR - complex.
189 $sorted = array();
190 if ( is_array( $arr ) && ! empty( $arr ) ) {
191 foreach ( array_keys( $arr ) as $key ) {
192 $temp[ $key ] = $arr[ $key ][ $index ];
193 }
194 if ( ! $natsort ) {
195 if ( 'asc' === $order ) {
196 asort( $temp );
197 } else {
198 arsort( $temp );
199 }
200 } else {
201 if ( true === $case_sensitive ) {
202 natsort( $temp );
203 } else {
204 natcasesort( $temp );
205 }
206 if ( 'asc' !== $order ) {
207 $temp = array_reverse( $temp, true );
208 }
209 }
210 foreach ( array_keys( $temp ) as $key ) {
211 if ( is_numeric( $key ) ) {
212 $sorted[] = $arr[ $key ];
213 } else {
214 $sorted[ $key ] = $arr[ $key ];
215 }
216 }
217
218 return $sorted;
219 }
220
221 return $sorted;
222 }
223
224 /**
225 * Method get_sub_array_having()
226 *
227 * Get sub array.
228 *
229 * @param mixed $arr Array to traverse.
230 * @param mixed $index Index of array.
231 * @param mixed $value Array values.
232 *
233 * void array $output Sub array.
234 */
235 public static function get_sub_array_having( $arr, $index, $value ) {
236 $output = array();
237 if ( is_array( $arr ) && ! empty( $arr ) ) {
238 foreach ( $arr as $arrvalue ) {
239 $existed = isset( $arrvalue[ $index ] ) ? $arrvalue[ $index ] : null;
240 if ( $existed === $value ) {
241 $output[] = $arrvalue;
242 }
243 }
244 }
245
246 return $output;
247 }
248
249 /**
250 * Method trim_slashes()
251 *
252 * Trim stashes from element.
253 *
254 * @param mixed $elem Element to trim.
255 *
256 * @return string Return string with no slashes.
257 */
258 public static function trim_slashes( $elem ) {
259 return trim( $elem, '/' );
260 }
261
262 /**
263 * Method sanitize()
264 *
265 * Sanitize given string.
266 *
267 * @param mixed $str String to sanitize.
268 *
269 * @return string Sanitized string.
270 */
271 public static function sanitize( $str ) {
272 return preg_replace( '/[\\\\\/\:"\*\?\<\>\|]+/', '', $str );
273 }
274
275 /**
276 * Method sanitize_alphanumeric()
277 *
278 * Sanitize given string.
279 *
280 * @param mixed $str String to sanitize.
281 *
282 * @return string Sanitized string.
283 */
284 public static function sanitize_attr_slug( $str ) {
285 $str = strtolower( $str );
286 $str = str_replace( array( '=', '?', '/' ), '-', $str );
287 $str = preg_replace( '/[^A-Za-z0-9^\-]/', '', $str );
288 return $str;
289 }
290
291 /**
292 * Method end_session()
293 *
294 * End a session.
295 *
296 * @return void
297 */
298 public static function end_session() {
299
300 if ( defined( 'WP_CLI' ) && WP_CLI ) {
301 return;
302 }
303
304 if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
305 return;
306 }
307
308 session_write_close();
309 if ( 0 < ob_get_length() ) {
310 ob_end_flush();
311 }
312 }
313
314 /**
315 * Method get_timestamp()
316 *
317 * Get time stamp in gmt_offset.
318 *
319 * @param mixed $timestamp Time stamp to convert.
320 *
321 * @return string Time stamp in general mountain time offset.
322 */
323 public static function get_timestamp( $timestamp = false ) {
324 if ( false === $timestamp ) {
325 $timestamp = time();
326 }
327 $gmtOffset = get_option( 'gmt_offset' );
328
329 return $gmtOffset ? ( $gmtOffset * HOUR_IN_SECONDS ) + $timestamp : $timestamp;
330 }
331
332 /**
333 * Method date()
334 *
335 * Show date in given format.
336 *
337 * @param mixed $format Format to display date in.
338 *
339 * @return string Date.
340 */
341 public static function date( $format ) {
342 // phpcs:ignore -- use local date function.
343 return date( $format, static::get_timestamp() );
344 }
345
346 /**
347 * Method format_timestamp()
348 *
349 * Format the given timestamp.
350 *
351 * @param mixed $timestamp Timestamp to format.
352 *
353 * @return string Formatted timestamp.
354 */
355 public static function format_timestamp( $timestamp ) {
356 return date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $timestamp );
357 }
358
359 /**
360 * Method format_timestamp()
361 *
362 * Format the given timestamp.
363 *
364 * @param mixed $timestamp Timestamp to format.
365 *
366 * @return string Formatted timestamp.
367 */
368 public static function format_date( $timestamp ) {
369 return date_i18n( get_option( 'date_format' ), $timestamp );
370 }
371
372 /**
373 * Format duration time to show.
374 *
375 * @param float $time timestamp.
376 * @return mixed result.
377 */
378 public static function format_duration_time( $time ) {
379
380 $original_sec = absint( $time );
381 $dura_sec = $original_sec;
382 $days = floor( $dura_sec / 86400 );
383 $dura_sec -= $days * 86400;
384 $dura_hour_sec = $dura_sec;
385 $dura_hours = floor( $dura_sec / 3600 );
386
387 if ( $days > 0 ) {
388 $formatted_dura = ( $days * 24 + $dura_hours ) . gmdate( 'i\m s\s', $dura_hour_sec );
389 } else {
390 $formatted_dura = gmdate( 'H\h i\m s\s', $original_sec );
391 }
392 return '<bdi>' . esc_html( $formatted_dura ) . '</bdi>';
393 }
394
395
396 /**
397 * Method human_filesize()
398 *
399 * Convert to human readable file size format,
400 * (B|kB|MB|GB|TB|PB|EB|ZB|YB).
401 *
402 * @param mixed $bytes File in bytes.
403 * @param integer $decimals Number of decimals to output.
404 *
405 * @return string Human readable file size.
406 */
407 public static function human_filesize( $bytes, $decimals = 2 ) {
408 $size = array( 'B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' );
409 $factor = floor( ( strlen( $bytes ) - 1 ) / 3 );
410
411 return sprintf( "%.{$decimals}f", $bytes / pow( 1024, $factor ) ) . @$size[ $factor ];
412 }
413
414 /**
415 * Method map_fields()
416 *
417 * Map Site.
418 *
419 * @param mixed $data data to map.
420 * @param mixed $keys Keys to map.
421 * @param bool $object_output Output format array|object.
422 *
423 * @return mixed Mapped data.
424 */
425 public static function map_fields( &$data, $keys, $object_output = true ) {
426 return static::map_site( $data, $keys, $object_output );
427 }
428
429 /**
430 * Method map_site()
431 *
432 * Map Site.
433 *
434 * @param mixed $website Website to map.
435 * @param mixed $keys Keys to map.
436 * @param bool $object_output Output format array|object.
437 *
438 * @return mixed $outputSite Mapped site.
439 */
440 public static function map_site( &$website, $keys, $object_output = true ) { // phpcs:ignore -- NOSONAR - complex.
441 if ( $object_output ) {
442 $outputSite = new \stdClass();
443 if ( ! empty( $website ) ) {
444 if ( is_object( $website ) ) {
445 foreach ( $keys as $key ) {
446 $outputSite->{$key} = $website->$key;
447 }
448 } elseif ( is_array( $website ) ) {
449 foreach ( $keys as $key ) {
450 $outputSite->{$key} = $website[ $key ];
451 }
452 }
453 }
454 } else {
455 $outputSite = array();
456 if ( ! empty( $website ) ) {
457 if ( is_object( $website ) ) {
458 foreach ( $keys as $key ) {
459 $outputSite[ $key ] = $website->$key;
460 }
461 } elseif ( is_array( $website ) ) {
462 foreach ( $keys as $key ) {
463 $outputSite[ $key ] = $website[ $key ];
464 }
465 }
466 }
467 }
468 return $outputSite;
469 }
470
471 /**
472 * Method array_merge()
473 *
474 * Merge two given arrays into one.
475 *
476 * @param mixed $arr1 First array.
477 * @param mixed $arr2 Second array.
478 *
479 * @return array Merged Array.
480 */
481 public static function array_merge( $arr1, $arr2 ) {
482 if ( ! is_array( $arr1 ) && ! is_array( $arr2 ) ) {
483 return array();
484 }
485 if ( ! is_array( $arr1 ) ) {
486 return $arr2;
487 }
488 if ( ! is_array( $arr2 ) ) {
489 return $arr1;
490 }
491
492 $output = array();
493 foreach ( $arr1 as $el ) {
494 $output[] = $el;
495 }
496 foreach ( $arr2 as $el ) {
497 $output[] = $el;
498 }
499
500 return $output;
501 }
502
503 /**
504 * Method update_option()
505 *
506 * Update option.
507 *
508 * @param mixed $option_name Option name.
509 * @param mixed $option_value Option value.
510 *
511 * @return (boolean) False if value was not updated and true if value was updated.
512 */
513 public static function update_option( $option_name, $option_value ) {
514 $success = add_option( $option_name, $option_value, '', 'no' );
515
516 if ( ! $success ) {
517 $success = update_option( $option_name, $option_value );
518 }
519
520 return $success;
521 }
522
523 /**
524 * Method update_user_option()
525 *
526 * Update option.
527 *
528 * @param mixed $option_name Option name.
529 * @param mixed $option_value Option value.
530 *
531 * @return (boolean) False if value was not updated and true if value was updated.
532 */
533 public static function update_user_option( $option_name, $option_value ) {
534 $user = wp_get_current_user();
535 if ( $user ) {
536 return update_user_option( $user->ID, $option_name, $option_value );
537 }
538 return false;
539 }
540
541 /**
542 * Method remove_preslash_spaces()
543 *
544 * Remove spaces before slashes.
545 *
546 * @param string $text String to strip.
547 *
548 * @return string $text Cleaned string.
549 */
550 public static function remove_preslash_spaces( $text ) {
551 while ( stristr( $text, ' /' ) ) {
552 $text = str_replace( ' /', '/', $text );
553 }
554
555 return $text;
556 }
557
558 /**
559 * Method remove_http_prefix()
560 *
561 * Remove http prefixes from given url.
562 *
563 * @param mixed $pUrl Given URL.
564 * @param bool $pTrimSlashes Whether or not to trim slashes. Default is false.
565 *
566 * @return string Trimmed URL.
567 */
568 public static function remove_http_prefix( $pUrl, $pTrimSlashes = false ) {
569 return str_replace( array( 'http:' . ( $pTrimSlashes ? '//' : '' ), 'https:' . ( $pTrimSlashes ? '//' : '' ) ), array( '', '' ), $pUrl );
570 }
571
572 /**
573 * Method remove_http_www_prefix()
574 *
575 * Remove 'www.' from given URL.
576 *
577 * @param mixed $pUrl Given URL.
578 *
579 * @return string Cleaned URL.
580 */
581 public static function remove_http_www_prefix( $pUrl ) {
582 $pUrl = static::remove_http_prefix( $pUrl, true );
583 if ( static::starts_with( strtolower( $pUrl ), 'www.' ) ) {
584 $pUrl = substr( $pUrl, 4 );
585 }
586 return $pUrl;
587 }
588
589 /**
590 * Method sanitize_file_name()
591 *
592 * Sanitize file names.
593 *
594 * @param mixed $filename File name to sanitize.
595 *
596 * @return string Sanitized filename.
597 */
598 public static function sanitize_file_name( $filename ) {
599 $filename = str_replace( array( '|', '/', '\\', ' ', ':' ), array( '-', '-', '-', '-', '-' ), $filename );
600 return sanitize_file_name( $filename );
601 }
602
603
604
605 /**
606 * Method esc_content()
607 *
608 * Escape content,
609 * allowed content (a,href,title,br,em,strong,p,hr,ul,ol,li,h1,h2 ... ).
610 *
611 * @param mixed $content Content to escape.
612 * @param string $type Type of content. Default = note.
613 * @param mixed $more_allowed input allowed tags - options.
614 *
615 * @return string Filtered content containing only the allowed HTML.
616 */
617 public static function esc_content( $content, $type = 'note', $more_allowed = array() ) {
618 if ( ! is_string( $content ) ) {
619 return $content;
620 }
621
622 if ( 'note' === $type ) {
623
624 $allowed_html = array(
625 'a' => array(
626 'href' => array(),
627 'title' => array(),
628 ),
629 'br' => array(),
630 'em' => array(),
631 'strong' => array(),
632 'p' => array(),
633 'hr' => array(),
634 'ul' => array(),
635 'ol' => array(),
636 'li' => array(),
637 'h1' => array(),
638 'h2' => array(),
639 );
640
641 if ( is_array( $more_allowed ) && ! empty( $more_allowed ) ) {
642 $allowed_html = array_merge( $allowed_html, $more_allowed );
643 }
644
645 $content = wp_kses( $content, $allowed_html );
646
647 } elseif ( 'mixed' === $type ) {
648
649 $allowed_html = array(
650 'a' => array(
651 'href' => array(),
652 'title' => array(),
653 'class' => array(),
654 'onclick' => array(),
655 ),
656 'img' => array(
657 'src' => array(),
658 'title' => array(),
659 'class' => array(),
660 'onclick' => array(),
661 'alt' => array(),
662 'width' => array(),
663 'height' => array(),
664 'sizes' => array(),
665 'srcset' => array(),
666 'usemap' => array(),
667 ),
668 'br' => array(),
669 'em' => array(),
670 'strong' => array(),
671 'p' => array(),
672 'hr' => array(),
673 'ul' => array(
674 'style' => array(),
675 ),
676 'ol' => array(),
677 'li' => array(),
678 'h1' => array(),
679 'h2' => array(),
680 'head' => array(),
681 'html' => array(
682 'lang' => array(),
683 ),
684 'meta' => array(
685 'name' => array(),
686 'http-equiv' => array(),
687 'content' => array(),
688 'charset' => array(),
689 ),
690 'title' => array(),
691 'body' => array(
692 'style' => array(),
693 ),
694 'span' => array(
695 'id' => array(),
696 'style' => array(),
697 'class' => array(),
698 ),
699 'form' => array(
700 'id' => array(),
701 'method' => array(),
702 'action' => array(),
703 'onsubmit' => array(),
704 ),
705 'table' => array(
706 'class' => array(),
707 ),
708 'thead' => array(
709 'class' => array(),
710 ),
711 'tbody' => array(
712 'class' => array(),
713 ),
714 'tr' => array(
715 'id' => array(),
716 ),
717 'td' => array(
718 'class' => array(),
719 ),
720 'div' => array(
721 'id' => array(),
722 'style' => array(),
723 'class' => array(),
724 ),
725 'input' => array(
726 'type' => array(),
727 'name' => array(),
728 'class' => array(),
729 'value' => array(),
730 'onclick' => array(),
731 ),
732 'button' => array(
733 'type' => array(),
734 'name' => array(),
735 'value' => array(),
736 'class' => array(),
737 'title' => array(),
738 'onclick' => array(),
739 ),
740 );
741
742 if ( is_array( $more_allowed ) && ! empty( $more_allowed ) ) {
743 $allowed_html = array_merge( $allowed_html, $more_allowed );
744 }
745
746 $content = wp_kses( $content, $allowed_html );
747 } else {
748 $content = wp_kses_post( $content );
749 }
750
751 return $content;
752 }
753
754 /**
755 * Method esc_mixed_content()
756 *
757 * Escape mixed content,
758 * allowed content (a,href,title,br,em,strong,p,hr,ul,ol,li,h1,h2 ... ).
759 *
760 * @param mixed $data data to escape.
761 * @param string $depth Maximum depth to walk through $data. Must be greater than 0.
762 * @param mixed $more_allowed input allowed tags - options.
763 *
764 * @throws \MainWP_Exception Excetpion message.
765 *
766 * @return string Filtered content containing only the allowed HTML.
767 */
768 public static function esc_mixed_content( $data, $depth, $more_allowed = array() ) { // phpcs:ignore -- NOSONAR - complex.
769 if ( $depth < 0 ) {
770 throw new MainWP_Exception( 'Reached depth limit' );
771 }
772
773 if ( is_array( $data ) ) {
774 $output = array();
775 foreach ( $data as $id => $el ) {
776 // Don't forget to sanitize the ID!
777 if ( is_string( $id ) ) {
778 $clean_id = static::esc_content( $id, 'mixed', $more_allowed );
779 } else {
780 $clean_id = $id;
781 }
782
783 // Check the element type, so that we're only recursing if we really have to.
784 if ( is_array( $el ) || is_object( $el ) ) {
785 $output[ $clean_id ] = static::esc_mixed_content( $el, $depth - 1 );
786 } elseif ( is_string( $el ) ) {
787 $output[ $clean_id ] = static::esc_content( $el, 'mixed', $more_allowed );
788 } else {
789 $output[ $clean_id ] = $el;
790 }
791 }
792 } elseif ( is_object( $data ) ) {
793 $output = new stdClass();
794 foreach ( $data as $id => $el ) {
795 if ( is_string( $id ) ) {
796 $clean_id = static::esc_content( $id, 'mixed', $more_allowed );
797 } else {
798 $clean_id = $id;
799 }
800
801 if ( is_array( $el ) || is_object( $el ) ) {
802 $output->$clean_id = static::esc_mixed_content( $el, $depth - 1, $more_allowed );
803 } elseif ( is_string( $el ) ) {
804 $output->$clean_id = static::esc_content( $el, 'mixed', $more_allowed );
805 } else {
806 $output->$clean_id = $el;
807 }
808 }
809 } elseif ( is_string( $data ) ) {
810 return static::esc_content( $data, 'mixed', $more_allowed );
811 } else {
812 return $data;
813 }
814
815 return $output;
816 }
817
818 /**
819 * Method parse_html_error_message()
820 *
821 * @param string $error_msg Error message.
822 *
823 * @return mixed array|string.
824 */
825 public static function parse_html_error_message( $error_msg ) {
826 // pasing error message that included link html.
827 preg_match( '/([^\<]*)(<a[^\>]*>)([^\<]*)(<[^\>]*>)(.*)/', $error_msg, $output_array );
828 if ( is_array( $output_array ) && 6 === count( $output_array ) ) {
829 preg_match( '/<a href="([^\"]*)"(.*)/', $output_array[2], $link_array );
830 $link = '';
831 if ( is_array( $link_array ) && 3 === count( $link_array ) ) {
832 $link = $link_array[1];
833 }
834 if ( ! empty( $link ) ) {
835 return array(
836 'el_before' => esc_html( $output_array[1] ),
837 'el_link' => esc_html( $link ),
838 'el_text' => esc_html( $output_array[3] ),
839 'el_after' => esc_html( $output_array[5] ),
840 );
841 }
842 }
843 return $error_msg;
844 }
845
846 /**
847 * Method show_mainwp_message()
848 *
849 * Check whenther or not to show the MainWP Message.
850 *
851 * @param mixed $type Type of message.
852 * @param mixed $notice_id Notice ID.
853 *
854 * @return boolean true|false.
855 */
856 public static function show_mainwp_message( $type, $notice_id ) {
857 unset( $type );
858 $status = get_user_option( 'mainwp_notice_saved_status' );
859 if ( ! is_array( $status ) ) {
860 $status = array();
861 }
862 if ( isset( $status[ $notice_id ] ) ) {
863 return false;
864 }
865 return true;
866 }
867
868 /**
869 * Method get_hide_notice_status()
870 *
871 * Check whenther or not to show the MainWP Message.
872 *
873 * @param mixed $notice_id Notice ID.
874 *
875 * @return mixed true|false|time.
876 */
877 public static function get_hide_notice_status( $notice_id ) {
878 $notices = get_user_option( 'mainwp_notice_saved_status' );
879 if ( ! is_array( $notices ) ) {
880 $notices = array();
881 }
882 if ( isset( $notices[ $notice_id ] ) ) {
883 return $notices[ $notice_id ];
884 }
885 return false;
886 }
887
888 /**
889 * Method get_flash_message()
890 *
891 * Get saved flash Message.
892 *
893 * @param mixed $message_id Notice ID.
894 * @param bool $delete True to delete the message after get it.
895 *
896 * @return boolean true|false.
897 */
898 public static function get_flash_message( $message_id, $delete = true ) {
899 $flash_messages = get_user_option( 'mainwp_flash_messages' );
900 if ( ! is_array( $flash_messages ) ) {
901 $flash_messages = array();
902 }
903 if ( ! isset( $flash_messages[ $message_id ] ) ) {
904 return false;
905 }
906 $content = $flash_messages[ $message_id ];
907 if ( $delete ) {
908 unset( $flash_messages[ $message_id ] );
909 static::update_user_option( 'mainwp_flash_messages', $flash_messages );
910 }
911 return $content;
912 }
913
914 /**
915 * Method update_flash_message()
916 *
917 * Check whenther or not to show the MainWP Message.
918 *
919 * @param mixed $message_id Notice ID.
920 * @param mixed $content Content of message.
921 *
922 * @return boolean true|false.
923 */
924 public static function update_flash_message( $message_id, $content ) {
925 $flash_messages = get_user_option( 'mainwp_flash_messages' );
926 if ( ! is_array( $flash_messages ) ) {
927 $flash_messages = array();
928 }
929 $current = isset( $flash_messages[ $message_id ] ) ? $flash_messages[ $message_id ] : '';
930 if ( empty( $current ) ) {
931 $current = $content;
932 } else {
933 $current .= '|' . $content;
934 }
935 $flash_messages[ $message_id ] = $current;
936 return static::update_user_option( 'mainwp_flash_messages', $flash_messages );
937 }
938
939 /**
940 * Method array_sort()
941 *
942 * Sort given array by given flags.
943 *
944 * @param mixed $arr Array to sort.
945 * @param mixed $key Array key.
946 * @param string $sort_flag Flags to sort by. Default = SORT_STRING.
947 */
948 public static function array_sort( &$arr, $key, $sort_flag = SORT_STRING ) {
949 $sorter = array();
950 $ret = array();
951 reset( $arr );
952 foreach ( $arr as $ii => $val ) {
953 $sorter[ $ii ] = $val[ $key ];
954 }
955 asort( $sorter, $sort_flag );
956 foreach ( $sorter as $ii => $val ) {
957 $ret[ $ii ] = $arr[ $ii ];
958 }
959 $arr = $ret;
960 }
961
962 /**
963 * Method array_sort_existed_keys()
964 *
965 * Sort given array by given flags.
966 *
967 * @param mixed $arr Array to sort.
968 * @param mixed $key Array key.
969 * @param string $sort_flag Flags to sort by. Default = SORT_STRING.
970 */
971 public static function array_sort_existed_keys( &$arr, $key, $sort_flag = SORT_STRING ) {
972 $sorter = array();
973 $ret = array();
974 reset( $arr );
975
976 // get items with $key to sort.
977 foreach ( $arr as $ii => $val ) {
978 if ( isset( $val[ $key ] ) ) {
979 $sorter[ $ii ] = $val[ $key ];
980 }
981 }
982 asort( $sorter, $sort_flag );
983
984 foreach ( $sorter as $ii => $val ) {
985 $ret[ $ii ] = $arr[ $ii ];
986 }
987
988 // asign other items (without $keys).
989 foreach ( $arr as $ii => $val ) {
990 if ( ! isset( $val[ $key ] ) ) {
991 $ret[ $ii ] = $val;
992 }
993 }
994
995 $arr = $ret;
996 }
997
998 /**
999 * Method numeric_filter()
1000 *
1001 * Filter given numeric.
1002 *
1003 * @param int $int_num Int number.
1004 * @return array $arr_ints Array filtered.
1005 */
1006 public static function numeric_filter( $int_num ) {
1007 return ( (string) (int) $int_num === (string) $int_num && 0 < $int_num ) ? $int_num : false;
1008 }
1009
1010 /**
1011 * Method array_numeric_filter()
1012 *
1013 * Filter given numeric array.
1014 *
1015 * @param array $arr_ints Array to filter.
1016 * @return array $arr_ints Array filtered.
1017 */
1018 public static function array_numeric_filter( $arr_ints ) {
1019 $arr_ints = array_filter(
1020 $arr_ints,
1021 function ( $e ) {
1022 return ( (string) (int) $e === (string) $e && 0 < $e ) ? true : false;
1023 }
1024 );
1025 return $arr_ints;
1026 }
1027
1028 /**
1029 * Method enabled_wp_seo()
1030 *
1031 * Check if Yoast SEO is enabled.
1032 *
1033 * @return boolean true|false.
1034 */
1035 public static function enabled_wp_seo() {
1036 if ( null === static::$enabled_wp_seo ) {
1037 static::$enabled_wp_seo = is_plugin_active( 'wordpress-seo-extension/wordpress-seo-extension.php' );
1038 }
1039 return static::$enabled_wp_seo;
1040 }
1041
1042 /**
1043 * Method value_to_string()
1044 *
1045 * Value to string.
1046 *
1047 * @param mixed $var_value Value to convert to string.
1048 *
1049 * @return string Value that has been converted into a string.
1050 */
1051 public static function value_to_string( $var_value ) {
1052 if ( is_array( $var_value ) || is_object( $var_value ) ) {
1053 //phpcs:ignore -- for debug only
1054 return print_r( $var_value, true );
1055 } elseif ( is_string( $var_value ) ) {
1056 return $var_value;
1057 }
1058 return '';
1059 }
1060
1061 /**
1062 * Get Health Site value.
1063 *
1064 * @param mixed $issue_counts Health site issues.
1065 *
1066 * @return array Health status value.
1067 */
1068 public static function get_site_health( $issue_counts ) {
1069
1070 if ( empty( $issue_counts ) ) {
1071 $issue_counts = array(
1072 'good' => 0,
1073 'recommended' => 0,
1074 'critical' => 0,
1075 );
1076 }
1077
1078 $totalTests = intval( $issue_counts['good'] ) + intval( $issue_counts['recommended'] ) + intval( $issue_counts['critical'] ) * 1.5;
1079 $failedTests = intval( $issue_counts['recommended'] ) * 0.5 + $issue_counts['critical'] * 1.5;
1080
1081 if ( empty( $totalTests ) ) {
1082 $val = 100;
1083 } else {
1084 $val = 100 - ceil( ( $failedTests / $totalTests ) * 100 );
1085 }
1086
1087 if ( 0 > $val ) {
1088 $val = 0;
1089 }
1090
1091 if ( 100 < $val ) {
1092 $val = 100;
1093 }
1094
1095 return array(
1096 'val' => $val,
1097 'critical' => $issue_counts['critical'],
1098 );
1099 }
1100
1101
1102 /**
1103 * Get HTTP code.
1104 *
1105 * @param int $code HTTP code.
1106 *
1107 * @return array $http_codes HTTP code.
1108 */
1109 public static function get_http_codes( $code = false ) {
1110
1111 $http_codes = array(
1112 100 => 'Continue',
1113 101 => 'Switching Protocols',
1114 200 => 'OK',
1115 201 => 'Created',
1116 202 => 'Accepted',
1117 203 => 'Non-Authoritative Information',
1118 204 => 'No Content',
1119 205 => 'Reset Content',
1120 206 => 'Partial Content',
1121 300 => 'Multiple Choices',
1122 301 => 'Moved Permanently',
1123 302 => 'Found',
1124 303 => 'See Other',
1125 304 => 'Not Modified',
1126 305 => 'Use Proxy',
1127 306 => '(Unused)',
1128 307 => 'Temporary Redirect',
1129 400 => 'Bad Request',
1130 401 => 'Unauthorized',
1131 402 => 'Payment Required',
1132 403 => 'Forbidden',
1133 404 => 'Not Found',
1134 405 => 'Method Not Allowed',
1135 406 => 'Not Acceptable',
1136 407 => 'Proxy Authentication Required',
1137 408 => 'Request Timeout',
1138 409 => 'Conflict',
1139 410 => 'Gone',
1140 411 => 'Length Required',
1141 412 => 'Precondition Failed',
1142 413 => 'Request Entity Too Large',
1143 414 => 'Request-URI Too Long',
1144 415 => 'Unsupported Media Type',
1145 416 => 'Requested Range Not Satisfiable',
1146 417 => 'Expectation Failed',
1147 500 => 'Internal Server Error',
1148 501 => 'Not Implemented',
1149 502 => 'Bad Gateway',
1150 503 => 'Service Unavailable',
1151 504 => 'Gateway Timeout',
1152 505 => 'HTTP Version Not Supported',
1153 );
1154
1155 if ( false === $code ) {
1156 return $http_codes;
1157 }
1158
1159 return isset( $http_codes[ $code ] ) ? $http_codes[ $code ] : '';
1160 }
1161
1162 /**
1163 * Method valid_input_emails().
1164 *
1165 * @param string $emails Input emails string.
1166 *
1167 * @return string $valid_emails Valid emails string.
1168 */
1169 public static function valid_input_emails( $emails ) {
1170
1171 if ( is_string( $emails ) ) {
1172 $emails = array_filter( explode( ',', $emails ) );
1173 }
1174
1175 $valid_emails = array();
1176 if ( is_array( $emails ) ) {
1177 foreach ( $emails as $email ) {
1178 $email = esc_html( trim( $email ) );
1179 if ( ! empty( $email ) && ! in_array( $email, $valid_emails, true ) ) {
1180 $valid_emails[] = $email;
1181 }
1182 }
1183 }
1184 $valid_emails = implode( ',', $valid_emails );
1185 return $valid_emails;
1186 }
1187
1188 /**
1189 * Method check_image_file_name()
1190 *
1191 * Check if the file image.
1192 *
1193 * @param string $filename Contains image (file) name.
1194 *
1195 * @return true|false valid name or not.
1196 */
1197 public static function check_image_file_name( $filename ) {
1198 if ( validate_file( $filename ) ) {
1199 return false;
1200 }
1201
1202 $allowed_files = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico' );
1203 $file_ext = array_values( array_slice( explode( '.', $filename ), -1 ) )[0];
1204 $file_ext = strtolower( $file_ext );
1205 if ( ! in_array( $file_ext, $allowed_files ) ) {
1206 return false;
1207 }
1208
1209 return true;
1210 }
1211
1212 /**
1213 * Method check_abandoned()
1214 *
1215 * Get site's icon.
1216 *
1217 * @param mixed $siteId site's id.
1218 * @param string $which to check plugin/theme.
1219 *
1220 * @return array result error or success
1221 * @throws \MainWP_Exception Error message.
1222 */
1223 public static function check_abandoned( $siteId = null, $which = '' ) { // phpcs:ignore -- NOSONAR - complex.
1224 if ( static::ctype_digit( $siteId ) ) {
1225 $website = MainWP_DB::instance()->get_website_by_id( $siteId );
1226 if ( MainWP_System_Utility::can_edit_website( $website ) ) {
1227 $error = '';
1228 try {
1229 $information = MainWP_Connect::fetch_url_authed( $website, 'check_abandoned', array( 'which' => $which ) );
1230 if ( is_array( $information ) && isset( $information['sync'] ) && ! empty( $information['sync'] ) ) {
1231 MainWP_Sync::sync_information_array( $website, $information['sync'] );
1232 unset( $information['sync'] );
1233 }
1234 } catch ( MainWP_Exception $e ) {
1235 $error = $e->getMessage();
1236 }
1237
1238 if ( '' !== $error ) {
1239 return array( 'error' => $error );
1240 } elseif ( isset( $information['success'] ) && ! empty( $information['success'] ) ) {
1241 return array( 'result' => 'success' );
1242 } else {
1243 return array( 'undefined_error' => true );
1244 }
1245 }
1246 }
1247 return array( 'result' => 'NOSITE' );
1248 }
1249
1250 /**
1251 * Get directory or slug of plugin.
1252 *
1253 * @param string $slug Plugin slug.
1254 *
1255 * @return string $value directory or slug of plugin.
1256 */
1257 public static function get_dir_slug( $slug ) {
1258 $value = '';
1259 if ( false === strpos( $slug, '/' ) ) {
1260 if ( false !== strpos( $slug, '.' ) ) {
1261 $value = substr( $slug, 0, strpos( $slug, '.' ) );
1262 }
1263 } else {
1264 $value = dirname( $slug );
1265 }
1266 if ( empty( $value ) ) {
1267 return $slug;
1268 }
1269 return $value;
1270 }
1271
1272 /**
1273 * Metho get_siteview_mode().
1274 *
1275 * Get site view mode.
1276 *
1277 * @return string $viewmode Site view mode.
1278 */
1279 public static function get_siteview_mode() {
1280 $viewmode = get_user_option( 'mainwp_sitesviewmode' );
1281 if ( 'grid' !== $viewmode && 'table' !== $viewmode ) {
1282 $viewmode = 'grid';
1283 }
1284 return $viewmode;
1285 }
1286
1287
1288 /**
1289 * Metho delete_file().
1290 *
1291 * Delete file.
1292 *
1293 * @param string $file_path File path.
1294 *
1295 * @return bool true|false.
1296 */
1297 public static function delete_file( $file_path ) {
1298
1299 global $wp_filesystem;
1300
1301 if ( ! empty( $file_path ) ) {
1302 if ( $wp_filesystem ) {
1303 if ( $wp_filesystem->exists( $file_path ) ) {
1304 $wp_filesystem->delete( $file_path );
1305 }
1306 } elseif ( file_exists( $file_path ) ) {
1307 wp_delete_file( $file_path );
1308 }
1309 return true;
1310 }
1311
1312 return false;
1313 }
1314
1315 /**
1316 * Method get_disable_functions()
1317 *
1318 * Get disable functions.
1319 *
1320 * @return string
1321 */
1322 public function get_disable_functions() {
1323 if ( null === static::$disabled_functions ) {
1324 static::$disabled_functions = ini_get( 'disable_functions' );
1325 }
1326 return static::$disabled_functions;
1327 }
1328
1329 /**
1330 * Method is_disable_functions()
1331 *
1332 * Check if it is disabled functions.
1333 *
1334 * @param string $func Function name to check.
1335 *
1336 * @return string
1337 */
1338 public function is_disabled_functions( $func ) {
1339 $dis_funcs = $this->get_disable_functions();
1340
1341 if ( ! empty( $dis_funcs ) && ( false !== stristr( $dis_funcs, $func ) ) ) {
1342 return true;
1343 }
1344 return false;
1345 }
1346
1347 /**
1348 * Method hook_verify_ping_nonce()
1349 *
1350 * Verify nonce without session and user id.
1351 *
1352 * @param bool $input_value Boolean value, it should always be FALSE.
1353 * @param string $nonce Nonce to verify.
1354 * @param mixed $siteid Site ID.
1355 *
1356 * @return mixed If verified return 1 or 2, if not return false.
1357 */
1358 public static function hook_verify_ping_nonce( $input_value, $nonce = '', $siteid = false ) {
1359 unset( $input_value );
1360 $action = 'pingnonce';
1361 return static::verify_site_nonce( $nonce, $action, $siteid );
1362 }
1363
1364 /**
1365 * Method create_site_nonce()
1366 *
1367 * Create action nonce for site.
1368 *
1369 * @param mixed $action Action to perform.
1370 * @param mixed $siteid Site ID.
1371 *
1372 * @return string Custom nonce.
1373 */
1374 public static function create_site_nonce( $action = - 1, $siteid = false ) {
1375 if ( empty( $action ) || empty( $siteid || ! is_numeric( $siteid ) ) ) {
1376 return false;
1377 }
1378 return substr( wp_hash( 'site|' . $siteid . '|' . $action, 'nonce' ), - 12, 10 );
1379 }
1380
1381 /**
1382 * Method verify_site_nonce()
1383 *
1384 * Verify nonce without session and user id.
1385 *
1386 * @param string $nonce Nonce to verify.
1387 * @param mixed $action Action to perform.
1388 * @param mixed $siteid Site ID.
1389 *
1390 * @return mixed If verified return 1 or 2, if not return false.
1391 */
1392 public static function verify_site_nonce( $nonce, $action = - 1, $siteid = 0 ) {
1393 $nonce = (string) $nonce;
1394 if ( empty( $nonce ) || empty( $siteid || ! is_numeric( $siteid ) ) ) {
1395 return false;
1396 }
1397
1398 $expected = substr( wp_hash( 'site|' . $siteid . '|' . $action, 'nonce' ), - 12, 10 );
1399 if ( hash_equals( $expected, $nonce ) ) {
1400 return 1;
1401 }
1402 return false;
1403 }
1404
1405
1406 /**
1407 * Find for multi keywords.
1408 *
1409 * @param string $name_str string find on.
1410 * @param array $words Array string input.
1411 * @return bool True|False.
1412 */
1413 public static function multi_find_keywords( $name_str, $words = array() ) {
1414 if ( ! is_array( $words ) ) {
1415 return false;
1416 }
1417 foreach ( $words as $word ) {
1418 if ( stristr( $name_str, $word ) ) {
1419 return true;
1420
1421 }
1422 }
1423 return false;
1424 }
1425
1426 /**
1427 * Merge values from right array to left array.
1428 *
1429 * @param array $left_array left array.
1430 * @param array $right_array right array.
1431 *
1432 * @return array $result result array.
1433 */
1434 public static function right_array_merge( $left_array, $right_array ) {
1435 if ( ! is_array( $left_array ) || ! is_array( $right_array ) ) {
1436 return array();
1437 }
1438 $result = array_intersect_key( $right_array, $left_array );
1439 return array_merge( $left_array, $result );
1440 }
1441
1442
1443 /**
1444 * Method get_set_deactivated_licenses_alerted().
1445 *
1446 * @param string $slug Extension slug.
1447 * @param bool $time_value Time value.
1448 * @param string $act get/set value.
1449 *
1450 * @return array $result result array.
1451 */
1452 public function get_set_deactivated_licenses_alerted( $slug, $time_value = false, $act = 'get' ) {
1453 if ( null === $this->last_deactivated_alerts ) {
1454 $this->last_deactivated_alerts = get_option( 'mainwp_cron_licenses_deactivated_alerted', array() );
1455 if ( ! is_array( $this->last_deactivated_alerts ) ) {
1456 $this->last_deactivated_alerts = array();
1457 }
1458 }
1459 if ( 'get' === $act ) {
1460 return isset( $this->last_deactivated_alerts[ $slug ] ) ? $this->last_deactivated_alerts[ $slug ] : 0;
1461 } elseif ( 'set' === $act ) {
1462 $this->last_deactivated_alerts[ $slug ] = intval( $time_value );
1463 get_option( 'mainwp_cron_licenses_deactivated_alerted', $this->last_deactivated_alerts );
1464 }
1465 }
1466
1467 /**
1468 * Method get_remote_favicon().
1469 *
1470 * @param string $url Url.
1471 * @param string $favi favicon file name.
1472 * @param int $item_id item id.
1473 * @param string $file_prefix favicon file prefix name.
1474 *
1475 * @return mixed result.
1476 */
1477 public static function get_remote_favicon( $url, $favi = '', $item_id = false, $file_prefix = '' ) { // phpcs:ignore -- NOSONAR - complex.
1478
1479 if ( empty( $favi ) ) {
1480 $favi = 'favicon.ico';
1481 }
1482
1483 if ( '/' !== substr( $url, - 1 ) ) {
1484 $url .= '/';
1485 }
1486
1487 $favi_url = $url . $favi;
1488
1489 $content = MainWP_Connect::get_file_content( $favi_url );
1490
1491 if ( empty( $content ) && 'favicon.ico' === $favi ) {
1492 $favi_url = $url . 'favicon.png';
1493 $content = MainWP_Connect::get_file_content( $favi_url ); // try other file.
1494 }
1495
1496 if ( ! empty( $content ) ) {
1497
1498 MainWP_System_Utility::get_wp_file_system();
1499
1500 global $wp_filesystem;
1501
1502 $dirs = MainWP_System_Utility::get_mainwp_dir( 'icons', true );
1503 $iconsDir = $dirs[0];
1504 if ( $favi ) {
1505
1506 $tmp = explode( '.', $favi );
1507 if ( 2 !== count( $tmp ) ) {
1508 return false;
1509 }
1510
1511 $favi_ext = $tmp[1];
1512
1513 if ( empty( $item_id ) ) {
1514 $item_id = time() . '-' . wp_rand( 100, 999 );
1515 }
1516 if ( ! empty( $file_prefix ) ) {
1517 $filename = $file_prefix . $item_id . '.' . $favi_ext;
1518 } else {
1519 $filename = 'favi-' . $item_id . '.' . $favi_ext;
1520 }
1521
1522 $size = $wp_filesystem->put_contents( $iconsDir . $filename, $content ); // phpcs:ignore --
1523 if ( $size ) {
1524 MainWP_Logger::instance()->debug( 'Icon Cost Product size :: ' . $size );
1525 return array(
1526 'result' => 'success',
1527 'file' => $filename,
1528 'dir' => $iconsDir,
1529 );
1530 } else {
1531 return array( 'error' => 'Save icon file failed.' );
1532 }
1533 }
1534 return false;
1535 } else {
1536 return array( 'error' => esc_html__( 'Download icon file failed', 'mainwp' ) );
1537 }
1538 }
1539
1540 /**
1541 * Method get_saved_favicon_url()
1542 *
1543 * @param string $favi Favicon file name.
1544 *
1545 * @return mixed $faviurl Favicon URL.
1546 */
1547 public static function get_saved_favicon_url( $favi ) {
1548 $faviurl = '';
1549 if ( ! empty( $favi ) ) {
1550 $dirs = MainWP_System_Utility::get_icons_dir();
1551 if ( file_exists( $dirs[0] . $favi ) ) {
1552 $faviurl = $dirs[1] . $favi;
1553 } else {
1554 $faviurl = '';
1555 }
1556 }
1557 return $faviurl;
1558 }
1559
1560 /**
1561 * Method delete_saved_favicon()
1562 *
1563 * @param string $favi Favicon file name.
1564 *
1565 * @return bool Success result.
1566 */
1567 public static function delete_saved_favicon( $favi ) {
1568 if ( ! empty( $favi ) ) {
1569 $hasWPFileSystem = MainWP_System_Utility::get_wp_file_system();
1570 global $wp_filesystem;
1571 $dirs = MainWP_System_Utility::get_icons_dir();
1572 if ( $hasWPFileSystem && $wp_filesystem->exists( $dirs[0] . $favi ) ) {
1573 $wp_filesystem->delete( $dirs[0] . $favi );
1574 return true;
1575 }
1576 }
1577 return false;
1578 }
1579
1580 /**
1581 * Delete icon file.
1582 *
1583 * @param string $sub_dir Sub dir file icon.
1584 * @param string $cost_icon file icon.
1585 */
1586 public function delete_uploaded_icon_file( $sub_dir, $cost_icon ) {
1587 $valid_file = 0 === validate_file( $cost_icon ) ? true : false;
1588 if ( $valid_file ) {
1589 $dirs = MainWP_System_Utility::get_mainwp_dir( $sub_dir, true );
1590 $f = $dirs[0] . $cost_icon;
1591 if ( file_exists( $f ) ) {
1592 wp_delete_file( $f );
1593 }
1594 }
1595 }
1596
1597 /**
1598 * Method get_table_orders().
1599 *
1600 * @param array $data table data.
1601 */
1602 public function get_table_orders( $data ) {
1603
1604 $values = array(
1605 'orderby' => null,
1606 'order' => null,
1607 );
1608
1609 if ( isset( $data['order'] ) ) {
1610 $columns = isset( $data['columns'] ) ? wp_unslash( $data['columns'] ) : array();
1611 $ord_col = isset( $data['order'][0]['column'] ) ? sanitize_text_field( wp_unslash( $data['order'][0]['column'] ) ) : '';
1612 if ( isset( $columns[ $ord_col ] ) ) {
1613 $values = array(
1614 'orderby' => isset( $columns[ $ord_col ]['data'] ) ? sanitize_text_field( wp_unslash( $columns[ $ord_col ]['data'] ) ) : '',
1615 'order' => isset( $data['order'][0]['dir'] ) ? sanitize_text_field( wp_unslash( $data['order'][0]['dir'] ) ) : '',
1616 );
1617 }
1618 }
1619
1620 return $values;
1621 }
1622 }
1623