Custom Taxonomy Order NE - Version 2.8.1

Version Description

  • 2016-10-06
  • Sort children with a float as ancestor.child when set to term_order.
Download this release

Release Info

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

Code changes from version 2.8.0 to 2.8.1

Files changed (2) hide show
  1. customtaxorder.php +39 -30
  2. readme.txt +5 -1
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.0
7
  Author: Marcel Pol
8
  Author URI: http://zenoweb.nl/
9
  License: GPLv2 or later
@@ -31,14 +31,12 @@ Domain Path: /lang/
31
 
32
 
33
  /* TODO:
34
- * - Find a proper fix for tree of terms/subterms and ordering.
35
  * - Add pagination, just like next_post_link().
36
- * - 3.0: Switch to term_meta.
37
  */
38
 
39
 
40
  // Plugin Version
41
- define('CUSTOMTAXORDER_VER', '2.8.0');
42
 
43
 
44
  function customtaxorder_register_settings() {
@@ -57,6 +55,27 @@ function customtaxorder_update_settings() {
57
  }
58
 
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  function customtaxorder_settings_validate($input) {
61
  $args = array( 'public' => true );
62
  $output = 'objects';
@@ -138,9 +157,9 @@ add_action('admin_print_scripts', 'customtaxorder_js_libs');
138
  * Sorting the query with get_terms() doesn't allow sorting with term_order
139
  */
140
  function customtax_cmp( $a, $b ) {
141
- if ( $a->term_order == $b->term_order ) {
142
  return 0;
143
- } else if ( $a->term_order < $b->term_order ) {
144
  return -1;
145
  } else {
146
  return 1;
@@ -295,6 +314,20 @@ function customtaxorder_wp_get_object_terms_order_filter( $terms ) {
295
  return $terms;
296
  }
297
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  usort($terms, 'customtax_cmp');
299
  return $terms;
300
  }
@@ -401,30 +434,6 @@ function customtaxorder_load_lang() {
401
  add_action('plugins_loaded', 'customtaxorder_load_lang');
402
 
403
 
404
- /*
405
- * - set defaults
406
- * - get settings
407
- *
408
- * $customtaxorder_settings is an array with key: $taxonomy->name and value: setting (0, 1, 2).
409
- */
410
- function customtaxorder_get_settings() {
411
- $customtaxorder_defaults = array('category' => 0);
412
-
413
- $args = array( 'public' => true, '_builtin' => false );
414
- $output = 'objects';
415
- $taxonomies = get_taxonomies( $args, $output );
416
- foreach ( $taxonomies as $taxonomy ) {
417
- $customtaxorder_defaults[$taxonomy->name] = 0;
418
- }
419
-
420
- $customtaxorder_defaults = apply_filters( 'customtaxorder_defaults', $customtaxorder_defaults );
421
- $customtaxorder_settings = get_option( 'customtaxorder_settings' );
422
- $customtaxorder_settings = wp_parse_args( $customtaxorder_settings, $customtaxorder_defaults );
423
-
424
- return $customtaxorder_settings;
425
- }
426
-
427
-
428
  /*
429
  * customtaxorder_activate
430
  * Function called at activation time.
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.1
7
  Author: Marcel Pol
8
  Author URI: http://zenoweb.nl/
9
  License: GPLv2 or later
31
 
32
 
33
  /* TODO:
 
34
  * - Add pagination, just like next_post_link().
 
35
  */
36
 
37
 
38
  // Plugin Version
39
+ define('CUSTOMTAXORDER_VER', '2.8.1');
40
 
41
 
42
  function customtaxorder_register_settings() {
55
  }
56
 
57
 
58
+ /*
59
+ * $customtaxorder_settings is an array with key: $taxonomy->name and value: setting (0, 1, 2).
60
+ */
61
+ function customtaxorder_get_settings() {
62
+ $customtaxorder_defaults = array('category' => 0);
63
+
64
+ $args = array( 'public' => true, '_builtin' => false );
65
+ $output = 'objects';
66
+ $taxonomies = get_taxonomies( $args, $output );
67
+ foreach ( $taxonomies as $taxonomy ) {
68
+ $customtaxorder_defaults[$taxonomy->name] = 0;
69
+ }
70
+
71
+ $customtaxorder_defaults = apply_filters( 'customtaxorder_defaults', $customtaxorder_defaults );
72
+ $customtaxorder_settings = get_option( 'customtaxorder_settings' );
73
+ $customtaxorder_settings = wp_parse_args( $customtaxorder_settings, $customtaxorder_defaults );
74
+
75
+ return $customtaxorder_settings;
76
+ }
77
+
78
+
79
  function customtaxorder_settings_validate($input) {
80
  $args = array( 'public' => true );
81
  $output = 'objects';
157
  * Sorting the query with get_terms() doesn't allow sorting with term_order
158
  */
159
  function customtax_cmp( $a, $b ) {
160
+ if ( (float) $a->term_order == (float) $b->term_order ) {
161
  return 0;
162
+ } else if ( (float) $a->term_order < (float) $b->term_order ) {
163
  return -1;
164
  } else {
165
  return 1;
314
  return $terms;
315
  }
316
  }
317
+ // Sort children after the ancestor, by using a float with "ancestor.child".
318
+ foreach ($terms as $term) {
319
+ if ( ! $term->parent == 0 ) {
320
+ $parents = get_ancestors( $term->term_id, $term->taxonomy, 'taxonomy' );
321
+ if ( is_array($parents) && !empty($parents) ) {
322
+ $ancestor_ID = array_pop( $parents );
323
+ $ancestor_term = get_term($ancestor_ID);
324
+ if ( is_object($ancestor_term) && isset($ancestor_term->term_order) ) {
325
+ $float = floatval($term->term_order) + 10000;
326
+ $term->term_order = floatval( strval($ancestor_term->term_order) . '.' . strval($float) );
327
+ }
328
+ }
329
+ }
330
+ }
331
  usort($terms, 'customtax_cmp');
332
  return $terms;
333
  }
434
  add_action('plugins_loaded', 'customtaxorder_load_lang');
435
 
436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
437
  /*
438
  * customtaxorder_activate
439
  * Function called at activation time.
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.6
6
- Stable tag: 2.8.0
7
  License: GPLv2 or later
8
 
9
 
@@ -134,6 +134,10 @@ The left metabox lists the toplevel terms. Right (or below) are the sub-terms.
134
 
135
  == Changelog ==
136
 
 
 
 
 
137
  = 2.8.0 =
138
  * 2016-10-04
139
  * Remove global var, add function customtaxorder_get_settings().
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.6
6
+ Stable tag: 2.8.1
7
  License: GPLv2 or later
8
 
9
 
134
 
135
  == Changelog ==
136
 
137
+ = 2.8.1 =
138
+ * 2016-10-06
139
+ * Sort children with a float as ancestor.child when set to term_order.
140
+
141
  = 2.8.0 =
142
  * 2016-10-04
143
  * Remove global var, add function customtaxorder_get_settings().