Custom Taxonomy Order NE - Version 3.1.0

Version Description

  • 2020-03-23
  • Add term_order field to edit screen of terms (thanks @li-an).
  • Add order button for slug (thanks @eric3d).
  • Only load admin functions at dashboard.
  • Remove included es_ES po file, it is maintained in GlotPress.
Download this release

Release Info

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

Code changes from version 3.0.1 to 3.1.0

admin-customtaxorder.php ADDED
@@ -0,0 +1,301 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ function customtaxorder_register_settings() {
5
+ register_setting('customtaxorder_settings', 'customtaxorder_settings', 'customtaxorder_settings_validate');
6
+ register_setting('customtaxorder_settings', 'customtaxorder_taxonomies', 'customtaxorder_taxonomies_validate');
7
+ }
8
+ add_action('admin_init', 'customtaxorder_register_settings');
9
+
10
+
11
+ function customtaxorder_settings_validate($input) {
12
+ $args = array( 'public' => true );
13
+ $output = 'objects';
14
+ $taxonomies = get_taxonomies( $args, $output );
15
+ foreach ( $taxonomies as $taxonomy ) {
16
+ if ( $input[$taxonomy->name] != 1 ) {
17
+ if ( $input[$taxonomy->name] != 2 ) {
18
+ if ( $input[$taxonomy->name] != 3 ) {
19
+ $input[$taxonomy->name] = 0; //default
20
+ }
21
+ }
22
+ }
23
+ }
24
+ $output = array();
25
+ foreach ( $input as $key => $value) {
26
+ $key = (string) sanitize_text_field( $key );
27
+ $output[$key] = (int) $value;
28
+ }
29
+ return $output;
30
+ }
31
+ function customtaxorder_taxonomies_validate($input) {
32
+ $input = (string) sanitize_text_field( $input );
33
+ return $input;
34
+ }
35
+
36
+
37
+ /*
38
+ * Add all the admin menu pages.
39
+ */
40
+ function customtaxorder_menu() {
41
+ $args = array( 'public' => true );
42
+ $output = 'objects';
43
+ $taxonomies = get_taxonomies($args, $output);
44
+
45
+ // Also make the link_category available if activated.
46
+ $active_plugins = get_option('active_plugins');
47
+ if ( in_array( 'link-manager/link-manager.php', $active_plugins ) ) {
48
+ $args = array( 'name' => 'link_category' );
49
+ $link_category = get_taxonomies( $args, $output );
50
+ $taxonomies = array_merge($taxonomies, $link_category);
51
+ }
52
+
53
+ $taxonomies = customtaxorder_sort_taxonomies( $taxonomies );
54
+ // Set your custom capability through this filter.
55
+ $custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
56
+
57
+ //add_menu_page( string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '', string $icon_url = '', int $position = null )
58
+ add_menu_page(__('Term Order', 'custom-taxonomy-order-ne'), __('Term Order', 'custom-taxonomy-order-ne'), $custom_cap, 'customtaxorder', 'customtaxorder_subpage', 'dashicons-list-view', 122.35);
59
+ //add_submenu_page( string $parent_slug, string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '', int $position = null )
60
+ add_submenu_page('customtaxorder', __('Order Taxonomies', 'custom-taxonomy-order-ne'), __('Order Taxonomies', 'custom-taxonomy-order-ne'), $custom_cap, 'customtaxorder-taxonomies', 'custom_taxonomy_order');
61
+
62
+ foreach ($taxonomies as $taxonomy ) {
63
+ // Set your finegrained capability for this taxonomy for this custom filter.
64
+ $custom_cap_tax = apply_filters( 'customtaxorder_custom_cap_' . $taxonomy->name, $custom_cap );
65
+ add_submenu_page('customtaxorder', __('Order ', 'custom-taxonomy-order-ne') . $taxonomy->label, __('Order ', 'custom-taxonomy-order-ne') . $taxonomy->label, $custom_cap_tax, 'customtaxorder-'.$taxonomy->name, 'customtaxorder_subpage');
66
+ }
67
+ add_submenu_page('customtaxorder', __('About', 'custom-taxonomy-order-ne'), __('About', 'custom-taxonomy-order-ne'), $custom_cap, 'customtaxorder-about', 'customtaxorder_about');
68
+ }
69
+ add_action('admin_menu', 'customtaxorder_menu');
70
+
71
+
72
+ function customtaxorder_css() {
73
+ if ( isset($_GET['page']) ) {
74
+ $pos_page = $_GET['page'];
75
+ $pos_args = 'customtaxorder';
76
+ $pos = strpos($pos_page,$pos_args);
77
+ if ( $pos === false ) {} else {
78
+ wp_enqueue_style('customtaxorder', plugins_url( 'css/customtaxorder.css', __FILE__), false, CUSTOMTAXORDER_VER, 'screen' );
79
+ }
80
+ }
81
+ }
82
+ add_action('admin_print_styles', 'customtaxorder_css');
83
+
84
+
85
+ function customtaxorder_js_libs() {
86
+ if ( isset($_GET['page']) ) {
87
+ $pos_page = $_GET['page'];
88
+ $pos_args = 'customtaxorder';
89
+ $pos = strpos($pos_page,$pos_args);
90
+ if ( $pos === false ) {} else {
91
+ wp_enqueue_script( 'jquery' );
92
+ wp_enqueue_script( 'jquery-ui-core' );
93
+ wp_enqueue_script( 'jquery-ui-sortable' );
94
+ wp_enqueue_script( 'customtaxorder', plugins_url( '/js/script.js', __FILE__ ), 'jquery-ui-sortable', CUSTOMTAXORDER_VER, true );
95
+ }
96
+ }
97
+ }
98
+ add_action('admin_print_scripts', 'customtaxorder_js_libs');
99
+
100
+
101
+ /*
102
+ * Add term_order input to tag edit screen.
103
+ * @since 3.1.0
104
+ */
105
+ function customtaxorder_tag_edit_screen() {
106
+ $options = customtaxorder_get_settings();
107
+ $args = array( 'public' => true );
108
+ $output = 'objects';
109
+ $taxonomies = get_taxonomies($args, $output);
110
+
111
+ // Also make the link_category available if activated.
112
+ $active_plugins = get_option('active_plugins');
113
+ if ( in_array( 'link-manager/link-manager.php', $active_plugins ) ) {
114
+ $args = array( 'name' => 'link_category' );
115
+ $link_category = get_taxonomies( $args, $output );
116
+ $taxonomies = array_merge($taxonomies, $link_category);
117
+ }
118
+ foreach ( $taxonomies as $taxonomy ) {
119
+ if ( is_object($taxonomy) && isset($taxonomy->name) ) {
120
+ if ( ! isset($options[$taxonomy->name]) ) {
121
+ $options[$taxonomy->name] = 0; // default if not set in options yet
122
+ }
123
+ if ( $options[$taxonomy->name] == 1 ) { // only when custom order is enabled.
124
+ add_action( "{$taxonomy->name}_add_form_fields", 'customtaxorder_term_order_add_form_field', 10, 1 );
125
+ add_action( "{$taxonomy->name}_edit_form_fields", 'customtaxorder_term_order_edit_form_field', 10, 2 );
126
+ }
127
+ }
128
+ }
129
+ }
130
+ add_action( 'admin_init', 'customtaxorder_tag_edit_screen' );
131
+
132
+
133
+ /*
134
+ * Output the "term_order" form field when adding a new term.
135
+ * @param string $taxonomy the name of the taxonomy.
136
+ * @since 3.1.0
137
+ */
138
+ function customtaxorder_term_order_add_form_field( $taxonomy ) {
139
+ $options = customtaxorder_get_settings();
140
+ if ( isset($options[$taxonomy]) && $options[$taxonomy] == 1 ) {
141
+ ?>
142
+ <div class="form-field form-required">
143
+ <label for="term_order">
144
+ <?php esc_html_e( 'Order', 'custom-taxonomy-order-ne' ); ?>
145
+ </label>
146
+ <input type="number" pattern="[0-9.]+" name="term_order" id="term_order" value="0" size="11">
147
+ <p class="description">
148
+ <?php esc_html_e( 'This taxonomy is sorted based on custom order. You can choose your own order by entering a number (1 for first, etc.) in this field.', 'custom-taxonomy-order-ne' ); ?>
149
+ </p>
150
+ </div>
151
+ <?php
152
+ }
153
+ }
154
+
155
+
156
+ /*
157
+ * Output the "term_order" form field when editing an existing term.
158
+ * @param object $term
159
+ * @param string $taxonomy the name of the taxonomy.
160
+ * @since 3.1.0
161
+ */
162
+ function customtaxorder_term_order_edit_form_field( $term = false, $taxonomy ) {
163
+ $options = customtaxorder_get_settings();
164
+ if ( isset($options[$taxonomy]) && $options[$taxonomy] == 1 ) {
165
+ if ( is_object($term) && isset($term->term_order) ) {
166
+ $term_order = $term->term_order;
167
+ } else {
168
+ $term_order = 0;
169
+ }
170
+ ?>
171
+ <tr class="form-field">
172
+ <th scope="row" valign="top">
173
+ <label for="term_order">
174
+ <?php esc_html_e( 'Order', 'custom-taxonomy-order-ne' ); ?>
175
+ </label>
176
+ </th>
177
+ <td>
178
+ <input name="term_order" id="term_order" type="text" value="<?php echo $term_order; ?>" size="11" />
179
+ <p class="description">
180
+ <?php
181
+ esc_html_e( 'This taxonomy is sorted based on custom order. You can choose your own order by entering a number (1 for first, etc.) in this field.', 'custom-taxonomy-order-ne' );
182
+ if ( isset($term->parent) && $term->parent != 0 ) {
183
+ echo '<br />';
184
+ esc_html_e( 'This sub-term will be sorted after the parent term, the order entered here is relative to other sub-terms.', 'custom-taxonomy-order-ne' );
185
+ }
186
+ ?>
187
+ </p>
188
+ </td>
189
+ </tr>
190
+ <?php
191
+ }
192
+ }
193
+
194
+
195
+ /*
196
+ * Set `term_order` to term when updating
197
+ * @since 3.1.0
198
+ * @param int $term_id The ID of the term
199
+ * @param int $tt_id Not used
200
+ * @param string $taxonomy Taxonomy of the term
201
+ */
202
+ function customtaxorder_add_term_order( $term_id = 0, $tt_id = 0, $taxonomy = '' ) {
203
+ if ( ! isset($_POST['term_order']) ) {
204
+ return;
205
+ }
206
+ if ( $term_id == 0 ) {
207
+ return;
208
+ }
209
+ $term = get_term( $term_id, $taxonomy );
210
+ if ( ! is_object( $term ) ) {
211
+ return;
212
+ }
213
+
214
+ $term_order = (int) $_POST['term_order'];
215
+
216
+ customtaxorder_set_db_term_order( $term_id, $term_order, $taxonomy );
217
+ }
218
+ add_action( 'create_term', 'customtaxorder_add_term_order', 10, 3 );
219
+ add_action( 'edit_term', 'customtaxorder_add_term_order', 10, 3 );
220
+
221
+
222
+
223
+ /*
224
+ * Set `term_order` in database for term.
225
+ * @since 3.1.0
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
+ function customtaxorder_set_db_term_order( $term_id = 0, $term_order = 0, $taxonomy = '' ) {
231
+ global $wpdb;
232
+
233
+ if ( $term_id == 0 ) {
234
+ return;
235
+ }
236
+ $term = get_term( $term_id, $taxonomy );
237
+ if ( ! is_object( $term ) ) {
238
+ return;
239
+ }
240
+
241
+ $wpdb->query( $wpdb->prepare(
242
+ "
243
+ UPDATE $wpdb->terms SET term_order = '%d' WHERE term_id ='%d'
244
+ ",
245
+ $term_order,
246
+ $term_id
247
+ ) );
248
+ $wpdb->query( $wpdb->prepare(
249
+ "
250
+ UPDATE $wpdb->term_relationships SET term_order = '%d' WHERE term_taxonomy_id ='%d'
251
+ ",
252
+ $term_order,
253
+ $term_id
254
+ ) );
255
+
256
+ clean_term_cache( $term_id, $taxonomy );
257
+ }
258
+
259
+
260
+ /*
261
+ * About page with text.
262
+ */
263
+ function customtaxorder_about() {
264
+ ?>
265
+ <div class='wrap'>
266
+ <h1><?php _e('About Custom Taxonomy Order NE', 'custom-taxonomy-order-ne'); ?></h1>
267
+ <div id="poststuff" class="metabox-holder">
268
+ <div class="widget">
269
+ <h2 class="widget-top"><?php _e('About this plugin.', 'custom-taxonomy-order-ne'); ?></h2>
270
+ <p><?php _e('This plugin is being maintained by Marcel Pol from', 'custom-taxonomy-order-ne'); ?>
271
+ <a href="http://zenoweb.nl" target="_blank" title="ZenoWeb">ZenoWeb</a>.
272
+ </p>
273
+
274
+ <h2 class="widget-top"><?php _e('Review this plugin.', 'custom-taxonomy-order-ne'); ?></h2>
275
+ <p><?php _e('If this plugin has any value to you, then please leave a review at', 'custom-taxonomy-order-ne'); ?>
276
+ <a href="https://wordpress.org/support/view/plugin-reviews/custom-taxonomy-order-ne?rate=5#postform" target="_blank" title="<?php esc_attr_e('The plugin page at wordpress.org.', 'custom-taxonomy-order-ne'); ?>">
277
+ <?php _e('the plugin page at wordpress.org', 'custom-taxonomy-order-ne'); ?></a>.
278
+ </p>
279
+
280
+ <h2 class="widget-top"><?php _e('Donate to the maintainer.', 'custom-taxonomy-order-ne'); ?></h2>
281
+ <p><?php _e('If you want to donate to the maintainer of the plugin, you can donate through PayPal.', 'custom-taxonomy-order-ne'); ?></p>
282
+ <p><?php _e('Donate through', 'custom-taxonomy-order-ne'); ?> <a href="https://www.paypal.com" target="_blank" title="<?php esc_attr_e('Donate to the maintainer.', 'custom-taxonomy-order-ne'); ?>"><?php _e('PayPal', 'custom-taxonomy-order-ne'); ?></a>
283
+ <?php _e('to', 'custom-taxonomy-order-ne'); ?> marcel@timelord.nl.
284
+ </p>
285
+ </div>
286
+ </div>
287
+ </div>
288
+ <?php
289
+ }
290
+
291
+
292
+ /*
293
+ * Add Settings link to the main plugin page.
294
+ */
295
+ function customtaxorder_links( $links, $file ) {
296
+ if ( $file == plugin_basename( dirname(__FILE__).'/customtaxorder.php' ) ) {
297
+ $links[] = '<a href="' . admin_url( 'admin.php?page=customtaxorder' ) . '">' . __( 'Settings', 'custom-taxonomy-order-ne' ) . '</a>';
298
+ }
299
+ return $links;
300
+ }
301
+ add_filter( 'plugin_action_links', 'customtaxorder_links', 10, 2 );
css/customtaxorder.css CHANGED
@@ -58,6 +58,10 @@ Plugin URI: http://timelord.nl/
58
  margin: 3px auto;
