Search & Filter - Version 1.2.12

Version Description

  • Fixed - some PHP warnings when using radio, checkbox and multiselects
  • Fixed - a typo (thanks sunjunkie)
  • Tested with WP 5.3
Download this release

Release Info

Developer DesignsAndCode
Plugin Icon 128x128 Search & Filter
Version 1.2.12
Comparing to
See all releases

Code changes from version 1.2.11 to 1.2.12

Files changed (4) hide show
  1. of-admin.php +1 -1
  2. of-taxonomy-walker.php +19 -34
  3. readme.txt +7 -2
  4. search-filter.php +13 -14
of-admin.php CHANGED
@@ -63,7 +63,7 @@
63
 
64
  This will display a search box, a category dropdown and a tag dropdown. You can use the shortcode within posts/pages and widget areas.<br /><br />
65
 
66
- To use this within a theme file you simple need to call the `do_shorcode` function with the shortcode above within the theme file:<br />
67
 
68
  <pre><code class="php">&lt;?php echo do_shortcode( \'[searchandfilter fields="search,category,post_tag"]\' ); ?&gt;</code></pre>
69
  </div>';
63
 
64
  This will display a search box, a category dropdown and a tag dropdown. You can use the shortcode within posts/pages and widget areas.<br /><br />
65
 
66
+ To use this within a theme file you simple need to call the `do_shortcode` function with the shortcode above within the theme file:<br />
67
 
68
  <pre><code class="php">&lt;?php echo do_shortcode( \'[searchandfilter fields="search,category,post_tag"]\' ); ?&gt;</code></pre>
69
  </div>';
of-taxonomy-walker.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
 
3
  class Taxonomy_Walker extends Walker_Category {
4
-
5
 
6
  private $type = '';
7
  private $defaults = array();
@@ -10,39 +9,19 @@ class Taxonomy_Walker extends Walker_Category {
10
  private $multilastdepthchange = 0; //manually calculate depth on multiselects
11
 
12
  function __construct($type = 'checkbox', $defaults = array()) {
13
- // fetch the list of term ids for the given post
14
- //$this->term_ids = wp_get_post_terms( $post_id, $taxonomy, 'fields=ids' );
15
 
16
  $this->type = $type;
17
  $this->defaults = $defaults;
18
  }
19
 
20
  function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
21
- /*$display = false;
22
 
23
- $id = $element->term_id;
24
-
25
- $display = true;
26
- if ( isset( $children_elements[ $id ] ) ) {
27
- // the current term has children
28
- foreach ( $children_elements[ $id ] as $child ) {
29
- if ( in_array( $child->term_id, $this->term_ids ) ) {
30
- // one of the term's children is in the list
31
- $display = true;
32
- // can stop searching now
33
- break;
34
- }
35
- }
36
- }
37
-
38
- if ( $display )*/
39
- parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
40
  }
41
 
42
 
43
  function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 )
44
  {
45
-
46
  if($this->type=="list")
47
  {
48
  extract($args);
@@ -119,15 +98,18 @@ class Taxonomy_Walker extends Walker_Category {
119
 
120
  if($defaults)
121
  {
122
- $noselected = count($this->defaults);
123
-
124
- if(($noselected>0)&&(is_array($defaults)))
125
  {
126
- foreach($defaults as $defaultid)
 
 
127
  {
128
- if($defaultid==$cat_id)
129
  {
130
- $checked = ' checked="checked"';
 
 
 
131
  }
132
  }
133
  }
@@ -170,15 +152,18 @@ class Taxonomy_Walker extends Walker_Category {
170
  $checked = "";
171
  if($defaults)
172
  {
173
- $noselected = count($this->defaults);
174
-
175
- if(($noselected>0)&&(is_array($defaults)))
176
  {
177
- foreach($defaults as $defaultid)
 
 
178
  {
179
- if($defaultid==$cat_id)
180
  {
181
- $checked = ' selected="selected"';
 
 
 
182
  }
183
  }
184
  }
1
  <?php
2
 
3
  class Taxonomy_Walker extends Walker_Category {
 
4
 
5
  private $type = '';
6
  private $defaults = array();
9
  private $multilastdepthchange = 0; //manually calculate depth on multiselects
10
 
11
  function __construct($type = 'checkbox', $defaults = array()) {
 
 
12
 
13
  $this->type = $type;
14
  $this->defaults = $defaults;
15
  }
16
 
17
  function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
 
18
 
19
+ parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  }
21
 
22
 
23
  function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 )
24
  {
 
25
  if($this->type=="list")
26
  {
27
  extract($args);
98
 
99
  if($defaults)
100
  {
101
+ if(is_array($defaults))
 
 
102
  {
103
+ $noselected = count($defaults);
104
+
105
+ if($noselected>0)
106
  {
107
+ foreach($defaults as $defaultid)
108
  {
109
+ if($defaultid==$cat_id)
110
+ {
111
+ $checked = ' checked="checked"';
112
+ }
113
  }
114
  }
115
  }
152
  $checked = "";
153
  if($defaults)
154
  {
155
+ if(is_array($defaults))
 
 
156
  {
157
+ $noselected = count($defaults);
158
+
159
+ if($noselected>0)
160
  {
161
+ foreach($defaults as $defaultid)
162
  {
163
+ if($defaultid==$cat_id)
164
+ {
165
+ $checked = ' selected="selected"';
166
+ }
167
  }
168
  }
169
  }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: DesignsAndCode
3
  Donate link:
4
  Tags: category, filter, taxonomy, search, wordpress, post type, post date
5
  Requires at least: 3.5
6
- Tested up to: 5.0
7
- Stable tag: 1.2.11
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -34,6 +34,11 @@ The documentation has been updated to include examples almost all configurable o
34
 
35
  == Changelog ==
36
 
 
 
 
 
 
37
  = 1.2.11 =
38
  * Fixed - a few typos in the admin screen
39
  * Tested with WP 5.0 RC2
3
  Donate link:
4
  Tags: category, filter, taxonomy, search, wordpress, post type, post date
5
  Requires at least: 3.5
6
+ Tested up to: 5.3
7
+ Stable tag: 1.2.12
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
34
 
35
  == Changelog ==
36
 
37
+ = 1.2.12 =
38
+ * Fixed - some PHP warnings when using radio, checkbox and multiselects
39
+ * Fixed - a typo (thanks sunjunkie)
40
+ * Tested with WP 5.3
41
+
42
  = 1.2.11 =
43
  * Fixed - a few typos in the admin screen
44
  * Tested with WP 5.0 RC2
search-filter.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.designsandcode.com/447/wordpress-search-filter-plugin-for
5
  Description: Search and Filtering system for Pages, Posts, Categories, Tags and Taxonomies
6
  Author: Designs & Code
7
  Author URI: http://www.designsandcode.com/
8
- Version: 1.2.11
9
  Text Domain: searchandfilter
10
  License: GPLv2
11
  */
@@ -14,7 +14,7 @@ License: GPLv2
14
  * Set up Plugin Globals
15
  */
16
  if (!defined('SEARCHANDFILTER_VERSION_NUM'))
17
- define('SEARCHANDFILTER_VERSION_NUM', '1.2.11');
18
 
19
  if (!defined('SEARCHANDFILTER_THEME_DIR'))
20
  define('SEARCHANDFILTER_THEME_DIR', ABSPATH . 'wp-content/themes/' . get_template());
@@ -1106,7 +1106,7 @@ if ( ! class_exists( 'SearchAndFilter' ) )
1106
  {
1107
  foreach($post_types as $post_type)
1108
  {
1109
- $returnvar .= "<input type=\"hidden\" name=\"".SF_FPRE."post_types[]\" value=\"".$post_type."\" />";
1110
  }
1111
  }
1112
  }
@@ -1127,7 +1127,7 @@ if ( ! class_exists( 'SearchAndFilter' ) )
1127
  $returnvar .= "<h4>".$labels[$i]."</h4>";
1128
  }
1129
  $clean_searchterm = (esc_attr($this->searchterm));
1130
- $returnvar .= '<input type="text" name="'.SF_FPRE.'search" placeholder="'.$search_placeholder.'" value="'.$clean_searchterm.'">';
1131
  $returnvar .= '</li>';
1132
  }
1133
  else if($field == "post_types") //a post can only every have 1 type, so checkboxes & multiselects will always be "OR"
@@ -1175,7 +1175,7 @@ if ( ! class_exists( 'SearchAndFilter' ) )
1175
 
1176
  $returnvar .=
1177
  '<input type="hidden" name="'.SF_FPRE.'submitted" value="1">
1178
- <input type="submit" value="'.$submitlabel.'">
1179
  </li>';
1180
 
1181
  $returnvar .= "</ul>";
@@ -1436,7 +1436,7 @@ if ( ! class_exists( 'SearchAndFilter' ) )
1436
 
1437
  if(($operators[$i]=="and")||($operators[$i]=="or"))
1438
  {
1439
- $returnvar .= '<input type="hidden" name="'.SF_FPRE.$taxonomy.'_operator" value="'.$operators[$i].'" />';
1440
  }
1441
  }
1442
 
@@ -1520,7 +1520,7 @@ if ( ! class_exists( 'SearchAndFilter' ) )
1520
 
1521
  $checked = ($defaultval=="0") ? " checked='checked'" : "";
1522
  $returnvar = '<ul>';
1523
- $returnvar .= '<li>'."<label><input type='radio' name='".$args['sf_name']."[]' value='0'$checked /> ".$show_option_all."</label>".'</li>';
1524
  $returnvar .= walk_taxonomy('radio', $args);
1525
  $returnvar .= "</ul>";
1526
 
@@ -1600,7 +1600,7 @@ if ( ! class_exists( 'SearchAndFilter' ) )
1600
  }
1601
  }
1602
  }
1603
- $returnvar .= '<li class="cat-item"><label><input class="postform cat-item" type="checkbox" name="'.SF_FPRE.$name.'[]" value="'.$dropdown->term_id.'"'.$checked.'> '.$dropdown->cat_name.'</label></li>';
1604
 
1605
  }
1606
 
@@ -1658,7 +1658,7 @@ if ( ! class_exists( 'SearchAndFilter' ) )
1658
  $all_items_name = "All ".$labels->name;
1659
  }
1660
 
1661
- $returnvar .= '<li class="cat-item"><label><input class="postform" type="radio" name="'.SF_FPRE.$name.'[]" value="'.$defaultval.'"'.$checked.'> '.$all_items_name.'</label></li>';
1662
  }
1663
 
1664
  foreach($dropdata as $dropdown)
@@ -1683,7 +1683,7 @@ if ( ! class_exists( 'SearchAndFilter' ) )
1683
  }
