Version Description
- 2021-11-26
- Bring back removed code for orderby clause in 'get_terms_orderby' filter.
- No need to check if function 'current_user_can' and 'is_multisite' exist.
- Use functions like 'esc_attr', 'esc_html' and 'esc_url' when appropriate.
Download this release
Release Info
Developer | mpol |
Plugin | Custom Taxonomy Order NE |
Version | 3.3.1 |
Comparing to | |
See all releases |
Code changes from version 3.3.0 to 3.3.1
- admin-customtaxorder.php +12 -10
- customtaxorder.php +24 -24
- page-customtaxorder.php +33 -34
- readme.txt +7 -1
- taxonomies.php +8 -9
admin-customtaxorder.php
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
<?php
|
2 |
-
|
|
|
|
|
3 |
|
4 |
function customtaxorder_register_settings() {
|
5 |
|
@@ -10,7 +12,7 @@ function customtaxorder_register_settings() {
|
|
10 |
'type' => 'string',
|
11 |
'show_in_rest' => false,
|
12 |
'default' => NULL,
|
13 |
-
'sanitize_callback' => 'customtaxorder_settings_validate'
|
14 |
));
|
15 |
register_setting(
|
16 |
'customtaxorder_settings',
|
@@ -19,7 +21,7 @@ function customtaxorder_register_settings() {
|
|
19 |
'type' => 'string',
|
20 |
'show_in_rest' => false,
|
21 |
'default' => NULL,
|
22 |
-
'sanitize_callback' => 'customtaxorder_taxonomies_validate'
|
23 |
));
|
24 |
|
25 |
}
|
@@ -54,10 +56,10 @@ add_action('admin_menu', 'customtaxorder_menu');
|
|
54 |
|
55 |
function customtaxorder_css() {
|
56 |
if ( isset($_GET['page']) ) {
|
57 |
-
$pos_page = $_GET['page'];
|
58 |
$pos_args = 'customtaxorder';
|
59 |
-
$pos = strpos($pos_page
|
60 |
-
if ( $pos
|
61 |
wp_enqueue_style('customtaxorder', plugins_url( 'css/customtaxorder.css', __FILE__), false, CUSTOMTAXORDER_VER, 'screen' );
|
62 |
}
|
63 |
}
|
@@ -67,10 +69,10 @@ add_action('admin_print_styles', 'customtaxorder_css');
|
|
67 |
|
68 |
function customtaxorder_js_libs() {
|
69 |
if ( isset($_GET['page']) ) {
|
70 |
-
$pos_page = $_GET['page'];
|
71 |
$pos_args = 'customtaxorder';
|
72 |
-
$pos = strpos($pos_page
|
73 |
-
if ( $pos
|
74 |
wp_enqueue_script( 'jquery' );
|
75 |
wp_enqueue_script( 'jquery-ui-core' );
|
76 |
wp_enqueue_script( 'jquery-ui-sortable' );
|
@@ -138,7 +140,7 @@ function customtaxorder_term_order_edit_form_field( $term, $taxonomy ) {
|
|
138 |
$options = customtaxorder_get_settings();
|
139 |
if ( isset($options[$taxonomy]) && $options[$taxonomy] == 1 ) {
|
140 |
if ( is_object($term) && isset($term->term_order) ) {
|
141 |
-
$term_order = $term->term_order;
|
142 |
} else {
|
143 |
$term_order = 0;
|
144 |
}
|
1 |
<?php
|
2 |
+
/*
|
3 |
+
* Admin functions for Custom Taxonomy Order.
|
4 |
+
*/
|
5 |
|
6 |
function customtaxorder_register_settings() {
|
7 |
|
12 |
'type' => 'string',
|
13 |
'show_in_rest' => false,
|
14 |
'default' => NULL,
|
15 |
+
'sanitize_callback' => 'customtaxorder_settings_validate',
|
16 |
));
|
17 |
register_setting(
|
18 |
'customtaxorder_settings',
|
21 |
'type' => 'string',
|
22 |
'show_in_rest' => false,
|
23 |
'default' => NULL,
|
24 |
+
'sanitize_callback' => 'customtaxorder_taxonomies_validate',
|
25 |
));
|
26 |
|
27 |
}
|
56 |
|
57 |
function customtaxorder_css() {
|
58 |
if ( isset($_GET['page']) ) {
|
59 |
+
$pos_page = sanitize_text_field( $_GET['page'] );
|
60 |
$pos_args = 'customtaxorder';
|
61 |
+
$pos = strpos($pos_page, $pos_args);
|
62 |
+
if ( $pos !== false ) {
|
63 |
wp_enqueue_style('customtaxorder', plugins_url( 'css/customtaxorder.css', __FILE__), false, CUSTOMTAXORDER_VER, 'screen' );
|
64 |
}
|
65 |
}
|
69 |
|
70 |
function customtaxorder_js_libs() {
|
71 |
if ( isset($_GET['page']) ) {
|
72 |
+
$pos_page = sanitize_text_field( $_GET['page'] );
|
73 |
$pos_args = 'customtaxorder';
|
74 |
+
$pos = strpos($pos_page, $pos_args);
|
75 |
+
if ( $pos !== false ) {
|
76 |
wp_enqueue_script( 'jquery' );
|
77 |
wp_enqueue_script( 'jquery-ui-core' );
|
78 |
wp_enqueue_script( 'jquery-ui-sortable' );
|
140 |
$options = customtaxorder_get_settings();
|
141 |
if ( isset($options[$taxonomy]) && $options[$taxonomy] == 1 ) {
|
142 |
if ( is_object($term) && isset($term->term_order) ) {
|
143 |
+
$term_order = (int) $term->term_order;
|
144 |
} else {
|
145 |
$term_order = 0;
|
146 |
}
|
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.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 - 2021 Marcel Pol (
|
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.3.
|
44 |
|
45 |
|
46 |
/*
|
@@ -102,15 +102,15 @@ function customtaxorder_apply_order_filter( $orderby, $args ) {
|
|
102 |
$options[$taxonomy] = 0; // Default if it was not set in options yet.
|
103 |
}
|
104 |
|
105 |
-
if ( $args['orderby'] == '
|
106 |
return 't.term_order';
|
107 |
-
}
|
108 |
return 't.name';
|
109 |
-
}
|
110 |
return 't.term_order';
|
111 |
-
}
|
112 |
return 't.name';
|
113 |
-
}
|
114 |
return 't.slug';
|
115 |
} else {
|
116 |
return $orderby;
|
@@ -121,7 +121,7 @@ add_filter('get_terms_orderby', 'customtaxorder_apply_order_filter', 10, 2);
|
|
121 |
|
122 |
/*
|
123 |
* Set defaults in Class WP_Term_Query->parse_query();
|
124 |
-
* Default is name now. Set it to term_order if desired.
|
125 |
*/
|
126 |
function customtaxorder_get_terms_defaults( $query_var_defaults, $taxonomies ) {
|
127 |
$options = customtaxorder_get_settings();
|
@@ -139,9 +139,9 @@ function customtaxorder_get_terms_defaults( $query_var_defaults, $taxonomies ) {
|
|
139 |
|
140 |
if ( $options[$taxonomy] == 1 ) {
|
141 |
$query_var_defaults['orderby'] = 'term_order';
|
142 |
-
}
|
143 |
$query_var_defaults['orderby'] = 'name';
|
144 |
-
}
|
145 |
$query_var_defaults['orderby'] = 'slug';
|
146 |
}
|
147 |
|
@@ -189,8 +189,8 @@ function customtaxorder_wp_get_object_terms_order_filter( $terms ) {
|
|
189 |
// filtering will happen in the tag_cloud_sort filter sometime later
|
190 |
// post_tag = default tags
|
191 |
// product_tag = woocommerce product tags
|
192 |
-
if ( current_filter() == 'get_terms' && !is_admin() ) {
|
193 |
-
$customtaxorder_exclude_taxonomies = array('post_tag', 'product_tag');
|
194 |
if ( in_array($taxonomy, apply_filters( 'customtaxorder_exclude_taxonomies', $customtaxorder_exclude_taxonomies )) ) {
|
195 |
return $terms;
|
196 |
}
|
@@ -201,8 +201,8 @@ function customtaxorder_wp_get_object_terms_order_filter( $terms ) {
|
|
201 |
if ( ! $term->parent == 0 ) {
|
202 |
$parents = get_ancestors( $term->term_id, $term->taxonomy, 'taxonomy' );
|
203 |
if ( is_array($parents) && ! empty($parents) ) {
|
204 |
-
$
|
205 |
-
$ancestor_term = get_term($
|
206 |
if ( is_object($ancestor_term) && isset($ancestor_term->term_order) ) {
|
207 |
$float_front = (string) $ancestor_term->term_order;
|
208 |
$float_rear = (string) ( $term->term_order + 10000 ); // Make it sort correctly. Not many websites have more than 90000 subterms.
|
@@ -323,12 +323,12 @@ function _customtaxorder_activate() {
|
|
323 |
}
|
324 |
|
325 |
|
326 |
-
function customtaxorder_activate($networkwide) {
|
327 |
global $wpdb;
|
328 |
-
if (
|
329 |
$blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
|
330 |
-
foreach ($blogids as $blog_id) {
|
331 |
-
switch_to_blog($blog_id);
|
332 |
_customtaxorder_activate();
|
333 |
restore_current_blog();
|
334 |
}
|
@@ -344,8 +344,8 @@ register_activation_hook( __FILE__, 'customtaxorder_activate' );
|
|
344 |
* Deprecated action since WP 5.1.0.
|
345 |
*
|
346 |
*/
|
347 |
-
function customtaxorder_activate_new_site($blog_id) {
|
348 |
-
switch_to_blog($blog_id);
|
349 |
_customtaxorder_activate();
|
350 |
restore_current_blog();
|
351 |
}
|
@@ -369,9 +369,9 @@ add_action( 'wp_initialize_site', 'customtaxorder_wp_initialize_site' );
|
|
369 |
|
370 |
if ( is_admin() ) {
|
371 |
// Admin functions
|
372 |
-
|
373 |
// Settingspage
|
374 |
-
|
375 |
}
|
376 |
// functions for sorting taxonomies
|
377 |
-
|
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.1
|
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 (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.1');
|
44 |
|
45 |
|
46 |
/*
|
102 |
$options[$taxonomy] = 0; // Default if it was not set in options yet.
|
103 |
}
|
104 |
|
105 |
+
if ( $args['orderby'] == 'term_order' ) {
|
106 |
return 't.term_order';
|
107 |
+
} else if ( $args['orderby'] == 'name' ) {
|
108 |
return 't.name';
|
109 |
+
} else if ( $options[$taxonomy] == 1 && ! isset($_GET['orderby']) ) {
|
110 |
return 't.term_order';
|
111 |
+
} else if ( $options[$taxonomy] == 2 && ! isset($_GET['orderby']) ) {
|
112 |
return 't.name';
|
113 |
+
} else if ( $options[$taxonomy] == 3 && ! isset($_GET['orderby']) ) {
|
114 |
return 't.slug';
|
115 |
} else {
|
116 |
return $orderby;
|
121 |
|
122 |
/*
|
123 |
* Set defaults in Class WP_Term_Query->parse_query();
|
124 |
+
* Default is name now. Set it to term_order or slug if desired.
|
125 |
*/
|
126 |
function customtaxorder_get_terms_defaults( $query_var_defaults, $taxonomies ) {
|
127 |
$options = customtaxorder_get_settings();
|
139 |
|
140 |
if ( $options[$taxonomy] == 1 ) {
|
141 |
$query_var_defaults['orderby'] = 'term_order';
|
142 |
+
} else if ( $options[$taxonomy] == 2 ) {
|
143 |
$query_var_defaults['orderby'] = 'name';
|
144 |
+
} else if ( $options[$taxonomy] == 3 ) {
|
145 |
$query_var_defaults['orderby'] = 'slug';
|
146 |
}
|
147 |
|
189 |
// filtering will happen in the tag_cloud_sort filter sometime later
|
190 |
// post_tag = default tags
|
191 |
// product_tag = woocommerce product tags
|
192 |
+
if ( current_filter() == 'get_terms' && ! is_admin() ) {
|
193 |
+
$customtaxorder_exclude_taxonomies = array( 'post_tag', 'product_tag' );
|
194 |
if ( in_array($taxonomy, apply_filters( 'customtaxorder_exclude_taxonomies', $customtaxorder_exclude_taxonomies )) ) {
|
195 |
return $terms;
|
196 |
}
|
201 |
if ( ! $term->parent == 0 ) {
|
202 |
$parents = get_ancestors( $term->term_id, $term->taxonomy, 'taxonomy' );
|
203 |
if ( is_array($parents) && ! empty($parents) ) {
|
204 |
+
$ancestor_id = array_pop( $parents );
|
205 |
+
$ancestor_term = get_term($ancestor_id, $term->taxonomy);
|
206 |
if ( is_object($ancestor_term) && isset($ancestor_term->term_order) ) {
|
207 |
$float_front = (string) $ancestor_term->term_order;
|
208 |
$float_rear = (string) ( $term->term_order + 10000 ); // Make it sort correctly. Not many websites have more than 90000 subterms.
|
323 |
}
|
324 |
|
325 |
|
326 |
+
function customtaxorder_activate( $networkwide ) {
|
327 |
global $wpdb;
|
328 |
+
if ( is_multisite() ) {
|
329 |
$blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
|
330 |
+
foreach ( $blogids as $blog_id ) {
|
331 |
+
switch_to_blog( $blog_id );
|
332 |
_customtaxorder_activate();
|
333 |
restore_current_blog();
|
334 |
}
|
344 |
* Deprecated action since WP 5.1.0.
|
345 |
*
|
346 |
*/
|
347 |
+
function customtaxorder_activate_new_site( $blog_id ) {
|
348 |
+
switch_to_blog( $blog_id );
|
349 |
_customtaxorder_activate();
|
350 |
restore_current_blog();
|
351 |
}
|
369 |
|
370 |
if ( is_admin() ) {
|
371 |
// Admin functions
|
372 |
+
require_once 'admin-customtaxorder.php';
|
373 |
// Settingspage
|
374 |
+
require_once 'page-customtaxorder.php';
|
375 |
}
|
376 |
// functions for sorting taxonomies
|
377 |
+
require_once 'taxonomies.php';
|
page-customtaxorder.php
CHANGED
@@ -10,8 +10,8 @@ function customtaxorder_subpage() {
|
|
10 |
|
11 |
$options = customtaxorder_get_settings();
|
12 |
$taxonomies = customtaxorder_get_taxonomies();
|
13 |
-
$
|
14 |
-
$this_page = $_GET['page'];
|
15 |
|
16 |
// Set your custom capability through this filter.
|
17 |
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
@@ -30,7 +30,7 @@ function customtaxorder_subpage() {
|
|
30 |
}
|
31 |
}
|
32 |
|
33 |
-
if (
|
34 |
die(esc_html__( 'You need a higher level of permission.', 'custom-taxonomy-order-ne' ));
|
35 |
}
|
36 |
|
@@ -38,7 +38,7 @@ function customtaxorder_subpage() {
|
|
38 |
customtaxorder_update_order();
|
39 |
$taxonomies = customtaxorder_get_taxonomies(); // get it fresh
|
40 |
}
|
41 |
-
if ( isset($_POST['option_page']) && $_POST['option_page']
|
42 |
customtaxorder_update_settings();
|
43 |
$options = customtaxorder_get_settings(); // get it fresh
|
44 |
}
|
@@ -61,7 +61,7 @@ function customtaxorder_subpage() {
|
|
61 |
echo '<li class="lineitem"><a href="' . admin_url( 'admin.php?page=customtaxorder-taxonomies' ) . '">' . esc_html__('Taxonomies', 'custom-taxonomy-order-ne') . '</a></li>
|
62 |
';
|
63 |
foreach ( $taxonomies as $taxonomy ) {
|
64 |
-
echo '<li class="lineitem"><a href="' . admin_url( 'admin.php?page=customtaxorder-' . $taxonomy->name ) . '">' . $taxonomy->label . '</a> (' . $taxonomy->name . ')</li>
|
65 |
';
|
66 |
}
|
67 |
}
|
@@ -89,35 +89,34 @@ function customtaxorder_subpage() {
|
|
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 |
}
|
96 |
|
97 |
-
$
|
98 |
if (isset($_POST['go-sub-posts'])) {
|
99 |
-
$
|
100 |
-
}
|
101 |
-
elseif (isset($_POST['hidden-parent-id'])) {
|
102 |
$parent_term = get_term($_POST['hidden-parent-id'], $tax_name);
|
103 |
-
$
|
104 |
if ( is_object($parent_term) && isset($parent_term->term_order) ) {
|
105 |
-
$
|
106 |
}
|
107 |
}
|
108 |
if (isset($_POST['return-sub-posts'])) {
|
109 |
$parent_term = get_term($_POST['hidden-parent-id'], $tax_name);
|
110 |
-
$
|
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 |
|
118 |
/* Nonce */
|
119 |
$nonce = wp_create_nonce( 'custom-taxonomy-order-ne-nonce' );
|
120 |
-
echo '<input type="hidden" id="custom-taxonomy-order-ne-nonce" name="custom-taxonomy-order-ne-nonce" value="' . $nonce . '" />';
|
121 |
|
122 |
// Remove filters for WPML and add one filter of our own.
|
123 |
$active_plugins = get_option('active_plugins');
|
@@ -133,7 +132,7 @@ function customtaxorder_subpage() {
|
|
133 |
'orderby' => 'term_order',
|
134 |
'order' => 'ASC',
|
135 |
'hide_empty' => false,
|
136 |
-
'parent' => $
|
137 |
);
|
138 |
$terms = get_terms( $tax_name, $args );
|
139 |
if ( $terms ) {
|
@@ -141,16 +140,16 @@ function customtaxorder_subpage() {
|
|
141 |
?>
|
142 |
<div id="poststuff" class="metabox-holder">
|
143 |
<div class="widget order-widget">
|
144 |
-
<h2 class="widget-top"><?php
|
145 |
<div class="misc-pub-section">
|
146 |
<ul id="custom-order-list">
|
147 |
<?php foreach ( $terms as $term ) { ?>
|
148 |
-
<li id="id_<?php echo $term->term_id; ?>" data-slug="<?php echo $term->slug; ?>" class="lineitem"><?php echo $term->name; ?></li>
|
149 |
<?php } ?>
|
150 |
</ul>
|
151 |
</div>
|
152 |
<div class="misc-pub-section misc-pub-section-last">
|
153 |
-
<?php if ($
|
154 |
<div id="publishing-action-return-sub-posts">
|
155 |
<input type="submit" class="button" id="return-sub-posts" name="return-sub-posts" value="<?php esc_html_e('Return to Parent', 'custom-taxonomy-order-ne'); ?>" />
|
156 |
</div>
|
@@ -165,14 +164,14 @@ function customtaxorder_subpage() {
|
|
165 |
<div class="clear"></div>
|
166 |
</div>
|
167 |
<input type="hidden" id="hidden-custom-order" name="hidden-custom-order" />
|
168 |
-
<input type="hidden" id="hidden-parent-id" name="hidden-parent-id" value="<?php echo $
|
169 |
-
<input type="hidden" id="hidden-parent-id-order" name="hidden-parent-id-order" value="<?php echo $
|
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
|
176 |
<div class="misc-pub-section misc-pub-section-last">
|
177 |
<select id="sub-posts" name="sub-posts">
|
178 |
<?php echo $dropdown; ?>
|
@@ -192,7 +191,7 @@ function customtaxorder_subpage() {
|
|
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">
|
@@ -234,11 +233,11 @@ function customtaxorder_update_order() {
|
|
234 |
return;
|
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' );
|
@@ -246,7 +245,7 @@ function customtaxorder_update_order() {
|
|
246 |
if ( ! empty( $taxonomies ) ) {
|
247 |
foreach ( $taxonomies as $taxonomy ) {
|
248 |
$com_page = 'customtaxorder-' . $taxonomy->name;
|
249 |
-
if ( $this_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 );
|
@@ -255,7 +254,7 @@ function customtaxorder_update_order() {
|
|
255 |
}
|
256 |
}
|
257 |
|
258 |
-
if (
|
259 |
die(esc_html__( 'You need a higher level of permission.', 'custom-taxonomy-order-ne' ));
|
260 |
} else {
|
261 |
|
@@ -264,11 +263,11 @@ function customtaxorder_update_order() {
|
|
264 |
$parent_id_order = (int) $_POST['hidden-parent-id-order'] + 1;
|
265 |
}
|
266 |
$new_order = $_POST['hidden-custom-order'];
|
267 |
-
$submitted_ids = explode(
|
268 |
$updated_ids = array();
|
269 |
$result = count($submitted_ids);
|
270 |
for ( $i = 0; $i < $result; $i++ ) {
|
271 |
-
$term_id = (int) str_replace(
|
272 |
$term_order = $i + $parent_id_order;
|
273 |
|
274 |
customtaxorder_set_db_term_order( $term_id, $term_order );
|
@@ -317,7 +316,7 @@ function customtaxorder_update_settings() {
|
|
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' );
|
@@ -325,7 +324,7 @@ function customtaxorder_update_settings() {
|
|
325 |
if ( ! empty( $taxonomies ) ) {
|
326 |
foreach ( $taxonomies as $taxonomy ) {
|
327 |
$com_page = 'customtaxorder-' . $taxonomy->name;
|
328 |
-
if ( $this_page
|
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 );
|
@@ -334,11 +333,11 @@ function customtaxorder_update_settings() {
|
|
334 |
}
|
335 |
}
|
336 |
|
337 |
-
if (
|
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
|
342 |
|
343 |
$options[$taxonomy->name] = $tax_setting;
|
344 |
$customtaxorder_settings = update_option( 'customtaxorder_settings', $options );
|
@@ -386,7 +385,7 @@ function customtaxorder_sub_query( $terms, $tax_name ) {
|
|
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 |
}
|
391 |
}
|
392 |
}
|
10 |
|
11 |
$options = customtaxorder_get_settings();
|
12 |
$taxonomies = customtaxorder_get_taxonomies();
|
13 |
+
$parent_id = 0;
|
14 |
+
$this_page = sanitize_text_field( $_GET['page'] );
|
15 |
|
16 |
// Set your custom capability through this filter.
|
17 |
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
30 |
}
|
31 |
}
|
32 |
|
33 |
+
if ( ! current_user_can( $custom_cap ) ) {
|
34 |
die(esc_html__( 'You need a higher level of permission.', 'custom-taxonomy-order-ne' ));
|
35 |
}
|
36 |
|
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 |
}
|
61 |
echo '<li class="lineitem"><a href="' . admin_url( 'admin.php?page=customtaxorder-taxonomies' ) . '">' . esc_html__('Taxonomies', 'custom-taxonomy-order-ne') . '</a></li>
|
62 |
';
|
63 |
foreach ( $taxonomies as $taxonomy ) {
|
64 |
+
echo '<li class="lineitem"><a href="' . esc_url( admin_url( 'admin.php?page=customtaxorder-' . $taxonomy->name ) ) . '">' . esc_html( $taxonomy->label ) . '</a> (' . esc_html( $taxonomy->name ) . ')</li>
|
65 |
';
|
66 |
}
|
67 |
}
|
89 |
$tax_label = $taxonomy->label;
|
90 |
$tax_name = $taxonomy->name;
|
91 |
|
92 |
+
$settings .= '<input name="customtaxorder_taxname" type="hidden" value="' . esc_attr( $tax_name ) . '" />';
|
93 |
}
|
94 |
}
|
95 |
}
|
96 |
|
97 |
+
$parent_id_order = 0;
|
98 |
if (isset($_POST['go-sub-posts'])) {
|
99 |
+
$parent_id = (int) $_POST['sub-posts'];
|
100 |
+
} else if (isset($_POST['hidden-parent-id'])) {
|
|
|
101 |
$parent_term = get_term($_POST['hidden-parent-id'], $tax_name);
|
102 |
+
$parent_id = (int) $_POST['hidden-parent-id'];
|
103 |
if ( is_object($parent_term) && isset($parent_term->term_order) ) {
|
104 |
+
$parent_id_order = (int) $parent_term->term_order;
|
105 |
}
|
106 |
}
|
107 |
if (isset($_POST['return-sub-posts'])) {
|
108 |
$parent_term = get_term($_POST['hidden-parent-id'], $tax_name);
|
109 |
+
$parent_id = (int) $parent_term->parent;
|
110 |
}
|
111 |
|
112 |
|
113 |
// Terms in this taxonomy, ordered according to settings. */ ?>
|
114 |
+
<h1><?php echo esc_html__('Order ', 'custom-taxonomy-order-ne') . esc_html( $tax_label ); ?></h1>
|
115 |
<form name="custom-order-form" method="post" action=""><?php
|
116 |
|
117 |
/* Nonce */
|
118 |
$nonce = wp_create_nonce( 'custom-taxonomy-order-ne-nonce' );
|
119 |
+
echo '<input type="hidden" id="custom-taxonomy-order-ne-nonce" name="custom-taxonomy-order-ne-nonce" value="' . esc_attr( $nonce ) . '" />';
|
120 |
|
121 |
// Remove filters for WPML and add one filter of our own.
|
122 |
$active_plugins = get_option('active_plugins');
|
132 |
'orderby' => 'term_order',
|
133 |
'order' => 'ASC',
|
134 |
'hide_empty' => false,
|
135 |
+
'parent' => $parent_id,
|
136 |
);
|
137 |
$terms = get_terms( $tax_name, $args );
|
138 |
if ( $terms ) {
|
140 |
?>
|
141 |
<div id="poststuff" class="metabox-holder">
|
142 |
<div class="widget order-widget">
|
143 |
+
<h2 class="widget-top"><?php echo esc_html( $tax_label ) ?> | <small><?php esc_html_e('Order the terms by dragging and dropping them into the desired order.', 'custom-taxonomy-order-ne') ?></small></h2>
|
144 |
<div class="misc-pub-section">
|
145 |
<ul id="custom-order-list">
|
146 |
<?php foreach ( $terms as $term ) { ?>
|
147 |
+
<li id="id_<?php echo (int) $term->term_id; ?>" data-slug="<?php echo esc_attr( $term->slug ); ?>" class="lineitem"><?php echo esc_html( $term->name ); ?></li>
|
148 |
<?php } ?>
|
149 |
</ul>
|
150 |
</div>
|
151 |
<div class="misc-pub-section misc-pub-section-last">
|
152 |
+
<?php if ( $parent_id !== 0 ) { ?>
|
153 |
<div id="publishing-action-return-sub-posts">
|
154 |
<input type="submit" class="button" id="return-sub-posts" name="return-sub-posts" value="<?php esc_html_e('Return to Parent', 'custom-taxonomy-order-ne'); ?>" />
|
155 |
</div>
|
164 |
<div class="clear"></div>
|
165 |
</div>
|
166 |
<input type="hidden" id="hidden-custom-order" name="hidden-custom-order" />
|
167 |
+
<input type="hidden" id="hidden-parent-id" name="hidden-parent-id" value="<?php echo $parent_id; ?>" />
|
168 |
+
<input type="hidden" id="hidden-parent-id-order" name="hidden-parent-id-order" value="<?php echo $parent_id_order; ?>" />
|
169 |
</div>
|
170 |
<?php
|
171 |
$dropdown = customtaxorder_sub_query( $terms, $tax_name );
|
172 |
if( ! empty($dropdown) ) { ?>
|
173 |
<div class="widget order-widget">
|
174 |
+
<h2 class="widget-top"><?php esc_html_e('Sub-', 'custom-taxonomy-order-ne') . esc_html( $tax_label ); ?> | <small><?php esc_html_e('Choose a term from the dropdown to order its sub-terms.', 'custom-taxonomy-order-ne'); ?></small></h2>
|
175 |
<div class="misc-pub-section misc-pub-section-last">
|
176 |
<select id="sub-posts" name="sub-posts">
|
177 |
<?php echo $dropdown; ?>
|
191 |
<?php
|
192 |
/* Nonce */
|
193 |
$nonce = wp_create_nonce( 'custom-taxonomy-order-ne-nonce' );
|
194 |
+
echo '<input type="hidden" id="custom-taxonomy-order-ne-nonce" name="custom-taxonomy-order-ne-nonce" value="' . esc_attr( $nonce ) . '" />';
|
195 |
settings_fields('customtaxorder_settings'); ?>
|
196 |
<div class="metabox-holder">
|
197 |
<div class="order-widget">
|
233 |
return;
|
234 |
}
|
235 |
|
236 |
+
if (isset($_POST['hidden-custom-order']) && $_POST['hidden-custom-order'] != '') {
|
237 |
|
238 |
$options = customtaxorder_get_settings();
|
239 |
$taxonomies = customtaxorder_get_taxonomies() ;
|
240 |
+
$this_page = sanitize_text_field( $_GET['page'] );
|
241 |
|
242 |
// Set your custom capability through this filter.
|
243 |
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
245 |
if ( ! empty( $taxonomies ) ) {
|
246 |
foreach ( $taxonomies as $taxonomy ) {
|
247 |
$com_page = 'customtaxorder-' . $taxonomy->name;
|
248 |
+
if ( $this_page === $com_page ) {
|
249 |
|
250 |
// For this taxonomy, set your finegrained capability with this custom filter.
|
251 |
$custom_cap = apply_filters( 'customtaxorder_custom_cap_' . $taxonomy->name, $custom_cap );
|
254 |
}
|
255 |
}
|
256 |
|
257 |
+
if ( ! current_user_can( $custom_cap ) ) {
|
258 |
die(esc_html__( 'You need a higher level of permission.', 'custom-taxonomy-order-ne' ));
|
259 |
} else {
|
260 |
|
263 |
$parent_id_order = (int) $_POST['hidden-parent-id-order'] + 1;
|
264 |
}
|
265 |
$new_order = $_POST['hidden-custom-order'];
|
266 |
+
$submitted_ids = explode(',', $new_order);
|
267 |
$updated_ids = array();
|
268 |
$result = count($submitted_ids);
|
269 |
for ( $i = 0; $i < $result; $i++ ) {
|
270 |
+
$term_id = (int) str_replace('id_', '', $submitted_ids[$i]);
|
271 |
$term_order = $i + $parent_id_order;
|
272 |
|
273 |
customtaxorder_set_db_term_order( $term_id, $term_order );
|
316 |
|
317 |
$options = customtaxorder_get_settings();
|
318 |
$taxonomies = customtaxorder_get_taxonomies() ;
|
319 |
+
$this_page = sanitize_text_field( $_GET['page'] );
|
320 |
|
321 |
// Set your custom capability through this filter.
|
322 |
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
324 |
if ( ! empty( $taxonomies ) ) {
|
325 |
foreach ( $taxonomies as $taxonomy ) {
|
326 |
$com_page = 'customtaxorder-' . $taxonomy->name;
|
327 |
+
if ( $this_page === $com_page && $tax_name === $taxonomy->name ) {
|
328 |
|
329 |
// For this taxonomy, set your finegrained capability with this custom filter.
|
330 |
$custom_cap = apply_filters( 'customtaxorder_custom_cap_' . $taxonomy->name, $custom_cap );
|
333 |
}
|
334 |
}
|
335 |
|
336 |
+
if ( ! current_user_can( $custom_cap ) ) {
|
337 |
die(esc_html__( 'You need a higher level of permission.', 'custom-taxonomy-order-ne' ));
|
338 |
} else {
|
339 |
foreach ( $taxonomies as $taxonomy ) {
|
340 |
+
if ( $taxonomy->name === $tax_name ) {
|
341 |
|
342 |
$options[$taxonomy->name] = $tax_setting;
|
343 |
$customtaxorder_settings = update_option( 'customtaxorder_settings', $options );
|
385 |
foreach ( $terms as $term ) {
|
386 |
$subterms = get_term_children( $term->term_id, $tax_name );
|
387 |
if ( $subterms ) {
|
388 |
+
$options .= '<option value="' . (int) $term->term_id . '">' . esc_html( $term->name ) . '</option>';
|
389 |
}
|
390 |
}
|
391 |
}
|
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.8
|
6 |
-
Stable tag: 3.3.
|
7 |
License: GPLv2 or later
|
8 |
|
9 |
|
@@ -163,6 +163,12 @@ The left metabox lists the toplevel terms. Right (or below) are the sub-terms.
|
|
163 |
|
164 |
== Changelog ==
|
165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
= 3.3.0 =
|
167 |
* 2021-02-23
|
168 |
* Save settings per taxonomy with capability 'manage_categories', not 'manage_options'.
|
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.1
|
7 |
License: GPLv2 or later
|
8 |
|
9 |
|
163 |
|
164 |
== Changelog ==
|
165 |
|
166 |
+
= 3.3.1 =
|
167 |
+
* 2021-11-26
|
168 |
+
* Bring back removed code for orderby clause in 'get_terms_orderby' filter.
|
169 |
+
* No need to check if function 'current_user_can' and 'is_multisite' exist.
|
170 |
+
* Use functions like 'esc_attr', 'esc_html' and 'esc_url' when appropriate.
|
171 |
+
|
172 |
= 3.3.0 =
|
173 |
* 2021-02-23
|
174 |
* Save settings per taxonomy with capability 'manage_categories', not 'manage_options'.
|
taxonomies.php
CHANGED
@@ -6,7 +6,7 @@ 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 (
|
10 |
die(esc_html__( 'You need a higher level of permission.', 'custom-taxonomy-order-ne' ));
|
11 |
}
|
12 |
|
@@ -23,7 +23,7 @@ function custom_taxonomy_order() {
|
|
23 |
|
24 |
/* Nonce */
|
25 |
$nonce = wp_create_nonce( 'custom-taxonomy-order-ne-nonce' );
|
26 |
-
echo '<input type="hidden" id="custom-taxonomy-order-ne-nonce" name="custom-taxonomy-order-ne-nonce" value="' . $nonce . '" />';
|
27 |
|
28 |
$taxonomies = customtaxorder_get_taxonomies() ;
|
29 |
|
@@ -42,7 +42,7 @@ function custom_taxonomy_order() {
|
|
42 |
<ul id="custom-taxonomy-list">
|
43 |
<?php
|
44 |
foreach ( $taxonomies_ordered as $taxonomy ) { ?>
|
45 |
-
<li id="<?php echo $taxonomy->name; ?>" class="lineitem"><?php echo
|
46 |
<?php
|
47 |
} ?>
|
48 |
</ul>
|
@@ -87,14 +87,13 @@ function customtaxorder_update_taxonomies() {
|
|
87 |
// Set your custom capability through this filter.
|
88 |
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
89 |
|
90 |
-
if (
|
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'];
|
97 |
-
$new_order = sanitize_text_field( $new_order );
|
98 |
update_option('customtaxorder_taxonomies', $new_order);
|
99 |
|
100 |
echo '<div id="message" class="updated fade notice is-dismissible"><p>'. esc_html__('Order updated successfully.', 'custom-taxonomy-order-ne').'</p></div>';
|
@@ -103,7 +102,7 @@ function customtaxorder_update_taxonomies() {
|
|
103 |
}
|
104 |
|
105 |
}
|
106 |
-
function customtaxorder_taxonomies_validate($input) {
|
107 |
|
108 |
$input = (string) sanitize_text_field( $input );
|
109 |
return $input;
|
@@ -122,7 +121,7 @@ function customtaxorder_taxonomies_validate($input) {
|
|
122 |
*/
|
123 |
function customtaxorder_sort_taxonomies( $taxonomies = array() ) {
|
124 |
$order = get_option( 'customtaxorder_taxonomies', '' );
|
125 |
-
$order = explode(
|
126 |
$taxonomies_ordered = array();
|
127 |
|
128 |
// Main sorted taxonomies.
|
6 |
// Set your custom capability through this filter.
|
7 |
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
8 |
|
9 |
+
if ( ! current_user_can( $custom_cap ) ) {
|
10 |
die(esc_html__( 'You need a higher level of permission.', 'custom-taxonomy-order-ne' ));
|
11 |
}
|
12 |
|
23 |
|
24 |
/* Nonce */
|
25 |
$nonce = wp_create_nonce( 'custom-taxonomy-order-ne-nonce' );
|
26 |
+
echo '<input type="hidden" id="custom-taxonomy-order-ne-nonce" name="custom-taxonomy-order-ne-nonce" value="' . esc_attr( $nonce ) . '" />';
|
27 |
|
28 |
$taxonomies = customtaxorder_get_taxonomies() ;
|
29 |
|
42 |
<ul id="custom-taxonomy-list">
|
43 |
<?php
|
44 |
foreach ( $taxonomies_ordered as $taxonomy ) { ?>
|
45 |
+
<li id="<?php echo esc_attr( $taxonomy->name ); ?>" class="lineitem"><?php echo esc_html( $taxonomy->label ) . ' (' . esc_html( $taxonomy->name ) . ')';?></li>
|
46 |
<?php
|
47 |
} ?>
|
48 |
</ul>
|
87 |
// Set your custom capability through this filter.
|
88 |
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
89 |
|
90 |
+
if ( ! 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 = sanitize_text_field( $_POST['hidden-taxonomy-order'] );
|
|
|
97 |
update_option('customtaxorder_taxonomies', $new_order);
|
98 |
|
99 |
echo '<div id="message" class="updated fade notice is-dismissible"><p>'. esc_html__('Order updated successfully.', 'custom-taxonomy-order-ne').'</p></div>';
|
102 |
}
|
103 |
|
104 |
}
|
105 |
+
function customtaxorder_taxonomies_validate( $input ) {
|
106 |
|
107 |
$input = (string) sanitize_text_field( $input );
|
108 |
return $input;
|
121 |
*/
|
122 |
function customtaxorder_sort_taxonomies( $taxonomies = array() ) {
|
123 |
$order = get_option( 'customtaxorder_taxonomies', '' );
|
124 |
+
$order = explode( ',', $order );
|
125 |
$taxonomies_ordered = array();
|
126 |
|
127 |
// Main sorted taxonomies.
|