59
  height: 30px;
60
  }
 
 
 
 
61
 
62
  /* Dark Mode */
63
  .dark-mode .customtaxorder h2.widget-top,
58
  margin: 3px auto;
59
  height: 30px;
60
  }
61
+ .customtaxorder #publishing-action-return-sub-posts {
62
+ margin: 0 0 10px 0;
63
+ }
64
+
65
 
66
  /* Dark Mode */
67
  .dark-mode .customtaxorder h2.widget-top,
css/index.html ADDED
File without changes
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.0.1
7
  Author: Marcel Pol
8
  Author URI: https://timelord.nl/
9
  License: GPLv2 or later
@@ -30,34 +30,17 @@ Domain Path: /lang/
30
  */
31
 
32
 
33
- /* TODO:
 
34
  * - Add pagination, just like next_post_link().
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', '3.0.1');
44
-
45
-
46
- function customtaxorder_register_settings() {
47
- register_setting('customtaxorder_settings', 'customtaxorder_settings', 'customtaxorder_settings_validate');
48
- register_setting('customtaxorder_settings', 'customtaxorder_taxonomies', 'customtaxorder_taxonomies_validate');
49
- }
50
- add_action('admin_init', 'customtaxorder_register_settings');
51
-
52
-
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
- }
60
- }
61
 
62
 
63
  /*
@@ -82,94 +65,6 @@ function customtaxorder_get_settings() {
82
  }
83
 
84
 
85
- function customtaxorder_settings_validate($input) {
86
- $args = array( 'public' => true );
87
- $output = 'objects';
88
- $taxonomies = get_taxonomies( $args, $output );
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
- }
98
- $output = array();
99
- foreach ( $input as $key => $value) {
100
- $key = (string) sanitize_text_field( $key );
101
- $output[$key] = (int) $value;
102
- }
103
- return $output;
104
- }
105
- function customtaxorder_taxonomies_validate($input) {
106
- $input = (string) sanitize_text_field( $input );
107
- return $input;
108
- }
109
-
110
-
111
- /*
112
- * Add all the admin menu pages.
113
- */
114
- function customtaxorder_menu() {
115
- $args = array( 'public' => true );
116
- $output = 'objects';
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 );
128
- // Set your custom capability through this filter.
129
- $custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
130
-
131
- add_menu_page(__('Term Order', 'customtaxorder'), __('Term Order', 'custom-taxonomy-order-ne'), $custom_cap, 'customtaxorder', 'customtaxorder', 'dashicons-list-view', 122.35);
132
- add_submenu_page('customtaxorder', __('Order Taxonomies', 'custom-taxonomy-order-ne'), __('Order Taxonomies', 'custom-taxonomy-order-ne'), $custom_cap, 'customtaxorder-taxonomies', 'custom_taxonomy_order');
133
-
134
- foreach ($taxonomies as $taxonomy ) {
135
- // Set your finegrained capability for this taxonomy for this custom filter.
136
- $custom_cap_tax = apply_filters( 'customtaxorder_custom_cap_' . $taxonomy->name, $custom_cap );
137
- add_submenu_page('customtaxorder', __('Order ', 'custom-taxonomy-order-ne') . $taxonomy->label, __('Order ', 'custom-taxonomy-order-ne') . $taxonomy->label, $custom_cap_tax, 'customtaxorder-'.$taxonomy->name, 'customtaxorder');
138
- }
139
- add_submenu_page('customtaxorder', __('About', 'custom-taxonomy-order-ne'), __('About', 'custom-taxonomy-order-ne'), $custom_cap, 'customtaxorder-about', 'customtaxorder_about');
140
- }
141
- add_action('admin_menu', 'customtaxorder_menu');
142
-
143
-
144
- function customtaxorder_css() {
145
- if ( isset($_GET['page']) ) {
146
- $pos_page = $_GET['page'];
147
- $pos_args = 'customtaxorder';
148
- $pos = strpos($pos_page,$pos_args);
149
- if ( $pos === false ) {} else {
150
- wp_enqueue_style('customtaxorder', plugins_url( 'css/customtaxorder.css', __FILE__), false, CUSTOMTAXORDER_VER, 'screen' );
151
- }
152
- }
153
- }
154
- add_action('admin_print_styles', 'customtaxorder_css');
155
-
156
-
157
- function customtaxorder_js_libs() {
158
- if ( isset($_GET['page']) ) {
159
- $pos_page = $_GET['page'];
160
- $pos_args = 'customtaxorder';
161
- $pos = strpos($pos_page,$pos_args);
162
- if ( $pos === false ) {} else {
163
- wp_enqueue_script( 'jquery' );
164
- wp_enqueue_script( 'jquery-ui-core' );
165
- wp_enqueue_script( 'jquery-ui-sortable' );
166
- wp_enqueue_script( 'customtaxorder', plugins_url( '/js/script.js', __FILE__ ), 'jquery-ui-sortable', CUSTOMTAXORDER_VER, true );
167
- }
168
- }
169
- }
170
- add_action('admin_print_scripts', 'customtaxorder_js_libs');
171
-
172
-
173
  /*
174
  * customtax_cmp
175
  * Sorting of an array with objects, ordered by term_order
@@ -186,60 +81,6 @@ function customtax_cmp( $a, $b ) {
186
  }
187
 
188
 
189
- /*
190
- * customtaxorder_update_order
191
- * Function to update the database with the submitted order
192
- */
193
- function customtaxorder_update_order() {
194
-
195
- /* Check Nonce */
196
- $verified = false;
197
- if ( isset($_POST['custom-taxonomy-order-ne-nonce']) ) {
198
- $verified = wp_verify_nonce( $_POST['custom-taxonomy-order-ne-nonce'], 'custom-taxonomy-order-ne-nonce' );
199
- }
200
- if ( $verified == false ) {
201
- // Nonce is invalid.
202
- echo '<div id="message" class="error fade notice is-dismissible"><p>' . __('The Nonce did not validate. Please try again.', 'custom-taxonomy-order-ne') . '</p></div>';
203
- return;
204
- }
205
-
206
- if (isset($_POST['hidden-custom-order']) && $_POST['hidden-custom-order'] != "") {
207
- global $wpdb;
208
- $parent_ID_order = 0;
209
- if ( isset($_POST['hidden-parent-id-order']) && $_POST['hidden-parent-id-order'] > 0 ) {
210
- $parent_ID_order = (int) $_POST['hidden-parent-id-order'] + 1;
211
- }
212
- $new_order = $_POST['hidden-custom-order'];
213
- $IDs = explode(",", $new_order);
214
- $ids = Array();
215
- $result = count($IDs);
216
- for($i = 0; $i < $result; $i++) {
217
- $id = (int) str_replace("id_", "", $IDs[$i]);
218
- $j = $i + $parent_ID_order;
219
- $wpdb->query( $wpdb->prepare(
220
- "
221
- UPDATE $wpdb->terms SET term_order = '%d' WHERE term_id ='%d'
222
- ",
223
- $j,
224
- $id
225
- ) );
226
- $wpdb->query( $wpdb->prepare(
227
- "
228
- UPDATE $wpdb->term_relationships SET term_order = '%d' WHERE term_taxonomy_id ='%d'
229
- ",
230
- $j,
231
- $id
232
- ) );
233
- $ids[] = $id;
234
- }
235
- echo '<div id="message" class="updated fade notice is-dismissible"><p>'. __('Order updated successfully.', 'custom-taxonomy-order-ne').'</p></div>';
236
- do_action('customtaxorder_update_order', $ids);
237
- } else {
238
- echo '<div id="message" class="error fade notice is-dismissible"><p>'. __('An error occured, order has not been saved.', 'custom-taxonomy-order-ne').'</p></div>';
239
- }
240
- }
241
-
242
-
243
  /*
244
  * Flush object cache when order is changed in taxonomy ordering plugin.
245
  *
@@ -252,23 +93,6 @@ function customtaxorder_flush_cache() {
252
  add_action( 'customtaxorder_update_order', 'customtaxorder_flush_cache' );
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;
269
- }
270
-
271
-
272
  /*
273
  * Function to sort the standard WordPress Queries for terms.
274
  *
@@ -495,50 +319,6 @@ function customtaxorder_woocommerce_attribute_taxonomies_public( $attribute_taxo
495
  add_filter( 'woocommerce_attribute_taxonomies', 'customtaxorder_woocommerce_attribute_taxonomies_public' );
496
 
497
 
498
- /*
499
- * About page with text.
500
- */
501
- function customtaxorder_about() {
502
- ?>
503
- <div class='wrap'>
504
- <h1><?php _e('About Custom Taxonomy Order NE', 'custom-taxonomy-order-ne'); ?></h1>
505
- <div id="poststuff" class="metabox-holder">
506
- <div class="widget">
507
- <h2 class="widget-top"><?php _e('About this plugin.', 'custom-taxonomy-order-ne'); ?></h2>
508
- <p><?php _e('This plugin is being maintained by Marcel Pol from', 'custom-taxonomy-order-ne'); ?>
509
- <a href="http://zenoweb.nl" target="_blank" title="ZenoWeb">ZenoWeb</a>.
510
- </p>
511
-
512
- <h2 class="widget-top"><?php _e('Review this plugin.', 'custom-taxonomy-order-ne'); ?></h2>
513
- <p><?php _e('If this plugin has any value to you, then please leave a review at', 'custom-taxonomy-order-ne'); ?>
514
- <a href="https://wordpress.org/support/view/plugin-reviews/custom-taxonomy-order-ne?rate=5#postform" target="_blank" title="<?php esc_attr_e('The plugin page at wordpress.org.', 'custom-taxonomy-order-ne'); ?>">
515
- <?php _e('the plugin page at wordpress.org', 'custom-taxonomy-order-ne'); ?></a>.
516
- </p>
517
-
518
- <h2 class="widget-top"><?php _e('Donate to the maintainer.', 'custom-taxonomy-order-ne'); ?></h2>
519
- <p><?php _e('If you want to donate to the maintainer of the plugin, you can donate through PayPal.', 'custom-taxonomy-order-ne'); ?></p>
520
- <p><?php _e('Donate through', 'custom-taxonomy-order-ne'); ?> <a href="https://www.paypal.com" target="_blank" title="<?php esc_attr_e('Donate to the maintainer.', 'custom-taxonomy-order-ne'); ?>"><?php _e('PayPal', 'custom-taxonomy-order-ne'); ?></a>
521
- <?php _e('to', 'custom-taxonomy-order-ne'); ?> marcel@timelord.nl.
522
- </p>
523
- </div>
524
- </div>
525
- </div>
526
- <?php
527
- }
528
-
529
-
530
- /*
531
- * Add Settings link to the main plugin page
532
- */
533
- function customtaxorder_links( $links, $file ) {
534
- if ( $file == plugin_basename( dirname(__FILE__).'/customtaxorder.php' ) ) {
535
- $links[] = '<a href="' . admin_url( 'admin.php?page=customtaxorder' ) . '">' . __( 'Settings', 'custom-taxonomy-order-ne' ) . '</a>';
536
- }
537
- return $links;
538
- }
539
- add_filter( 'plugin_action_links', 'customtaxorder_links', 10, 2 );
540
-
541
-
542
  /*
543
  * Load language files.
544
  */
