Version Description
- 2020-07-06
- Improve compatibility with WPML plugin.
- Add function 'customtaxorder_get_taxonomies()' to remove duplicate code.
- Be able to sort all taxonomies, public and non-public.
- Use more esc_html functions.
- Update About page.
- Only load translations at the dashboard.
Download this release
Release Info
Developer | mpol |
Plugin | Custom Taxonomy Order NE |
Version | 3.2.0 |
Comparing to | |
See all releases |
Code changes from version 3.1.0 to 3.2.0
- admin-customtaxorder.php +62 -50
- customtaxorder.php +46 -54
- page-customtaxorder.php +77 -65
- readme.txt +13 -6
- taxonomies.php +18 -29
admin-customtaxorder.php
CHANGED
@@ -9,9 +9,9 @@ add_action('admin_init', 'customtaxorder_register_settings');
|
|
9 |
|
10 |
|
11 |
function customtaxorder_settings_validate($input) {
|
12 |
-
|
13 |
-
$
|
14 |
-
|
15 |
foreach ( $taxonomies as $taxonomy ) {
|
16 |
if ( $input[$taxonomy->name] != 1 ) {
|
17 |
if ( $input[$taxonomy->name] != 2 ) {
|
@@ -38,33 +38,24 @@ function customtaxorder_taxonomies_validate($input) {
|
|
38 |
* Add all the admin menu pages.
|
39 |
*/
|
40 |
function customtaxorder_menu() {
|
41 |
-
|
42 |
-
$
|
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(
|
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',
|
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',
|
66 |
}
|
67 |
-
add_submenu_page('customtaxorder',
|
68 |
}
|
69 |
add_action('admin_menu', 'customtaxorder_menu');
|
70 |
|
@@ -103,18 +94,9 @@ add_action('admin_print_scripts', 'customtaxorder_js_libs');
|
|
103 |
* @since 3.1.0
|
104 |
*/
|
105 |
function customtaxorder_tag_edit_screen() {
|
106 |
-
|
107 |
-
$
|
108 |
-
|
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]) ) {
|
@@ -263,27 +245,36 @@ function customtaxorder_set_db_term_order( $term_id = 0, $term_order = 0, $taxon
|
|
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 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
}
|
@@ -294,8 +285,29 @@ function customtaxorder_about() {
|
|
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' ) . '">' .
|
298 |
}
|
299 |
return $links;
|
300 |
}
|
301 |
add_filter( 'plugin_action_links', 'customtaxorder_links', 10, 2 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
|
11 |
function customtaxorder_settings_validate($input) {
|
12 |
+
|
13 |
+
$taxonomies = customtaxorder_get_taxonomies() ;
|
14 |
+
|
15 |
foreach ( $taxonomies as $taxonomy ) {
|
16 |
if ( $input[$taxonomy->name] != 1 ) {
|
17 |
if ( $input[$taxonomy->name] != 2 ) {
|
38 |
* Add all the admin menu pages.
|
39 |
*/
|
40 |
function customtaxorder_menu() {
|
41 |
+
|
42 |
+
$taxonomies = customtaxorder_get_taxonomies() ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
$taxonomies = customtaxorder_sort_taxonomies( $taxonomies );
|
45 |
// Set your custom capability through this filter.
|
46 |
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
47 |
|
48 |
//add_menu_page( string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '', string $icon_url = '', int $position = null )
|
49 |
+
add_menu_page(esc_html__('Term Order', 'custom-taxonomy-order-ne'), esc_html__('Term Order', 'custom-taxonomy-order-ne'), $custom_cap, 'customtaxorder', 'customtaxorder_subpage', 'dashicons-list-view', 122.35);
|
50 |
//add_submenu_page( string $parent_slug, string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '', int $position = null )
|
51 |
+
add_submenu_page('customtaxorder', esc_html__('Order Taxonomies', 'custom-taxonomy-order-ne'), esc_html__('Order Taxonomies', 'custom-taxonomy-order-ne'), $custom_cap, 'customtaxorder-taxonomies', 'custom_taxonomy_order');
|
52 |
|
53 |
foreach ($taxonomies as $taxonomy ) {
|
54 |
// Set your finegrained capability for this taxonomy for this custom filter.
|
55 |
$custom_cap_tax = apply_filters( 'customtaxorder_custom_cap_' . $taxonomy->name, $custom_cap );
|
56 |
+
add_submenu_page('customtaxorder', esc_html__('Order ', 'custom-taxonomy-order-ne') . $taxonomy->label, esc_html__('Order ', 'custom-taxonomy-order-ne') . $taxonomy->label, $custom_cap_tax, 'customtaxorder-'.$taxonomy->name, 'customtaxorder_subpage');
|
57 |
}
|
58 |
+
add_submenu_page('customtaxorder', esc_html__('About', 'custom-taxonomy-order-ne'), esc_html__('About', 'custom-taxonomy-order-ne'), $custom_cap, 'customtaxorder-about', 'customtaxorder_about');
|
59 |
}
|
60 |
add_action('admin_menu', 'customtaxorder_menu');
|
61 |
|
94 |
* @since 3.1.0
|
95 |
*/
|
96 |
function customtaxorder_tag_edit_screen() {
|
97 |
+
|
98 |
+
$taxonomies = customtaxorder_get_taxonomies() ;
|
99 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
foreach ( $taxonomies as $taxonomy ) {
|
101 |
if ( is_object($taxonomy) && isset($taxonomy->name) ) {
|
102 |
if ( ! isset($options[$taxonomy->name]) ) {
|
245 |
function customtaxorder_about() {
|
246 |
?>
|
247 |
<div class='wrap'>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
|
249 |
+
<h1><?php esc_html_e('About Custom Taxonomy Order NE', 'custom-taxonomy-order-ne'); ?></h1>
|
250 |
+
<h2><?php esc_html_e('Support', 'custom-taxonomy-order-ne'); ?></h2>
|
251 |
+
<p><?php
|
252 |
+
$support = '<a href="https://wordpress.org/support/plugin/custom-taxonomy-order-ne" target="_blank">';
|
253 |
+
/* translators: %s is a link */
|
254 |
+
echo sprintf( esc_html__( 'If you have a problem or a feature request, please post it on the %ssupport forum at wordpress.org%s.', 'custom-taxonomy-order-ne' ), $support, '</a>' ); ?>
|
255 |
+
<?php esc_html_e('I will do my best to respond as soon as possible.', 'custom-taxonomy-order-ne'); ?><br />
|
256 |
+
<?php esc_html_e('If you send me an email, I will not reply. Please use the support forum.', 'custom-taxonomy-order-ne'); ?>
|
257 |
+
</p>
|
258 |
+
|
259 |
+
|
260 |
+
<h2><?php esc_html_e('Review this plugin.', 'custom-taxonomy-order-ne'); ?></h2>
|
261 |
+
<p><?php
|
262 |
+
$review = '<a href="https://wordpress.org/support/view/plugin-reviews/custom-taxonomy-order-ne?rate=5#postform" target="_blank">';
|
263 |
+
/* translators: %s is a link */
|
264 |
+
echo sprintf( esc_html__( 'If this plugin has any value to you, then please leave a review at %sthe plugin page%s at wordpress.org.', 'custom-taxonomy-order-ne' ), $review, '</a>' ); ?>
|
265 |
+
</p>
|
266 |
+
|
267 |
+
<h2><?php esc_html_e('Translations', 'custom-taxonomy-order-ne'); ?></h2>
|
268 |
+
<p><?php
|
269 |
+
$link = '<a href="https://translate.wordpress.org/projects/wp-plugins/custom-taxonomy-order-ne" target="_blank">';
|
270 |
+
/* translators: %s is a link */
|
271 |
+
echo sprintf( esc_html__( 'Translations can be added very easily through %sGlotPress%s.', 'custom-taxonomy-order-ne' ), $link, '</a>' ); echo '<br />';
|
272 |
+
echo sprintf( esc_html__( "You can start translating strings there for your locale. They need to be validated though, so if there's no validator yet, and you want to apply for being validator (PTE), please post it on the %ssupport forum%s.", 'custom-taxonomy-order-ne' ), $support, '</a>' ); echo '<br />';
|
273 |
+
$make = '<a href="https://make.wordpress.org/polyglots/" target="_blank">';
|
274 |
+
/* translators: %s is a link */
|
275 |
+
echo sprintf( esc_html__( 'I will make a request on %smake/polyglots%s to have you added as validator for this plugin/locale.', 'custom-taxonomy-order-ne' ), $make, '</a>' ); ?>
|
276 |
+
</p>
|
277 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
278 |
</div>
|
279 |
<?php
|
280 |
}
|
285 |
*/
|
286 |
function customtaxorder_links( $links, $file ) {
|
287 |
if ( $file == plugin_basename( dirname(__FILE__).'/customtaxorder.php' ) ) {
|
288 |
+
$links[] = '<a href="' . admin_url( 'admin.php?page=customtaxorder' ) . '">' . esc_html__( 'Settings', 'custom-taxonomy-order-ne' ) . '</a>';
|
289 |
}
|
290 |
return $links;
|
291 |
}
|
292 |
add_filter( 'plugin_action_links', 'customtaxorder_links', 10, 2 );
|
293 |
+
|
294 |
+
|
295 |
+
/*
|
296 |
+
* Flush object cache when order is changed in taxonomy ordering plugin.
|
297 |
+
*
|
298 |
+
* @since 2.7.8
|
299 |
+
*
|
300 |
+
*/
|
301 |
+
function customtaxorder_flush_cache() {
|
302 |
+
wp_cache_flush();
|
303 |
+
}
|
304 |
+
add_action( 'customtaxorder_update_order', 'customtaxorder_flush_cache' );
|
305 |
+
|
306 |
+
|
307 |
+
/*
|
308 |
+
* Load language files.
|
309 |
+
*/
|
310 |
+
function customtaxorder_load_lang() {
|
311 |
+
load_plugin_textdomain('custom-taxonomy-order-ne', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/');
|
312 |
+
}
|
313 |
+
add_action('plugins_loaded', 'customtaxorder_load_lang');
|
customtaxorder.php
CHANGED
@@ -3,31 +3,31 @@
|
|
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
|
10 |
Text Domain: custom-taxonomy-order-ne
|
11 |
Domain Path: /lang/
|
12 |
|
13 |
-
/*
|
14 |
-
Copyright 2011 - 2011 Drew Gourley
|
15 |
-
Copyright 2013 - 2020 Marcel Pol (email: marcel@timelord.nl)
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
GNU General Public License for more details.
|
26 |
|
27 |
-
You should have received a copy of the GNU General Public License
|
28 |
-
along with this program; if not, write to the Free Software
|
29 |
-
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
30 |
-
*/
|
31 |
|
32 |
|
33 |
/*
|
@@ -40,7 +40,7 @@ Domain Path: /lang/
|
|
40 |
|
41 |
|
42 |
// Plugin Version
|
43 |
-
define('CUSTOMTAXORDER_VER', '3.
|
44 |
|
45 |
|
46 |
/*
|
@@ -50,9 +50,7 @@ define('CUSTOMTAXORDER_VER', '3.1.0');
|
|
50 |
function customtaxorder_get_settings() {
|
51 |
$customtaxorder_defaults = array('category' => 0);
|
52 |
|
53 |
-
$
|
54 |
-
$output = 'objects';
|
55 |
-
$taxonomies = get_taxonomies( $args, $output );
|
56 |
foreach ( $taxonomies as $taxonomy ) {
|
57 |
$customtaxorder_defaults[$taxonomy->name] = 0;
|
58 |
}
|
@@ -81,18 +79,6 @@ function customtax_cmp( $a, $b ) {
|
|
81 |
}
|
82 |
|
83 |
|
84 |
-
/*
|
85 |
-
* Flush object cache when order is changed in taxonomy ordering plugin.
|
86 |
-
*
|
87 |
-
* @since 2.7.8
|
88 |
-
*
|
89 |
-
*/
|
90 |
-
function customtaxorder_flush_cache() {
|
91 |
-
wp_cache_flush();
|
92 |
-
}
|
93 |
-
add_action( 'customtaxorder_update_order', 'customtaxorder_flush_cache' );
|
94 |
-
|
95 |
-
|
96 |
/*
|
97 |
* Function to sort the standard WordPress Queries for terms.
|
98 |
*
|
@@ -194,7 +180,7 @@ function customtaxorder_wp_get_object_terms_order_filter( $terms ) {
|
|
194 |
break; // just the first one :)
|
195 |
}
|
196 |
|
197 |
-
if ( !isset ( $options[$taxonomy] ) ) {
|
198 |
$options[$taxonomy] = 0; // default if not set in options yet
|
199 |
}
|
200 |
if ( $options[$taxonomy] == 1 && ! isset($_GET['orderby']) ) {
|
@@ -203,7 +189,7 @@ function customtaxorder_wp_get_object_terms_order_filter( $terms ) {
|
|
203 |
// filtering will happen in the tag_cloud_sort filter sometime later
|
204 |
// post_tag = default tags
|
205 |
// product_tag = woocommerce product tags
|
206 |
-
if (current_filter() == 'get_terms'
|
207 |
$customtaxorder_exclude_taxonomies = array('post_tag', 'product_tag');
|
208 |
if ( in_array($taxonomy, apply_filters( 'customtaxorder_exclude_taxonomies', $customtaxorder_exclude_taxonomies )) ) {
|
209 |
return $terms;
|
@@ -281,7 +267,7 @@ function customtaxorder_order_categories( $categories ) {
|
|
281 |
|
282 |
$terms_old_order = $categories;
|
283 |
|
284 |
-
if ( !isset
|
285 |
$options['category'] = 0; // default if not set in options yet
|
286 |
}
|
287 |
if ( $options['category'] == 1 && ! isset($_GET['orderby']) ) {
|
@@ -307,25 +293,29 @@ add_filter( 'get_the_categories', 'customtaxorder_order_categories' );
|
|
307 |
|
308 |
|
309 |
/*
|
310 |
-
*
|
311 |
-
*
|
|
|
|
|
|
|
312 |
*/
|
313 |
-
function
|
314 |
-
foreach ( $attribute_taxonomies as $attribute_taxonomy ) {
|
315 |
-
$attribute_taxonomy->attribute_public = 1;
|
316 |
-
}
|
317 |
-
return $attribute_taxonomies;
|
318 |
-
}
|
319 |
-
add_filter( 'woocommerce_attribute_taxonomies', 'customtaxorder_woocommerce_attribute_taxonomies_public' );
|
320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
|
322 |
-
/*
|
323 |
-
* Load language files.
|
324 |
-
*/
|
325 |
-
function customtaxorder_load_lang() {
|
326 |
-
load_plugin_textdomain('custom-taxonomy-order-ne', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/');
|
327 |
}
|
328 |
-
add_action('plugins_loaded', 'customtaxorder_load_lang');
|
329 |
|
330 |
|
331 |
/*
|
@@ -334,7 +324,9 @@ add_action('plugins_loaded', 'customtaxorder_load_lang');
|
|
334 |
function _customtaxorder_activate() {
|
335 |
global $wpdb;
|
336 |
$init_query = $wpdb->query("SHOW COLUMNS FROM $wpdb->terms LIKE 'term_order'");
|
337 |
-
if ($init_query == 0) {
|
|
|
|
|
338 |
}
|
339 |
|
340 |
|
@@ -355,7 +347,7 @@ register_activation_hook( __FILE__, 'customtaxorder_activate' );
|
|
355 |
|
356 |
|
357 |
/*
|
358 |
-
* Install database
|
359 |
* Deprecated action since WP 5.1.0.
|
360 |
*
|
361 |
*/
|
@@ -368,9 +360,9 @@ add_action( 'wpmu_new_blog', 'customtaxorder_activate_new_site' );
|
|
368 |
|
369 |
|
370 |
/*
|
371 |
-
* Install database
|
372 |
* Used since WP 5.1.0.
|
373 |
-
* Do not use wp_insert_site, since the options table doesn't exist yet
|
374 |
*
|
375 |
* @since 2.10.1
|
376 |
*/
|
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.2.0
|
7 |
Author: Marcel Pol
|
8 |
Author URI: https://timelord.nl/
|
9 |
License: GPLv2 or later
|
10 |
Text Domain: custom-taxonomy-order-ne
|
11 |
Domain Path: /lang/
|
12 |
|
|
|
|
|
|
|
13 |
|
14 |
+
Copyright 2011 - 2011 Drew Gourley
|
15 |
+
Copyright 2013 - 2020 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
|
19 |
+
as published by the Free Software Foundation; either version 2
|
20 |
+
of the License, or (at your option) any later version.
|
21 |
+
|
22 |
+
This program is distributed in the hope that it will be useful,
|
23 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
24 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
25 |
+
GNU General Public License for more details.
|
26 |
|
27 |
+
You should have received a copy of the GNU General Public License
|
28 |
+
along with this program; if not, write to the Free Software
|
29 |
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
30 |
|
|
|
|
|
|
|
|
|
31 |
|
32 |
|
33 |
/*
|
40 |
|
41 |
|
42 |
// Plugin Version
|
43 |
+
define('CUSTOMTAXORDER_VER', '3.2.0');
|
44 |
|
45 |
|
46 |
/*
|
50 |
function customtaxorder_get_settings() {
|
51 |
$customtaxorder_defaults = array('category' => 0);
|
52 |
|
53 |
+
$taxonomies = customtaxorder_get_taxonomies() ;
|
|
|
|
|
54 |
foreach ( $taxonomies as $taxonomy ) {
|
55 |
$customtaxorder_defaults[$taxonomy->name] = 0;
|
56 |
}
|
79 |
}
|
80 |
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
/*
|
83 |
* Function to sort the standard WordPress Queries for terms.
|
84 |
*
|
180 |
break; // just the first one :)
|
181 |
}
|
182 |
|
183 |
+
if ( ! isset ( $options[$taxonomy] ) ) {
|
184 |
$options[$taxonomy] = 0; // default if not set in options yet
|
185 |
}
|
186 |
if ( $options[$taxonomy] == 1 && ! isset($_GET['orderby']) ) {
|
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;
|
267 |
|
268 |
$terms_old_order = $categories;
|
269 |
|
270 |
+
if ( ! isset( $options['category'] ) ) {
|
271 |
$options['category'] = 0; // default if not set in options yet
|
272 |
}
|
273 |
if ( $options['category'] == 1 && ! isset($_GET['orderby']) ) {
|
293 |
|
294 |
|
295 |
/*
|
296 |
+
* Get list of taxonomies.
|
297 |
+
*
|
298 |
+
* @return array list of taxonomies.
|
299 |
+
*
|
300 |
+
* @since 3.2.0
|
301 |
*/
|
302 |
+
function customtaxorder_get_taxonomies() {
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
|
304 |
+
$args = array(); // Just get them all and don't mess about with setting some taxonomies to public.
|
305 |
+
$output = 'objects';
|
306 |
+
$taxonomies = get_taxonomies( $args, $output );
|
307 |
+
|
308 |
+
// Also make the link_category available if activated.
|
309 |
+
$active_plugins = get_option('active_plugins');
|
310 |
+
if ( in_array( 'link-manager/link-manager.php', $active_plugins ) ) {
|
311 |
+
$args = array( 'name' => 'link_category' );
|
312 |
+
$taxonomies2 = get_taxonomies( $args, $output );
|
313 |
+
$taxonomies = array_merge($taxonomies, $taxonomies2);
|
314 |
+
}
|
315 |
+
|
316 |
+
return $taxonomies;
|
317 |
|
|
|
|
|
|
|
|
|
|
|
318 |
}
|
|
|
319 |
|
320 |
|
321 |
/*
|
324 |
function _customtaxorder_activate() {
|
325 |
global $wpdb;
|
326 |
$init_query = $wpdb->query("SHOW COLUMNS FROM $wpdb->terms LIKE 'term_order'");
|
327 |
+
if ( $init_query == 0 ) {
|
328 |
+
$wpdb->query("ALTER TABLE $wpdb->terms ADD term_order INT( 4 ) NULL DEFAULT '0'");
|
329 |
+
}
|
330 |
}
|
331 |
|
332 |
|
347 |
|
348 |
|
349 |
/*
|
350 |
+
* Install database column for new blog on MultiSite.
|
351 |
* Deprecated action since WP 5.1.0.
|
352 |
*
|
353 |
*/
|
360 |
|
361 |
|
362 |
/*
|
363 |
+
* Install database column for new blog on MultiSite.
|
364 |
* Used since WP 5.1.0.
|
365 |
+
* Do not use 'wp_insert_site' action, since the options table doesn't exist yet at that time.
|
366 |
*
|
367 |
* @since 2.10.1
|
368 |
*/
|
page-customtaxorder.php
CHANGED
@@ -10,24 +10,11 @@ function customtaxorder_subpage() {
|
|
10 |
|
11 |
customtaxorder_update_settings();
|
12 |
$options = customtaxorder_get_settings();
|
13 |
-
$settings = ''; // The input and text for the taxonomy that's shown
|
14 |
$parent_ID = 0;
|
15 |
|
16 |
-
|
17 |
-
$args = array( 'public' => true );
|
18 |
-
$output = 'objects';
|
19 |
-
$taxonomies = get_taxonomies( $args, $output );
|
20 |
-
|
21 |
-
// Also make the link_category available if activated.
|
22 |
-
$linkplugin = "link-manager/link-manager.php";
|
23 |
-
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
24 |
-
if ( is_plugin_active($linkplugin) ) {
|
25 |
-
$args = array( 'name' => 'link_category' );
|
26 |
-
$taxonomies2 = get_taxonomies( $args, $output );
|
27 |
-
$taxonomies = array_merge($taxonomies, $taxonomies2);
|
28 |
-
}
|
29 |
|
30 |
-
if ( !empty( $taxonomies ) ) {
|
31 |
foreach ( $taxonomies as $taxonomy ) {
|
32 |
$com_page = 'customtaxorder-'.$taxonomy->name;
|
33 |
if ( !isset($options[$taxonomy->name]) ) {
|
@@ -41,16 +28,13 @@ function customtaxorder_subpage() {
|
|
41 |
// Set your finegrained capability for this taxonomy for this custom filter.
|
42 |
$custom_cap_tax = apply_filters( 'customtaxorder_custom_cap_' . $taxonomy->name, $custom_cap );
|
43 |
|
44 |
-
if ( function_exists('current_user_can') && !current_user_can( $custom_cap_tax ) ) {
|
45 |
-
die(
|
46 |
}
|
47 |
}
|
48 |
}
|
49 |
}
|
50 |
|
51 |
-
// Remove filter for WPML
|
52 |
-
remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ), 10 );
|
53 |
-
remove_filter( 'get_terms', array( $sitepress, 'get_terms_filter' ),10 );
|
54 |
?>
|
55 |
<div class='wrap customtaxorder'>
|
56 |
<div id="icon-customtaxorder"></div>
|
@@ -63,18 +47,18 @@ function customtaxorder_subpage() {
|
|
63 |
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
64 |
|
65 |
if ( function_exists('current_user_can') && ! current_user_can( $custom_cap ) ) {
|
66 |
-
die(
|
67 |
}
|
68 |
|
69 |
?>
|
70 |
<h1>Custom Taxonomy Order</h1>
|
71 |
<div class="order-widget">
|
72 |
-
<p><?php
|
73 |
<?php
|
74 |
if ( ! empty( $taxonomies ) ) {
|
75 |
-
echo '<h2>' .
|
76 |
$taxonomies = customtaxorder_sort_taxonomies( $taxonomies );
|
77 |
-
echo '<li class="lineitem"><a href="' . admin_url( 'admin.php?page=customtaxorder-taxonomies' ) . '">' .
|
78 |
';
|
79 |
foreach ( $taxonomies as $taxonomy ) {
|
80 |
echo '<li class="lineitem"><a href="' . admin_url( 'admin.php?page=customtaxorder-' . $taxonomy->name ) . '">' . $taxonomy->label . '</a> (' . $taxonomy->name . ')</li>
|
@@ -83,33 +67,35 @@ function customtaxorder_subpage() {
|
|
83 |
}
|
84 |
echo '</ul></div></div><!-- #wrap -->';
|
85 |
return;
|
86 |
-
}
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
if ( ! isset($options[$taxonomy->name]) ) {
|
91 |
$options[$taxonomy->name] = 0; // default if not set in options yet
|
92 |
}
|
93 |
-
|
94 |
-
$settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="0" ' . checked('0', $options[$taxonomy->name], false) . ' /> ' . __('Order by ID (default).', 'custom-taxonomy-order-ne') . '</label><br />
|
95 |
-
';
|
96 |
-
$settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="1" ' . checked('1', $options[$taxonomy->name], false) . ' /> ' . __('Custom Order as defined above.', 'custom-taxonomy-order-ne') . '</label><br />
|
97 |
-
';
|
98 |
-
$settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="2" ' . checked('2', $options[$taxonomy->name], false) . ' /> ' . __('Alphabetical Order by name.', 'custom-taxonomy-order-ne') . '</label><br />
|
99 |
-
';
|
100 |
-
$settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="3" ' . checked('3', $options[$taxonomy->name], false) . ' /> ' . __('Alphabetical Order by slug.', 'custom-taxonomy-order-ne') . '</label><br />
|
101 |
-
';
|
102 |
-
$tax_label = $taxonomy->label;
|
103 |
-
$tax = $taxonomy->name;
|
104 |
-
} else {
|
105 |
-
if ( ! isset($options[$taxonomy->name]) ) {
|
106 |
-
$options[$taxonomy->name] = 0; // default if not set in options yet
|
107 |
-
}
|
108 |
-
$settings .= '<input name="customtaxorder_settings[' . $taxonomy->name . ']" type="hidden" value="' . $options[$taxonomy->name] . '" />';
|
109 |
-
}
|
110 |
}
|
111 |
}
|
112 |
}
|
|
|
113 |
$parent_ID_order = 0;
|
114 |
if (isset($_POST['go-sub-posts'])) {
|
115 |
$parent_ID = $_POST['sub-posts'];
|
@@ -129,18 +115,28 @@ function customtaxorder_subpage() {
|
|
129 |
customtaxorder_update_order();
|
130 |
} ?>
|
131 |
|
132 |
-
<h1><?php echo
|
133 |
<form name="custom-order-form" method="post" action=""><?php
|
134 |
|
135 |
/* Nonce */
|
136 |
$nonce = wp_create_nonce( 'custom-taxonomy-order-ne-nonce' );
|
137 |
echo '<input type="hidden" id="custom-taxonomy-order-ne-nonce" name="custom-taxonomy-order-ne-nonce" value="' . $nonce . '" />';
|
138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
$args = array(
|
140 |
-
'orderby'
|
141 |
-
'order'
|
142 |
'hide_empty' => false,
|
143 |
-
'parent'
|
144 |
);
|
145 |
$terms = get_terms( $tax, $args );
|
146 |
if ( $terms ) {
|
@@ -148,7 +144,7 @@ function customtaxorder_subpage() {
|
|
148 |
?>
|
149 |
<div id="poststuff" class="metabox-holder">
|
150 |
<div class="widget order-widget">
|
151 |
-
<h2 class="widget-top"><?php
|
152 |
<div class="misc-pub-section">
|
153 |
<ul id="custom-order-list">
|
154 |
<?php foreach ( $terms as $term ) { ?>
|
@@ -159,14 +155,14 @@ function customtaxorder_subpage() {
|
|
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
|
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
|
168 |
-
<input type="submit" name="order-alpha" id="order-alpha" class="button" value="<?php
|
169 |
-
<input type="submit" name="order-slug" id="order-slug" class="button" value="<?php
|
170 |
<?php do_action('custom_taxonomy_order_ne_settings_buttons'); ?>
|
171 |
</div>
|
172 |
<div class="clear"></div>
|
@@ -179,28 +175,28 @@ function customtaxorder_subpage() {
|
|
179 |
$dropdown = customtaxorder_sub_query( $terms, $tax );
|
180 |
if( ! empty($dropdown) ) { ?>
|
181 |
<div class="widget order-widget">
|
182 |
-
<h2 class="widget-top"><?php print(__('Sub-', 'custom-taxonomy-order-ne') . $tax_label); ?> | <small><?php
|
183 |
<div class="misc-pub-section misc-pub-section-last">
|
184 |
<select id="sub-posts" name="sub-posts">
|
185 |
<?php echo $dropdown; ?>
|
186 |
</select>
|
187 |
-
<input type="submit" name="go-sub-posts" class="button" id="go-sub-posts" value="<?php
|
188 |
</div>
|
189 |
</div>
|
190 |
<?php } ?>
|
191 |
</div>
|
192 |
<?php } else { ?>
|
193 |
-
<p><?php
|
194 |
<?php } ?>
|
195 |
</form>
|
196 |
<form method="post" action="options.php" class="clear">
|
197 |
<?php settings_fields('customtaxorder_settings'); ?>
|
198 |
<div class="metabox-holder">
|
199 |
<div class="order-widget">
|
200 |
-
<h2 class="widget-top"><?php
|
201 |
<table class="form-table">
|
202 |
<tr valign="top">
|
203 |
-
<th scope="row"><?php
|
204 |
</tr>
|
205 |
<tr valign="top">
|
206 |
<td><?php echo $settings; ?></td>
|
@@ -208,7 +204,7 @@ function customtaxorder_subpage() {
|
|
208 |
</table>
|
209 |
<input type="hidden" name="customtaxorder_settings[update]" value="Updated" />
|
210 |
<p class="submit">
|
211 |
-
<input type="submit" class="button-primary" value="<?php
|
212 |
</p>
|
213 |
</div>
|
214 |
</div>
|
@@ -220,12 +216,12 @@ function customtaxorder_subpage() {
|
|
220 |
|
221 |
|
222 |
/*
|
223 |
-
* Called from
|
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>' .
|
229 |
unset($options['update']);
|
230 |
update_option('customtaxorder_settings', $options);
|
231 |
}
|
@@ -245,7 +241,7 @@ function customtaxorder_update_order() {
|
|
245 |
}
|
246 |
if ( $verified == false ) {
|
247 |
// Nonce is invalid.
|
248 |
-
echo '<div id="message" class="error fade notice is-dismissible"><p>' .
|
249 |
return;
|
250 |
}
|
251 |
|
@@ -267,10 +263,10 @@ function customtaxorder_update_order() {
|
|
267 |
|
268 |
$ids[] = $term_id;
|
269 |
}
|
270 |
-
echo '<div id="message" class="updated fade notice is-dismissible"><p>'.
|
271 |
do_action('customtaxorder_update_order', $ids);
|
272 |
} else {
|
273 |
-
echo '<div id="message" class="error fade notice is-dismissible"><p>'.
|
274 |
}
|
275 |
}
|
276 |
|
@@ -290,3 +286,19 @@ function customtaxorder_sub_query( $terms, $tax ) {
|
|
290 |
}
|
291 |
return $options;
|
292 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
customtaxorder_update_settings();
|
12 |
$options = customtaxorder_get_settings();
|
|
|
13 |
$parent_ID = 0;
|
14 |
|
15 |
+
$taxonomies = customtaxorder_get_taxonomies() ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
if ( ! empty( $taxonomies ) ) {
|
18 |
foreach ( $taxonomies as $taxonomy ) {
|
19 |
$com_page = 'customtaxorder-'.$taxonomy->name;
|
20 |
if ( !isset($options[$taxonomy->name]) ) {
|
28 |
// Set your finegrained capability for this taxonomy for this custom filter.
|
29 |
$custom_cap_tax = apply_filters( 'customtaxorder_custom_cap_' . $taxonomy->name, $custom_cap );
|
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>
|
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">
|
56 |
+
<p><?php esc_html_e('The ordering of categories, tags and terms through a simple drag-and-drop interface.', 'custom-taxonomy-order-ne'); ?></p>
|
57 |
<?php
|
58 |
if ( ! empty( $taxonomies ) ) {
|
59 |
+
echo '<h2>' . esc_html__('Taxonomies', 'custom-taxonomy-order-ne') . '</h2><ul>';
|
60 |
$taxonomies = customtaxorder_sort_taxonomies( $taxonomies );
|
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>
|
67 |
}
|
68 |
echo '</ul></div></div><!-- #wrap -->';
|
69 |
return;
|
70 |
+
}
|
71 |
+
|
72 |
+
$settings = ''; // The input and text for the taxonomy that's shown.
|
73 |
+
if ( ! empty( $taxonomies ) ) {
|
74 |
+
foreach ( $taxonomies as $taxonomy ) {
|
75 |
+
$com_page = 'customtaxorder-'.$taxonomy->name;
|
76 |
+
if ( ! isset($options[$taxonomy->name]) ) {
|
77 |
+
$options[$taxonomy->name] = 0; // default if not set in options yet
|
78 |
+
}
|
79 |
+
if ( $_GET['page'] == $com_page ) {
|
80 |
+
$settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="0" ' . checked('0', $options[$taxonomy->name], false) . ' /> ' . esc_html__('Order by ID (default).', 'custom-taxonomy-order-ne') . '</label><br />
|
81 |
+
';
|
82 |
+
$settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="1" ' . checked('1', $options[$taxonomy->name], false) . ' /> ' . esc_html__('Custom Order as defined above.', 'custom-taxonomy-order-ne') . '</label><br />
|
83 |
+
';
|
84 |
+
$settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="2" ' . checked('2', $options[$taxonomy->name], false) . ' /> ' . esc_html__('Alphabetical Order by name.', 'custom-taxonomy-order-ne') . '</label><br />
|
85 |
+
';
|
86 |
+
$settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="3" ' . checked('3', $options[$taxonomy->name], false) . ' /> ' . esc_html__('Alphabetical Order by slug.', 'custom-taxonomy-order-ne') . '</label><br />
|
87 |
+
';
|
88 |
+
$tax_label = $taxonomy->label;
|
89 |
+
$tax = $taxonomy->name;
|
90 |
+
} else {
|
91 |
if ( ! isset($options[$taxonomy->name]) ) {
|
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 |
}
|
98 |
+
|
99 |
$parent_ID_order = 0;
|
100 |
if (isset($_POST['go-sub-posts'])) {
|
101 |
$parent_ID = $_POST['sub-posts'];
|
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 |
|
121 |
/* Nonce */
|
122 |
$nonce = wp_create_nonce( 'custom-taxonomy-order-ne-nonce' );
|
123 |
echo '<input type="hidden" id="custom-taxonomy-order-ne-nonce" name="custom-taxonomy-order-ne-nonce" value="' . $nonce . '" />';
|
124 |
|
125 |
+
// Remove filters for WPML and add one filter of our own.
|
126 |
+
$active_plugins = get_option('active_plugins');
|
127 |
+
if ( in_array( 'sitepress-multilingual-cms/sitepress.php', $active_plugins ) ) {
|
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 ); // Not needed.
|
131 |
+
remove_filter( "pre_option_{$tax}_children", array( $sitepress, 'pre_option_tax_children' ), 10, 0 );
|
132 |
+
add_filter( "pre_option_{$tax}_children", 'customtaxorder_pre_option_tax_children', 99, 0 );
|
133 |
+
}
|
134 |
+
|
135 |
$args = array(
|
136 |
+
'orderby' => 'term_order',
|
137 |
+
'order' => 'ASC',
|
138 |
'hide_empty' => false,
|
139 |
+
'parent' => $parent_ID,
|
140 |
);
|
141 |
$terms = get_terms( $tax, $args );
|
142 |
if ( $terms ) {
|
144 |
?>
|
145 |
<div id="poststuff" class="metabox-holder">
|
146 |
<div class="widget order-widget">
|
147 |
+
<h2 class="widget-top"><?php esc_html_e( $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>
|
148 |
<div class="misc-pub-section">
|
149 |
<ul id="custom-order-list">
|
150 |
<?php foreach ( $terms as $term ) { ?>
|
155 |
<div class="misc-pub-section misc-pub-section-last">
|
156 |
<?php if ($parent_ID != 0) { ?>
|
157 |
<div id="publishing-action-return-sub-posts">
|
158 |
+
<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'); ?>" />
|
159 |
</div>
|
160 |
<?php } ?>
|
161 |
<div id="publishing-action">
|
162 |
<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" id="custom-loading" style="display:none" alt="" />
|
163 |
+
<input type="submit" name="order-submit" id="order-submit" class="button-primary" value="<?php esc_html_e('Update Order', 'custom-taxonomy-order-ne') ?>" />
|
164 |
+
<input type="submit" name="order-alpha" id="order-alpha" class="button" value="<?php esc_html_e('Sort Alphabetical', 'custom-taxonomy-order-ne') ?>" />
|
165 |
+
<input type="submit" name="order-slug" id="order-slug" class="button" value="<?php esc_html_e('Sort on Slug', 'custom-taxonomy-order-ne') ?>" />
|
166 |
<?php do_action('custom_taxonomy_order_ne_settings_buttons'); ?>
|
167 |
</div>
|
168 |
<div class="clear"></div>
|
175 |
$dropdown = customtaxorder_sub_query( $terms, $tax );
|
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>
|
179 |
<div class="misc-pub-section misc-pub-section-last">
|
180 |
<select id="sub-posts" name="sub-posts">
|
181 |
<?php echo $dropdown; ?>
|
182 |
</select>
|
183 |
+
<input type="submit" name="go-sub-posts" class="button" id="go-sub-posts" value="<?php esc_html_e('Order Sub-terms', 'custom-taxonomy-order-ne') ?>" />
|
184 |
</div>
|
185 |
</div>
|
186 |
<?php } ?>
|
187 |
</div>
|
188 |
<?php } else { ?>
|
189 |
+
<p><?php esc_html_e('No terms found', 'custom-taxonomy-order-ne'); ?></p>
|
190 |
<?php } ?>
|
191 |
</form>
|
192 |
<form method="post" action="options.php" class="clear">
|
193 |
<?php settings_fields('customtaxorder_settings'); ?>
|
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>
|
197 |
<table class="form-table">
|
198 |
<tr valign="top">
|
199 |
+
<th scope="row"><?php esc_html_e('Auto-Sort Queries of this Taxonomy', 'custom-taxonomy-order-ne') ?></th>
|
200 |
</tr>
|
201 |
<tr valign="top">
|
202 |
<td><?php echo $settings; ?></td>
|
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>
|
209 |
</div>
|
210 |
</div>
|
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 |
}
|
241 |
}
|
242 |
if ( $verified == false ) {
|
243 |
// Nonce is invalid.
|
244 |
+
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>';
|
245 |
return;
|
246 |
}
|
247 |
|
263 |
|
264 |
$ids[] = $term_id;
|
265 |
}
|
266 |
+
echo '<div id="message" class="updated fade notice is-dismissible"><p>'. esc_html__('Order updated successfully.', 'custom-taxonomy-order-ne').'</p></div>';
|
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 |
|
286 |
}
|
287 |
return $options;
|
288 |
}
|
289 |
+
|
290 |
+
|
291 |
+
/*
|
292 |
+
* Compatibility with WPML and list of term children for the list of sub-terms.
|
293 |
+
*
|
294 |
+
* @since 3.2.0
|
295 |
+
*/
|
296 |
+
function customtaxorder_pre_option_tax_children() {
|
297 |
+
|
298 |
+
$taxonomy = str_replace( array( 'pre_option_', '_children' ), '', current_filter() );
|
299 |
+
$option_key = "{$taxonomy}_children_all";
|
300 |
+
$tax_children = get_option( $option_key, false );
|
301 |
+
|
302 |
+
return ! empty( $tax_children ) ? $tax_children : false;
|
303 |
+
|
304 |
+
}
|
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.
|
7 |
License: GPLv2 or later
|
8 |
|
9 |
|
@@ -52,6 +52,7 @@ First you can disable the plugin. Then in wp_options you can delete the field:
|
|
52 |
In wp_terms you can remove the column
|
53 |
* term_order
|
54 |
|
|
|
55 |
== Frequently Asked Questions ==
|
56 |
|
57 |
= I sorted the terms in the WordPress backend, but I don't see it changed in the frontend =
|
@@ -59,11 +60,6 @@ In wp_terms you can remove the column
|
|
59 |
Did you set the option for that taxonomy to use that custom order? Make sure to check it so the filters run
|
60 |
with your taxonomy.
|
61 |
|
62 |
-
= My custom taxonomy is not available in the menu page =
|
63 |
-
|
64 |
-
This plugin will only offer to sort them when the taxonomy is set to public. Make sure you use 'register_taxonomy'
|
65 |
-
with the public parameter set to true (default).
|
66 |
-
|
67 |
= How do I sort the terms when using a custom query? =
|
68 |
|
69 |
When you use default functions like get_terms or get_categories, this should not be needed.
|
@@ -153,14 +149,25 @@ You can start translating strings there for your locale. They need to be validat
|
|
153 |
and you want to apply for being validator, please post it on the support forum. I will make a request on make/polyglots to
|
154 |
have you added as validator for this plugin/locale.
|
155 |
|
|
|
156 |
== Screenshots ==
|
157 |
|
158 |
1. Screenshot of the menu page for Custom Taxonomy Order.
|
159 |
The WordPress menu completely left lists the different taxonomies.
|
160 |
The left metabox lists the toplevel terms. Right (or below) are the sub-terms.
|
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).
|
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.2.0
|
7 |
License: GPLv2 or later
|
8 |
|
9 |
|
52 |
In wp_terms you can remove the column
|
53 |
* term_order
|
54 |
|
55 |
+
|
56 |
== Frequently Asked Questions ==
|
57 |
|
58 |
= I sorted the terms in the WordPress backend, but I don't see it changed in the frontend =
|
60 |
Did you set the option for that taxonomy to use that custom order? Make sure to check it so the filters run
|
61 |
with your taxonomy.
|
62 |
|
|
|
|
|
|
|
|
|
|
|
63 |
= How do I sort the terms when using a custom query? =
|
64 |
|
65 |
When you use default functions like get_terms or get_categories, this should not be needed.
|
149 |
and you want to apply for being validator, please post it on the support forum. I will make a request on make/polyglots to
|
150 |
have you added as validator for this plugin/locale.
|
151 |
|
152 |
+
|
153 |
== Screenshots ==
|
154 |
|
155 |
1. Screenshot of the menu page for Custom Taxonomy Order.
|
156 |
The WordPress menu completely left lists the different taxonomies.
|
157 |
The left metabox lists the toplevel terms. Right (or below) are the sub-terms.
|
158 |
|
159 |
+
|
160 |
== Changelog ==
|
161 |
|
162 |
+
= 3.2.0 =
|
163 |
+
* 2020-07-06
|
164 |
+
* Improve compatibility with WPML plugin.
|
165 |
+
* Add function 'customtaxorder_get_taxonomies()' to remove duplicate code.
|
166 |
+
* Be able to sort all taxonomies, public and non-public.
|
167 |
+
* Use more esc_html functions.
|
168 |
+
* Update About page.
|
169 |
+
* Only load translations at the dashboard.
|
170 |
+
|
171 |
= 3.1.0 =
|
172 |
* 2020-03-23
|
173 |
* Add term_order field to edit screen of terms (thanks @li-an).
|
taxonomies.php
CHANGED
@@ -7,7 +7,7 @@ function custom_taxonomy_order() {
|
|
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(
|
11 |
}
|
12 |
|
13 |
if (isset($_POST['order-submit'])) {
|
@@ -17,7 +17,7 @@ function custom_taxonomy_order() {
|
|
17 |
?>
|
18 |
<div class='wrap customtaxorder'>
|
19 |
<div id="icon-customtaxorder"></div>
|
20 |
-
<h1><?php
|
21 |
|
22 |
<form name="custom-order-form" method="post" action=""><?php
|
23 |
|
@@ -25,20 +25,9 @@ function custom_taxonomy_order() {
|
|
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 |
-
$
|
29 |
-
$output = 'objects';
|
30 |
-
$taxonomies = get_taxonomies( $args, $output );
|
31 |
-
|
32 |
-
// Also make the link_category available if activated.
|
33 |
-
$linkplugin = "link-manager/link-manager.php";
|
34 |
-
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
35 |
-
if ( is_plugin_active($linkplugin) ) {
|
36 |
-
$args = array( 'name' => 'link_category' );
|
37 |
-
$taxonomies2 = get_taxonomies( $args, $output );
|
38 |
-
$taxonomies = array_merge($taxonomies, $taxonomies2);
|
39 |
-
}
|
40 |
|
41 |
-
if ( $taxonomies ) {
|
42 |
|
43 |
$taxonomies_ordered = customtaxorder_sort_taxonomies( $taxonomies );
|
44 |
?>
|
@@ -46,8 +35,8 @@ function custom_taxonomy_order() {
|
|
46 |
<div id="poststuff" class="metabox-holder">
|
47 |
<div class="widget order-widget">
|
48 |
<h2 class="widget-top">
|
49 |
-
<?php
|
50 |
-
<small><?php
|
51 |
</h2>
|
52 |
<div class="misc-pub-section">
|
53 |
<ul id="custom-taxonomy-list">
|
@@ -61,7 +50,7 @@ function custom_taxonomy_order() {
|
|
61 |
<div class="misc-pub-section misc-pub-section-last">
|
62 |
<div id="publishing-action">
|
63 |
<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" id="custom-loading" style="display:none" alt="" />
|
64 |
-
<input type="submit" name="order-submit" id="order-submit" class="button-primary" value="<?php
|
65 |
</div>
|
66 |
<div class="clear"></div>
|
67 |
</div>
|
@@ -70,7 +59,7 @@ function custom_taxonomy_order() {
|
|
70 |
</div>
|
71 |
|
72 |
<?php } else { ?>
|
73 |
-
<p><?php
|
74 |
<?php }
|
75 |
?>
|
76 |
</form>
|
@@ -80,7 +69,7 @@ function custom_taxonomy_order() {
|
|
80 |
|
81 |
|
82 |
/*
|
83 |
-
* Save order of the taxonomies in an option
|
84 |
*/
|
85 |
function customtaxorder_update_taxonomies() {
|
86 |
|
@@ -91,7 +80,7 @@ function customtaxorder_update_taxonomies() {
|
|
91 |
}
|
92 |
if ( $verified == false ) {
|
93 |
// Nonce is invalid.
|
94 |
-
echo '<div id="message" class="error fade notice is-dismissible"><p>' .
|
95 |
return;
|
96 |
}
|
97 |
|
@@ -101,19 +90,19 @@ function customtaxorder_update_taxonomies() {
|
|
101 |
$new_order = sanitize_text_field( $new_order );
|
102 |
update_option('customtaxorder_taxonomies', $new_order);
|
103 |
|
104 |
-
echo '<div id="message" class="updated fade notice is-dismissible"><p>'.
|
105 |
} else {
|
106 |
-
echo '<div id="message" class="error fade notice is-dismissible"><p>'.
|
107 |
}
|
108 |
}
|
109 |
|
110 |
|
111 |
/*
|
112 |
-
* Sort the taxonomies
|
113 |
*
|
114 |
-
*
|
115 |
*
|
116 |
-
*
|
117 |
*
|
118 |
* @since: 2.7.0
|
119 |
*
|
@@ -145,11 +134,11 @@ function customtaxorder_sort_taxonomies( $taxonomies = array() ) {
|
|
145 |
|
146 |
|
147 |
/*
|
148 |
-
* Sort the taxonomies for WooCommerce
|
149 |
*
|
150 |
-
*
|
151 |
*
|
152 |
-
*
|
153 |
*
|
154 |
* @since: 2.10.0
|
155 |
*
|
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__( 'Cheatin’ uh?', 'custom-taxonomy-order-ne' ));
|
11 |
}
|
12 |
|
13 |
if (isset($_POST['order-submit'])) {
|
17 |
?>
|
18 |
<div class='wrap customtaxorder'>
|
19 |
<div id="icon-customtaxorder"></div>
|
20 |
+
<h1><?php esc_html_e('Order Taxonomies', 'custom-taxonomy-order-ne'); ?></h1>
|
21 |
|
22 |
<form name="custom-order-form" method="post" action=""><?php
|
23 |
|
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 |
|
30 |
+
if ( ! empty($taxonomies) ) {
|
31 |
|
32 |
$taxonomies_ordered = customtaxorder_sort_taxonomies( $taxonomies );
|
33 |
?>
|
35 |
<div id="poststuff" class="metabox-holder">
|
36 |
<div class="widget order-widget">
|
37 |
<h2 class="widget-top">
|
38 |
+
<?php esc_html_e('Order Taxonomies', 'custom-taxonomy-order-ne'); ?> |
|
39 |
+
<small><?php esc_html_e('Order the taxonomies by dragging and dropping them into the desired order.', 'custom-taxonomy-order-ne') ?></small>
|
40 |
</h2>
|
41 |
<div class="misc-pub-section">
|
42 |
<ul id="custom-taxonomy-list">
|
50 |
<div class="misc-pub-section misc-pub-section-last">
|
51 |
<div id="publishing-action">
|
52 |
<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" id="custom-loading" style="display:none" alt="" />
|
53 |
+
<input type="submit" name="order-submit" id="order-submit" class="button-primary" value="<?php esc_attr_e('Update Order', 'custom-taxonomy-order-ne') ?>" />
|
54 |
</div>
|
55 |
<div class="clear"></div>
|
56 |
</div>
|
59 |
</div>
|
60 |
|
61 |
<?php } else { ?>
|
62 |
+
<p><?php esc_html_e('No taxonomies found', 'custom-taxonomy-order-ne'); ?></p>
|
63 |
<?php }
|
64 |
?>
|
65 |
</form>
|
69 |
|
70 |
|
71 |
/*
|
72 |
+
* Save order of the taxonomies in an option.
|
73 |
*/
|
74 |
function customtaxorder_update_taxonomies() {
|
75 |
|
80 |
}
|
81 |
if ( $verified == false ) {
|
82 |
// Nonce is invalid.
|
83 |
+
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>';
|
84 |
return;
|
85 |
}
|
86 |
|
90 |
$new_order = sanitize_text_field( $new_order );
|
91 |
update_option('customtaxorder_taxonomies', $new_order);
|
92 |
|
93 |
+
echo '<div id="message" class="updated fade notice is-dismissible"><p>'. esc_html__('Order updated successfully.', 'custom-taxonomy-order-ne').'</p></div>';
|
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.
|
102 |
*
|
103 |
+
* @param $taxonomies, array with a list of taxonomy objects.
|
104 |
*
|
105 |
+
* @return array list of taxonomies, ordered correctly.
|
106 |
*
|
107 |
* @since: 2.7.0
|
108 |
*
|
134 |
|
135 |
|
136 |
/*
|
137 |
+
* Sort the taxonomies for WooCommerce automatically.
|
138 |
*
|
139 |
+
* @param $attributes array with a list of taxonomy objects of WC_Product_Attribute.
|
140 |
*
|
141 |
+
* @rturn array list of taxonomies, ordered correctly.
|
142 |
*
|
143 |
* @since: 2.10.0
|
144 |
*
|