Version Description
- 2021-02-23
- Save settings per taxonomy with capability 'manage_categories', not 'manage_options'.
- Rewrite some code for settings pages.
- Fix deprecated jQuery calls with WP 5.6 and jQuery 3.5.
- Rename script.js to customtaxorder.js.
Download this release
Release Info
Developer | mpol |
Plugin | Custom Taxonomy Order NE |
Version | 3.3.0 |
Comparing to | |
See all releases |
Code changes from version 3.2.2 to 3.3.0
- admin-customtaxorder.php +20 -28
- customtaxorder.php +3 -4
- js/{script.js → customtaxorder.js} +5 -5
- page-customtaxorder.php +182 -76
- readme.txt +13 -2
- taxonomies.php +15 -2
admin-customtaxorder.php
CHANGED
@@ -2,36 +2,28 @@
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
$taxonomies = customtaxorder_get_taxonomies() ;
|
14 |
-
|
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 |
/*
|
@@ -82,7 +74,7 @@ function customtaxorder_js_libs() {
|
|
82 |
wp_enqueue_script( 'jquery' );
|
83 |
wp_enqueue_script( 'jquery-ui-core' );
|
84 |
wp_enqueue_script( 'jquery-ui-sortable' );
|
85 |
-
wp_enqueue_script( 'customtaxorder', plugins_url( '/js/
|
86 |
}
|
87 |
}
|
88 |
}
|
2 |
|
3 |
|
4 |
function customtaxorder_register_settings() {
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
register_setting(
|
7 |
+
'customtaxorder_settings',
|
8 |
+
'customtaxorder_settings',
|
9 |
+
array(
|
10 |
+
'type' => 'string',
|
11 |
+
'show_in_rest' => false,
|
12 |
+
'default' => NULL,
|
13 |
+
'sanitize_callback' => 'customtaxorder_settings_validate'
|
14 |
+
));
|
15 |
+
register_setting(
|
16 |
+
'customtaxorder_settings',
|
17 |
+
'customtaxorder_taxonomies',
|
18 |
+
array(
|
19 |
+
'type' => 'string',
|
20 |
+
'show_in_rest' => false,
|
21 |
+
'default' => NULL,
|
22 |
+
'sanitize_callback' => 'customtaxorder_taxonomies_validate'
|
23 |
+
));
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
}
|
26 |
+
add_action('admin_init', 'customtaxorder_register_settings');
|
27 |
|
28 |
|
29 |
/*
|
74 |
wp_enqueue_script( 'jquery' );
|
75 |
wp_enqueue_script( 'jquery-ui-core' );
|
76 |
wp_enqueue_script( 'jquery-ui-sortable' );
|
77 |
+
wp_enqueue_script( 'customtaxorder', plugins_url( '/js/customtaxorder.js', __FILE__ ), 'jquery-ui-sortable', CUSTOMTAXORDER_VER, true );
|
78 |
}
|
79 |
}
|
80 |
}
|
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.
|
7 |
Author: Marcel Pol
|
8 |
Author URI: https://timelord.nl/
|
9 |
License: GPLv2 or later
|
@@ -12,7 +12,7 @@ Domain Path: /lang/
|
|
12 |
|
13 |
|
14 |
Copyright 2011 - 2011 Drew Gourley
|
15 |
-
Copyright 2013 -
|
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 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
40 |
|
41 |
|
42 |
// Plugin Version
|
43 |
-
define('CUSTOMTAXORDER_VER', '3.
|
44 |
|
45 |
|
46 |
/*
|
@@ -307,7 +307,6 @@ function customtaxorder_get_taxonomies() {
|
|
307 |
$taxonomies = get_taxonomies( $args, $output );
|
308 |
|
309 |
return $taxonomies;
|
310 |
-
return $taxonomies;
|
311 |
|
312 |
}
|
313 |
|
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.3.0
|
7 |
Author: Marcel Pol
|
8 |
Author URI: https://timelord.nl/
|
9 |
License: GPLv2 or later
|
12 |
|
13 |
|
14 |
Copyright 2011 - 2011 Drew Gourley
|
15 |
+
Copyright 2013 - 2021 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.3.0');
|
44 |
|
45 |
|
46 |
/*
|
307 |
$taxonomies = get_taxonomies( $args, $output );
|
308 |
|
309 |
return $taxonomies;
|
|
|
310 |
|
311 |
}
|
312 |
|
js/{script.js → customtaxorder.js}
RENAMED
@@ -8,30 +8,30 @@ jQuery(document).ready(function(jQuery) {
|
|
8 |
|
9 |
/* Submit button click event */
|
10 |
jQuery("#custom-loading").hide();
|
11 |
-
jQuery("#order-submit").click
|
12 |
customtaxorder_ordersubmit();
|
13 |
});
|
14 |
|
15 |
/* Button to sort the list alphabetically */
|
16 |
-
jQuery("#order-alpha").click
|
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
|
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 |
});
|
8 |
|
9 |
/* Submit button click event */
|
10 |
jQuery("#custom-loading").hide();
|
11 |
+
jQuery("#order-submit").on( 'click', function() {
|
12 |
customtaxorder_ordersubmit();
|
13 |
});
|
14 |
|
15 |
/* Button to sort the list alphabetically */
|
16 |
+
jQuery("#order-alpha").on( 'click', function(e) {
|
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").trigger('blur');
|
24 |
});
|
25 |
|
26 |
/* Button to sort the list on slug */
|
27 |
+
jQuery("#order-slug").on( '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").trigger('blur');
|
35 |
});
|
36 |
|
37 |
});
|
page-customtaxorder.php
CHANGED
@@ -8,48 +8,48 @@
|
|
8 |
function customtaxorder_subpage() {
|
9 |
global $sitepress;
|
10 |
|
11 |
-
customtaxorder_update_settings();
|
12 |
$options = customtaxorder_get_settings();
|
|
|
13 |
$parent_ID = 0;
|
|
|
14 |
|
15 |
-
|
|
|
16 |
|
17 |
if ( ! empty( $taxonomies ) ) {
|
18 |
foreach ( $taxonomies as $taxonomy ) {
|
19 |
-
$com_page = 'customtaxorder-'
|
20 |
-
if ( !isset($options[$taxonomy->name]) ) {
|
21 |
$options[$taxonomy->name] = 0; // default if not set in options yet
|
22 |
}
|
23 |
-
if ( $_GET['page'] == $com_page ) {
|
24 |
-
|
25 |
-
// Set your custom capability through this filter.
|
26 |
-
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
if ( function_exists('current_user_can') && ! current_user_can( $custom_cap_tax ) ) {
|
32 |
-
die(esc_html__( 'Cheatin’ uh?', 'custom-taxonomy-order-ne' ));
|
33 |
-
}
|
34 |
}
|
35 |
}
|
36 |
}
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
?>
|
39 |
<div class='wrap customtaxorder'>
|
40 |
<div id="icon-customtaxorder"></div>
|
41 |
|
42 |
<?php
|
43 |
-
if ( $
|
44 |
// Main admin page with just a set of links to the taxonomy pages.
|
45 |
-
|
46 |
-
// Set your custom capability through this filter.
|
47 |
-
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
48 |
-
|
49 |
-
if ( function_exists('current_user_can') && ! current_user_can( $custom_cap ) ) {
|
50 |
-
die(esc_html__( 'Cheatin’ uh?', 'custom-taxonomy-order-ne' ));
|
51 |
-
}
|
52 |
-
|
53 |
?>
|
54 |
<h1>Custom Taxonomy Order</h1>
|
55 |
<div class="order-widget">
|
@@ -66,6 +66,7 @@ function customtaxorder_subpage() {
|
|
66 |
}
|
67 |
}
|
68 |
echo '</ul></div></div><!-- #wrap -->';
|
|
|
69 |
return;
|
70 |
}
|
71 |
|
@@ -76,22 +77,19 @@ function customtaxorder_subpage() {
|
|
76 |
if ( ! isset($options[$taxonomy->name]) ) {
|
77 |
$options[$taxonomy->name] = 0; // default if not set in options yet
|
78 |
}
|
79 |
-
if ( $
|
80 |
-
$settings .= '<label><input type="radio" name="customtaxorder_settings
|
81 |
';
|
82 |
-
$settings .= '<label><input type="radio" name="customtaxorder_settings
|
83 |
';
|
84 |
-
$settings .= '<label><input type="radio" name="customtaxorder_settings
|
85 |
';
|
86 |
-
$settings .= '<label><input type="radio" name="customtaxorder_settings
|
87 |
';
|
88 |
$tax_label = $taxonomy->label;
|
89 |
-
$
|
90 |
-
|
91 |
-
|
92 |
-
$options[$taxonomy->name] = 0; // default if not set in options yet
|
93 |
-
}
|
94 |
-
$settings .= '<input name="customtaxorder_settings[' . $taxonomy->name . ']" type="hidden" value="' . $options[$taxonomy->name] . '" />';
|
95 |
}
|
96 |
}
|
97 |
}
|
@@ -101,20 +99,19 @@ function customtaxorder_subpage() {
|
|
101 |
$parent_ID = $_POST['sub-posts'];
|
102 |
}
|
103 |
elseif (isset($_POST['hidden-parent-id'])) {
|
104 |
-
$parent_term = get_term($_POST['hidden-parent-id'], $
|
105 |
$parent_ID = $_POST['hidden-parent-id'];
|
106 |
if ( is_object($parent_term) && isset($parent_term->term_order) ) {
|
107 |
$parent_ID_order = $parent_term->term_order;
|
108 |
}
|
109 |
}
|
110 |
if (isset($_POST['return-sub-posts'])) {
|
111 |
-
$parent_term = get_term($_POST['hidden-parent-id'], $
|
112 |
$parent_ID = $parent_term->parent;
|
113 |
}
|
114 |
-
if (isset($_POST['order-submit'])) {
|
115 |
-
customtaxorder_update_order();
|
116 |
-
} ?>
|
117 |
|
|
|
|
|
118 |
<h1><?php echo esc_html__('Order ', 'custom-taxonomy-order-ne') . $tax_label; ?></h1>
|
119 |
<form name="custom-order-form" method="post" action=""><?php
|
120 |
|
@@ -128,8 +125,8 @@ function customtaxorder_subpage() {
|
|
128 |
remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ), 10 );
|
129 |
remove_filter( 'get_terms', array( $sitepress, 'get_terms_filter' ), 10 );
|
130 |
remove_filter( 'get_terms_args', array( $sitepress, 'get_terms_args_filter' ), 10, 2 ); // Needed to get the correct list of sub-terms.
|
131 |
-
remove_filter( "pre_option_{$
|
132 |
-
add_filter( "pre_option_{$
|
133 |
}
|
134 |
|
135 |
$args = array(
|
@@ -138,7 +135,7 @@ function customtaxorder_subpage() {
|
|
138 |
'hide_empty' => false,
|
139 |
'parent' => $parent_ID,
|
140 |
);
|
141 |
-
$terms = get_terms( $
|
142 |
if ( $terms ) {
|
143 |
usort($terms, 'customtax_cmp');
|
144 |
?>
|
@@ -172,7 +169,7 @@ function customtaxorder_subpage() {
|
|
172 |
<input type="hidden" id="hidden-parent-id-order" name="hidden-parent-id-order" value="<?php echo $parent_ID_order; ?>" />
|
173 |
</div>
|
174 |
<?php
|
175 |
-
$dropdown = customtaxorder_sub_query( $terms, $
|
176 |
if( ! empty($dropdown) ) { ?>
|
177 |
<div class="widget order-widget">
|
178 |
<h2 class="widget-top"><?php print(__('Sub-', 'custom-taxonomy-order-ne') . $tax_label); ?> | <small><?php esc_html_e('Choose a term from the dropdown to order its sub-terms.', 'custom-taxonomy-order-ne'); ?></small></h2>
|
@@ -189,8 +186,14 @@ function customtaxorder_subpage() {
|
|
189 |
<p><?php esc_html_e('No terms found', 'custom-taxonomy-order-ne'); ?></p>
|
190 |
<?php } ?>
|
191 |
</form>
|
192 |
-
|
193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
<div class="metabox-holder">
|
195 |
<div class="order-widget">
|
196 |
<h2 class="widget-top"><?php esc_html_e( 'Settings', 'custom-taxonomy-order-ne' ); ?></h2>
|
@@ -202,7 +205,6 @@ function customtaxorder_subpage() {
|
|
202 |
<td><?php echo $settings; ?></td>
|
203 |
</tr>
|
204 |
</table>
|
205 |
-
<input type="hidden" name="customtaxorder_settings[update]" value="Updated" />
|
206 |
<p class="submit">
|
207 |
<input type="submit" class="button-primary" value="<?php esc_attr_e('Save Settings', 'custom-taxonomy-order-ne') ?>" />
|
208 |
</p>
|
@@ -215,19 +217,6 @@ function customtaxorder_subpage() {
|
|
215 |
}
|
216 |
|
217 |
|
218 |
-
/*
|
219 |
-
* Called from customtaxorder_subpage().
|
220 |
-
*/
|
221 |
-
function customtaxorder_update_settings() {
|
222 |
-
$options = customtaxorder_get_settings();
|
223 |
-
if ( isset($options['update']) ) {
|
224 |
-
echo '<div class="updated fade notice is-dismissible" id="message"><p>' . esc_html__('Custom Taxonomy Order settings', 'custom-taxonomy-order-ne') . ' ' . $options['update'] . '</p></div>';
|
225 |
-
unset($options['update']);
|
226 |
-
update_option('customtaxorder_settings', $options);
|
227 |
-
}
|
228 |
-
}
|
229 |
-
|
230 |
-
|
231 |
/*
|
232 |
* customtaxorder_update_order
|
233 |
* Function to update the database with the submitted order
|
@@ -246,39 +235,156 @@ function customtaxorder_update_order() {
|
|
246 |
}
|
247 |
|
248 |
if (isset($_POST['hidden-custom-order']) && $_POST['hidden-custom-order'] != "") {
|
249 |
-
|
250 |
-
$
|
251 |
-
|
252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
}
|
254 |
-
$new_order = $_POST['hidden-custom-order'];
|
255 |
-
$IDs = explode(",", $new_order);
|
256 |
-
$ids = Array();
|
257 |
-
$result = count($IDs);
|
258 |
-
for ( $i = 0; $i < $result; $i++ ) {
|
259 |
-
$term_id = (int) str_replace("id_", "", $IDs[$i]);
|
260 |
-
$term_order = $i + $parent_ID_order;
|
261 |
|
262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
|
264 |
-
$ids[] = $term_id;
|
265 |
}
|
266 |
-
|
267 |
-
do_action('customtaxorder_update_order', $ids);
|
268 |
} else {
|
269 |
echo '<div id="message" class="error fade notice is-dismissible"><p>'. esc_html__('An error occured, order has not been saved.', 'custom-taxonomy-order-ne').'</p></div>';
|
270 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
}
|
272 |
|
273 |
|
274 |
/*
|
275 |
* Function to give dropdown options for the list of sub-terms.
|
276 |
*/
|
277 |
-
function customtaxorder_sub_query( $terms, $
|
278 |
$options = '';
|
279 |
if ( isset( $terms ) && is_array( $terms ) ) {
|
280 |
foreach ( $terms as $term ) {
|
281 |
-
$subterms = get_term_children( $term->term_id, $
|
282 |
if ( $subterms ) {
|
283 |
$options .= '<option value="' . $term->term_id . '">' . $term->name . '</option>';
|
284 |
}
|
8 |
function customtaxorder_subpage() {
|
9 |
global $sitepress;
|
10 |
|
|
|
11 |
$options = customtaxorder_get_settings();
|
12 |
+
$taxonomies = customtaxorder_get_taxonomies();
|
13 |
$parent_ID = 0;
|
14 |
+
$this_page = $_GET['page'];
|
15 |
|
16 |
+
// Set your custom capability through this filter.
|
17 |
+
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
18 |
|
19 |
if ( ! empty( $taxonomies ) ) {
|
20 |
foreach ( $taxonomies as $taxonomy ) {
|
21 |
+
$com_page = 'customtaxorder-' . $taxonomy->name;
|
22 |
+
if ( ! isset($options[$taxonomy->name]) ) {
|
23 |
$options[$taxonomy->name] = 0; // default if not set in options yet
|
24 |
}
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
if ( $this_page == $com_page ) {
|
27 |
+
// For this taxonomy, set your finegrained capability with this custom filter.
|
28 |
+
$custom_cap = apply_filters( 'customtaxorder_custom_cap_' . $taxonomy->name, $custom_cap );
|
|
|
|
|
|
|
29 |
}
|
30 |
}
|
31 |
}
|
32 |
|
33 |
+
if ( function_exists('current_user_can') && ! current_user_can( $custom_cap ) ) {
|
34 |
+
die(esc_html__( 'You need a higher level of permission.', 'custom-taxonomy-order-ne' ));
|
35 |
+
}
|
36 |
+
|
37 |
+
if (isset($_POST['order-submit'])) {
|
38 |
+
customtaxorder_update_order();
|
39 |
+
$taxonomies = customtaxorder_get_taxonomies(); // get it fresh
|
40 |
+
}
|
41 |
+
if ( isset($_POST['option_page']) && $_POST['option_page'] == 'customtaxorder_settings' ) {
|
42 |
+
customtaxorder_update_settings();
|
43 |
+
$options = customtaxorder_get_settings(); // get it fresh
|
44 |
+
}
|
45 |
+
|
46 |
?>
|
47 |
<div class='wrap customtaxorder'>
|
48 |
<div id="icon-customtaxorder"></div>
|
49 |
|
50 |
<?php
|
51 |
+
if ( $this_page == 'customtaxorder' ) {
|
52 |
// Main admin page with just a set of links to the taxonomy pages.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
?>
|
54 |
<h1>Custom Taxonomy Order</h1>
|
55 |
<div class="order-widget">
|
66 |
}
|
67 |
}
|
68 |
echo '</ul></div></div><!-- #wrap -->';
|
69 |
+
|
70 |
return;
|
71 |
}
|
72 |
|
77 |
if ( ! isset($options[$taxonomy->name]) ) {
|
78 |
$options[$taxonomy->name] = 0; // default if not set in options yet
|
79 |
}
|
80 |
+
if ( $this_page == $com_page ) {
|
81 |
+
$settings .= '<label><input type="radio" name="customtaxorder_settings" value="0" ' . checked('0', $options[$taxonomy->name], false) . ' /> ' . esc_html__('Order by ID (default).', 'custom-taxonomy-order-ne') . '</label><br />
|
82 |
';
|
83 |
+
$settings .= '<label><input type="radio" name="customtaxorder_settings" value="1" ' . checked('1', $options[$taxonomy->name], false) . ' /> ' . esc_html__('Custom Order as defined above.', 'custom-taxonomy-order-ne') . '</label><br />
|
84 |
';
|
85 |
+
$settings .= '<label><input type="radio" name="customtaxorder_settings" value="2" ' . checked('2', $options[$taxonomy->name], false) . ' /> ' . esc_html__('Alphabetical Order by name.', 'custom-taxonomy-order-ne') . '</label><br />
|
86 |
';
|
87 |
+
$settings .= '<label><input type="radio" name="customtaxorder_settings" value="3" ' . checked('3', $options[$taxonomy->name], false) . ' /> ' . esc_html__('Alphabetical Order by slug.', 'custom-taxonomy-order-ne') . '</label><br />
|
88 |
';
|
89 |
$tax_label = $taxonomy->label;
|
90 |
+
$tax_name = $taxonomy->name;
|
91 |
+
|
92 |
+
$settings .= '<input name="customtaxorder_taxname" type="hidden" value="' . $tax_name . '" />';
|
|
|
|
|
|
|
93 |
}
|
94 |
}
|
95 |
}
|
99 |
$parent_ID = $_POST['sub-posts'];
|
100 |
}
|
101 |
elseif (isset($_POST['hidden-parent-id'])) {
|
102 |
+
$parent_term = get_term($_POST['hidden-parent-id'], $tax_name);
|
103 |
$parent_ID = $_POST['hidden-parent-id'];
|
104 |
if ( is_object($parent_term) && isset($parent_term->term_order) ) {
|
105 |
$parent_ID_order = $parent_term->term_order;
|
106 |
}
|
107 |
}
|
108 |
if (isset($_POST['return-sub-posts'])) {
|
109 |
+
$parent_term = get_term($_POST['hidden-parent-id'], $tax_name);
|
110 |
$parent_ID = $parent_term->parent;
|
111 |
}
|
|
|
|
|
|
|
112 |
|
113 |
+
|
114 |
+
// Terms in this taxonomy, ordered according to settings. */ ?>
|
115 |
<h1><?php echo esc_html__('Order ', 'custom-taxonomy-order-ne') . $tax_label; ?></h1>
|
116 |
<form name="custom-order-form" method="post" action=""><?php
|
117 |
|
125 |
remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ), 10 );
|
126 |
remove_filter( 'get_terms', array( $sitepress, 'get_terms_filter' ), 10 );
|
127 |
remove_filter( 'get_terms_args', array( $sitepress, 'get_terms_args_filter' ), 10, 2 ); // Needed to get the correct list of sub-terms.
|
128 |
+
remove_filter( "pre_option_{$tax_name}_children", array( $sitepress, 'pre_option_tax_children' ), 10, 0 );
|
129 |
+
add_filter( "pre_option_{$tax_name}_children", 'customtaxorder_pre_option_tax_children', 99, 0 ); // Needed to fill the dropdown of sub-terms.
|
130 |
}
|
131 |
|
132 |
$args = array(
|
135 |
'hide_empty' => false,
|
136 |
'parent' => $parent_ID,
|
137 |
);
|
138 |
+
$terms = get_terms( $tax_name, $args );
|
139 |
if ( $terms ) {
|
140 |
usort($terms, 'customtax_cmp');
|
141 |
?>
|
169 |
<input type="hidden" id="hidden-parent-id-order" name="hidden-parent-id-order" value="<?php echo $parent_ID_order; ?>" />
|
170 |
</div>
|
171 |
<?php
|
172 |
+
$dropdown = customtaxorder_sub_query( $terms, $tax_name );
|
173 |
if( ! empty($dropdown) ) { ?>
|
174 |
<div class="widget order-widget">
|
175 |
<h2 class="widget-top"><?php print(__('Sub-', 'custom-taxonomy-order-ne') . $tax_label); ?> | <small><?php esc_html_e('Choose a term from the dropdown to order its sub-terms.', 'custom-taxonomy-order-ne'); ?></small></h2>
|
186 |
<p><?php esc_html_e('No terms found', 'custom-taxonomy-order-ne'); ?></p>
|
187 |
<?php } ?>
|
188 |
</form>
|
189 |
+
|
190 |
+
<?php // Settings for this taxonomy */ ?>
|
191 |
+
<form method="post" action="" class="clear">
|
192 |
+
<?php
|
193 |
+
/* Nonce */
|
194 |
+
$nonce = wp_create_nonce( 'custom-taxonomy-order-ne-nonce' );
|
195 |
+
echo '<input type="hidden" id="custom-taxonomy-order-ne-nonce" name="custom-taxonomy-order-ne-nonce" value="' . $nonce . '" />';
|
196 |
+
settings_fields('customtaxorder_settings'); ?>
|
197 |
<div class="metabox-holder">
|
198 |
<div class="order-widget">
|
199 |
<h2 class="widget-top"><?php esc_html_e( 'Settings', 'custom-taxonomy-order-ne' ); ?></h2>
|
205 |
<td><?php echo $settings; ?></td>
|
206 |
</tr>
|
207 |
</table>
|
|
|
208 |
<p class="submit">
|
209 |
<input type="submit" class="button-primary" value="<?php esc_attr_e('Save Settings', 'custom-taxonomy-order-ne') ?>" />
|
210 |
</p>
|
217 |
}
|
218 |
|
219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
/*
|
221 |
* customtaxorder_update_order
|
222 |
* Function to update the database with the submitted order
|
235 |
}
|
236 |
|
237 |
if (isset($_POST['hidden-custom-order']) && $_POST['hidden-custom-order'] != "") {
|
238 |
+
|
239 |
+
$options = customtaxorder_get_settings();
|
240 |
+
$taxonomies = customtaxorder_get_taxonomies() ;
|
241 |
+
$this_page = $_GET['page'];
|
242 |
+
|
243 |
+
// Set your custom capability through this filter.
|
244 |
+
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
245 |
+
|
246 |
+
if ( ! empty( $taxonomies ) ) {
|
247 |
+
foreach ( $taxonomies as $taxonomy ) {
|
248 |
+
$com_page = 'customtaxorder-' . $taxonomy->name;
|
249 |
+
if ( $this_page == $com_page ) {
|
250 |
+
|
251 |
+
// For this taxonomy, set your finegrained capability with this custom filter.
|
252 |
+
$custom_cap = apply_filters( 'customtaxorder_custom_cap_' . $taxonomy->name, $custom_cap );
|
253 |
+
|
254 |
+
}
|
255 |
+
}
|
256 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
|
258 |
+
if ( function_exists('current_user_can') && ! current_user_can( $custom_cap ) ) {
|
259 |
+
die(esc_html__( 'You need a higher level of permission.', 'custom-taxonomy-order-ne' ));
|
260 |
+
} else {
|
261 |
+
|
262 |
+
$parent_id_order = 0;
|
263 |
+
if ( isset($_POST['hidden-parent-id-order']) && $_POST['hidden-parent-id-order'] > 0 ) {
|
264 |
+
$parent_id_order = (int) $_POST['hidden-parent-id-order'] + 1;
|
265 |
+
}
|
266 |
+
$new_order = $_POST['hidden-custom-order'];
|
267 |
+
$submitted_ids = explode(",", $new_order);
|
268 |
+
$updated_ids = array();
|
269 |
+
$result = count($submitted_ids);
|
270 |
+
for ( $i = 0; $i < $result; $i++ ) {
|
271 |
+
$term_id = (int) str_replace("id_", "", $submitted_ids[$i]);
|
272 |
+
$term_order = $i + $parent_id_order;
|
273 |
+
|
274 |
+
customtaxorder_set_db_term_order( $term_id, $term_order );
|
275 |
+
|
276 |
+
$updated_ids[] = $term_id;
|
277 |
+
}
|
278 |
+
echo '<div id="message" class="updated fade notice is-dismissible"><p>'. esc_html__('Order updated successfully.', 'custom-taxonomy-order-ne').'</p></div>';
|
279 |
+
do_action('customtaxorder_update_order', $updated_ids);
|
280 |
|
|
|
281 |
}
|
282 |
+
|
|
|
283 |
} else {
|
284 |
echo '<div id="message" class="error fade notice is-dismissible"><p>'. esc_html__('An error occured, order has not been saved.', 'custom-taxonomy-order-ne').'</p></div>';
|
285 |
}
|
286 |
+
|
287 |
+
}
|
288 |
+
|
289 |
+
|
290 |
+
/*
|
291 |
+
* Called from customtaxorder_subpage().
|
292 |
+
*/
|
293 |
+
function customtaxorder_update_settings() {
|
294 |
+
|
295 |
+
/* Check Nonce */
|
296 |
+
$verified = false;
|
297 |
+
if ( isset($_POST['custom-taxonomy-order-ne-nonce']) ) {
|
298 |
+
$verified = wp_verify_nonce( $_POST['custom-taxonomy-order-ne-nonce'], 'custom-taxonomy-order-ne-nonce' );
|
299 |
+
}
|
300 |
+
if ( $verified == false ) {
|
301 |
+
// Nonce is invalid.
|
302 |
+
echo '<div id="message" class="error fade notice is-dismissible"><p>' . esc_html__('The Nonce did not validate. Please try again.', 'custom-taxonomy-order-ne') . '</p></div>';
|
303 |
+
return;
|
304 |
+
}
|
305 |
+
|
306 |
+
$tax_name = '';
|
307 |
+
$tax_setting = 0; // default if not set in options yet
|
308 |
+
|
309 |
+
if ( isset( $_POST['customtaxorder_taxname'] ) ) {
|
310 |
+
$tax_name = (string) sanitize_text_field( $_POST['customtaxorder_taxname'] );
|
311 |
+
}
|
312 |
+
if ( isset( $_POST['customtaxorder_settings'] ) ) {
|
313 |
+
$tax_setting = (int) $_POST['customtaxorder_settings'];
|
314 |
+
}
|
315 |
+
|
316 |
+
if ( strlen( $tax_name ) > 0 ) {
|
317 |
+
|
318 |
+
$options = customtaxorder_get_settings();
|
319 |
+
$taxonomies = customtaxorder_get_taxonomies() ;
|
320 |
+
$this_page = $_GET['page'];
|
321 |
+
|
322 |
+
// Set your custom capability through this filter.
|
323 |
+
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
324 |
+
|
325 |
+
if ( ! empty( $taxonomies ) ) {
|
326 |
+
foreach ( $taxonomies as $taxonomy ) {
|
327 |
+
$com_page = 'customtaxorder-' . $taxonomy->name;
|
328 |
+
if ( $this_page == $com_page && $tax_name == $taxonomy->name ) {
|
329 |
+
|
330 |
+
// For this taxonomy, set your finegrained capability with this custom filter.
|
331 |
+
$custom_cap = apply_filters( 'customtaxorder_custom_cap_' . $taxonomy->name, $custom_cap );
|
332 |
+
|
333 |
+
}
|
334 |
+
}
|
335 |
+
}
|
336 |
+
|
337 |
+
if ( function_exists('current_user_can') && ! current_user_can( $custom_cap ) ) {
|
338 |
+
die(esc_html__( 'You need a higher level of permission.', 'custom-taxonomy-order-ne' ));
|
339 |
+
} else {
|
340 |
+
foreach ( $taxonomies as $taxonomy ) {
|
341 |
+
if ( $taxonomy->name == $tax_name ) {
|
342 |
+
|
343 |
+
$options[$taxonomy->name] = $tax_setting;
|
344 |
+
$customtaxorder_settings = update_option( 'customtaxorder_settings', $options );
|
345 |
+
echo '<div class="updated fade notice is-dismissible" id="message"><p>' . esc_html__('Settings have been saved', 'custom-taxonomy-order-ne') . '</p></div>';
|
346 |
+
return;
|
347 |
+
|
348 |
+
}
|
349 |
+
}
|
350 |
+
}
|
351 |
+
|
352 |
+
}
|
353 |
+
echo '<div id="message" class="error fade notice is-dismissible"><p>' . esc_html__('The Settings could not be saved. Please try again.', 'custom-taxonomy-order-ne') . '</p></div>';
|
354 |
+
|
355 |
+
}
|
356 |
+
/* Called from settings API, register_settings(). */
|
357 |
+
function customtaxorder_settings_validate( $input ) {
|
358 |
+
|
359 |
+
$taxonomies = customtaxorder_get_taxonomies() ;
|
360 |
+
|
361 |
+
foreach ( $taxonomies as $taxonomy ) {
|
362 |
+
if ( $input[$taxonomy->name] != 1 ) {
|
363 |
+
if ( $input[$taxonomy->name] != 2 ) {
|
364 |
+
if ( $input[$taxonomy->name] != 3 ) {
|
365 |
+
$input[$taxonomy->name] = 0; //default
|
366 |
+
}
|
367 |
+
}
|
368 |
+
}
|
369 |
+
}
|
370 |
+
$output = array();
|
371 |
+
foreach ( $input as $key => $value) {
|
372 |
+
$key = (string) sanitize_text_field( $key );
|
373 |
+
$output[$key] = (int) $value;
|
374 |
+
}
|
375 |
+
return $output;
|
376 |
+
|
377 |
}
|
378 |
|
379 |
|
380 |
/*
|
381 |
* Function to give dropdown options for the list of sub-terms.
|
382 |
*/
|
383 |
+
function customtaxorder_sub_query( $terms, $tax_name ) {
|
384 |
$options = '';
|
385 |
if ( isset( $terms ) && is_array( $terms ) ) {
|
386 |
foreach ( $terms as $term ) {
|
387 |
+
$subterms = get_term_children( $term->term_id, $tax_name );
|
388 |
if ( $subterms ) {
|
389 |
$options .= '<option value="' . $term->term_id . '">' . $term->name . '</option>';
|
390 |
}
|
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: 5.
|
6 |
-
Stable tag: 3.
|
7 |
License: GPLv2 or later
|
8 |
|
9 |
|
@@ -29,6 +29,10 @@ It supports the following features:
|
|
29 |
|
30 |
This plugin is compatible with [ClassicPress](https://www.classicpress.net).
|
31 |
|
|
|
|
|
|
|
|
|
32 |
|
33 |
== Installation ==
|
34 |
|
@@ -159,6 +163,13 @@ The left metabox lists the toplevel terms. Right (or below) are the sub-terms.
|
|
159 |
|
160 |
== Changelog ==
|
161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
= 3.2.2 =
|
163 |
* 2020-12-04
|
164 |
* Fix category/tag edit screen, extra field.
|
2 |
Contributors: mpol
|
3 |
Tags: term order, category order, taxonomy order, order
|
4 |
Requires at least: 3.7
|
5 |
+
Tested up to: 5.8
|
6 |
+
Stable tag: 3.3.0
|
7 |
License: GPLv2 or later
|
8 |
|
9 |
|
29 |
|
30 |
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 ==
|
38 |
|
163 |
|
164 |
== Changelog ==
|
165 |
|
166 |
+
= 3.3.0 =
|
167 |
+
* 2021-02-23
|
168 |
+
* Save settings per taxonomy with capability 'manage_categories', not 'manage_options'.
|
169 |
+
* Rewrite some code for settings pages.
|
170 |
+
* Fix deprecated jQuery calls with WP 5.6 and jQuery 3.5.
|
171 |
+
* Rename script.js to customtaxorder.js.
|
172 |
+
|
173 |
= 3.2.2 =
|
174 |
* 2020-12-04
|
175 |
* Fix category/tag edit screen, extra field.
|
taxonomies.php
CHANGED
@@ -6,8 +6,8 @@ function custom_taxonomy_order() {
|
|
6 |
// Set your custom capability through this filter.
|
7 |
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
8 |
|
9 |
-
if ( function_exists('current_user_can') && !current_user_can( $custom_cap ) ) {
|
10 |
-
die(esc_html__( '
|
11 |
}
|
12 |
|
13 |
if (isset($_POST['order-submit'])) {
|
@@ -84,6 +84,13 @@ function customtaxorder_update_taxonomies() {
|
|
84 |
return;
|
85 |
}
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
if (isset($_POST['hidden-taxonomy-order']) && $_POST['hidden-taxonomy-order'] != "") {
|
88 |
|
89 |
$new_order = $_POST['hidden-taxonomy-order'];
|
@@ -94,8 +101,14 @@ function customtaxorder_update_taxonomies() {
|
|
94 |
} else {
|
95 |
echo '<div id="message" class="error fade notice is-dismissible"><p>'. esc_html__('An error occured, order has not been saved.', 'custom-taxonomy-order-ne').'</p></div>';
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
|
|
|
|
|
|
|
|
|
99 |
|
100 |
/*
|
101 |
* Sort the taxonomies.
|
6 |
// Set your custom capability through this filter.
|
7 |
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
8 |
|
9 |
+
if ( function_exists('current_user_can') && ! current_user_can( $custom_cap ) ) {
|
10 |
+
die(esc_html__( 'You need a higher level of permission.', 'custom-taxonomy-order-ne' ));
|
11 |
}
|
12 |
|
13 |
if (isset($_POST['order-submit'])) {
|
84 |
return;
|
85 |
}
|
86 |
|
87 |
+
// Set your custom capability through this filter.
|
88 |
+
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
89 |
+
|
90 |
+
if ( function_exists('current_user_can') && ! current_user_can( $custom_cap ) ) {
|
91 |
+
die(esc_html__( 'You need a higher level of permission.', 'custom-taxonomy-order-ne' ));
|
92 |
+
}
|
93 |
+
|
94 |
if (isset($_POST['hidden-taxonomy-order']) && $_POST['hidden-taxonomy-order'] != "") {
|
95 |
|
96 |
$new_order = $_POST['hidden-taxonomy-order'];
|
101 |
} else {
|
102 |
echo '<div id="message" class="error fade notice is-dismissible"><p>'. esc_html__('An error occured, order has not been saved.', 'custom-taxonomy-order-ne').'</p></div>';
|
103 |
}
|
104 |
+
|
105 |
}
|
106 |
+
function customtaxorder_taxonomies_validate($input) {
|
107 |
|
108 |
+
$input = (string) sanitize_text_field( $input );
|
109 |
+
return $input;
|
110 |
+
|
111 |
+
}
|
112 |
|
113 |
/*
|
114 |
* Sort the taxonomies.
|