@@ -602,7 +382,11 @@ function customtaxorder_wp_initialize_site( $blog ) {
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
 
 
 
 
608
  include('taxonomies.php');
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.1.0
7
  Author: Marcel Pol
8
  Author URI: https://timelord.nl/
9
  License: GPLv2 or later
30
  */
31
 
32
 
33
+ /*
34
+ * TODO:
35
  * - Add pagination, just like next_post_link().
36
  * https://wordpress.org/support/topic/how-to-create-a-navigation-in-archivephp-with-the-given-order/
37
  * - Order by post count (and other orderby's)
38
  * https://wordpress.org/support/topic/order-terms-by-post-count/
 
39
  */
40
 
41
 
42
  // Plugin Version
43
+ define('CUSTOMTAXORDER_VER', '3.1.0');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
 
46
  /*
65
  }
66
 
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  /*
69
  * customtax_cmp
70
  * Sorting of an array with objects, ordered by term_order
81
  }
82
 
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  /*
85
  * Flush object cache when order is changed in taxonomy ordering plugin.
86
  *
93
  add_action( 'customtaxorder_update_order', 'customtaxorder_flush_cache' );
94
 
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  /*
97
  * Function to sort the standard WordPress Queries for terms.
98
  *
319
  add_filter( 'woocommerce_attribute_taxonomies', 'customtaxorder_woocommerce_attribute_taxonomies_public' );
320
 
321
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  /*
323
  * Load language files.
324
  */
382
  add_action( 'wp_initialize_site', 'customtaxorder_wp_initialize_site' );
383
 
384
 
385
+ if ( is_admin() ) {
386
+ // Admin functions
387
+ include('admin-customtaxorder.php');
388
+ // Settingspage
389
+ include('page-customtaxorder.php');
390
+ }
391
+ // functions for sorting taxonomies
392
  include('taxonomies.php');
images/index.html ADDED
File without changes
js/index.html ADDED
File without changes
js/script.js CHANGED
@@ -17,13 +17,23 @@ jQuery(document).ready(function(jQuery) {
17
  e.preventDefault();
18
  jQuery("#custom-loading").show();
19
  customtaxorder_orderalpha();
20
- //jQuery("#order-submit").trigger("click");
21
  setTimeout(function(){
22
  jQuery("#custom-loading").hide();
23
  },500);
24
  jQuery("#order-alpha").blur();
25
  });
26
 
 
 
 
 
 
 
 
 
 
 
 
27
  });
