Custom Taxonomy Order NE - Version 3.0.0

Version Description

  • 2019-12-21
  • Always overwrite orderby according to our settings.
  • Add option to sort by slug.
  • Support new wp_initialize_site action for multisite.
  • Simplify checking for Link Manager plugin.
  • Small fixes found by the phan tool.
Download this release

Release Info

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

Code changes from version 2.10.0 to 3.0.0

Files changed (3) hide show
  1. customtaxorder.php +48 -21
  2. page-customtaxorder.php +6 -4
  3. readme.txt +24 -3
customtaxorder.php CHANGED
@@ -1,18 +1,18 @@
1
  <?php
2
  /*
3
  Plugin Name: Custom Taxonomy Order
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.10.0
7
  Author: Marcel Pol
8
- Author URI: http://zenoweb.nl/
9
  License: GPLv2 or later
10
  Text Domain: custom-taxonomy-order-ne
11
  Domain Path: /lang/
12
 
13
  /*
14
  Copyright 2011 - 2011 Drew Gourley
15
- Copyright 2013 - 2018 Marcel Pol (email: marcel@timelord.nl)
16
 
17
  This program is free software; you can redistribute it and/or
18
  modify it under the terms of the GNU General Public License
@@ -40,7 +40,7 @@ Domain Path: /lang/
40
 
41
 
42
  // Plugin Version
43
- define('CUSTOMTAXORDER_VER', '2.10.0');
44
 
45
 
46
  function customtaxorder_register_settings() {
@@ -53,7 +53,7 @@ add_action('admin_init', 'customtaxorder_register_settings');
53
  function customtaxorder_update_settings() {
54
  $options = customtaxorder_get_settings();
55
  if ( isset($options['update']) ) {
56
- echo '<div class="updated fade notice is-dismissible" id="message"><p>' . __('Custom Taxonomy Order NE settings', 'custom-taxonomy-order-ne') . ' ' . $options['update'] . '</p></div>';
57
  unset($options['update']);
58
  update_option('customtaxorder_settings', $options);
59
  }
@@ -89,7 +89,9 @@ function customtaxorder_settings_validate($input) {
89
  foreach ( $taxonomies as $taxonomy ) {
90
  if ( $input[$taxonomy->name] != 1 ) {
91
  if ( $input[$taxonomy->name] != 2 ) {
92
- $input[$taxonomy->name] = 0; //default
 
 
93
  }
94
  }
95
  }
@@ -115,12 +117,11 @@ function customtaxorder_menu() {
115
  $taxonomies = get_taxonomies($args, $output);
116
 
117
  // Also make the link_category available if activated.
118
- $linkplugin = 'link-manager/link-manager.php';
119
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
120
- if ( is_plugin_active($linkplugin) ) {
121
  $args = array( 'name' => 'link_category' );
122
- $taxonomies2 = get_taxonomies( $args, $output );
123
- $taxonomies = array_merge($taxonomies, $taxonomies2);
124
  }
125
 
126
  $taxonomies = customtaxorder_sort_taxonomies( $taxonomies );
@@ -252,14 +253,16 @@ add_action( 'customtaxorder_update_order', 'customtaxorder_flush_cache' );
252
 
253
 
254
  /*
255
- * Function to give dropdown options for the list of sub-taxonomies.
256
  */
