Custom Taxonomy Order NE - Version 2.9.0

Version Description

  • 2017-07-10
  • Drop support for attributes in WooCommerce (deprecated).
  • Use the correct number of parameters with add_filter calls.
  • Set default order in WP_Term_Query->get_terms() according to our settings (probably WP 4.9).
Download this release

Release Info

Developer mpol
Plugin Icon 128x128 Custom Taxonomy Order NE
Version 2.9.0
Comparing to
See all releases

Code changes from version 2.8.3 to 2.9.0

Files changed (4) hide show
  1. customtaxorder.php +42 -11
  2. page-customtaxorder.php +1 -2
  3. readme.txt +7 -1
  4. taxonomies.php +0 -37
customtaxorder.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Custom Taxonomy Order NE
4
  Plugin URI: http://products.zenoweb.nl/free-wordpress-plugins/custom-taxonomy-order-ne/
5
  Description: Allows for the ordering of categories and custom taxonomy terms through a simple drag-and-drop interface.
6
- Version: 2.8.3
7
  Author: Marcel Pol
8
  Author URI: http://zenoweb.nl/
9
  License: GPLv2 or later
@@ -35,13 +35,12 @@ Domain Path: /lang/
35
  * https://wordpress.org/support/topic/how-to-create-a-navigation-in-archivephp-with-the-given-order/
