2015-10-15 22:52:37 +10:00
< ? php
2020-05-05 20:13:38 +07:00
namespace MainWP\Child ;
2020-05-14 17:26:44 +07:00
// phpcs:disable WordPress.WP.AlternativeFunctions -- to custom functions.
2015-10-15 22:52:37 +10:00
class MainWP_Helper {
2020-02-03 22:55:50 +07:00
2020-05-07 12:38:30 +00:00
public static $instance = null ;
2020-05-11 20:30:56 +07:00
/**
* Method get_class_name ()
*
* Get Class Name .
*
* @ return object
*/
public static function get_class_name () {
return __CLASS__ ;
}
2020-05-11 13:33:45 +00:00
2020-05-07 19:34:36 +07:00
public static function instance () {
if ( null === self :: $instance ) {
self :: $instance = new self ();
}
return self :: $instance ;
}
2020-05-07 12:38:30 +00:00
2020-05-20 20:15:29 +07:00
public static function write ( $val ) {
2020-05-04 23:02:02 +07:00
if ( isset ( $_REQUEST [ 'json_result' ] ) && true == $_REQUEST [ 'json_result' ] ) :
2020-05-14 00:57:25 +07:00
$output = wp_json_encode ( $val );
2020-05-04 23:02:02 +07:00
else :
2020-05-07 23:22:05 +07:00
$output = serialize ( $val ); // phpcs:ignore -- to compatible.
2020-05-04 23:02:02 +07:00
endif ;
2020-03-27 13:05:05 +00:00
2020-05-08 16:44:48 +07:00
die ( '<mainwp>' . base64_encode ( $output ) . '</mainwp>' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- to compatible with http encoding.
2020-02-03 22:55:50 +07:00
}
2015-10-15 22:52:37 +10:00
2020-05-04 23:02:02 +07:00
public static function error ( $error , $code = null ) {
2015-10-15 22:52:37 +10:00
$information [ 'error' ] = $error ;
2020-05-04 23:02:02 +07:00
if ( null !== $code ) {
2016-02-15 22:08:39 +01:00
$information [ 'error_code' ] = $code ;
2020-05-04 23:02:02 +07:00
}
2020-05-20 13:17:13 +00:00
self :: write ( $information );
2015-10-15 22:52:37 +10:00
}
2020-05-06 00:47:59 +07:00
public static function get_mainwp_dir ( $what = null , $dieOnError = true ) {
2020-05-14 17:26:44 +07:00
/** @var $wp_filesystem WP_Filesystem_Base */
global $wp_filesystem ;
2020-05-14 10:28:20 +00:00
self :: get_wp_filesystem ();
2015-10-15 22:52:37 +10:00
$upload_dir = wp_upload_dir ();
$dir = $upload_dir [ 'basedir' ] . DIRECTORY_SEPARATOR . 'mainwp' . DIRECTORY_SEPARATOR ;
2020-05-06 00:47:59 +07:00
self :: check_dir ( $dir , $dieOnError );
2020-05-14 17:26:44 +07:00
if ( ! $wp_filesystem -> exists ( $dir . 'index.php' ) ) {
2020-05-04 23:02:02 +07:00
touch ( $dir . 'index.php' );
2015-10-15 22:52:37 +10:00
}
$url = $upload_dir [ 'baseurl' ] . '/mainwp/' ;
if ( 'backup' === $what ) {
$dir .= 'backup' . DIRECTORY_SEPARATOR ;
2020-05-06 00:47:59 +07:00
self :: check_dir ( $dir , $dieOnError );
2020-05-14 17:26:44 +07:00
if ( ! $wp_filesystem -> exists ( $dir . 'index.php' ) ) {
2020-05-04 23:02:02 +07:00
touch ( $dir . 'index.php' );
2015-10-15 22:52:37 +10:00
}
$another_name = '.htaccess' ;
2020-05-14 17:26:44 +07:00
if ( ! $wp_filesystem -> exists ( $dir . $another_name ) ) {
2020-05-04 23:02:02 +07:00
$file = fopen ( $dir . $another_name , 'w+' );
fwrite ( $file , 'deny from all' );
fclose ( $file );
2015-10-15 22:52:37 +10:00
}
$url .= 'backup/' ;
}
return array ( $dir , $url );
}
2020-05-06 00:47:59 +07:00
public static function check_dir ( $dir , $dieOnError , $chmod = 0755 ) {
self :: get_wp_filesystem ();
2015-10-15 22:52:37 +10:00
global $wp_filesystem ;
2020-05-14 10:28:20 +00:00
2015-10-15 22:52:37 +10:00
if ( ! file_exists ( $dir ) ) {
if ( empty ( $wp_filesystem ) ) {
2020-05-04 23:02:02 +07:00
mkdir ( $dir , $chmod , true );
2015-10-15 22:52:37 +10:00
} else {
if ( ( 'ftpext' === $wp_filesystem -> method ) && defined ( 'FTP_BASE' ) ) {
$ftpBase = FTP_BASE ;
$ftpBase = trailingslashit ( $ftpBase );
$tmpdir = str_replace ( ABSPATH , $ftpBase , $dir );
} else {
$tmpdir = $dir ;
}
2016-06-12 18:33:51 +02:00
$wp_filesystem -> mkdir ( $tmpdir , $chmod );
2015-10-15 22:52:37 +10:00
}
if ( ! file_exists ( $dir ) ) {
$error = __ ( 'Unable to create directory ' , 'mainwp-child' ) . str_replace ( ABSPATH , '' , $dir ) . '.' . __ ( ' Is its parent directory writable by the server?' , 'mainwp-child' );
if ( $dieOnError ) {
self :: error ( $error );
} else {
2020-05-07 01:03:56 +07:00
throw new \Exception ( $error );
2015-10-15 22:52:37 +10:00
}
}
}
}
2020-05-04 23:02:02 +07:00
public static function search ( $array , $key ) {
2015-10-15 22:52:37 +10:00
if ( is_object ( $array ) ) {
$array = ( array ) $array ;
}
if ( is_array ( $array ) || is_object ( $array ) ) {
if ( isset ( $array [ $key ] ) ) {
return $array [ $key ];
}
foreach ( $array as $subarray ) {
$result = self :: search ( $subarray , $key );
if ( null !== $result ) {
return $result ;
}
}
}
return null ;
}
/**
* @ return WP_Filesystem_Base
*/
2020-05-06 00:47:59 +07:00
public static function get_wp_filesystem () {
2015-10-15 22:52:37 +10:00
global $wp_filesystem ;
if ( empty ( $wp_filesystem ) ) {
ob_start ();
if ( file_exists ( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
2020-05-04 23:02:02 +07:00
include_once ABSPATH . '/wp-admin/includes/screen.php' ;
2015-10-15 22:52:37 +10:00
}
if ( file_exists ( ABSPATH . '/wp-admin/includes/template.php' ) ) {
2020-05-04 23:02:02 +07:00
include_once ABSPATH . '/wp-admin/includes/template.php' ;
2015-10-15 22:52:37 +10:00
}
$creds = request_filesystem_credentials ( 'test' );
ob_end_clean ();
if ( empty ( $creds ) ) {
if ( ! defined ( 'MAINWP_SAVE_FS_METHOD' ) ) {
define ( 'MAINWP_SAVE_FS_METHOD' , get_filesystem_method () );
}
define ( 'FS_METHOD' , 'direct' );
}
$init = WP_Filesystem ( $creds );
} else {
$init = true ;
}
return $init ;
}
2020-05-11 13:33:45 +00:00
public static function check_wp_filesystem () {
2020-05-12 13:21:04 +00:00
2020-05-12 20:19:58 +07:00
$FTP_ERROR = 'Failed! Please, add FTP details for automatic updates.' ;
2020-05-12 13:21:04 +00:00
2020-05-11 13:33:45 +00:00
self :: get_wp_filesystem ();
2020-05-12 13:21:04 +00:00
2020-05-11 20:30:56 +07:00
global $wp_filesystem ;
if ( empty ( $wp_filesystem ) ) {
2020-05-12 20:19:58 +07:00
self :: error ( $FTP_ERROR );
2020-05-11 20:30:56 +07:00
} elseif ( is_wp_error ( $wp_filesystem -> errors ) ) {
$errorCodes = $wp_filesystem -> errors -> get_error_codes ();
if ( ! empty ( $errorCodes ) ) {
2020-05-11 13:33:45 +00:00
self :: error ( __ ( 'WordPress Filesystem error: ' , 'mainwp-child' ) . $wp_filesystem -> errors -> get_error_message () );
2020-05-11 20:30:56 +07:00
}
}
return $wp_filesystem ;
}
2020-05-11 13:33:45 +00:00
2020-05-11 20:30:56 +07:00
public static function reject_unsafe_urls ( $r , $url ) {
$r [ 'reject_unsafe_urls' ] = false ;
if ( isset ( $_POST [ 'wpadmin_user' ] ) && ! empty ( $_POST [ 'wpadmin_user' ] ) && isset ( $_POST [ 'wpadmin_passwd' ] ) && ! empty ( $_POST [ 'wpadmin_passwd' ] ) ) {
$auth = base64_encode ( $_POST [ 'wpadmin_user' ] . ':' . $_POST [ 'wpadmin_passwd' ] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
$r [ 'headers' ][ 'Authorization' ] = " Basic $auth " ;
}
return $r ;
}
2020-05-11 13:33:45 +00:00
2020-05-06 00:47:59 +07:00
public static function starts_with ( $haystack , $needle ) {
2015-10-15 22:52:37 +10:00
return ! strncmp ( $haystack , $needle , strlen ( $needle ) );
}
2020-05-06 00:47:59 +07:00
public static function ends_with ( $haystack , $needle ) {
2015-10-15 22:52:37 +10:00
$length = strlen ( $needle );
2015-12-09 20:32:56 +01:00
if ( 0 == $length ) {
2015-10-15 22:52:37 +10:00
return true ;
2020-05-01 16:46:35 +07:00
}
2015-12-09 20:32:56 +01:00
return ( substr ( $haystack , - $length ) == $needle );
2015-10-15 22:52:37 +10:00
}
2020-05-06 00:47:59 +07:00
public static function get_nice_url ( $pUrl , $showHttp = false ) {
2015-10-15 22:52:37 +10:00
$url = $pUrl ;
2020-05-06 00:47:59 +07:00
if ( self :: starts_with ( $url , 'http://' ) ) {
2015-10-15 22:52:37 +10:00
if ( ! $showHttp ) {
$url = substr ( $url , 7 );
}
2020-05-06 00:47:59 +07:00
} elseif ( self :: starts_with ( $pUrl , 'https://' ) ) {
2015-10-15 22:52:37 +10:00
if ( ! $showHttp ) {
$url = substr ( $url , 8 );
}
} else {
if ( $showHttp ) {
$url = 'http://' . $url ;
}
}
2020-05-06 00:47:59 +07:00
if ( self :: ends_with ( $url , '/' ) ) {
2015-10-15 22:52:37 +10:00
if ( ! $showHttp ) {
$url = substr ( $url , 0 , strlen ( $url ) - 1 );
}
} else {
$url = $url . '/' ;
}
return $url ;
}
2020-05-06 00:47:59 +07:00
public static function end_session () {
2020-05-04 23:02:02 +07:00
session_write_close ();
ob_end_flush ();
2015-10-15 22:52:37 +10:00
}
2020-05-06 00:47:59 +07:00
public static function rand_string ( $length , $charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ) {
2015-10-15 22:52:37 +10:00
$str = '' ;
$count = strlen ( $charset );
while ( $length -- ) {
2020-05-04 23:02:02 +07:00
$str .= $charset [ mt_rand ( 0 , $count - 1 ) ]; // phpcs:ignore
2015-10-15 22:52:37 +10:00
}
return $str ;
}
2018-11-14 21:33:36 +07:00
public static function return_bytes ( $val ) {
2015-10-15 22:52:37 +10:00
$val = trim ( $val );
2018-04-17 20:33:10 +02:00
$last = $val [ strlen ( $val ) - 1 ];
2020-05-04 23:02:02 +07:00
$val = rtrim ( $val , $last );
2018-11-14 21:33:36 +07:00
$last = strtolower ( $last );
2015-10-15 22:52:37 +10:00
switch ( $last ) {
case 'g' :
$val *= 1024 ;
2020-05-07 19:34:36 +07:00
break ;
2015-10-15 22:52:37 +10:00
case 'm' :
$val *= 1024 ;
2020-05-07 19:34:36 +07:00
break ;
2015-10-15 22:52:37 +10:00
case 'k' :
$val *= 1024 ;
2020-05-07 12:38:30 +00:00
break ;
2015-10-15 22:52:37 +10:00
}
return $val ;
}
public static function human_filesize ( $bytes , $decimals = 2 ) {
$size = array ( 'B' , 'kB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' );
$factor = floor ( ( strlen ( $bytes ) - 1 ) / 3 );
2017-01-14 13:16:52 +01:00
2020-05-04 23:02:02 +07:00
return sprintf ( " %. { $decimals } f " , $bytes / pow ( 1024 , $factor ) ) . $size [ $factor ];
2015-10-15 22:52:37 +10:00
}
2017-01-14 13:16:52 +01:00
2015-10-15 22:52:37 +10:00
public static function is_dir_empty ( $dir ) {
if ( ! is_readable ( $dir ) ) {
return null ;
}
return ( 2 === count ( scandir ( $dir ) ) );
}
public static function delete_dir ( $dir ) {
$nodes = glob ( $dir . '*' );
if ( is_array ( $nodes ) ) {
foreach ( $nodes as $node ) {
if ( is_dir ( $node ) ) {
self :: delete_dir ( $node . DIRECTORY_SEPARATOR );
} else {
2020-05-04 23:02:02 +07:00
unlink ( $node );
2015-10-15 22:52:37 +10:00
}
}
}
2020-05-04 23:02:02 +07:00
rmdir ( $dir );
2015-10-15 22:52:37 +10:00
}
2020-05-15 01:04:08 +07:00
public static function funct_exists ( $func ) {
2015-10-15 22:52:37 +10:00
if ( ! function_exists ( $func ) ) {
return false ;
}
if ( extension_loaded ( 'suhosin' ) ) {
2020-05-04 23:02:02 +07:00
$suhosin = ini_get ( 'suhosin.executor.func.blacklist' );
2015-10-15 22:52:37 +10:00
if ( ! empty ( $suhosin ) ) {
$suhosin = explode ( ',' , $suhosin );
$suhosin = array_map ( 'trim' , $suhosin );
$suhosin = array_map ( 'strtolower' , $suhosin );
2017-02-22 21:39:22 +01:00
2015-10-15 22:52:37 +10:00
return ( function_exists ( $func ) && ! array_search ( $func , $suhosin ) );
2020-05-01 16:46:35 +07:00
}
2017-08-24 20:41:12 +02:00
}
2015-10-15 22:52:37 +10:00
return true ;
}
2020-05-06 00:47:59 +07:00
public static function get_timestamp ( $timestamp ) {
2015-10-15 22:52:37 +10:00
$gmtOffset = get_option ( 'gmt_offset' );
return ( $gmtOffset ? ( $gmtOffset * HOUR_IN_SECONDS ) + $timestamp : $timestamp );
}
2020-05-06 00:47:59 +07:00
public static function format_date ( $timestamp ) {
2017-01-14 13:16:52 +01:00
return date_i18n ( get_option ( 'date_format' ), $timestamp );
}
2020-05-06 00:47:59 +07:00
public static function format_time ( $timestamp ) {
2017-01-14 13:16:52 +01:00
return date_i18n ( get_option ( 'time_format' ), $timestamp );
}
2020-05-06 00:47:59 +07:00
public static function format_timestamp ( $timestamp ) {
2015-10-15 22:52:37 +10:00
return date_i18n ( get_option ( 'date_format' ) . ' ' . get_option ( 'time_format' ), $timestamp );
}
2020-05-04 23:02:02 +07:00
public static function update_option ( $option_name , $option_value , $autoload = 'no' ) {
2015-10-15 22:52:37 +10:00
$success = add_option ( $option_name , $option_value , '' , $autoload );
if ( ! $success ) {
$success = update_option ( $option_name , $option_value );
}
return $success ;
}
2020-05-06 00:47:59 +07:00
public static function in_excludes ( $excludes , $value ) {
2015-10-15 22:52:37 +10:00
if ( empty ( $value ) ) {
return false ;
}
2015-12-09 20:32:56 +01:00
if ( null != $excludes ) {
2015-10-15 22:52:37 +10:00
foreach ( $excludes as $exclude ) {
2020-05-06 00:47:59 +07:00
if ( self :: ends_with ( $exclude , '*' ) ) {
if ( self :: starts_with ( $value , substr ( $exclude , 0 , strlen ( $exclude ) - 1 ) ) ) {
2015-10-15 22:52:37 +10:00
return true ;
2020-03-26 19:51:58 +00:00
}
2020-05-04 23:02:02 +07:00
} elseif ( $value == $exclude ) {
2015-10-15 22:52:37 +10:00
return true ;
2020-05-06 00:47:59 +07:00
} elseif ( self :: starts_with ( $value , $exclude . '/' ) ) {
2015-10-15 22:52:37 +10:00
return true ;
2018-01-22 20:21:06 +01:00
}
2015-10-15 22:52:37 +10:00
}
}
return false ;
}
2015-12-22 19:18:07 +01:00
public static function sanitize_filename ( $filename ) {
2020-05-04 23:02:02 +07:00
if ( ! function_exists ( 'mb_ereg_replace' ) ) {
return sanitize_file_name ( $filename );
2016-03-15 20:54:21 +01:00
}
2020-05-04 23:02:02 +07:00
// Remove anything which isn't a word, whitespace, number or any of the following caracters -_~,;:[]().
// If you don't need to handle multi-byte characters you can use preg_replace rather than mb_ereg_replace.
2020-05-07 19:34:36 +07:00
// Thanks @<40> ?ukasz Rysiak!
2020-05-04 23:02:02 +07:00
$filename = mb_ereg_replace ( '([^\w\s\d\-_~,;:\[\]\(\).])' , '' , $filename );
// Remove any runs of periods (thanks falstro!).
$filename = mb_ereg_replace ( '([\.]{2,})' , '' , $filename );
2015-12-22 19:18:07 +01:00
return $filename ;
}
2016-02-15 22:08:39 +01:00
2020-05-04 23:02:02 +07:00
public static function ctype_digit ( $str ) {
2016-02-15 22:08:39 +01:00
return ( is_string ( $str ) || is_int ( $str ) || is_float ( $str ) ) && preg_match ( '/^\d+\z/' , $str );
}
2016-03-15 20:54:21 +01:00
2020-05-06 00:47:59 +07:00
public static function is_admin () {
2016-12-08 20:54:26 +01:00
global $current_user ;
2020-05-04 23:02:02 +07:00
if ( 0 == $current_user -> ID ) {
2016-12-08 20:54:26 +01:00
return false ;
}
2020-05-04 23:02:02 +07:00
if ( 10 == $current_user -> wp_user_level || ( isset ( $current_user -> user_level ) && 10 == $current_user -> user_level ) || current_user_can ( 'level_10' ) ) {
2016-12-08 20:54:26 +01:00
return true ;
}
return false ;
}
2020-05-06 00:47:59 +07:00
public static function is_ssl_enabled () {
2020-05-04 23:02:02 +07:00
if ( defined ( 'MAINWP_NOSSL' ) ) {
return ! MAINWP_NOSSL ;
}
2016-12-25 14:38:20 +01:00
return function_exists ( 'openssl_verify' );
2016-12-08 20:54:26 +01:00
}
2016-12-25 14:38:20 +01:00
2020-05-20 20:15:29 +07:00
public static function is_updates_screen () {
2020-05-04 23:02:02 +07:00
if ( ( defined ( 'DOING_AJAX' ) && DOING_AJAX ) || ( defined ( 'DOING_CRON' ) && DOING_CRON ) ) {
return false ;
}
if ( function_exists ( 'get_current_screen' ) ) {
$screen = get_current_screen ();
if ( $screen ) {
if ( 'update-core' == $screen -> base && 'index.php' == $screen -> parent_file ) {
return true ;
}
}
2020-03-26 19:51:58 +00:00
}
2020-05-04 23:02:02 +07:00
return false ;
2020-04-21 20:09:40 +02:00
}
2020-05-04 23:02:02 +07:00
public static function is_wp_engine () {
return function_exists ( 'is_wpe' ) && is_wpe ();
2020-04-21 20:09:40 +02:00
}
2018-11-14 21:33:36 +07:00
2020-05-21 20:10:15 +07:00
public static function check_files_exists ( $files = array (), $return = false ) {
$missing = array ();
2020-05-04 23:02:02 +07:00
if ( is_array ( $files ) ) {
foreach ( $files as $name ) {
if ( ! file_exists ( $name ) ) {
$missing [] = $name ;
}
}
} else {
if ( ! file_exists ( $files ) ) {
$missing [] = $files ;
2020-03-26 19:51:58 +00:00
}
}
2020-05-04 23:02:02 +07:00
if ( ! empty ( $missing ) ) {
$message = 'Missing file(s): ' . implode ( ',' , $missing );
if ( $return ) {
return $message ;
} else {
2020-05-07 01:03:56 +07:00
throw new \Exception ( $message );
2020-05-04 23:02:02 +07:00
}
2020-03-26 19:51:58 +00:00
}
2020-05-04 23:02:02 +07:00
return true ;
2018-06-26 19:52:53 +02:00
}
2018-11-14 21:33:36 +07:00
2020-05-07 19:34:36 +07:00
public function check_classes_exists ( $classes = array (), $return = false ) {
2020-05-04 23:02:02 +07:00
$missing = array ();
if ( is_array ( $classes ) ) {
foreach ( $classes as $name ) {
if ( ! class_exists ( $name ) ) {
$missing [] = $name ;
}
}
} else {
if ( ! class_exists ( $classes ) ) {
$missing [] = $classes ;
}
}
if ( ! empty ( $missing ) ) {
$message = 'Missing classes: ' . implode ( ',' , $missing );
if ( $return ) {
return $message ;
} else {
2020-05-07 01:03:56 +07:00
throw new \Exception ( $message );
2020-05-04 23:02:02 +07:00
}
}
return true ;
2018-06-26 19:52:53 +02:00
}
2018-11-14 21:33:36 +07:00
2020-05-07 19:34:36 +07:00
public function check_methods ( $object , $methods = array (), $return = false ) {
2020-05-04 23:02:02 +07:00
$missing = array ();
if ( is_array ( $methods ) ) {
$missing = array ();
foreach ( $methods as $name ) {
if ( ! method_exists ( $object , $name ) ) {
$missing [] = $name ;
}
}
} elseif ( ! empty ( $methods ) ) {
if ( ! method_exists ( $object , $methods ) ) {
$missing [] = $methods ;
}
}
if ( ! empty ( $missing ) ) {
$message = 'Missing method: ' . implode ( ',' , $missing );
if ( $return ) {
return $message ;
} else {
2020-05-07 01:03:56 +07:00
throw new \Exception ( $message );
2020-05-04 23:02:02 +07:00
}
2020-03-26 19:51:58 +00:00
}
2020-05-04 23:02:02 +07:00
return true ;
}
public static function check_properties ( $object , $properties = array (), $return = false ) {
$missing = array ();
if ( is_array ( $properties ) ) {
foreach ( $properties as $name ) {
if ( ! property_exists ( $object , $name ) ) {
$missing [] = $name ;
}
}
} elseif ( ! empty ( $properties ) ) {
if ( ! property_exists ( $object , $properties ) ) {
$missing [] = $properties ;
}
2020-03-26 19:51:58 +00:00
}
2020-05-04 23:02:02 +07:00
if ( ! empty ( $missing ) ) {
$message = 'Missing properties: ' . implode ( ',' , $missing );
if ( $return ) {
return $message ;
} else {
2020-05-07 01:03:56 +07:00
throw new \Exception ( $message );
2020-05-04 23:02:02 +07:00
}
2020-03-26 19:51:58 +00:00
}
2020-05-04 23:02:02 +07:00
return true ;
2018-06-26 19:52:53 +02:00
}
2018-11-14 21:33:36 +07:00
2020-05-04 23:02:02 +07:00
public static function check_functions ( $funcs = array (), $return = false ) {
$missing = array ();
if ( is_array ( $funcs ) ) {
foreach ( $funcs as $name ) {
if ( ! function_exists ( $name ) ) {
$missing [] = $name ;
}
}
} elseif ( ! empty ( $funcs ) ) {
if ( ! function_exists ( $funcs ) ) {
$missing [] = $funcs ;
}
}
if ( ! empty ( $missing ) ) {
$message = 'Missing functions: ' . implode ( ',' , $missing );
if ( $return ) {
return $message ;
} else {
2020-05-07 01:03:56 +07:00
throw new \Exception ( $message );
2020-03-26 19:51:58 +00:00
}
}
2020-05-04 23:02:02 +07:00
return true ;
2020-03-27 15:13:11 +00:00
}
2018-11-14 21:33:36 +07:00
2020-05-12 20:19:58 +07:00
public static function log_debug ( $msg ) {
2020-05-13 01:18:02 +07:00
if ( defined ( 'MAINWP_CHILD_DEBUG' ) && MAINWP_CHILD_DEBUG ) {
2020-05-12 20:19:58 +07:00
error_log ( $msg ); // phpcs:ignore -- debug mode only.
2020-05-12 13:21:04 +00:00
}
2020-05-12 20:19:58 +07:00
}
2020-05-14 18:09:17 +00:00
public static function set_limit ( $timeout , $mem = false ) {
2020-05-15 01:04:08 +07:00
// phpcs:disable
if ( ! empty ( $mem ) ) {
ini_set ( 'memory_limit' , $mem );
}
set_time_limit ( $timeout );
ini_set ( 'max_execution_time' , $timeout );
// phpcs:enable
}
2020-03-26 14:05:04 +00:00
}