257
  function customtaxorder_sub_query( $terms, $tax ) {
258
  $options = '';
259
- foreach ( $terms as $term ) {
260
- $subterms = get_term_children( $term->term_id, $tax );
261
- if ( $subterms ) {
262
- $options .= '<option value="' . $term->term_id . '">' . $term->name . '</option>';
 
 
263
  }
264
  }
265
  return $options;
@@ -289,14 +292,16 @@ function customtaxorder_apply_order_filter( $orderby, $args ) {
289
  $options[$taxonomy] = 0; // Default if it was not set in options yet.
290
  }
291
 
292
- if ( $args['orderby'] == 'term_order' ) {
293
  return 't.term_order';
294
- } elseif ( $args['orderby'] == 'name' ) {
295
  return 't.name';
296
- } elseif ( $options[$taxonomy] == 1 && !isset($_GET['orderby']) ) {
297
  return 't.term_order';
298
- } elseif ( $options[$taxonomy] == 2 && !isset($_GET['orderby']) ) {
299
  return 't.name';
 
 
300
  } else {
301
  return $orderby;
302
  }
@@ -326,6 +331,8 @@ function customtaxorder_get_terms_defaults( $query_var_defaults, $taxonomies ) {
326
  $query_var_defaults['orderby'] = 'term_order';
327
  } elseif ( $options[$taxonomy] == 2 ) {
328
  $query_var_defaults['orderby'] = 'name';
 
 
329
  }
330
 
331
  return $query_var_defaults;
@@ -567,6 +574,11 @@ function customtaxorder_activate($networkwide) {
567
  register_activation_hook( __FILE__, 'customtaxorder_activate' );
568
 
569
 
 
 
 
 
 
570
  function customtaxorder_activate_new_site($blog_id) {
571
  switch_to_blog($blog_id);
572
  _customtaxorder_activate();
@@ -575,6 +587,21 @@ function customtaxorder_activate_new_site($blog_id) {
575
  add_action( 'wpmu_new_blog', 'customtaxorder_activate_new_site' );
576
 
577
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
578
  // Include Settingspage
579
  include('page-customtaxorder.php');
580
  // Include functions for sorting taxonomies
1
  <?php
2
  /*
3
  Plugin Name: Custom Taxonomy Order
4
+ Plugin URI: https://zenoweb.nl/
5
  Description: Allows for the ordering of categories and custom taxonomy terms through a simple drag-and-drop interface.
6
+ Version: 3.0.0
7
  Author: Marcel Pol
8
+ Author URI: https://timelord.nl/
9
  License: GPLv2 or later
10
  Text Domain: custom-taxonomy-order-ne
11
  Domain Path: /lang/
12
 
13
  /*
14
  Copyright 2011 - 2011 Drew Gourley
15
+ Copyright 2013 - 2019 Marcel Pol (email: marcel@timelord.nl)
16
 
17
  This program is free software; you can redistribute it and/or
18
  modify it under the terms of the GNU General Public License
40
 
41
 
42
  // Plugin Version
43
+ define('CUSTOMTAXORDER_VER', '3.0.0');
44
 
45
 
46
  function customtaxorder_register_settings() {
53
  function customtaxorder_update_settings() {
54
  $options = customtaxorder_get_settings();
55
  if ( isset($options['update']) ) {
56
+ echo '<div class="updated fade notice is-dismissible" id="message"><p>' . __('Custom Taxonomy Order settings', 'custom-taxonomy-order-ne') . ' ' . $options['update'] . '</p></div>';
57
  unset($options['update']);
58
  update_option('customtaxorder_settings', $options);
59
  }
89
  foreach ( $taxonomies as $taxonomy ) {
90
  if ( $input[$taxonomy->name] != 1 ) {
91
  if ( $input[$taxonomy->name] != 2 ) {
92
+ if ( $input[$taxonomy->name] != 3 ) {
93
+ $input[$taxonomy->name] = 0; //default
94
+ }
95
  }
96
  }
97
  }
117
  $taxonomies = get_taxonomies($args, $output);
118
 
119
  // Also make the link_category available if activated.
120
+ $active_plugins = get_option('active_plugins');
121
+ if ( in_array( 'link-manager/link-manager.php', $active_plugins ) ) {
 
122
  $args = array( 'name' => 'link_category' );
123
+ $link_category = get_taxonomies( $args, $output );
124
+ $taxonomies = array_merge($taxonomies, $link_category);
125
  }
126
 
127
  $taxonomies = customtaxorder_sort_taxonomies( $taxonomies );
253
 
254
 
255
  /*
256
+ * Function to give dropdown options for the list of sub-terms.
257
  */
258
  function customtaxorder_sub_query( $terms, $tax ) {
259
  $options = '';
260
+ if ( isset( $terms ) && is_array( $terms ) ) {
261
+ foreach ( $terms as $term ) {
262
+ $subterms = get_term_children( $term->term_id, $tax );
263
+ if ( $subterms ) {
264
+ $options .= '<option value="' . $term->term_id . '">' . $term->name . '</option>';
265
+ }
266
  }
267
  }
268
  return $options;
292
  $options[$taxonomy] = 0; // Default if it was not set in options yet.
293
  }
294
 
295
+ if ( $args['orderby'] == 'term_order_' ) { // leave for now...
296
  return 't.term_order';
297
+ } elseif ( $args['orderby'] == 'name_' ) {
298
  return 't.name';
299
+ } elseif ( $options[$taxonomy] == 1 && ! isset($_GET['orderby']) ) {
300
  return 't.term_order';
301
+ } elseif ( $options[$taxonomy] == 2 && ! isset($_GET['orderby']) ) {
302
  return 't.name';
303
+ } elseif ( $options[$taxonomy] == 3 && ! isset($_GET['orderby']) ) {
304
+ return 't.slug';
305
  } else {
306
  return $orderby;
307
  }
331
  $query_var_defaults['orderby'] = 'term_order';
332
  } elseif ( $options[$taxonomy] == 2 ) {
333
  $query_var_defaults['orderby'] = 'name';
334
+ } elseif ( $options[$taxonomy] == 3 ) {
335
+ $query_var_defaults['orderby'] = 'slug';
336
  }
337
 
338
  return $query_var_defaults;
574
  register_activation_hook( __FILE__, 'customtaxorder_activate' );
575
 
576
 
577
+ /*
578
+ * Install database tables for new blog on MultiSite.
579
+ * Deprecated action since WP 5.1.0.
580
+ *
581
+ */
582
  function customtaxorder_activate_new_site($blog_id) {
583
  switch_to_blog($blog_id);
584
  _customtaxorder_activate();
587
  add_action( 'wpmu_new_blog', 'customtaxorder_activate_new_site' );
588
 
589
 
590
+ /*
591
+ * Install database tables for new blog on MultiSite.
592
+ * Used since WP 5.1.0.
593
+ * Do not use wp_insert_site, since the options table doesn't exist yet...
594
+ *
595
+ * @since 2.10.1
596
+ */
597
+ function customtaxorder_wp_initialize_site( $blog ) {
598
+ switch_to_blog( $blog->id );
599
+ _customtaxorder_activate();
600
+ restore_current_blog();
601
+ }
602
+ add_action( 'wp_initialize_site', 'customtaxorder_wp_initialize_site' );
603
+
604
+
605
  // Include Settingspage
606
  include('page-customtaxorder.php');
607
  // Include functions for sorting taxonomies
page-customtaxorder.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- * Admin Settingspage for Custom Taxonomy Order NE
4
  */
5
 
6
 
@@ -48,8 +48,8 @@ function customtaxorder() {
48
  }
49
 
50
  // Remove filter for WPML
51
- remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ), 10, 4 );
52
- remove_filter( 'get_terms', array( $sitepress, 'get_terms_filter' ) );
53
  ?>
54
  <div class='wrap customtaxorder'>
55
  <div id="icon-customtaxorder"></div>
@@ -94,7 +94,9 @@ function customtaxorder() {
94
  ';
95
  $settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="1" ' . checked('1', $options[$taxonomy->name], false) . ' /> ' . __('Custom Order as defined above.', 'custom-taxonomy-order-ne') . '</label><br />
96
  ';
97
- $settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="2" ' . checked('2', $options[$taxonomy->name], false) . ' /> ' . __('Alphabetical Order.', 'custom-taxonomy-order-ne') . '</label><br />
 
 
98
  ';
99
  $tax_label = $taxonomy->label;
100
  $tax = $taxonomy->name;
1
  <?php
2
  /*
3
+ * Admin Settingspage for Custom Taxonomy Order
4
  */
5
 
6
 
48
  }
49
 
50
  // Remove filter for WPML
51
+ remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ), 10 );
52
+ remove_filter( 'get_terms', array( $sitepress, 'get_terms_filter' ),10 );
53
  ?>