28
 
29
 
@@ -47,6 +57,7 @@ function customtaxorder_addloadevent(){
47
  addLoadEvent(customtaxorder_addloadevent);
48
 
49
 
 
50
  function customtaxorder_ordersubmit() {
51
 
52
  /* Terms */
@@ -62,7 +73,7 @@ function customtaxorder_ordersubmit() {
62
  return true;
63
  }
64
 
65
-
66
  function customtaxorder_orderalpha() {
67
  jQuery("#custom-order-list li").sort(customtaxorder_asc_sort).appendTo('#custom-order-list');
68
  var newOrder = jQuery("#custom-order-list").sortable("toArray");
@@ -70,9 +81,19 @@ function customtaxorder_orderalpha() {
70
  jQuery("#hidden-custom-order").val(newOrder);
71
  return true;
72
  }
73
-
74
-
75
- // Ascending sort
76
  function customtaxorder_asc_sort(a, b) {
77
  return jQuery(a).text().localeCompare(jQuery(b).text(), undefined, {numeric: true, sensitivity: 'base'});
78
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  e.preventDefault();
18
  jQuery("#custom-loading").show();
19
  customtaxorder_orderalpha();
 
20
  setTimeout(function(){
21
  jQuery("#custom-loading").hide();
22
  },500);
23
  jQuery("#order-alpha").blur();
24
  });
25
 
26
+ /* Button to sort the list on slug */
27
+ jQuery("#order-slug").click(function(e) {
28
+ e.preventDefault();
29
+ jQuery("#custom-loading").show();
30
+ customtaxorder_orderslug();
31
+ setTimeout(function(){
32
+ jQuery("#custom-loading").hide();
33
+ },500);
34
+ jQuery("#order-slug").blur();
35
+ });
36
+
37
  });