1684
  }
1685
  }
1686
- $returnvar .= '<li class="cat-item"><label><input class="postform" type="radio" name="'.SF_FPRE.$name.'[]" value="'.$dropdown->term_id.'"'.$checked.'> '.$dropdown->cat_name.'</label></li>';
1687
 
1688
  }
1689
 
@@ -1710,7 +1710,7 @@ if ( ! class_exists( 'SearchAndFilter' ) )
1710
  }
1711
  }
1712
 
1713
- $returnvar .= '<input class="postform" type="date" name="'.SF_FPRE.$name.'[]" value="' . $current_date . '" />';
1714
 
1715
  return $returnvar;
1716
  }
@@ -1722,11 +1722,10 @@ function walk_taxonomy( $type = "checkbox", $args = array() ) {
1722
 
1723
  $args['walker'] = new Taxonomy_Walker($type, $args['sf_name']);
1724
 
1725
- //unset($args['sf_name']);
1726
-
1727
  $output = wp_list_categories($args);
1728
- if ( $output )
1729
  return $output;
 
1730
  }
1731
 
1732
 
5
  Description: Search and Filtering system for Pages, Posts, Categories, Tags and Taxonomies
6
  Author: Designs & Code
7
  Author URI: http://www.designsandcode.com/
8
+ Version: 1.2.12
9
  Text Domain: searchandfilter
