style="" src="" />
$value ) {
if ( is_array( $value ) && isset( $new_args[ $key ] ) ) {
$new_args[ $key ] = self::rec_parse_args( $value, $new_args[ $key ] );
} else {
$new_args[ $key ] = $value;
}
}
return $new_args;
}
/**
* Map sanitize function name to field type.
*
* @param string $field_type
* @return string
*/
protected static function sanitize_functions_mapping( $field_type ) {
$fields_sanitize_mapping = array(
'text' => 'sanitize_text_field',
'textarea' => 'sanitize_textarea',
'url' => 'esc_url_raw',
'email' => 'sanitize_email',
);
return ( ! empty( $fields_sanitize_mapping[ $field_type ] ) ? $fields_sanitize_mapping[ $field_type ] : 'sanitize_text_field' );
}
/**
* Apply function on array.
*
* @param array $arr
* @param string|array $func_name
* @param string $casting
* @return array
*/
protected static function mapping_func( $arr, $func_name, $casting = null ) {
foreach ( $arr as $key => $value ) {
$func_name = (array) $func_name;
foreach ( $func_name as $func ) {
$value = call_user_func( $func, $value );
if ( ! is_null( $casting ) ) {
settype( $value, $casting );
}
}
$arr[ $key ] = $value;
}
return $arr;
}
/**
* Check if WooCommerce is active.
*
* @return boolean
*/
public static function is_woocommerce_active() {
require_once \ABSPATH . 'wp-admin/includes/plugin.php';
return is_plugin_active( 'woocommerce/woocommerce.php' ) && class_exists( '\WooCommerce' );
}
/**
* Check if current user is admin.
*
* @return boolean
*/
protected static function is_admin_user() {
return current_user_can( 'administrator' );
}
/**
* Handle Enqueue JS and CSS Assets.
*
* @param array $assets
* @return void
*/
private function handle_enqueue_assets( $assets ) {
foreach ( $assets as $asset_file ) {
// Conditional Tab.
if ( ! empty( $asset_file['conditional'] ) ) {
foreach ( $asset_file['conditional'] as $key => $value ) {
if ( empty( $_GET[ $key ] ) || sanitize_text_field( wp_unslash( $_GET[ $key ] ) ) !== $value ) {
continue;
}
}
}
// CSS.
if ( 'css' === $asset_file['type'] ) {
// Registered or other Asset.
if ( empty( $asset_file['url'] ) ) {
if ( ! wp_script_is( $asset_file['handle'] ) ) {
wp_enqueue_style( $asset_file['handle'] );
}
} else {
wp_enqueue_style( $asset_file['handle'], $asset_file['url'], ! empty( $asset_file['dependency'] ) ? $asset_file['dependency'] : array(), self::$plugin_info['version'], ! empty( $asset_file['media'] ) ? $asset_file['media'] : 'all' );
}
}
// JS.
if ( 'js' === $asset_file['type'] ) {
if ( empty( $asset_file['url'] ) ) {
if ( ! wp_script_is( $asset_file['handle'] ) ) {
wp_enqueue_script( $asset_file['handle'] );
}
} else {
wp_enqueue_script( $asset_file['handle'], $asset_file['url'], ! empty( $asset_file['dependency'] ) ? $asset_file['dependency'] : array(), self::$plugin_info['version'], isset( $asset_file['in_footer'] ) ? $asset_file['in_footer'] : true );
}
if ( ! empty( $asset_file['localized'] ) ) {
wp_localize_script( $asset_file['handle'], isset( $asset_file['localized']['name'] ) ? $asset_file['localized']['name'] : str_replace( '-', '_', self::$plugin_info['name'] ), $asset_file['localized']['data'] );
}
}
}
}
/**
* Install Status Icon.
*
* @param string $status
* @param string $version
* @return void
*/
public static function install_and_version_icon( $status = 'green', $version = '' ) {
if ( 'red' === $status ) {
?>
$val ) {
$key = sanitize_text_field( $key );
if ( is_array( $val ) ) {
$field[ $key ] = self::deep_sanitize_field( $field[ $key ] );
} else {
$field[ $key ] = sanitize_text_field( $val );
}
}
return $field;
}
}