38
 
39
 
57
  addLoadEvent(customtaxorder_addloadevent);
58
 
59
 
60
+ /* Get all the term_orders and send it in a submit. */
61
  function customtaxorder_ordersubmit() {
62
 
63
  /* Terms */
73
  return true;
74
  }
75
 
76
+ /* Alphabetical ascending sort based on text. */
77
  function customtaxorder_orderalpha() {
78
  jQuery("#custom-order-list li").sort(customtaxorder_asc_sort).appendTo('#custom-order-list');
79
  var newOrder = jQuery("#custom-order-list").sortable("toArray");
81
  jQuery("#hidden-custom-order").val(newOrder);
82
  return true;
83
  }
 
 
 
84
  function customtaxorder_asc_sort(a, b) {
85
  return jQuery(a).text().localeCompare(jQuery(b).text(), undefined, {numeric: true, sensitivity: 'base'});
86
  }
87
+
88
+
89
+ /* Alphabetical ascending sort based on slug. */
90
+ function customtaxorder_orderslug() {
91
+ jQuery("#custom-order-list li").sort(customtaxorder_slug_sort).appendTo('#custom-order-list');
92
+ var newOrder = jQuery("#custom-order-list").sortable("toArray");
93
+ jQuery("#custom-loading").show();
94
+ jQuery("#hidden-custom-order").val(newOrder);
95
+ return true;
96
+ }
97
+ function customtaxorder_slug_sort(a, b) {
98
+ return jQuery(a).attr('data-slug').localeCompare(jQuery(b).attr('data-slug'), undefined, {numeric: true, sensitivity: 'base'});
99
+ }
lang/custom-taxonomy-order-ne-es_ES.mo DELETED
Binary file
lang/custom-taxonomy-order-ne-es_ES.po DELETED
@@ -1,120 +0,0 @@
1
- # Custom Tax Order NE.
2
- # Copyright (C) 2013 Marcel Pol
3
- # This file is distributed under the same license as the Custom Tax Order NE package.
4
- # Marcel Pol <marcel@timelord.nl>, 2013.
5
- #
6
- msgid ""
7
- msgstr ""
8
- "Project-Id-Version: 2.1\n"
9
- "Report-Msgid-Bugs-To: \n"
10
- "POT-Creation-Date: 2014-08-06 14:49+0200\n"
11
- "PO-Revision-Date: 2013-12-10 15:22+0100\n"
12
- "Last-Translator: Marcel Pol <marcel@timelord.nl>\n"
13
- "Language-Team: LANGUAGE <LL@li.org>\n"
14
- "Language: es_ES\n"
15
- "MIME-Version: 1.0\n"
16
- "Content-Type: text/plain; charset=UTF-8\n"
17
- "Content-Transfer-Encoding: 8bit\n"
18
- "X-Generator: Poedit 1.5.4\n"
19
-
20
- #: customtaxorder.php:61
21
- msgid "Term Order"
22
- msgstr "Orden del Término"
23
-
24
- #: customtaxorder.php:63 customtaxorder.php:176
25
- msgid "Order "
26
- msgstr "Orden "
27
-
28
- #: customtaxorder.php:118
29
- msgid ""
30
- "The ordering of categories and custom taxonomy terms through a simple drag-"
31
- "and-drop interface."
32
- msgstr ""
33
-
34
- #: customtaxorder.php:120
35
- msgid "Go to the plugin's Homepage"
36
- msgstr ""
37
-
38
- #: customtaxorder.php:127
39
- msgid "Taxonomies"
40
- msgstr ""
41
-
42
- #: customtaxorder.php:145
43
- msgid "Order by ID (default)."
44
- msgstr ""
45
-
46
- #: customtaxorder.php:146
47
- msgid "Custom Order as defined above."
48
- msgstr ""
49
-
50
- #: customtaxorder.php:147
51
- msgid "Alphabetical Order."
52
- msgstr ""
53
-
54
- #: customtaxorder.php:191
55
- msgid ""
56
- "Order the taxonomies by dragging and dropping them into the desired order."
57
- msgstr ""
58
- "Ordene las taxonomías arrastrándolas y soltándolas en el orden deseado."
59
-
60
- #: customtaxorder.php:201
61
- msgid "Return to Parent"
62
- msgstr "Volver al Padre"
63
-
64
- #: customtaxorder.php:205
65
- msgid "Update Order"
66
- msgstr "Orden de Actualización"
67
-
68
- #: customtaxorder.php:206
69
- msgid "Sort Alphabetical"
70
- msgstr ""
71
-
72
- #: customtaxorder.php:215
73
- msgid "Sub-"
74
- msgstr "Sub-"
75
-
76
- #: customtaxorder.php:215
77
- msgid "Choose a term from the drop down to order its sub-terms."
78
- msgstr ""
79
- "Escoja un término desde el menú desplegable para ordenar sus sub términos."
80
-
81
- #: customtaxorder.php:220
82
- msgid "Order Sub-terms"
83
- msgstr "Ordenar Sub términos"
84
-
85
- #: customtaxorder.php:226
86
- msgid "No terms found"
87
- msgstr "No se encontraron términos"
88
-
89
- #: customtaxorder.php:233 customtaxorder.php:465
90
- msgid "Settings"
91
- msgstr ""
92
-
93
- #: customtaxorder.php:236
94
- msgid "Auto-Sort Queries of this Taxonomy"
95
- msgstr ""
96
-
97
- #: customtaxorder.php:244
98
- msgid "Save Settings"
99
- msgstr "Salvar Ajustes"
100
-
101
- #: customtaxorder.php:337
102
- msgid "Order updated successfully."
103
- msgstr "Ordenamiento actualizado satisfactoriamente."
104
-
105
- #: customtaxorder.php:339
106
- msgid "An error occured, order has not been saved."
107
- msgstr "Un error ocurrió, el orden no ha sido salvado."
108
-
109
- #~ msgid "Order Categories"
110
- #~ msgstr "Categorías del Orden"
111
-
112
- #~ msgid ""
113
- #~ "Check this box if you want to enable Automatic Sorting of all instances "
114
- #~ "from this taxonomy."
115
- #~ msgstr ""
116
- #~ "Seleccione esta casilla si desea habilitar el Ordenamiento Automático "
117
- #~ "para todas las instancias de esta taxonomía."
118
-
119
- #~ msgid "Auto-Sort Queries"
120
- #~ msgstr "Consultas de auto ordenamiento"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lang/index.html ADDED
File without changes
page-customtaxorder.php CHANGED
@@ -1,10 +1,11 @@
1
  <?php