54
  <div class='wrap customtaxorder'>
55
  <div id="icon-customtaxorder"></div>
94
  ';
95
  $settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="1" ' . checked('1', $options[$taxonomy->name], false) . ' /> ' . __('Custom Order as defined above.', 'custom-taxonomy-order-ne') . '</label><br />
96
  ';
97
+ $settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="2" ' . checked('2', $options[$taxonomy->name], false) . ' /> ' . __('Alphabetical Order by name.', 'custom-taxonomy-order-ne') . '</label><br />
98
+ ';
99
+ $settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="3" ' . checked('3', $options[$taxonomy->name], false) . ' /> ' . __('Alphabetical Order by slug.', 'custom-taxonomy-order-ne') . '</label><br />
100
  ';
101
  $tax_label = $taxonomy->label;
102
  $tax = $taxonomy->name;
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: mpol
3
  Tags: term order, category order, taxonomy order, order
4
  Requires at least: 3.7
5
- Tested up to: 4.9
6
- Stable tag: 2.10.0
7
  License: GPLv2 or later
8
 
9
 
@@ -25,6 +25,10 @@ It supports the following features:
25
  * Custom functions to order the taxonomies themselves.
26
  * There is no Pro version, everything works in the Free version.
27
 
 
 
 
 
28
 
