} if (isset($values['taxonomies_settings'][$taxonomy->name]['include_exclude'])) { $sval = $values['taxonomies_settings'][$taxonomy->name]['include_exclude']; } } echo '<select name="settings_taxonomies[' . $taxonomy->name . '][include_exclude]" class="meta_key" id="' . $taxonomy->name . '_include_exclude">'; echo '<option value="include"' . $this->set_selected($sval, "include", false) . '>Include</option>'; echo '<option value="exclude"' . $this->set_selected($sval, "exclude", false) . '>Exclude</option>'; echo '</select>'; $ids_string = ""; if ($tval != "") { $ids_array = array_map("intval", explode(",", $tval)); if (Search_Filter_Helper::has_wpml()) { $res = array(); foreach ($ids_array as $id) { $xlat = Search_Filter_Helper::wpml_object_id($id, $taxonomy->name, false); if (!is_null($xlat)) { $res[] = $xlat; } } $ids_array = $res; } $ids_string = implode(",", $ids_array); } ?> </td> <td> <input class="settings_exclude_ids" id="<?php echo esc_attr($taxonomy->name); ?> _ids" name="settings_taxonomies[<?php
public function display_shortcode($atts, $content = null) { $lazy_load_js = get_option('search_filter_lazy_load_js'); if ($lazy_load_js == 1) { $this->enqueue_scripts(); } // extract the attributes into variables extract(shortcode_atts(array('id' => '', 'show' => 'form', 'action' => ''), $atts)); $returnvar = ""; //make sure its set if ($id != "") { $base_form_id = (int) $id; if (Search_Filter_Helper::has_wpml()) { $base_form_id = Search_Filter_Helper::wpml_object_id($id, 'search-filter-widget', true, ICL_LANGUAGE_CODE); } if (get_post_status($base_form_id) != "publish") { return; } $fields = get_post_meta($base_form_id, '_search-filter-fields', true); $settings = get_post_meta($base_form_id, '_search-filter-settings', true); $addclass = ""; global $searchandfilter; $searchform = $searchandfilter->get($base_form_id); $this->set_defaults($base_form_id); if ($action == "prep_query") { return $returnvar; } else { if ($action == "do_archive_query") { do_action("search_filter_archive_query", $base_form_id); //legacy do_action("search_filter_do_query", $base_form_id); return $returnvar; } else { if ($action == "setup_pagination") { //$searchform->query()->prep_query(); $searchform->query()->setup_pagination(); return $returnvar; } else { if ($show == "form") { /* TODO set auto count somewhere else */ //make sure there are fields if (isset($fields)) { //make sure fields are in array format as expected if (is_array($fields)) { $use_ajax = isset($settings['use_ajax_toggle']) ? (bool) $settings['use_ajax_toggle'] : false; $use_history_api = true; $ajax_target = isset($settings['ajax_target']) ? esc_attr($settings['ajax_target']) : ''; $results_url = isset($settings['results_url']) ? esc_attr($settings['results_url']) : ''; $page_slug = isset($settings['page_slug']) ? esc_attr($settings['page_slug']) : ''; $ajax_links_selector = isset($settings['ajax_links_selector']) ? esc_attr($settings['ajax_links_selector']) : ''; $ajax_auto_submit = isset($settings['auto_submit']) ? (int) $settings['auto_submit'] : ''; $auto_count = isset($settings['enable_auto_count']) ? (int) $settings['enable_auto_count'] : ''; $auto_count_refresh_mode = isset($settings['auto_count_refresh_mode']) ? (int) $settings['auto_count_refresh_mode'] : ''; $use_results_shortcode = isset($settings['use_results_shortcode']) ? (int) $settings['use_results_shortcode'] : ''; /* legacy */ $display_results_as = isset($settings['display_results_as']) ? esc_attr($settings['display_results_as']) : 'shortcode'; $update_ajax_url = isset($settings['update_ajax_url']) ? (int) $settings['update_ajax_url'] : 1; $only_results_ajax = isset($settings['only_results_ajax']) ? (int) $settings['only_results_ajax'] : ''; $scroll_to_pos = isset($settings['scroll_to_pos']) ? esc_attr($settings['scroll_to_pos']) : ''; $scroll_on_action = isset($settings['scroll_on_action']) ? esc_attr($settings['scroll_on_action']) : ''; $custom_scroll_to = isset($settings['custom_scroll_to']) ? esc_html($settings['custom_scroll_to']) : ''; //$is_woocommerce = isset($settings['is_woocommerce']) ? esc_html($settings['is_woocommerce']) : ''; /* legacy */ if (isset($settings['use_results_shortcode'])) { if ($settings['use_results_shortcode'] == 1) { $display_results_as = "shortcode"; } else { $display_results_as = "archive"; } } /* end legacy */ //if($display_results_as=="shortcode") //{ //prep the query so we can get the counts for the items in the search form - should not really be loaded here - needs to run before page load $searchform->query()->prep_query(); //} if ($display_results_as == "shortcode") { //if we're using a shortcode, grab the selector automatically from the id $ajax_target = "#search-filter-results-" . $base_form_id; } $post_types = isset($settings['post_types']) ? $settings['post_types'] : ''; //url /*$ajax_url = ""; $start_url = home_url(); $full_url = $this->get_current_URL(); if(substr($full_url, 0, strlen($start_url)) == $start_url) { $ajax_url = substr($full_url, strlen($start_url)); }*/ $form_attr = ' data-sf-form-id="' . $base_form_id . '" data-is-rtl="' . (int) is_rtl() . '"'; $ajax_url = ""; /* figure out the ajax/results urls */ if ($display_results_as == "archive") { //get search & filter results url respecting permalink settings $results_url = home_url("?sfid=" . $base_form_id); //$results_url = add_query_arg(array('sfid' => $base_form_id), pll_home_url()); if (get_option('permalink_structure')) { $page_slug = $settings['page_slug']; if ($page_slug != "") { $results_url = trailingslashit(home_url($page_slug)); } } if (has_filter('sf_archive_results_url')) { $results_url = apply_filters('sf_archive_results_url', $results_url, $base_form_id, $page_slug); } } else { if ($display_results_as == "post_type_archive") { //get the post type for this form (should only be one set) //then find out the proper url for the archive page according to permalink option if (isset($settings['post_types'])) { $post_types = array_keys($settings['post_types']); if (isset($post_types[0])) { $post_type = $post_types[0]; if ($post_type == "post") { if (get_option('show_on_front') == 'page') { $results_url = get_permalink(get_option('page_for_posts')); } else { $results_url = home_url('/'); } } else { $results_url = get_post_type_archive_link($post_type); } } } } else { if ($display_results_as == "shortcode") { //use the results_url defined by the user $ajax_url = home_url("?sfid=" . $base_form_id . "&sf_action=get_results"); } else { if ($display_results_as == "custom_edd_store") { //use the results_url defined by the user } else { if ($display_results_as == "custom_woocommerce_store" && function_exists('woocommerce_get_page_id')) { //find woocommerce shop page $results_url = home_url("?post_type=product"); $searchform->query()->remove_permalink_filters(); if (get_option('permalink_structure')) { $results_url = get_permalink(woocommerce_get_page_id('shop')); } $searchform->query()->add_permalink_filters(); } } } } } if ($results_url != "") { if (has_filter('sf_results_url')) { $results_url = apply_filters('sf_results_url', $results_url, $base_form_id); } $form_attr .= ' data-results-url="' . $results_url . '"'; } if ($use_ajax && $ajax_url != "") { if (has_filter('sf_ajax_results_url')) { $ajax_url = apply_filters('sf_ajax_results_url', $ajax_url, $base_form_id); } $form_attr .= ' data-ajax-url="' . $ajax_url . '"'; } $ajax_form_url = home_url("?sfid=" . $base_form_id . "&sf_action=get_form"); if ($ajax_form_url != "") { if (has_filter('sf_ajax_form_url')) { $ajax_form_url = apply_filters('sf_ajax_form_url', $ajax_form_url, $base_form_id); } $form_attr .= ' data-ajax-form-url="' . $ajax_form_url . '"'; } $form_attr .= ' data-use-history-api="' . (int) $use_history_api . '"'; $form_attr .= ' data-template-loaded="' . (int) $this->is_template_loaded . '"'; $lang_code = ""; if (Search_Filter_Helper::has_wpml()) { $lang_code = ICL_LANGUAGE_CODE; } $form_attr .= ' data-lang-code="' . $lang_code . '"'; $form_attr .= ' data-ajax="' . (int) $use_ajax . '"'; if ($use_ajax) { if ($ajax_target != "") { $form_attr .= ' data-ajax-target="' . $ajax_target . '"'; } if ($ajax_links_selector != "") { $form_attr .= ' data-ajax-links-selector="' . $ajax_links_selector . '"'; } if ($update_ajax_url != "") { $form_attr .= ' data-update-ajax-url="' . $update_ajax_url . '"'; } if ($only_results_ajax != "") { $form_attr .= ' data-only-results-ajax="' . $only_results_ajax . '"'; } if ($scroll_to_pos != "") { $form_attr .= ' data-scroll-to-pos="' . $scroll_to_pos . '"'; if ($scroll_to_pos == "custom") { if ($custom_scroll_to != "") { $form_attr .= ' data-custom-scroll-to="' . $custom_scroll_to . '"'; } } } if ($scroll_on_action != "") { $form_attr .= ' data-scroll-on-action="' . $scroll_on_action . '"'; } } $form_attr .= ' data-auto-update="' . $ajax_auto_submit . '"'; if ($auto_count == 1) { $form_attr .= ' data-auto-count="' . esc_attr($auto_count) . '"'; if ($auto_count_refresh_mode == 1) { $form_attr .= ' data-auto-count-refresh-mode="' . esc_attr($auto_count_refresh_mode) . '"'; } } $returnvar .= '<form action="' . $results_url . '" method="post" class="searchandfilter' . $addclass . '"' . $form_attr . ' id="search-filter-form-' . $base_form_id . '" autocomplete="off">'; $returnvar .= "<ul>"; $this->fields = new Search_Filter_Fields($this->plugin_slug, $base_form_id); //loop through each field and grab html foreach ($fields as $field) { $returnvar .= $this->get_field($field, $post_types, $base_form_id); } $returnvar .= "</ul>"; $returnvar .= "</form>"; } } } else { if ($show == "results") { /* legacy */ if ($searchform->settings('use_results_shortcode') == 1) { $display_results_as = "shortcode"; } else { $display_results_as = "archive"; } /* end legacy */ if ($searchform->settings('display_results_as') != "") { $display_results_as = $searchform->settings('display_results_as'); } if ($display_results_as == "shortcode") { $returnvar = $this->display_results->output_results($base_form_id, $settings); } else { if (current_user_can('edit_posts')) { $returnvar = __("<p><strong>Notice:</strong> This Search Form has not been configured to use a shortcode. <a href='" . get_edit_post_link($base_form_id) . "'>Edit settings</a>.</p>", $this->plugin_slug); } } } } } } } } return $returnvar; }
function form($instance) { if (isset($instance['title']) && isset($instance['formid'])) { $title = __(esc_attr($instance['title']), $this->plugin_slug); $formid = esc_attr($instance['formid']); } else { $title = __('', $this->plugin_slug); $formid = __('', $this->plugin_slug); } ?> <div class="sf-widget-content"> <p><label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " type="text" value="<?php echo $title; ?> " /></label></p> <p> <label for="<?php echo $this->get_field_id('formid'); ?> ">Choose a Search Form: <select class="widefat" name="<?php echo $this->get_field_name('formid'); ?> " id="<?php echo $this->get_field_id('formid'); ?> "> <option value="0"><?php _e('Please choose'); ?> </option> <?php // $custom_posts = new WP_Query('post_type=search-filter-widget&post_status=publish&posts_per_page=-1'); if (Search_Filter_Helper::has_wpml()) { $formid = Search_Filter_Helper::wpml_object_id($formid, 'search-filter-widget', true, ICL_LANGUAGE_CODE); } //var_dump($custom_posts); while ($custom_posts->have_posts()) { $custom_posts->the_post(); ?> <option value="<?php the_ID(); ?> " <?php if ($formid == get_the_ID()) { echo ' selected="selected"'; } ?> ><?php the_title(); ?> </option> <?php } ?> </select> </label> </p> <p class="sf-widget-text-last"> <?php _e('Don\'t see a Search Form you want to use? <a href="' . admin_url('post-new.php?post_type=search-filter-widget') . '">Create a new Search Form</a>.'); ?> </p> </div> <?php }
function lang_object_ids($ids_array, $type) { if (Search_Filter_Helper::has_wpml()) { $res = array(); foreach ($ids_array as $id) { $xlat = Search_Filter_Helper::wpml_object_id($id, $type, false); if (!is_null($xlat)) { $res[] = $xlat; } } return $res; } else { return $ids_array; } }