true ), 'objects' );
$deprecated = apply_filters(
'jet-popup/post-types-list/deprecated',
array(
'page',
'jet-woo-builder',
'e-landing-page',
'jet-form-builder',
'jet-engine',
'jet-menu',
'attachment',
'elementor_library',
'jet-theme-core',
jet_popup()->post_type->slug(),
)
);
$result = array();
if ( empty( $post_types ) ) {
return $result;
}
foreach ( $post_types as $slug => $post_type ) {
if ( in_array( $slug, $deprecated ) ) {
continue;
}
$result[ $slug ] = $post_type->label;
}
return $result;
}
/**
* Get post types options list
*
* @return array
*/
public static function get_post_types_options() {
$post_types = self::get_post_types();
$result = [];
if ( empty( $post_types ) ) {
return $result;
}
foreach ( $post_types as $slug => $label ) {
$result[] = [
'label' => $label,
'value' => $slug,
];
}
return $result;
}
/**
* Get cherry popups query
*
* @since 1.0.0
* @return object
*/
public static function get_avaliable_popups() {
$avaliable_popups = [];
$avaliable_popups = [
'' => esc_html__( 'Not Selected', 'jet-popup' ),
];
$query_args = apply_filters( 'jet_popup_default_query_args',
[
'post_type' => jet_popup()->post_type->slug(),
'order' => 'DESC',
'orderby' => 'date',
'posts_per_page' => -1,
'post_status' => 'publish',
]
);
$popups_query = new WP_Query( $query_args );
if ( is_wp_error( $popups_query ) ) {
return false;
}
if ( $popups_query->have_posts() ) {
foreach ( $popups_query->posts as $popup ) {
$post_id = $popup->ID;
$post_title = $popup->post_title;
$avaliable_popups[ $post_id ] = $post_title;
}
} else {
return false;
}
return $avaliable_popups;
}
/**
* [get_avaliable_popups description]
* @return [type] [description]
*/
public static function get_roles_list() {
if ( ! function_exists( 'get_editable_roles' ) ) {
require_once ABSPATH . 'wp-admin/includes/user.php';
}
$roles['guest'] = esc_html__( 'Guest', 'jet-popup' );
foreach ( get_editable_roles() as $role_slug => $role_data ) {
$roles[ $role_slug ] = $role_data['name'];
}
return $roles;
}
/**
* [is_avaliable_for_user description]
* @param [type] $popup_roles [description]
* @return boolean [description]
*/
public static function is_avaliable_for_user( $roles ) {
if ( empty( $roles ) ) {
return true;
}
$user = wp_get_current_user();
$is_guest = empty( $user->roles ) ? true : false;
if ( ! $is_guest ) {
$user_role = $user->roles[0];
} else {
$user_role = 'guest';
}
if ( in_array( $user_role, $roles ) ) {
return true;
}
return false;
}
/**
* Returns all custom taxonomies
*
* @return [type] [description]
*/
public static function get_taxonomies() {
$taxonomies = get_taxonomies( array(
'public' => true,
'_builtin' => false
), 'objects' );
$deprecated = apply_filters(
'jet-popup/taxonomies-list/deprecated',
array()
);
$result = array();
if ( empty( $taxonomies ) ) {
return $result;
}
foreach ( $taxonomies as $slug => $tax ) {
if ( in_array( $slug, $deprecated ) ) {
continue;
}
$result[ $slug ] = $tax->label;
}
return $result;
}
/**
* Get post types options list
*
* @return array
*/
public static function get_taxonomies_options() {
$taxonomies = self::get_taxonomies();
$result = [];
if ( empty( $taxonomies ) ) {
return $result;
}
foreach ( $taxonomies as $slug => $label ) {
$result[] = [
'label' => $label,
'value' => $slug,
];
}
return $result;
}
/**
* @param false $post_type
*
* @return array
*/
public static function get_taxonomies_by_post_type( $post_type = false ) {
$taxonomies = get_object_taxonomies( $post_type, 'objects' );
$post_type_taxonomies = wp_filter_object_list( $taxonomies, [
'public' => true,
'show_in_nav_menus' => true,
] );
return $post_type_taxonomies;
}
/**
* Force query to look in post title while searching
* @return [type] [description]
*/
public static function force_search_by_title( $where, $query ) {
$args = $query->query;
if ( ! isset( $args['s_title'] ) ) {
return $where;
} else {
global $wpdb;
$searh = esc_sql( $wpdb->esc_like( $args['s_title'] ) );
$where .= " AND {$wpdb->posts}.post_title LIKE '%$searh%'";
}
return $where;
}
/**
* [search_posts_by_type description]
* @param [type] $type [description]
* @param [type] $query [description]
* @return [type] [description]
*/
public static function get_posts_by_type( $type, $query = '', $ids = [], $include_all = true ) {
add_filter( 'posts_where', [ __CLASS__, 'force_search_by_title' ], 10, 2 );
$posts = get_posts( [
'post_type' => $type,
'ignore_sticky_posts' => true,
'posts_per_page' => -1,
'suppress_filters' => false,
's_title' => $query,
'post_status' => [ 'publish', 'private' ],
'include' => $ids,
] );
remove_filter( 'posts_where', array( __CLASS__, 'force_search_by_title' ), 10, 2 );
$result = [];
if ( ( empty( $ids ) || in_array( 'all', $ids ) ) && $include_all ) {
$result[] = [
'value' => 'all',
'label' => __( 'All', 'jet-popup' ),
];
}
if ( ! empty( $posts ) ) {
foreach ( $posts as $post ) {
$result[] = [
'value' => $post->ID,
'label' => $post->post_title,
];
}
}
return $result;
}
/**
* [search_terms_by_tax description]
* @param [type] $tax [description]
* @param [type] $query [description]
* @return [type] [description]
*/
public static function get_terms_by_tax( $tax, $query = '', $ids = [] ) {
$terms = get_terms( [
'taxonomy' => $tax,
'hide_empty' => false,
'name__like' => $query,
'include' => $ids,
] );
$result = [];
if ( empty( $ids ) || in_array( 'all', $ids ) ) {
$result[] = [
'value' => 'all',
'label' => __( 'All', 'jet-popup' ),
];
}
if ( ! empty( $terms ) ) {
foreach ( $terms as $term ) {
$result[] = [
'value' => $term->term_id,
'label' => $term->name,
];
}
}
return $result;
}
/**
* @param $tax
* @param string $query
* @param array $ids
*
* @return array
*/
public static function get_terms_options_by_taxonomy( $tax, $query = '', $ids = [] ) {
$terms = get_terms( [
'taxonomy' => $tax,
'hide_empty' => false,
'name__like' => $query,
'include' => $ids,
] );
$options = [];
if ( empty( $ids ) || in_array( 'all', $ids ) ) {
$options[] = [
'value' => 'all',
'label' => __( 'All', 'jet-popup' ),
];
}
if ( ! empty( $terms ) ) {
foreach ( $terms as $term ) {
$options[] = [
'label' => $term->name,
'value' => $term->term_id,
];
}
}
return $options;
}
/**
* [get_avaliable_mailchimp_list description]
*/
public static function get_avaliable_mailchimp_list() {
$mailchimp_data = get_option( 'jet-popup-settings_mailchimp', [] );
$apikey = jet_popup()->settings->get( 'apikey', '' );
if ( empty( $mailchimp_data ) ) {
return false;
}
if ( empty( $apikey ) ) {
return false;
}
if ( ! array_key_exists( $apikey , $mailchimp_data ) ) {
return false;
}
$mailchimp_account = $mailchimp_data[ $apikey ];
if ( ! array_key_exists( 'lists' , $mailchimp_account ) ) {
return false;
}
$lists = $mailchimp_account['lists'];
$avaliable_lists = [];
foreach ( $lists as $key => $data ) {
$info = $data['info'];
$avaliable_lists[ $info['id'] ] = $info['name'];
}
if ( ! empty( $avaliable_lists ) ) {
return $avaliable_lists;
}
return false;
}
/**
* [get_avaliable_mailchimp_merge_fields description]
* @param [type] $list_id [description]
* @return [type] [description]
*/
public static function get_avaliable_mailchimp_merge_fields( $list_id ) {
$mailchimp_data = get_option( 'jet-popup-settings_mailchimp', [] );
$apikey = jet_popup()->settings->get( 'apikey', '' );
if ( empty( $mailchimp_data ) ) {
return false;
}
if ( empty( $apikey ) ) {
return false;
}
if ( ! array_key_exists( $apikey , $mailchimp_data ) ) {
return false;
}
$mailchimp_account = $mailchimp_data[ $apikey ];
if ( ! array_key_exists( 'lists', $mailchimp_account ) ) {
return false;
}
$lists = $mailchimp_account['lists'];
if ( ! array_key_exists( $list_id, $lists ) ){
return false;
}
$list = $lists[ $list_id ];
if ( ! array_key_exists( 'merge_fields', $list ) ) {
return false;
}
return $list['merge_fields'];
}
/**
* Print HTML icon template
*
* @param array $setting
* @param string $format
* @param string $icon_class
* @param bool $echo
*
* @return void|string
*/
public static function __render_icon( $settings = null, $setting = null, $format = '%s', $icon_class = '', $echo = false ) {
$new_setting = 'selected_' . $setting;
$migrated = isset( $settings[ $new_setting ] );
$is_new = empty( $settings[ $setting ] ) && class_exists( 'Elementor\Icons_Manager' ) && Elementor\Icons_Manager::is_migration_allowed();
$icon_html = '';
if ( $is_new || $migrated ) {
$attr = array( 'aria-hidden' => 'true' );
if ( ! empty( $icon_class ) ) {
$attr['class'] = $icon_class;
}
if ( isset( $settings[ $new_setting ] ) ) {
ob_start();
Elementor\Icons_Manager::render_icon( $settings[ $new_setting ], $attr );
$icon_html = ob_get_clean();
}
} else if ( ! empty( $settings[ $setting ] ) ) {
if ( empty( $icon_class ) ) {
$icon_class = $settings[ $setting ];
} else {
$icon_class .= ' ' . $settings[ $setting ];
}
$icon_html = sprintf( '', $icon_class );
}
if ( empty( $icon_html ) ) {
return false;
}
if ( ! $echo ) {
return sprintf( $format, $icon_html );
}
printf( $format, $icon_html );
}
/**
* @param string $svg_id
* @param bool $wrapper
*
* @return string
*/
public static function get_svg_icon_html( $svg_id = '', $default = '', $attr = array(), $wrapper = true ) {
if ( empty( $svg_id ) ) {
return $default;
}
$url = wp_get_attachment_url( $svg_id );
if ( ! $url ) {
return $default;
}
return self::get_image_by_url( $url, $attr, $wrapper );
}
/**
* Rturns image tag or raw SVG
*
* @param string $url image URL.
* @param array $attr [description]
*
* @return string
*/
public static function get_image_by_url( $url = null, $attr = array (), $wrapper = true ) {
$url = esc_url( $url );
if ( empty( $url ) ) {
return;
}
$ext = pathinfo( $url, PATHINFO_EXTENSION );
$attr = array_merge( array ( 'alt' => '' ), $attr );
if ( 'svg' !== $ext ) {
return sprintf( '', $url, self::get_attr_string( $attr ) );
}
$base_url = site_url( '/' );
$svg_path = str_replace( $base_url, ABSPATH, $url );
$key = md5( $svg_path );
$svg = get_transient( $key );
if ( ! $svg ) {
$svg = file_get_contents( $svg_path );
}
if ( ! $svg ) {
return sprintf( '
', $url, self::get_attr_string( $attr ) );
}
set_transient( $key, $svg, DAY_IN_SECONDS );
if ( ! $wrapper ) {
return $svg;
}
unset( $attr[ 'alt' ] );
return sprintf( '