Custom Taxonomy Order NE - Version 3.4.4

Version Description

  • 2022-07-27
  • Use correct value for updating term_relationships table. this should fix some reported issues where the problem was unclear.
  • On updating order, list the number of terms that were updated.
Download this release

Release Info

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

Code changes from version 3.4.3 to 3.4.4

admin-customtaxorder.php CHANGED
@@ -220,38 +220,50 @@ add_action( 'edit_term', 'customtaxorder_add_term_order', 10, 3 );
220
 
221
  /*
222
  * Set `term_order` in database for term.
 
223
  * @since 3.1.0
 
224
  * @param int $term_id The ID of the term.
225
  * @param int $term_order The order of the term.
226
  * @param string $taxonomy Taxonomy of the term.
 
 
227
  */
228
  function customtaxorder_set_db_term_order( $term_id = 0, $term_order = 0, $taxonomy = '' ) {
229
  global $wpdb;
230
 
231
  if ( $term_id == 0 ) {
232
- return;
233
  }
234
  $term = get_term( $term_id, $taxonomy );
235
  if ( ! is_object( $term ) ) {
236
- return;
237
  }
238
 
239
- $wpdb->query( $wpdb->prepare(
240
  "
241
  UPDATE $wpdb->terms SET term_order = '%d' WHERE term_id ='%d'
242
  ",
243
  $term_order,
244
  $term_id
245
  ) );
246
- $wpdb->query( $wpdb->prepare(
247
  "
248
  UPDATE $wpdb->term_relationships SET term_order = '%d' WHERE term_taxonomy_id ='%d'
249
  ",
250
  $term_order,
251
- $term_id
252
  ) );
253
 
254
  clean_term_cache( $term_id, $taxonomy );
 
 
 
 
 
 
 
 
255
  }
256
 
257
 
220
 
221
  /*
222
  * Set `term_order` in database for term.
223
+ *
224
  * @since 3.1.0
225
+ *
226
  * @param int $term_id The ID of the term.
227
  * @param int $term_order The order of the term.
228
  * @param string $taxonomy Taxonomy of the term.
229
+ *
230
+ * @return int 0 if no term was updated, 1 if term was updated. Usefull for using a counter in a message. (since 3.4.4)
231
  */
232
  function customtaxorder_set_db_term_order( $term_id = 0, $term_order = 0, $taxonomy = '' ) {
233
  global $wpdb;
234
 
235
  if ( $term_id == 0 ) {
236
+ return 0;
237
  }
238
  $term = get_term( $term_id, $taxonomy );
239
  if ( ! is_object( $term ) ) {
240
+ return 0;
241
  }
242
 
243
+ $result1 = $wpdb->query( $wpdb->prepare(
244
  "
245
  UPDATE $wpdb->terms SET term_order = '%d' WHERE term_id ='%d'
246
  ",
247
  $term_order,
248
  $term_id
249
  ) );
250
+ $result2 = $wpdb->query( $wpdb->prepare(
251
  "
252
  UPDATE $wpdb->term_relationships SET term_order = '%d' WHERE term_taxonomy_id ='%d'
253
  ",
254
  $term_order,
255
+ $term->term_taxonomy_id
256
  ) );
257
 
258
  clean_term_cache( $term_id, $taxonomy );
259
+
260
+ if ( $result1 > 0 && $result2 > 0 ) {
261
+ // results are the rows affected according to $wpdb->query()
262
+ return 1;
263
+
264
+ }
265
+ return 0;
266
+
267
  }
268
 
269
 
customtaxorder.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Custom Taxonomy Order
4
  Plugin URI: https://wordpress.org/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: 3.4.3
7
  Author: Marcel Pol
8
  Author URI: https://timelord.nl/
9
  License: GPLv2 or later
@@ -39,7 +39,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
39
 
40
 
41
  // Plugin Version
42
- define('CUSTOMTAXORDER_VER', '3.4.3');
43
 
44
 