10
  License: GPLv2
11
  */
14
  * Set up Plugin Globals
15
  */
16
  if (!defined('SEARCHANDFILTER_VERSION_NUM'))
17
+ define('SEARCHANDFILTER_VERSION_NUM', '1.2.12');
18
 
19
  if (!defined('SEARCHANDFILTER_THEME_DIR'))
20
  define('SEARCHANDFILTER_THEME_DIR', ABSPATH . 'wp-content/themes/' . get_template());
1106
  {
1107
  foreach($post_types as $post_type)
1108
  {
1109
+ $returnvar .= "<input type=\"hidden\" name=\"".SF_FPRE."post_types[]\" value=\"".esc_attr($post_type)."\" />";
1110
  }
1111
  }
1112
  }
1127
  $returnvar .= "<h4>".$labels[$i]."</h4>";
1128
  }
1129
  $clean_searchterm = (esc_attr($this->searchterm));
1130
+ $returnvar .= '<input type="text" name="'.SF_FPRE.'search" placeholder="'.esc_attr($search_placeholder).'" value="'.esc_attr($clean_searchterm).'">';
1131
  $returnvar .= '</li>';
1132
  }
1133
  else if($field == "post_types") //a post can only every have 1 type, so checkboxes & multiselects will always be "OR"
1175
 
