true ), 'names' ); unset($post_types['attachment'], $post_types['adsforwp'], $post_types['adsforwp-groups']); return $post_types; } public function adsforwp_visitor_condition_type_values($data = '', $saved_data= '',$selected_val_key_4='',$selected_val_key_5='', $current_number = '', $current_group_number = '') { $response = $data; $is_ajax = false; if( $_SERVER['REQUEST_METHOD']=='POST'){ $is_ajax = true; if(wp_verify_nonce($_POST["adsforwp_visitor_condition_call_nonce"],'adsforwp_visitor_condition_action_nonce')){ if ( isset( $_POST["id"] ) ) { $response = sanitize_text_field(wp_unslash($_POST["id"])); } if ( isset( $_POST["number"] ) ) { $current_number = intval($_POST["number"]); } if ( isset( $_POST["group_number"] ) ) { $current_group_number = intval($_POST["group_number"]); } }else{ exit; } } // send the response back to the front end // vars $choices = array(); $options['param'] = $response; switch($options['param']) { case "device": $choices = array( 'desktop' => 'Desktop', 'mobile' => 'Mobile or Tablet', ); break; case "referrer_url": $choices = array( 'https://www.google.com/' => 'Google', 'https://www.bing.com/' => 'Bing', 'https://www.yahoo.com/' => 'Yahoo', 'url_custom' => 'Custom', ); break; case "geo_location": $choices = array( 'usa' => 'USA', 'ind' => 'India', ); break; case "logged_in_visitor": $choices = array( 'true' => 'True', 'false' => 'False', ); break; case "user_agent": $choices = array( 'opera' => 'Opera', 'edge' => 'Edge', 'chrome' => 'Chrome', 'safari' => 'Safari', 'firefox' => 'Firefox', 'internet_explorer' => 'MSIE', 'android' => 'Android', 'iphone' => 'iPhone', 'ipad' => 'iPad', 'ipod' => 'iPod', 'user_agent_custom' => 'Custom', ); break; case "user_type" : global $wp_roles; $choices = $wp_roles->get_names(); if( is_multisite() ) { $choices['super_admin'] = esc_html__('Super Admin','ads-for-wp'); } break; case "browser_language" : $choices = array( 'af' => 'Afrikanns', 'sq' => 'Albanian', 'ar' => 'Arabic', 'hy' => 'Armenian', 'eu' => 'Basque', 'bn' => 'Bengali', 'bg' => 'Bulgarian', 'ca' => 'Catalan', 'km' => 'Cambodian', 'zh' => 'Chinese (Mandarin)', 'hr' => 'Croation', 'cs' => 'Czech', 'da' => 'Danish', 'nl' => 'Dutch', 'en' => 'English', 'et' => 'Estonian', 'fj' => 'Fiji', 'fi' => 'Finnish', 'fr' => 'French', 'ka' => 'Georgian', 'de' => 'German', 'el' => 'Greek', 'gu' => 'Gujarati', 'he' => 'Hebrew', 'hi' => 'Hindi', 'hu' => 'Hungarian', 'is' => 'Icelandic', 'id' => 'Indonesian', 'ga' => 'Irish', 'it' => 'Italian', 'ja' => 'Japanese', 'jw' => 'Javanese', 'ko' => 'Korean', 'la' => 'Latin', 'lv' => 'Latvian', 'lt' => 'Lithuanian', 'mk' => 'Macedonian', 'ms' => 'Malay', 'ml' => 'Malayalam', 'mt' => 'Maltese', 'mi' => 'Maori', 'mr' => 'Marathi', 'mn' => 'Mongolian', 'ne' => 'Nepali', 'no' => 'Norwegian', 'fa' => 'Persian', 'pl' => 'Polish', 'pt' => 'Portuguese', 'pa' => 'Punjabi', 'qu' => 'Quechua', 'ro' => 'Romanian', 'ru' => 'Russian', 'sm' => 'Samoan', 'sr' => 'Serbian', 'sk' => 'Slovak', 'sl' => 'Slovenian', 'es' => 'Spanish', 'sw' => 'Swahili', 'sv' => 'Swedish ', 'ta' => 'Tamil', 'tt' => 'Tatar', 'te' => 'Telugu', 'th' => 'Thai', 'bo' => 'Tibetan', 'to' => 'Tonga', 'tr' => 'Turkish', 'uk' => 'Ukranian', 'ur' => 'Urdu', 'uz' => 'Uzbek', 'vi' => 'Vietnamese', 'cy' => 'Welsh', 'xh' => 'Xhosa' ); break; } $choices = $choices; if($options['param'] == 'url_parameter') { $output = ''; }else{ if ( empty( $choices)) { $choices = array('none' => esc_html__('No Items', 'ads-for-wp') ); } $output = ' '; if ( $saved_data == 'url_custom' || $response =='referrer_url') { if($selected_val_key_4 && $saved_data == 'url_custom'){ $output .= ' '; }else{ $output .= ' '; } } if ( $saved_data == 'user_agent_custom' || $response =='user_agent') { if($selected_val_key_5 && $saved_data == 'user_agent_custom'){ $output .= ' '; } else{ $output .= ' '; } } } $common_function_obj = new adsforwp_admin_common_functions(); $allowed_html = $common_function_obj->adsforwp_expanded_allowed_tags(); echo wp_kses($output, $allowed_html); if ( $is_ajax ) { die(); } } /** * Here, We are getting dynamic value for dropdown in conditions metabox * @global type $wp_roles * @param type $data * @param type $saved_data * @param type $current_number */ public function adsforwp_ajax_select_creator($data = '', $saved_data= '', $current_number = '', $current_group_number = '') { $response = $data; $is_ajax = false; if( $_SERVER['REQUEST_METHOD']=='POST'){ $is_ajax = true; if(wp_verify_nonce($_POST["adsforwp_call_nonce"],'adsforwp_select_action_nonce')){ if ( isset( $_POST["id"] ) ) { $response = sanitize_text_field(wp_unslash($_POST["id"])); } if ( isset( $_POST["number"] ) ) { $current_number = intval($_POST["number"]); } if ( isset( $_POST["group_number"] ) ) { $current_group_number = intval($_POST["group_number"]); } }else{ exit; } } // send the response back to the front end // vars $choices = array(); $options['param'] = $response; // some case's have the same outcome if($options['param'] == "page_parent") { $options['param'] = "page"; } switch($options['param']) { case "post_type": $choices = $this->adsforwp_post_type_generator(); $choices = apply_filters('adsforwp_modify_select_post_type', $choices ); break; case "page": $post_type = 'page'; $posts = get_posts(array( 'posts_per_page' => -1, 'post_type' => $post_type, 'orderby' => 'menu_order title', 'order' => 'ASC', 'post_status' => 'any', 'suppress_filters' => false, 'update_post_meta_cache' => false, )); if( $posts ) { // sort into hierachial order! if( is_post_type_hierarchical( $post_type ) ) { $posts = get_page_children( 0, $posts ); } foreach( $posts as $page ) { $title = ''; $ancestors = get_ancestors($page->ID, 'page'); if($ancestors) { foreach($ancestors as $a) { $title .= '- '; } } $title .= apply_filters( 'the_title', $page->post_title, $page->ID ); // status if($page->post_status != "publish") { $title .= " ($page->post_status)"; } $choices[ $page->ID ] = $title; } // foreach($pages as $page) } break; case "page_template" : $choices = array( 'default' => esc_html__('Default Template','ads-for-wp'), ); $templates = get_page_templates(); foreach($templates as $k => $v) { $choices[$v] = $k; } break; case "post" : $post_types = get_post_types(); unset( $post_types['page'], $post_types['attachment'], $post_types['revision'] , $post_types['nav_menu_item'], $post_types['acf'] , $post_types['amp_acf'] ); if( $post_types ) { foreach( $post_types as $post_type ) { $posts = get_posts(array( 'numberposts' => '-1', 'post_type' => $post_type, 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'), 'suppress_filters' => false, )); if( $posts) { $choices[$post_type] = array(); foreach($posts as $post) { $title = apply_filters( 'the_title', $post->post_title, $post->ID ); // status if($post->post_status != "publish") { $title .= " ($post->post_status)"; } $choices[$post_type][$post->ID] = $title; } // foreach($posts as $post) } // if( $posts ) } // foreach( $post_types as $post_type ) } // if( $post_types ) break; case "post_category" : $terms = get_terms( 'category', array( 'hide_empty' => false ) ); if( !empty($terms) ) { foreach( $terms as $term ) { $choices[ $term->term_id ] = $term->name; } } break; case "post_format" : $choices = get_post_format_strings(); break; case "user_type" : global $wp_roles; $choices = $wp_roles->get_names(); if( is_multisite() ) { $choices['super_admin'] = esc_html__('Super Admin','ads-for-wp'); } break; case "ef_taxonomy" : $choices = array('all' => esc_html__('All','ads-for-wp')); $taxonomies = $this->adsforwp_post_taxonomy_generator(); $choices = array_merge($choices, $taxonomies); break; } // allow custom location rules $choices = $choices; // Add None if no elements found in the current selected items if ( empty( $choices) ) { $choices = array('none' => esc_html__('No Items', 'ads-for-wp') ); } // echo $current_number; // echo $saved_data; $output = ' '; $common_function_obj = new adsforwp_admin_common_functions(); $allowed_html = $common_function_obj->adsforwp_expanded_allowed_tags(); echo wp_kses($output, $allowed_html); if ( $is_ajax ) { die(); } // endif; } /** * Here, this function generate taxonomy * @return type */ public function adsforwp_post_taxonomy_generator(){ $taxonomies = ''; $choices = array(); $taxonomies = get_taxonomies( array('public' => true), 'objects' ); foreach($taxonomies as $taxonomy) { $choices[ $taxonomy->name ] = $taxonomy->labels->name; } // unset post_format (why is this a public taxonomy?) if( isset($choices['post_format']) ) { unset( $choices['post_format']) ; } return $choices; } /** * Here, We are getting value for taxonomy * @param type $selectedParentValue * @param type $selectedValue * @param type $current_number */ public function adsforwp_create_ajax_select_taxonomy($selectedParentValue = '',$selectedValue='', $current_number ='', $current_group_number = ''){ $is_ajax = false; if( $_SERVER['REQUEST_METHOD']=='POST'){ $is_ajax = true; if(wp_verify_nonce($_POST["adsforwp_call_nonce"],'adsforwp_select_action_nonce')){ if(isset($_POST['id'])){ $selectedParentValue = sanitize_text_field(wp_unslash($_POST['id'])); } if(isset($_POST['number'])){ $current_number = intval($_POST['number']); } if ( isset( $_POST["group_number"] ) ) { $current_group_number = intval($_POST["group_number"]); } }else{ exit; } } $taxonomies = array(); if($selectedParentValue == 'all'){ $taxonomies = get_terms( array( 'hide_empty' => true, ) ); }else{ $taxonomies = get_terms($selectedParentValue, array( 'hide_empty' => true, ) ); } $choices = ''; foreach($taxonomies as $taxonomy) { $sel=""; if($selectedValue == $taxonomy->slug){ $sel = "selected"; } $choices .= ''; } $common_function_obj = new adsforwp_admin_common_functions(); $allowed_html = $common_function_obj->adsforwp_expanded_allowed_tags(); echo ''; if($is_ajax){ die; } } } if (class_exists('adsforwp_ajax_selectbox')) { new adsforwp_ajax_selectbox; };