2
  /*
3
- * Admin Settingspage for Custom Taxonomy Order
 
4
  */
5
 
6
 
7
- function customtaxorder() {
8
  global $sitepress;
9
 
10
  customtaxorder_update_settings();
@@ -147,28 +148,31 @@ function customtaxorder() {
147
  ?>
148
  <div id="poststuff" class="metabox-holder">
149
  <div class="widget order-widget">
150
- <h2 class="widget-top"><?php _e( $tax_label) ?> | <small><?php _e('Order the taxonomies by dragging and dropping them into the desired order.', 'custom-taxonomy-order-ne') ?></small></h2>
151
  <div class="misc-pub-section">
152
  <ul id="custom-order-list">
153
  <?php foreach ( $terms as $term ) { ?>
154
- <li id="id_<?php echo $term->term_id; ?>" class="lineitem"><?php echo $term->name; ?></li>
155
  <?php } ?>
156
  </ul>
157
  </div>
158
  <div class="misc-pub-section misc-pub-section-last">
159
  <?php if ($parent_ID != 0) { ?>
160
- <input type="submit" class="button" style="float:left" id="return-sub-posts" name="return-sub-posts" value="<?php _e('Return to Parent', 'custom-taxonomy-order-ne'); ?>" />
 
 
161
  <?php } ?>
162
  <div id="publishing-action">
163
  <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" id="custom-loading" style="display:none" alt="" />
164
  <input type="submit" name="order-submit" id="order-submit" class="button-primary" value="<?php _e('Update Order', 'custom-taxonomy-order-ne') ?>" />
165
- <input type="submit" name="order-alpha" id="order-alpha" class="button" value="<?php _e('Sort Alphabetical', 'custom-taxonomy-order-ne') ?>" />
 
166
  <?php do_action('custom_taxonomy_order_ne_settings_buttons'); ?>
167
  </div>
168
  <div class="clear"></div>
169
  </div>
170
- <input type="hidden" id="hidden-custom-order" name="hidden-custom-order" />
171
- <input type="hidden" id="hidden-parent-id" name="hidden-parent-id" value="<?php echo $parent_ID; ?>" />
172
  <input type="hidden" id="hidden-parent-id-order" name="hidden-parent-id-order" value="<?php echo $parent_ID_order; ?>" />
173
  </div>
174
  <?php
@@ -213,3 +217,76 @@ function customtaxorder() {
213
 
214
  <?php
215
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
  /*
3
+ * Admin Settingspage for Custom Taxonomy Order.
4
+ * Generated for each taxonomy.
5
  */
6
 
7
 
8
+ function customtaxorder_subpage() {
9
  global $sitepress;
10
 
11
  customtaxorder_update_settings();
148
  ?>
149
  <div id="poststuff" class="metabox-holder">
150
  <div class="widget order-widget">
151
+ <h2 class="widget-top"><?php _e( $tax_label) ?> | <small><?php _e('Order the terms by dragging and dropping them into the desired order.', 'custom-taxonomy-order-ne') ?></small></h2>
152
  <div class="misc-pub-section">
153
  <ul id="custom-order-list">
154
  <?php foreach ( $terms as $term ) { ?>
155
+ <li id="id_<?php echo $term->term_id; ?>" data-slug="<?php echo $term->slug; ?>" class="lineitem"><?php echo $term->name; ?></li>
156
  <?php } ?>
157
  </ul>
158
  </div>
159
  <div class="misc-pub-section misc-pub-section-last">
160
  <?php if ($parent_ID != 0) { ?>
161
+ <div id="publishing-action-return-sub-posts">
162
+ <input type="submit" class="button" id="return-sub-posts" name="return-sub-posts" value="<?php _e('Return to Parent', 'custom-taxonomy-order-ne'); ?>" />
163
+ </div>
164
  <?php } ?>
165
  <div id="publishing-action">
166
  <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" id="custom-loading" style="display:none" alt="" />
167
  <input type="submit" name="order-submit" id="order-submit" class="button-primary" value="<?php _e('Update Order', 'custom-taxonomy-order-ne') ?>" />
168
+ <input type="submit" name="order-alpha" id="order-alpha" class="button" value="<?php _e('Sort Alphabetical', 'custom-taxonomy-order-ne') ?>" />
169
+ <input type="submit" name="order-slug" id="order-slug" class="button" value="<?php _e('Sort on slug', 'custom-taxonomy-order-ne') ?>" />
170
  <?php do_action('custom_taxonomy_order_ne_settings_buttons'); ?>
171
  </div>
172
  <div class="clear"></div>
173
  </div>
174
+ <input type="hidden" id="hidden-custom-order" name="hidden-custom-order" />
175
+ <input type="hidden" id="hidden-parent-id" name="hidden-parent-id" value="<?php echo $parent_ID; ?>" />
176
  <input type="hidden" id="hidden-parent-id-order" name="hidden-parent-id-order" value="<?php echo $parent_ID_order; ?>" />
177
  </div>
178
  <?php
217
 
218
  <?php
219
  }
220
+
221
+
222
+ /*
223
+ * Called from customtaxorder().
224
+ */
225
+ function customtaxorder_update_settings() {
226
+ $options = customtaxorder_get_settings();
227
+ if ( isset($options['update']) ) {
228
+ echo '<div class="updated fade notice is-dismissible" id="message"><p>' . __('Custom Taxonomy Order settings', 'custom-taxonomy-order-ne') . ' ' . $options['update'] . '</p></div>';
229
+ unset($options['update']);
230
+ update_option('customtaxorder_settings', $options);
231
+ }
232
+ }
233
+
234
+
235
+ /*
236
+ * customtaxorder_update_order
237
+ * Function to update the database with the submitted order
238
+ */
239
+ function customtaxorder_update_order() {
240
+
241
+ /* Check Nonce */
242
+ $verified = false;
243
+ if ( isset($_POST['custom-taxonomy-order-ne-nonce']) ) {
244
+ $verified = wp_verify_nonce( $_POST['custom-taxonomy-order-ne-nonce'], 'custom-taxonomy-order-ne-nonce' );
245
+ }
246
+ if ( $verified == false ) {
247
+ // Nonce is invalid.
248
+ echo '<div id="message" class="error fade notice is-dismissible"><p>' . __('The Nonce did not validate. Please try again.', 'custom-taxonomy-order-ne') . '</p></div>';
249
+ return;
250
+ }
251
+
252
+ if (isset($_POST['hidden-custom-order']) && $_POST['hidden-custom-order'] != "") {
253
+ global $wpdb;
254
+ $parent_ID_order = 0;
255
+ if ( isset($_POST['hidden-parent-id-order']) && $_POST['hidden-parent-id-order'] > 0 ) {
256
+ $parent_ID_order = (int) $_POST['hidden-parent-id-order'] + 1;
257
+ }
258
+ $new_order = $_POST['hidden-custom-order'];
259
+ $IDs = explode(",", $new_order);
260
+ $ids = Array();
261
+ $result = count($IDs);
262
+ for ( $i = 0; $i < $result; $i++ ) {
263
+ $term_id = (int) str_replace("id_", "", $IDs[$i]);
264
+ $term_order = $i + $parent_ID_order;
265
+
266
+ customtaxorder_set_db_term_order( $term_id, $term_order );
267
+
268
+ $ids[] = $term_id;
269
+ }
270
+ echo '<div id="message" class="updated fade notice is-dismissible"><p>'. __('Order updated successfully.', 'custom-taxonomy-order-ne').'</p></div>';
271
+ do_action('customtaxorder_update_order', $ids);
272
+ } else {
273
+ echo '<div id="message" class="error fade notice is-dismissible"><p>'. __('An error occured, order has not been saved.', 'custom-taxonomy-order-ne').'</p></div>';
274
+ }
275
+ }
276
+
277
+
278
+ /*
279
+ * Function to give dropdown options for the list of sub-terms.
280
+ */
281
+ function customtaxorder_sub_query( $terms, $tax ) {
282
+ $options = '';
283
+ if ( isset( $terms ) && is_array( $terms ) ) {
284
+ foreach ( $terms as $term ) {
285
+ $subterms = get_term_children( $term->term_id, $tax );
286
+ if ( $subterms ) {
287
+ $options .= '<option value="' . $term->term_id . '">' . $term->name . '</option>';
288
+ }
289
+ }
290
+ }
291
+ return $options;
292
+ }
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: mpol
3
  Tags: term order, category order, taxonomy order, order
4
  Requires at least: 3.7
5
  Tested up to: 5.4
6
- Stable tag: 3.0.1
7
  License: GPLv2 or later
8
 
9
 
@@ -161,6 +161,13 @@ The left metabox lists the toplevel terms. Right (or below) are the sub-terms.
161
 
162
  == Changelog ==
163
 
 
 
 
 
 
 
 
164
  = 3.0.1 =
165
  * 2020-01-07
166
  * Add taxonomy parameter to get_term call for compatibility with WP 4.3.
3
  Tags: term order, category order, taxonomy order, order
4
  Requires at least: 3.7
5
  Tested up to: 5.4
6
+ Stable tag: 3.1.0
7
  License: GPLv2 or later
8
 
9
 
161
 
162
  == Changelog ==
163
 
164
+ = 3.1.0 =
165
+ * 2020-03-23
166
+ * Add term_order field to edit screen of terms (thanks @li-an).
167
+ * Add order button for slug (thanks @eric3d).
168
+ * Only load admin functions at dashboard.
169
+ * Remove included es_ES po file, it is maintained in GlotPress.
170
+
171
  = 3.0.1 =
172
  * 2020-01-07
173
  * Add taxonomy parameter to get_term call for compatibility with WP 4.3.