45
  /*
3
  Plugin Name: Custom Taxonomy Order
4
  Plugin URI: https://wordpress.org/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: 3.4.4
7
  Author: Marcel Pol
8
  Author URI: https://timelord.nl/
9
  License: GPLv2 or later
39
 
40
 
41
  // Plugin Version
42
+ define('CUSTOMTAXORDER_VER', '3.4.4');
43
 
44
 
45
  /*
page-customtaxorder.php CHANGED
@@ -279,16 +279,20 @@ function customtaxorder_update_order() {
279
  $submitted_ids = explode(',', $new_order);
280
  $updated_ids = array();
281
  $result = count($submitted_ids);
 
282
  for ( $i = 0; $i < $result; $i++ ) {
283
  $term_id = (int) str_replace('id_', '', $submitted_ids[$i]);
284
  $term_order = $i + $parent_id_order;
285
 
286
- customtaxorder_set_db_term_order( $term_id, $term_order );
 
287
 
288
  $updated_ids[] = $term_id;
289
  }
290
- echo '<div id="message" class="updated fade notice is-dismissible"><p>'. esc_html__('Order updated successfully.', 'custom-taxonomy-order-ne').'</p></div>';
291
- do_action('customtaxorder_update_order', $updated_ids);
 
 
292
 
293
  }
294
 
279
  $submitted_ids = explode(',', $new_order);
280
  $updated_ids = array();
281
  $result = count($submitted_ids);
282
+ $counter_updated_terms = 0;
283
  for ( $i = 0; $i < $result; $i++ ) {
284
  $term_id = (int) str_replace('id_', '', $submitted_ids[$i]);
285
  $term_order = $i + $parent_id_order;
286
 
287
+ $counter = (int) customtaxorder_set_db_term_order( $term_id, $term_order );
288
+ $counter_updated_terms = $counter_updated_terms + $counter;
289
 
290
  $updated_ids[] = $term_id;
291
  }
292
+ echo '<div id="message" class="updated fade notice is-dismissible"><p>' .
293
+ sprintf( _n( 'Order of %d term updated.', 'Order of %d terms updated.', $counter_updated_terms, 'custom-taxonomy-order-ne' ), $counter_updated_terms ) .
294
+ '</p></div>';
295
+ do_action('customtaxorder_update_order', $updated_ids, $counter_updated_terms);
296
 
297
  }
298
 
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Custom Taxonomy Order ===
2
  Contributors: mpol
3
  Tags: term order, category order, taxonomy order, order
4
- Requires at least: 3.7
5
- Tested up to: 6.0
6
- Stable tag: 3.4.3
7
  License: GPLv2 or later
8
 
9
 
@@ -31,7 +31,7 @@ This plugin is compatible with [ClassicPress](https://www.classicpress.net).
31
 
32
  = Contributions =
33
 
34
- This plugin is also available in [GitLab](https://gitlab.com/toomanybicycles/custom-taxonomy-order-ne)
35
 
36
 
37
  == Installation ==
@@ -213,6 +213,12 @@ The left metabox lists the toplevel terms. Right (or below) are the sub-terms.
213
 
214
  == Changelog ==
215
 
 
 
 
 
 
 
216
  = 3.4.3 =
217
  * 2022-04-30
218
  * Ouch, don't do those calculations on frontend either when there are too many terms, it is too expensive.
1
  === Custom Taxonomy Order ===
2
  Contributors: mpol
3
  Tags: term order, category order, taxonomy order, order
4
+ Requires at least: 4.1
5
+ Tested up to: 6.1
6
+ Stable tag: 3.4.4
7
  License: GPLv2 or later
8
 
9
 
31
 
32
  = Contributions =
33
 
34
+ This plugin is also available in [Codeberg](https://codeberg.org/cyclotouriste/custom-taxonomy-order-ne).
35
 
36
 
37
  == Installation ==
213
 
214
  == Changelog ==
215
 
216
+ = 3.4.4 =
217
+ * 2022-07-27
218
+ * Use correct value for updating `term_relationships` table.
219
+ this should fix some reported issues where the problem was unclear.
220
+ * On updating order, list the number of terms that were updated.
221
+
222
  = 3.4.3 =
223
  * 2022-04-30
224
  * Ouch, don't do those calculations on frontend either when there are too many terms, it is too expensive.