36
  * - Order by post count (and other orderby's)
37
  * https://wordpress.org/support/topic/order-terms-by-post-count/
38
- * - Order Woo terms, also after filtering products with widgets:
39
- * https://wordpress.org/support/topic/plugin-does-not-keep-custom-order-when-using-filter/
40
  */
41
 
42
 
43
  // Plugin Version
44
- define('CUSTOMTAXORDER_VER', '2.8.3');
45
 
46
 
47
  function customtaxorder_register_settings() {
@@ -302,6 +301,35 @@ function customtaxorder_apply_order_filter( $orderby, $args ) {
302
  add_filter('get_terms_orderby', 'customtaxorder_apply_order_filter', 10, 2);
303
 
304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
  /*
306
  * customtaxorder_wp_get_object_terms_order_filter
307
  *
@@ -310,6 +338,7 @@ add_filter('get_terms_orderby', 'customtaxorder_apply_order_filter', 10, 2);
310
  * get_terms is used in wp_list_categories and get_terms functions.
311
  * get_the_terms is used in the the_tags function.
312
  * tag_cloud_sort is used in the wp_tag_cloud and wp_generate_tag_cloud functions (but then the get_terms filter here does nothing).
 
313
  *
314
  * Default sorting is by name (according to the codex).
315
  *
@@ -332,7 +361,7 @@ function customtaxorder_wp_get_object_terms_order_filter( $terms ) {
332
  if ( !isset ( $options[$taxonomy] ) ) {
333
  $options[$taxonomy] = 0; // default if not set in options yet
334
  }
335
- if ( $options[$taxonomy] == 1 && !isset($_GET['orderby']) ) {
336
 
337
  // no filtering so the test in wp_generate_tag_cloud() works out right for us
338
  // filtering will happen in the tag_cloud_sort filter sometime later
@@ -349,7 +378,7 @@ function customtaxorder_wp_get_object_terms_order_filter( $terms ) {
349
  foreach ($terms as $term) {
350
  if ( ! $term->parent == 0 ) {
351
  $parents = get_ancestors( $term->term_id, $term->taxonomy, 'taxonomy' );
352
- if ( is_array($parents) && !empty($parents) ) {
353
  $ancestor_ID = array_pop( $parents );
354
  $ancestor_term = get_term($ancestor_ID);
355
  if ( is_object($ancestor_term) && isset($ancestor_term->term_order) ) {
@@ -365,10 +394,11 @@ function customtaxorder_wp_get_object_terms_order_filter( $terms ) {
365
  }
366
  return $terms;
367
  }
368
- add_filter( 'wp_get_object_terms', 'customtaxorder_wp_get_object_terms_order_filter', 10, 3 );
369
- add_filter( 'get_terms', 'customtaxorder_wp_get_object_terms_order_filter', 10, 3 );
370
- add_filter( 'get_the_terms', 'customtaxorder_wp_get_object_terms_order_filter', 10, 3 );
371
- add_filter( 'tag_cloud_sort', 'customtaxorder_wp_get_object_terms_order_filter', 10, 3 );
 
372
 
373
 
374
  /*
@@ -399,6 +429,7 @@ add_filter('acf/format_value_for_api', 'customtaxorder_wp_get_object_terms_order
399
  */
400
  function customtaxorder_order_categories( $categories ) {
401
  $options = customtaxorder_get_settings();
 
402
  if ( !isset ( $options['category'] ) ) {
403
  $options['category'] = 0; // default if not set in options yet
404
  }
@@ -408,7 +439,7 @@ function customtaxorder_order_categories( $categories ) {
408
  }
409
  return $categories;
410
  }
411
- add_filter('get_the_categories', 'customtaxorder_order_categories', 10, 3);
412
 
413
 
414
  /*
3
  Plugin Name: Custom Taxonomy Order NE
4
  Plugin URI: http://products.zenoweb.nl/free-wordpress-plugins/custom-taxonomy-order-ne/
5
  Description: Allows for the ordering of categories and custom taxonomy terms through a simple drag-and-drop interface.
6
+ Version: 2.9.0
7
  Author: Marcel Pol
8
  Author URI: http://zenoweb.nl/
9
  License: GPLv2 or later
35
  * https://wordpress.org/support/topic/how-to-create-a-navigation-in-archivephp-with-the-given-order/
36
  * - Order by post count (and other orderby's)
37
  * https://wordpress.org/support/topic/order-terms-by-post-count/
38
+ *
 
39
  */
40
 
41
 
42
  // Plugin Version
43
+ define('CUSTOMTAXORDER_VER', '2.9.0');
44
 
45
 
46
  function customtaxorder_register_settings() {
301
  add_filter('get_terms_orderby', 'customtaxorder_apply_order_filter', 10, 2);
302
 
303
 
304
+ /*
305
+ * Set defaults in Class WP_Term_Query->parse_query();
306
+ * Default is name now. Set it to term_order if desired.
307
+ */
308
+ function customtaxorder_get_terms_defaults( $query_var_defaults, $taxonomies ) {
309
+ $options = customtaxorder_get_settings();
310
+
311
+ $taxonomy = 'category';
312
+ if ( isset( $query_var_defaults['taxonomy'] ) ) {
313
+ if ( is_string( $query_var_defaults['taxonomy'] ) && ! empty( $query_var_defaults['taxonomy'] ) ) {
314
+ $taxonomy = $query_var_defaults['taxonomy'];
315
+ }
316
+ }
317
+
318
+ if ( ! isset( $options[$taxonomy] ) ) {
319
+ $options[$taxonomy] = 0; // Default if it was not set in options yet.
320
+ }
321
+
322
+ if ( $options[$taxonomy] == 1 ) {
323
+ $query_var_defaults['orderby'] = 'term_order';
324
+ } elseif ( $options[$taxonomy] == 2 ) {
325
+ $query_var_defaults['orderby'] = 'name';
326
+ }
327
+
328
+ return $query_var_defaults;
329
+ }
330
+ add_filter('get_terms_defaults', 'customtaxorder_get_terms_defaults', 10, 2);
331
+
332
+
333
  /*
334
  * customtaxorder_wp_get_object_terms_order_filter
335
  *
338
  * get_terms is used in wp_list_categories and get_terms functions.
339
  * get_the_terms is used in the the_tags function.
340
  * tag_cloud_sort is used in the wp_tag_cloud and wp_generate_tag_cloud functions (but then the get_terms filter here does nothing).
341
+ * term_query_results is used in WP_Term_Query->get_terms() (probably in WP 4.9+).
342
  *
343
  * Default sorting is by name (according to the codex).
344
  *
361
  if ( !isset ( $options[$taxonomy] ) ) {
362
  $options[$taxonomy] = 0; // default if not set in options yet
363
  }
364
+ if ( $options[$taxonomy] == 1 && ! isset($_GET['orderby']) ) {
365
 
366
  // no filtering so the test in wp_generate_tag_cloud() works out right for us
367
  // filtering will happen in the tag_cloud_sort filter sometime later
378
  foreach ($terms as $term) {
379
  if ( ! $term->parent == 0 ) {
380
  $parents = get_ancestors( $term->term_id, $term->taxonomy, 'taxonomy' );
381
+ if ( is_array($parents) && ! empty($parents) ) {
382
  $ancestor_ID = array_pop( $parents );
383
  $ancestor_term = get_term($ancestor_ID);
384
  if ( is_object($ancestor_term) && isset($ancestor_term->term_order) ) {
394
  }
395
  return $terms;
396
  }
397
+ add_filter( 'wp_get_object_terms', 'customtaxorder_wp_get_object_terms_order_filter' );
398
+ add_filter( 'get_terms', 'customtaxorder_wp_get_object_terms_order_filter');
399
+ add_filter( 'get_the_terms', 'customtaxorder_wp_get_object_terms_order_filter' );
400
+ add_filter( 'tag_cloud_sort', 'customtaxorder_wp_get_object_terms_order_filter' );
401
+ add_filter( 'term_query_results', 'customtaxorder_wp_get_object_terms_order_filter' );
402
 
403
 
404
  /*
429
  */
430
  function customtaxorder_order_categories( $categories ) {
431
  $options = customtaxorder_get_settings();
432
+
433
  if ( !isset ( $options['category'] ) ) {
434
  $options['category'] = 0; // default if not set in options yet
435
  }
439
  }
440
  return $categories;
441
  }
442
+ add_filter( 'get_the_categories', 'customtaxorder_order_categories' );
443
 
444
 
445
  /*
page-customtaxorder.php CHANGED
@@ -125,8 +125,7 @@ function customtaxorder() {
125
  $message = "";
126
  if (isset($_POST['order-submit'])) {
127
  customtaxorder_update_order();
128
- }
129
- ?>
130
 
131
  <h1><?php echo __('Order ', 'custom-taxonomy-order-ne') . $tax_label; ?></h1>
132
  <form name="custom-order-form" method="post" action=""><?php
125
  $message = "";
126
  if (isset($_POST['order-submit'])) {
127
  customtaxorder_update_order();
128
+ } ?>
 
129
 
130
  <h1><?php echo __('Order ', 'custom-taxonomy-order-ne') . $tax_label; ?></h1>
131
  <form name="custom-order-form" method="post" action=""><?php
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: mpol
3
  Tags: order, ordering, sorting, terms, term order, term ordering, terms order, terms ordering, categories, category order, category ordering, categories order, categories ordering, custom taxonomies, taxonomy order, taxonomy ordering, taxonomies order, taxonomies ordering
4
  Requires at least: 3.7
5
  Tested up to: 4.8
6
- Stable tag: 2.8.3
7
  License: GPLv2 or later
8
 
9
 
@@ -132,6 +132,12 @@ The left metabox lists the toplevel terms. Right (or below) are the sub-terms.
132
 
133
  == Changelog ==
134
 
 
 
 
 
 
 
135
  = 2.8.3 =
136
  * 2017-03-29
137
  * Add Nonce check to admin pages.
3
  Tags: order, ordering, sorting, terms, term order, term ordering, terms order, terms ordering, categories, category order, category ordering, categories order, categories ordering, custom taxonomies, taxonomy order, taxonomy ordering, taxonomies order, taxonomies ordering
4
  Requires at least: 3.7
5
  Tested up to: 4.8
6
+ Stable tag: 2.9.0
7
  License: GPLv2 or later
8
 
9
 
132
 
133
  == Changelog ==
134
 
135
+ = 2.9.0 =
136
+ * 2017-07-10
137
+ * Drop support for attributes in WooCommerce (deprecated).
138
+ * Use the correct number of parameters with add_filter calls.
139
+ * Set default order in WP_Term_Query->get_terms() according to our settings (probably WP 4.9).
140
+
141
  = 2.8.3 =
142
  * 2017-03-29
143
  * Add Nonce check to admin pages.
taxonomies.php CHANGED
@@ -142,40 +142,3 @@ function customtaxorder_sort_taxonomies( $taxonomies = array() ) {
142
 
143
  return $taxonomies_ordered;
144
  }
145
-
146
-
147
- /*
148
- * Same as customtaxorder_sort_taxonomies, but for WooCommerce.
149
- *
150
- * Parameter: $taxonomies, array with a list of taxonomy arrays.
151
- *
152
- * Returns: array with list of taxonomies, ordered correctly.
153
- *
154
- * Since: 2.7.0
155
- *
156
- */
157
- function customtaxorder_sort_taxonomies_array( $taxonomies = array() ) {
158
- $order = get_option( 'customtaxorder_taxonomies', '' );
159
- $order = explode( ",", $order );
160
- $taxonomies_woo = array();
161
-
162
- // Main sorted taxonomies.
163
- if ( ! empty($order) && is_array($order) && ! empty($taxonomies) && is_array($taxonomies) ) {
164
- foreach ( $order as $tax ) {
165
- foreach ( $taxonomies as $key => $taxonomy ) {
166
- if ( is_array( $taxonomy ) && $tax === $taxonomy['name'] ) {
167
- $taxonomies_woo[ $taxonomy['name'] ] = $taxonomy;
168
- unset( $taxonomies[$taxonomy['name']] );
169
- }
170
- }
171
- }
172
- }
173
-
174
- // Unsorted taxonomies, the leftovers.
175
- foreach ( $taxonomies as $key => $taxonomy ) {
176
- $taxonomies_woo[ $key ] = $taxonomy;
177
- }
178
-
179
- return $taxonomies_woo;
180
- }
181
- add_filter( 'woocommerce_get_product_attributes', 'customtaxorder_sort_taxonomies_array' );
142
 
143
  return $taxonomies_ordered;
144
  }