Category Order and Taxonomy Terms Order - Version 1.4.4

Version Description

  • User role switch from deprecated user_level to capabilities
    • Taxonomy sort for media
    • Admin Options update
Download this release

Release Info

Developer nsp-code
Plugin Icon 128x128 Category Order and Taxonomy Terms Order
Version 1.4.4
Comparing to
See all releases

Code changes from version 1.4.2 to 1.4.4

include/functions.php CHANGED
@@ -1,5 +1,28 @@
1
  <?php
2
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  function tto_info_box()
5
  {
1
  <?php
2
+
3
+ /**
4
+ * @desc
5
+ *
6
+ * Return UserLevel
7
+ *
8
+ */
9
+ function tto_userdata_get_user_level($return_as_numeric = FALSE)
10
+ {
11
+ global $userdata;
12
+
13
+ $user_level = '';
14
+ for ($i=10; $i >= 0;$i--)
15
+ {
16
+ if (current_user_can('level_' . $i) === TRUE)
17
+ {
18
+ $user_level = $i;
19
+ if ($return_as_numeric === FALSE)
20
+ $user_level = 'level_'.$i;
21
+ break;
22
+ }
23
+ }
24
+ return ($user_level);
25
+ }
26
 
27
  function tto_info_box()
28
  {
include/interface.php CHANGED
@@ -6,7 +6,26 @@
6
  global $wpdb, $wp_locale;
7
 
8
  $taxonomy = isset($_GET['taxonomy']) ? $_GET['taxonomy'] : '';
9
- $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  $post_type_data = get_post_type_object($post_type);
12
 
@@ -30,11 +49,29 @@
30
 
31
  <div class="clear"></div>
32
 
33
- <form action="edit.php" method="get" id="to_form">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  <input type="hidden" name="page" value="to-interface-<?php echo $post_type ?>" />
35
  <?php
36
 
37
- if ($post_type != 'post')
38
  echo '<input type="hidden" name="post_type" value="'. $post_type .'" />';
39
 
40
  //output all available taxonomies for this post type
6
  global $wpdb, $wp_locale;
7
 
8
  $taxonomy = isset($_GET['taxonomy']) ? $_GET['taxonomy'] : '';
9
+ $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : '';
10
+ if(empty($post_type))
11
+ {
12
+ $screen = get_current_screen();
13
+
14
+ if(isset($screen->post_type) && !empty($screen->post_type))
15
+ $post_type = $screen->post_type;
16
+ else
17
+ {
18
+ switch($screen->parent_file)
19
+ {
20
+ case "upload.php" :
21
+ $post_type = 'attachment';
22
+ break;
23
+
24
+ default:
25
+ $post_type = 'post';
26
+ }
27
+ }
28
+ }
29
 
30
  $post_type_data = get_post_type_object($post_type);
31
 
49
 
50
  <div class="clear"></div>
51
 
52
+ <?php
53
+
54
+ $current_section_parent_file = '';
55
+ switch($post_type)
56
+ {
57
+
58
+ case "attachment" :
59
+ $current_section_parent_file = "upload.php";
60
+ break;
61
+
62
+ default :
63
+ $current_section_parent_file = "edit.php";
64
+ break;
65
+ }
66
+
67
+
68
+ ?>
69
+
70
+ <form action="<?php echo $current_section_parent_file ?>" method="get" id="to_form">
71
  <input type="hidden" name="page" value="to-interface-<?php echo $post_type ?>" />
72
  <?php
73
 
74
+ if (!in_array($post_type, array('post', 'attachment')))
75
  echo '<input type="hidden" name="post_type" value="'. $post_type .'" />';
76
 
77
  //output all available taxonomies for this post type
include/options.php CHANGED
@@ -8,7 +8,7 @@ function to_plugin_options()
8
  if (isset($_POST['form_submit']))
9
  {
10
 
11
- $options['level'] = $_POST['level'];
12
 
13
  $options['autosort'] = isset($_POST['autosort']) ? $_POST['autosort'] : '';
14
  $options['adminsort'] = isset($_POST['adminsort']) ? $_POST['adminsort'] : '';
@@ -34,12 +34,12 @@ function to_plugin_options()
34
  <tr valign="top">
35
  <th scope="row" style="text-align: right;"><label><?php _e( "Minimum Level to use this plugin", 'tto' ) ?></label></th>
36
  <td>
37
- <select id="role" name="level">
38
- <option value="0" <?php if ($options['level'] == "0") echo 'selected="selected"'?>><?php _e('Subscriber', 'tto') ?></option>
39
- <option value="1" <?php if ($options['level'] == "1") echo 'selected="selected"'?>><?php _e('Contributor', 'tto') ?></option>
40
- <option value="2" <?php if ($options['level'] == "2") echo 'selected="selected"'?>><?php _e('Author', 'tto') ?></option>
41
- <option value="5" <?php if ($options['level'] == "5") echo 'selected="selected"'?>><?php _e('Editor', 'tto') ?></option>
42
- <option value="8" <?php if ($options['level'] == "8") echo 'selected="selected"'?>><?php _e('Administrator', 'tto') ?></option>
43
  </select>
44
  </td>
45
  </tr>
@@ -51,39 +51,19 @@ function to_plugin_options()
51
  <select id="role" name="autosort">
52
  <option value="0" <?php if ($options['autosort'] == "0") echo 'selected="selected"'?>><?php _e('OFF', 'tto') ?></option>
53
  <option value="1" <?php if ($options['autosort'] == "1") echo 'selected="selected"'?>><?php _e('ON', 'tto') ?></option>
54
- </select> *(<?php _e( "global setting", 'tto' ) ?>)
55
  </td>
56
  </tr>
57
 
58
  <tr valign="top">
59
  <th scope="row" style="text-align: right;"><label><?php _e( "Admin Sort", 'tto' ) ?></label></th>
60
  <td>
61
- <label for="users_can_register">
62
- <input type="checkbox" <?php if ($options['adminsort'] == "1") {echo ' checked="checked"';} ?> value="1" name="adminsort">
63
- <?php _e("This will change the order of terms within the admin interface", 'tto') ?>.</label>
64
  </td>
65
  </tr>
66
 
67
- <tr valign="top">
68
- <th scope="row" style="text-align: right;"></th>
69
- <td>
70
- <br /><br /><br />
71
- <p><b><u><?php _e( "Autosort OFF", 'tto' ) ?></u></b></p>
72
- <p class="example"><?php _e('No query will be changed, the terms will appear in the original order. To retrieve the terms in the required order you must use the term_order on the orderby parameter', 'tto') ?>:</p>
73
- <pre class="example">
74
- $argv = array(
75
- 'orderby' => 'term_order',
76
- 'hide_empty' => false
77
- );
78
- get_terms('category', $argv);
79
- </pre>
80
- <p><?php _e( "See more info on the get_terms usage", 'tto' ) ?> <a href="http://codex.wordpress.org/Function_Reference/get_terms" target="_blank"><?php _e( "here", 'tto' ) ?></a></p>
81
-
82
- <p><b><u><?php _e( "Autosort ON", 'tto' ) ?></u></b></p>
83
- <p class="example"><?php _e('The queries will be updated, all terms will appear in the order you manually defined. This is recommended if you don\'t want to change any theme code to apply the terms order', 'tto') ?></p>
84
-
85
- </td>
86
- </tr>
87
 
88
  </tbody>
89
  </table>
8
  if (isset($_POST['form_submit']))
9
  {
10
 
11
+ $options['capability'] = $_POST['capability'];
12
 
13
  $options['autosort'] = isset($_POST['autosort']) ? $_POST['autosort'] : '';
14
  $options['adminsort'] = isset($_POST['adminsort']) ? $_POST['adminsort'] : '';
34
  <tr valign="top">
35
  <th scope="row" style="text-align: right;"><label><?php _e( "Minimum Level to use this plugin", 'tto' ) ?></label></th>
36
  <td>
37
+ <select id="role" name="capability">
38
+ <option value="read" <?php if (isset($options['capability']) && $options['capability'] == "read") echo 'selected="selected"'?>><?php _e('Subscriber', 'cpt') ?></option>
39
+ <option value="edit_posts" <?php if (isset($options['capability']) && $options['capability'] == "edit_posts") echo 'selected="selected"'?>><?php _e('Contributor', 'cpt') ?></option>
40
+ <option value="publish_posts" <?php if (isset($options['capability']) && $options['capability'] == "publish_posts") echo 'selected="selected"'?>><?php _e('Author', 'cpt') ?></option>
41
+ <option value="publish_pages" <?php if (isset($options['capability']) && $options['capability'] == "publish_pages") echo 'selected="selected"'?>><?php _e('Editor', 'cpt') ?></option>
42
+ <option value="install_plugins" <?php if (!isset($options['capability']) || empty($options['capability']) || (isset($options['capability']) && $options['capability'] == "install_plugins")) echo 'selected="selected"'?>><?php _e('Administrator', 'cpt') ?></option>
43
  </select>
44
  </td>
45
  </tr>
51
  <select id="role" name="autosort">
52
  <option value="0" <?php if ($options['autosort'] == "0") echo 'selected="selected"'?>><?php _e('OFF', 'tto') ?></option>
53
  <option value="1" <?php if ($options['autosort'] == "1") echo 'selected="selected"'?>><?php _e('ON', 'tto') ?></option>
54
+ </select> *(<?php _e( "global setting", 'tto' ) ?>) <?php _e( "Additional description and details at ", 'tto' ) ?><a target="_blank" href="http://www.nsp-code.com/taxonomy-terms-order-and-auto-sort-admin-sort-description-an-usage/"><?php _e( "Auto Sort Description", 'tto' ) ?></a>
55
  </td>
56
  </tr>
57
 
58
  <tr valign="top">
59
  <th scope="row" style="text-align: right;"><label><?php _e( "Admin Sort", 'tto' ) ?></label></th>
60
  <td>
61
+ <input id="adminsort" type="checkbox" <?php if ($options['adminsort'] == "1") {echo ' checked="checked"';} ?> value="1" name="adminsort">
62
+ <label for="adminsort"><?php _e("This will change the order of terms within the admin interface", 'tto') ?>. <?php _e( "Additional description and details at ", 'tto' ) ?><a target="_blank" href="http://www.nsp-code.com/taxonomy-terms-order-and-auto-sort-admin-sort-description-an-usage/"><?php _e( "Auto Sort Description", 'tto' ) ?></a></label>
 
63
  </td>
64
  </tr>
65
 
66
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
  </tbody>
69
  </table>
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: Nsp Code
3
  Donate link: http://www.nsp-code.com/donate.php
4
  Tags: category order,terms order, taxonomy order, admin order
5
  Requires at least: 2.8
6
- Tested up to: 4.2.2
7
 
8
  Order Categories and all custom taxonomies terms (hierarchically) and child terms using a Drag and Drop Sortable javascript capability. No Theme update is required.
9
 
@@ -48,6 +48,11 @@ All ideas are welcome and i put them on my list to be implemented into the new v
48
 
49
  == Change Log ==
50
 
 
 
 
 
 
51
  = 1.4.2 =
52
  - Iranian Language (eydaaad@gmail.com)
53
  - Admin css updates.
3
  Donate link: http://www.nsp-code.com/donate.php
4
  Tags: category order,terms order, taxonomy order, admin order
5
  Requires at least: 2.8
6
+ Tested up to: 4.3
7
 
8
  Order Categories and all custom taxonomies terms (hierarchically) and child terms using a Drag and Drop Sortable javascript capability. No Theme update is required.
9
 
48
 
49
  == Change Log ==
50
 
51
+ = 1.4.4 =
52
+ - User role switch from deprecated user_level to capabilities
53
+ - Taxonomy sort for media
54
+ - Admin Options update
55
+
56
  = 1.4.2 =
57
  - Iranian Language (eydaaad@gmail.com)
58
  - Admin css updates.
taxonomy-terms-order.php CHANGED
@@ -3,188 +3,199 @@
3
  Plugin Name: Category Order and Taxonomy Terms Order
4
  Plugin URI: http://www.nsp-code.com
5
  Description: Category Order and Taxonomy Terms Order
6
- Version: 1.4.2
7
  Author: Nsp-Code
8
  Author URI: http://www.nsp-code.com
9
  Author Email: electronice_delphi@yahoo.com
10
  */
11
 
12
 
13
- define('TOPATH', plugin_dir_path(__FILE__));
14
- define('TOURL', plugins_url('', __FILE__));
15
 
16
- register_deactivation_hook(__FILE__, 'TO_deactivated');
17
- register_activation_hook(__FILE__, 'TO_activated');
18
 
19
- function TO_activated()
20
- {
21
- global $wpdb;
22
-
23
- //check if the menu_order column exists;
24
- $query = "SHOW COLUMNS FROM $wpdb->terms
25
- LIKE 'term_order'";
26
- $result = $wpdb->query($query);
27
-
28
- if ($result == 0)
29
- {
30
- $query = "ALTER TABLE $wpdb->terms ADD `term_order` INT( 4 ) NULL DEFAULT '0'";
31
- $result = $wpdb->query($query);
32
- }
33
 
34
- //make sure the vars are set as default
35
- $options = get_option('tto_options');
36
- if (!isset($options['autosort']))
37
- $options['autosort'] = '1';
38
 
39
- if (!isset($options['adminsort']))
40
- $options['adminsort'] = '1';
 
 
 
41
 
42
- if (!isset($options['level']))
43
- $options['level'] = 8;
44
 
45
- update_option('tto_options', $options);
46
- }
47
-
48
- function TO_deactivated()
49
- {
 
 
 
 
 
 
50
 
51
- }
 
 
 
52
 
53
- include_once(TOPATH . '/include/functions.php');
54
-
55
- add_action( 'plugins_loaded', 'to_load_textdomain');
56
- function to_load_textdomain()
57
- {
58
- load_plugin_textdomain('to', FALSE, dirname( plugin_basename( __FILE__ ) ) . '/lang');
59
- }
60
-
61
- add_action('admin_print_scripts', 'TO_admin_scripts');
62
- function TO_admin_scripts()
63
- {
64
- wp_enqueue_script('jquery');
65
 
66
- wp_enqueue_script('jquery-ui-sortable');
 
 
 
 
67
 
68
- $myJsFile = TOURL . '/js/to-javascript.js';
69
- wp_register_script('to-javascript.js', $myJsFile);
70
- wp_enqueue_script( 'to-javascript.js');
71
-
72
- }
73
-
74
- add_action('admin_print_styles', 'TO_admin_styles');
75
- function TO_admin_styles()
76
- {
77
- $myCssFile = TOURL . '/css/to.css';
78
- wp_register_style('to.css', $myCssFile);
79
- wp_enqueue_style( 'to.css');
80
- }
81
-
82
- add_action('admin_menu', 'TOPluginMenu', 99);
83
-
84
- function TOPluginMenu()
85
- {
86
- include (TOPATH . '/include/interface.php');
87
- include (TOPATH . '/include/terms_walker.php');
88
 
89
- include (TOPATH . '/include/options.php');
90
- add_options_page('Taxonomy Terms Order', '<img class="menu_tto" src="'. TOURL .'/images/menu-icon.png" alt="" />' . __('Taxonomy Terms Order', 'tto'), 'manage_options', 'to-options', 'to_plugin_options');
91
-
92
- $options = get_option('tto_options');
 
 
 
93
 
94
- if (!isset($options['level']))
95
- $options['level'] = 8;
96
-
97
- //put a menu within all custom types if apply
98
- $post_types = get_post_types();
99
- foreach( $post_types as $post_type)
100
- {
 
 
101
 
102
- //check if there are any taxonomy for this post type
103
- $post_type_taxonomies = get_object_taxonomies($post_type);
104
-
105
- foreach ($post_type_taxonomies as $key => $taxonomy_name)
 
 
 
 
 
 
106
  {
107
- $taxonomy_info = get_taxonomy($taxonomy_name);
108
- if ($taxonomy_info->hierarchical !== TRUE)
109
- unset($post_type_taxonomies[$key]);
110
- }
111
 
112
- if (count($post_type_taxonomies) == 0)
113
- continue;
114
-
115
- if ($post_type == 'post')
116
- add_submenu_page('edit.php', __('Taxonomy Order', 'tto'), __('Taxonomy Order', 'tto'), 'level_'.$options['level'], 'to-interface-'.$post_type, 'TOPluginInterface' );
117
- else
118
- add_submenu_page('edit.php?post_type='.$post_type, __('Taxonomy Order', 'tto'), __('Taxonomy Order', 'tto'), 'level_'.$options['level'], 'to-interface-'.$post_type, 'TOPluginInterface' );
119
- }
120
- }
121
-
122
-
123
- add_action( 'wp_ajax_update-custom-type-order-hierarchical', array(&$this, 'saveAjaxOrderHierarchical') );
124
-
125
-
126
- function TO_applyorderfilter($orderby, $args)
127
- {
128
- $options = get_option('tto_options');
129
-
130
- //if admin make sure use the admin setting
131
- if (is_admin())
132
- {
133
- if ($options['adminsort'] == "1")
134
- return 't.term_order';
135
 
136
- return $orderby;
137
- }
 
 
 
 
 
 
 
138
 
139
- //if autosort, then force the menu_order
140
- if ($options['autosort'] == 1)
141
- {
142
- return 't.term_order';
143
- }
 
144
 
145
- return $orderby;
146
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
- add_filter('get_terms_orderby', 'TO_applyorderfilter', 10, 2);
149
 
150
- add_filter('get_terms_orderby', 'TO_get_terms_orderby', 1, 2);
151
- function TO_get_terms_orderby($orderby, $args)
152
- {
153
- if (isset($args['orderby']) && $args['orderby'] == "term_order" && $orderby != "term_order")
154
- return "t.term_order";
155
-
156
- return $orderby;
157
- }
158
 
159
- add_action( 'wp_ajax_update-taxonomy-order', 'TOsaveAjaxOrder' );
160
- function TOsaveAjaxOrder()
161
- {
162
- global $wpdb;
163
- $taxonomy = stripslashes($_POST['taxonomy']);
164
- $data = stripslashes($_POST['order']);
165
- $unserialised_data = unserialize($data);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
 
167
- if (is_array($unserialised_data))
168
- foreach($unserialised_data as $key => $values )
169
- {
170
- //$key_parent = str_replace("item_", "", $key);
171
- $items = explode("&", $values);
172
- unset($item);
173
- foreach ($items as $item_key => $item_)
174
- {
175
- $items[$item_key] = trim(str_replace("item[]=", "",$item_));
176
- }
177
 
178
- if (is_array($items) && count($items) > 0)
179
- foreach( $items as $item_key => $term_id )
180
- {
181
- $wpdb->update( $wpdb->terms, array('term_order' => ($item_key + 1)), array('term_id' => $term_id) );
182
- }
183
- }
184
-
185
-
186
- die();
187
- }
188
 
189
 
190
  ?>
3
  Plugin Name: Category Order and Taxonomy Terms Order
4
  Plugin URI: http://www.nsp-code.com
5
  Description: Category Order and Taxonomy Terms Order
6
+ Version: 1.4.4
7
  Author: Nsp-Code
8
  Author URI: http://www.nsp-code.com
9
  Author Email: electronice_delphi@yahoo.com
10
  */
11
 
12
 
13
+ define('TOPATH', plugin_dir_path(__FILE__));
14
+ define('TOURL', plugins_url('', __FILE__));
15
 
16
+ register_deactivation_hook(__FILE__, 'TO_deactivated');
17
+ register_activation_hook(__FILE__, 'TO_activated');
18
 
19
+ function TO_activated()
20
+ {
21
+ global $wpdb;
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ //check if the menu_order column exists;
24
+ $query = "SHOW COLUMNS FROM $wpdb->terms
25
+ LIKE 'term_order'";
26
+ $result = $wpdb->query($query);
27
 
28
+ if ($result == 0)
29
+ {
30
+ $query = "ALTER TABLE $wpdb->terms ADD `term_order` INT( 4 ) NULL DEFAULT '0'";
31
+ $result = $wpdb->query($query);
32
+ }
33
 
34
+ $options = get_option('tto_options');
 
35
 
36
+ $defaults = array (
37
+ 'autosort' => '1',
38
+ 'adminsort' => '1',
39
+ 'capability' => 'install_plugins'
40
+ );
41
+
42
+ // Parse incoming $args into an array and merge it with $defaults
43
+ $options = wp_parse_args( $options, $defaults );
44
+
45
+ update_option('tto_options', $options);
46
+ }
47
 
48
+ function TO_deactivated()
49
+ {
50
+
51
+ }
52
 
53
+ include_once(TOPATH . '/include/functions.php');
 
 
 
 
 
 
 
 
 
 
 
54
 
55
+ add_action( 'plugins_loaded', 'to_load_textdomain');
56
+ function to_load_textdomain()
57
+ {
58
+ load_plugin_textdomain('to', FALSE, dirname( plugin_basename( __FILE__ ) ) . '/lang');
59
+ }
60
 
61
+ add_action('admin_print_scripts', 'TO_admin_scripts');
62
+ function TO_admin_scripts()
63
+ {
64
+ wp_enqueue_script('jquery');
65
+
66
+ wp_enqueue_script('jquery-ui-sortable');
67
+
68
+ $myJsFile = TOURL . '/js/to-javascript.js';
69
+ wp_register_script('to-javascript.js', $myJsFile);
70
+ wp_enqueue_script( 'to-javascript.js');
71
+
72
+ }
 
 
 
 
 
 
 
 
73
 
74
+ add_action('admin_print_styles', 'TO_admin_styles');
75
+ function TO_admin_styles()
76
+ {
77
+ $myCssFile = TOURL . '/css/to.css';
78
+ wp_register_style('to.css', $myCssFile);
79
+ wp_enqueue_style( 'to.css');
80
+ }
81
 
82
+ add_action('admin_menu', 'TOPluginMenu', 99);
83
+
84
+ function TOPluginMenu()
85
+ {
86
+ include (TOPATH . '/include/interface.php');
87
+ include (TOPATH . '/include/terms_walker.php');
88
+
89
+ include (TOPATH . '/include/options.php');
90
+ add_options_page('Taxonomy Terms Order', '<img class="menu_tto" src="'. TOURL .'/images/menu-icon.png" alt="" />' . __('Taxonomy Terms Order', 'tto'), 'manage_options', 'to-options', 'to_plugin_options');
91
 
92
+ $options = get_option('tto_options');
93
+
94
+ if(isset($options['capability']) && !empty($options['capability']))
95
+ $capability = $options['capability'];
96
+ else if (is_numeric($options['level']))
97
+ {
98
+ //maintain the old user level compatibility
99
+ $capability = tto_userdata_get_user_level();
100
+ }
101
+ else
102
  {
103
+ $capability = 'install_plugins';
104
+ }
 
 
105
 
106
+ //put a menu within all custom types if apply
107
+ $post_types = get_post_types();
108
+ foreach( $post_types as $post_type)
109
+ {
110
+
111
+ //check if there are any taxonomy for this post type
112
+ $post_type_taxonomies = get_object_taxonomies($post_type);
113
+
114
+ foreach ($post_type_taxonomies as $key => $taxonomy_name)
115
+ {
116
+ $taxonomy_info = get_taxonomy($taxonomy_name);
117
+ if ($taxonomy_info->hierarchical !== TRUE)
118
+ unset($post_type_taxonomies[$key]);
119
+ }
120
+
121
+ if (count($post_type_taxonomies) == 0)
122
+ continue;
 
 
 
 
 
 
123
 
124
+ if ($post_type == 'post')
125
+ add_submenu_page('edit.php', __('Taxonomy Order', 'tto'), __('Taxonomy Order', 'tto'), $capability, 'to-interface-'.$post_type, 'TOPluginInterface' );
126
+ elseif ($post_type == 'attachment')
127
+ $hookID = add_submenu_page('upload.php', __('Taxonomy Order', 'tto'), __('Taxonomy Order', 'tto'), $capability, 'to-interface-'.$post_type, 'TOPluginInterface' );
128
+ else
129
+ add_submenu_page('edit.php?post_type='.$post_type, __('Taxonomy Order', 'tto'), __('Taxonomy Order', 'tto'), $capability, 'to-interface-'.$post_type, 'TOPluginInterface' );
130
+ }
131
+ }
132
+
133
 
134
+ add_action( 'wp_ajax_update-custom-type-order-hierarchical', array(&$this, 'saveAjaxOrderHierarchical') );
135
+
136
+
137
+ function TO_applyorderfilter($orderby, $args)
138
+ {
139
+ $options = get_option('tto_options');
140
 
141
+ //if admin make sure use the admin setting
142
+ if (is_admin())
143
+ {
144
+ if ($options['adminsort'] == "1")
145
+ return 't.term_order';
146
+
147
+ return $orderby;
148
+ }
149
+
150
+ //if autosort, then force the menu_order
151
+ if ($options['autosort'] == 1)
152
+ {
153
+ return 't.term_order';
154
+ }
155
+
156
+ return $orderby;
157
+ }
158
 
159
+ add_filter('get_terms_orderby', 'TO_applyorderfilter', 10, 2);
160
 
161
+ add_filter('get_terms_orderby', 'TO_get_terms_orderby', 1, 2);
162
+ function TO_get_terms_orderby($orderby, $args)
163
+ {
164
+ if (isset($args['orderby']) && $args['orderby'] == "term_order" && $orderby != "term_order")
165
+ return "t.term_order";
166
+
167
+ return $orderby;
168
+ }
169
 
170
+ add_action( 'wp_ajax_update-taxonomy-order', 'TOsaveAjaxOrder' );
171
+ function TOsaveAjaxOrder()
172
+ {
173
+ global $wpdb;
174
+ $taxonomy = stripslashes($_POST['taxonomy']);
175
+ $data = stripslashes($_POST['order']);
176
+ $unserialised_data = unserialize($data);
177
+
178
+ if (is_array($unserialised_data))
179
+ foreach($unserialised_data as $key => $values )
180
+ {
181
+ //$key_parent = str_replace("item_", "", $key);
182
+ $items = explode("&", $values);
183
+ unset($item);
184
+ foreach ($items as $item_key => $item_)
185
+ {
186
+ $items[$item_key] = trim(str_replace("item[]=", "",$item_));
187
+ }
188
+
189
+ if (is_array($items) && count($items) > 0)
190
+ foreach( $items as $item_key => $term_id )
191
+ {
192
+ $wpdb->update( $wpdb->terms, array('term_order' => ($item_key + 1)), array('term_id' => $term_id) );
193
+ }
194
+ }
195
 
 
 
 
 
 
 
 
 
 
 
196
 
197
+ die();
198
+ }
 
 
 
 
 
 
 
 
199
 
200
 
201
  ?>