listings->macros->do_macros( $arg[1], $url );
}
}
if ( ! empty( $final_query_args ) ) {
$url = add_query_arg( $final_query_args, $url );
}
return $url;
}
public static function safe_get( $key, $list = array(), $default = false ) {
return isset( $list[ $key ] ) ? $list[ $key ] : $default;
}
public static function sanitize_html_tag( $input ) {
$available_tags = array(
'div',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'p',
'span',
'a',
'section',
'header',
'footer',
'main',
'b',
'em',
'i',
'nav',
'article',
'aside',
'tr',
'ul',
'ol',
'li'
);
return in_array( strtolower( $input ), $available_tags ) ? $input : 'div';
}
public static function prepare_controls_for_js( $controls = array() ) {
$result = array();
foreach ( $controls as $key => $data ) {
$data['name'] = $key;
if ( ! empty( $data['options'] ) ) {
if ( ! empty( $data['add_placeholder'] ) ) {
$data['options'] = array_merge( array( '' => $data['add_placeholder'] ), $data['options'] );
}
$data['options'] = self::prepare_list_for_js( $data['options'], ARRAY_A );
}
if ( ! empty( $data['groups'] ) ) {
$groups = array();
foreach ( $data['groups'] as $group ) {
$groups[] = array(
'label' => $group['label'],
'values' => self::prepare_list_for_js( $group['options'], ARRAY_A ),
);
}
$data['groups'] = $groups;
}
$result[] = $data;
}
return $result;
}
/**
* Returns all post types list to use in JS components
*
* @return [type] [description]
*/
public static function get_post_types_for_js( $placeholder = false, $key = false ) {
$post_types = get_post_types( array(), 'objects' );
$types_list = self::prepare_list_for_js( $post_types, 'name', 'label', $key );
if ( $placeholder && is_array( $placeholder ) ) {
$types_list = array_merge( array( $placeholder ), $types_list );
}
return $types_list;
}
/**
* Return all taxonomies list to use in JS components
*
* @return [type] [description]
*/
public static function get_taxonomies_for_js( $key = false ) {
$taxonomies = get_taxonomies( array(), 'objects' );
return self::prepare_list_for_js( $taxonomies, 'name', 'label', $key );
}
/**
* Returns all registeredroles for JS
*/
public static function get_user_roles_for_js() {
$roles = self::get_user_roles();
$result = array();
foreach ( $roles as $role => $label ) {
if ( ! isset( $result[ $role ] ) ) {
$result[ $role ] = array(
'value' => $role,
'label' => $label,
);
}
}
return array_values( $result );
}
/**
* Returns all registered user roles
*
* @return [type] [description]
*/
public static function get_user_roles() {
if ( ! function_exists( 'get_editable_roles' ) ) {
return array();
} else {
$roles = get_editable_roles();
$result = array();
foreach ( $roles as $role => $data ) {
$result[ $role ] = $data['name'];
}
return $result;
}
}
/**
* Prepare passed array for using in JS options
*
* @return [type] [description]
*/
public static function prepare_list_for_js( $array = array(), $value_key = null, $label_key = null, $key = false ) {
$result = array();
if ( ! is_array( $array ) || empty( $array ) ) {
return $result;
}
$array_key = false;
foreach ( $array as $index => $item ) {
$value = null;
$label = null;
if ( is_object( $item ) ) {
$value = $item->$value_key;
$label = $item->$label_key;
if ( $key ) {
$array_key = $item->$key;
}
} elseif ( is_array( $item ) ) {
$value = $item[ $value_key ];
$label = $item[ $label_key ];
if ( $key ) {
$array_key = $item[ $key ];
}
} else {
if ( ARRAY_A === $value_key ) {
$value = $index;
} else {
$value = $item;
}
$label = $item;
if ( $key ) {
$array_key = $index;
}
}
if ( $key && false !== $array_key ) {
$result[ $array_key ] = array(
'value' => $value,
'label' => $label,
);
} else {
$result[] = array(
'value' => $value,
'label' => $label,
);
}
}
return $result;
}
/**
* Render new elementor icons
*
* @return [type] [description]
*/
public static function render_icon( $icon = null, $icon_class = '', $custom_atts = array() ) {
$custom_atts_string = '';
if ( ! empty( $custom_atts ) ) {
foreach ( $custom_atts as $key => $value ) {
$custom_atts_string .= sprintf( ' %1$s="%2$s"', $key, $value );
}
}
static $total = 0;
if ( ! is_array( $icon ) && is_numeric( $icon ) ) {
ob_start();
echo '
';
$mime = get_post_mime_type( $icon );
if ( 'image/svg+xml' === $mime ) {
$file = get_attached_file( $icon );
if ( file_exists( $file ) ) {
include $file;
}
} else {
echo wp_get_attachment_image( $icon, 'full' );
}
echo '
';
return ob_get_clean();
}
// Render Bricks svg icon
elseif ( ! is_array( $icon ) && false !== str_contains( $icon, '