29
  == Installation ==
30
 
@@ -35,10 +39,19 @@ It supports the following features:
35
  5. Optionally set `'orderby' => 'term_order', 'order' => 'ASC'` to manually sort queries by this order.
36
  6. Enjoy!
37
 
38
- == Upgrade Notice ==
39
 
40
  If you update from the original Custom Taxonomy Order please deactivate that first, then activate this plugin.
41
 
 
 
 
 
 
 
 
 
 
42
  == Frequently Asked Questions ==
43
 
44
  = I sorted the terms in the WordPress backend, but I don't see it changed in the frontend =
@@ -148,6 +161,14 @@ The left metabox lists the toplevel terms. Right (or below) are the sub-terms.
148
 
149
  == Changelog ==
150
 
 
 
 
 
 
 
 
 
151
  = 2.10.0 =
152
  * 2018-10-17
153
  * Sort attributes for WooCommerce automatically.
2
  Contributors: mpol
3
  Tags: term order, category order, taxonomy order, order
4
  Requires at least: 3.7
5
+ Tested up to: 5.3
6
+ Stable tag: 3.0.0
7
  License: GPLv2 or later
8
 
9
 
25
  * Custom functions to order the taxonomies themselves.
26
  * There is no Pro version, everything works in the Free version.
27
 
28
+ = Compatibility =
29
+
30
+ This plugin is compatible with [ClassicPress](https://www.classicpress.net).
31
+
32
 
33
  == Installation ==
34
 
39
  5. Optionally set `'orderby' => 'term_order', 'order' => 'ASC'` to manually sort queries by this order.
40
  6. Enjoy!
41
 
42
+ = Upgrade Notice =
43
 
44
  If you update from the original Custom Taxonomy Order please deactivate that first, then activate this plugin.
45
 
46
+ = Removal of database changes =
47
+
48
+ First you can disable the plugin. Then in wp_options you can delete the field:
49
+ * customtaxorder_settings
50
+ * customtaxorder_taxonomies
51
+
52
+ In wp_terms you can remove the column
53
+ * term_order
54
+
55
  == Frequently Asked Questions ==
56
 
57
  = I sorted the terms in the WordPress backend, but I don't see it changed in the frontend =
161
 
162
  == Changelog ==
163
 
164
+ = 3.0.0 =
165
+ * 2019-12-21
166
+ * Always overwrite orderby according to our settings.
167
+ * Add option to sort by slug.
168
+ * Support new wp_initialize_site action for multisite.
169
+ * Simplify checking for Link Manager plugin.
170
+ * Small fixes found by the phan tool.
171
+
172
  = 2.10.0 =
173
  * 2018-10-17
174
  * Sort attributes for WooCommerce automatically.