1176
  $returnvar .=
1177
  '<input type="hidden" name="'.SF_FPRE.'submitted" value="1">
1178
+ <input type="submit" value="'.esc_attr($submitlabel).'">
1179
  </li>';
1180
 
1181
  $returnvar .= "</ul>";
1436
 
1437
  if(($operators[$i]=="and")||($operators[$i]=="or"))
1438
  {
1439
+ $returnvar .= '<input type="hidden" name="'.esc_attr(SF_FPRE.$taxonomy).'_operator" value="'.esc_attr($operators[$i]).'" />';
1440
  }
1441
  }
1442
 
1520
 
1521
  $checked = ($defaultval=="0") ? " checked='checked'" : "";
1522
  $returnvar = '<ul>';
1523
+ $returnvar .= '<li>'."<label><input type='radio' name='".esc_attr($args['sf_name'])."[]' value='0'$checked /> ".$show_option_all."</label>".'</li>';
1524
  $returnvar .= walk_taxonomy('radio', $args);
1525
  $returnvar .= "</ul>";
1526
 
1600
  }
1601
  }
1602
  }
1603
+ $returnvar .= '<li class="cat-item"><label><input class="postform cat-item" type="checkbox" name="'.esc_attr(SF_FPRE.$name).'[]" value="'.esc_attr($dropdown->term_id).'"'.$checked.'> '.$dropdown->cat_name.'</label></li>';
1604
 
1605
  }
1606
 
1658
  $all_items_name = "All ".$labels->name;
1659
  }
1660
 
1661
+ $returnvar .= '<li class="cat-item"><label><input class="postform" type="radio" name="'.esc_attr(SF_FPRE.$name).'[]" value="'.esc_attr($defaultval).'"'.$checked.'> '.$all_items_name.'</label></li>';
1662
  }
1663
 
1664
  foreach($dropdata as $dropdown)
1683
  }
1684
  }
1685
  }
1686
+ $returnvar .= '<li class="cat-item"><label><input class="postform" type="radio" name="'.esc_attr(SF_FPRE.$name).'[]" value="'.esc_attr($dropdown->term_id).'"'.$checked.'> '.$dropdown->cat_name.'</label></li>';
1687
 
1688
  }
1689
 
1710
  }
1711
  }
1712
 
1713
+ $returnvar .= '<input class="postform" type="date" name="'.esc_attr(SF_FPRE.$name).'[]" value="'. esc_attr($current_date) .'" />';
1714
 
1715
  return $returnvar;
1716
  }
1722
 
1723
  $args['walker'] = new Taxonomy_Walker($type, $args['sf_name']);
1724
 
 
 
1725
  $output = wp_list_categories($args);
1726
+ if ( $output ){
1727
  return $output;
1728
+ }
1729
  }
1730
 
1731