Version Description
- 2018-10-17
- Sort attributes for WooCommerce automatically.
- Show name and label of taxonomy in the lists.
Download this release
Release Info
Developer | mpol |
Plugin | Custom Taxonomy Order NE |
Version | 2.10.0 |
Comparing to | |
See all releases |
Code changes from version 2.9.5 to 2.10.0
- customtaxorder.php +11 -10
- page-customtaxorder.php +14 -13
- readme.txt +6 -1
- taxonomies.php +30 -2
customtaxorder.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Custom Taxonomy Order
|
4 |
Plugin URI: http://products.zenoweb.nl/free-wordpress-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: 2.
|
7 |
Author: Marcel Pol
|
8 |
Author URI: http://zenoweb.nl/
|
9 |
License: GPLv2 or later
|
@@ -40,7 +40,7 @@ Domain Path: /lang/
|
|
40 |
|
41 |
|
42 |
// Plugin Version
|
43 |
-
define('CUSTOMTAXORDER_VER', '2.
|
44 |
|
45 |
|
46 |
function customtaxorder_register_settings() {
|
@@ -61,6 +61,7 @@ function customtaxorder_update_settings() {
|
|
61 |
|
62 |
|
63 |
/*
|
|
|
64 |
* $customtaxorder_settings is an array with key: $taxonomy->name and value: setting (0, 1, 2).
|
65 |
*/
|
66 |
function customtaxorder_get_settings() {
|
@@ -104,13 +105,17 @@ function customtaxorder_taxonomies_validate($input) {
|
|
104 |
return $input;
|
105 |
}
|
106 |
|
|
|
|
|
|
|
|
|
107 |
function customtaxorder_menu() {
|
108 |
$args = array( 'public' => true );
|
109 |
$output = 'objects';
|
110 |
$taxonomies = get_taxonomies($args, $output);
|
111 |
|
112 |
// Also make the link_category available if activated.
|
113 |
-
$linkplugin =
|
114 |
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
115 |
if ( is_plugin_active($linkplugin) ) {
|
116 |
$args = array( 'name' => 'link_category' );
|
@@ -247,17 +252,16 @@ add_action( 'customtaxorder_update_order', 'customtaxorder_flush_cache' );
|
|
247 |
|
248 |
|
249 |
/*
|
250 |
-
*
|
251 |
-
* Function to give an option for the list of sub-taxonomies
|
252 |
*/
|
253 |
function customtaxorder_sub_query( $terms, $tax ) {
|
254 |
$options = '';
|
255 |
-
foreach ( $terms as $term )
|
256 |
$subterms = get_term_children( $term->term_id, $tax );
|
257 |
if ( $subterms ) {
|
258 |
$options .= '<option value="' . $term->term_id . '">' . $term->name . '</option>';
|
259 |
}
|
260 |
-
|
261 |
return $options;
|
262 |
}
|
263 |
|
@@ -517,9 +521,7 @@ function customtaxorder_about() {
|
|
517 |
|
518 |
|
519 |
/*
|
520 |
-
* customtaxorder_links
|
521 |
* Add Settings link to the main plugin page
|
522 |
-
*
|
523 |
*/
|
524 |
function customtaxorder_links( $links, $file ) {
|
525 |
if ( $file == plugin_basename( dirname(__FILE__).'/customtaxorder.php' ) ) {
|
@@ -540,7 +542,6 @@ add_action('plugins_loaded', 'customtaxorder_load_lang');
|
|
540 |
|
541 |
|
542 |
/*
|
543 |
-
* customtaxorder_activate
|
544 |
* Function called at activation time.
|
545 |
*/
|
546 |
function _customtaxorder_activate() {
|
3 |
Plugin Name: Custom Taxonomy Order
|
4 |
Plugin URI: http://products.zenoweb.nl/free-wordpress-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: 2.10.0
|
7 |
Author: Marcel Pol
|
8 |
Author URI: http://zenoweb.nl/
|
9 |
License: GPLv2 or later
|
40 |
|
41 |
|
42 |
// Plugin Version
|
43 |
+
define('CUSTOMTAXORDER_VER', '2.10.0');
|
44 |
|
45 |
|
46 |
function customtaxorder_register_settings() {
|
61 |
|
62 |
|
63 |
/*
|
64 |
+
* Get settings for ordering this taxonomy.
|
65 |
* $customtaxorder_settings is an array with key: $taxonomy->name and value: setting (0, 1, 2).
|
66 |
*/
|
67 |
function customtaxorder_get_settings() {
|
105 |
return $input;
|
106 |
}
|
107 |
|
108 |
+
|
109 |
+
/*
|
110 |
+
* Add all the admin menu pages.
|
111 |
+
*/
|
112 |
function customtaxorder_menu() {
|
113 |
$args = array( 'public' => true );
|
114 |
$output = 'objects';
|
115 |
$taxonomies = get_taxonomies($args, $output);
|
116 |
|
117 |
// Also make the link_category available if activated.
|
118 |
+
$linkplugin = 'link-manager/link-manager.php';
|
119 |
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
120 |
if ( is_plugin_active($linkplugin) ) {
|
121 |
$args = array( 'name' => 'link_category' );
|
252 |
|
253 |
|
254 |
/*
|
255 |
+
* Function to give dropdown options for the list of sub-taxonomies.
|
|
|
256 |
*/
|
257 |
function customtaxorder_sub_query( $terms, $tax ) {
|
258 |
$options = '';
|
259 |
+
foreach ( $terms as $term ) {
|
260 |
$subterms = get_term_children( $term->term_id, $tax );
|
261 |
if ( $subterms ) {
|
262 |
$options .= '<option value="' . $term->term_id . '">' . $term->name . '</option>';
|
263 |
}
|
264 |
+
}
|
265 |
return $options;
|
266 |
}
|
267 |
|
521 |
|
522 |
|
523 |
/*
|
|
|
524 |
* Add Settings link to the main plugin page
|
|
|
525 |
*/
|
526 |
function customtaxorder_links( $links, $file ) {
|
527 |
if ( $file == plugin_basename( dirname(__FILE__).'/customtaxorder.php' ) ) {
|
542 |
|
543 |
|
544 |
/*
|
|
|
545 |
* Function called at activation time.
|
546 |
*/
|
547 |
function _customtaxorder_activate() {
|
page-customtaxorder.php
CHANGED
@@ -61,32 +61,32 @@ function customtaxorder() {
|
|
61 |
// Set your custom capability through this filter.
|
62 |
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
63 |
|
64 |
-
if ( function_exists('current_user_can') && !current_user_can( $custom_cap ) ) {
|
65 |
die(__( 'Cheatin’ uh?', 'custom-taxonomy-order-ne' ));
|
66 |
}
|
67 |
|
68 |
?>
|
69 |
-
<h1>Custom Taxonomy Order
|
70 |
<div class="order-widget">
|
71 |
<p><?php _e('The ordering of categories and custom taxonomy terms through a simple drag-and-drop interface.', 'custom-taxonomy-order-ne'); ?></p>
|
72 |
<?php
|
73 |
-
if ( !empty( $taxonomies ) ) {
|
74 |
-
echo
|
75 |
$taxonomies = customtaxorder_sort_taxonomies( $taxonomies );
|
76 |
echo '<li class="lineitem"><a href="' . admin_url( 'admin.php?page=customtaxorder-taxonomies' ) . '">' . __('Taxonomies', 'custom-taxonomy-order-ne') . '</a></li>
|
77 |
';
|
78 |
foreach ( $taxonomies as $taxonomy ) {
|
79 |
-
echo '<li class="lineitem"><a href="' . admin_url( 'admin.php?page=customtaxorder-' . $taxonomy->name ) . '">' . $taxonomy->label . '</a
|
80 |
';
|
81 |
}
|
82 |
}
|
83 |
echo '</ul></div></div><!-- #wrap -->';
|
84 |
return;
|
85 |
} else {
|
86 |
-
if ( !empty( $taxonomies ) ) {
|
87 |
foreach ( $taxonomies as $taxonomy ) {
|
88 |
$com_page = 'customtaxorder-'.$taxonomy->name;
|
89 |
-
if ( !isset($options[$taxonomy->name]) ) {
|
90 |
$options[$taxonomy->name] = 0; // default if not set in options yet
|
91 |
}
|
92 |
if ( $_GET['page'] == $com_page ) {
|
@@ -99,7 +99,7 @@ function customtaxorder() {
|
|
99 |
$tax_label = $taxonomy->label;
|
100 |
$tax = $taxonomy->name;
|
101 |
} else {
|
102 |
-
if ( !isset($options[$taxonomy->name]) ) {
|
103 |
$options[$taxonomy->name] = 0; // default if not set in options yet
|
104 |
}
|
105 |
$settings .= '<input name="customtaxorder_settings[' . $taxonomy->name . ']" type="hidden" value="' . $options[$taxonomy->name] . '" />';
|
@@ -122,7 +122,6 @@ function customtaxorder() {
|
|
122 |
$parent_term = get_term($_POST['hidden-parent-id'], $tax);
|
123 |
$parent_ID = $parent_term->parent;
|
124 |
}
|
125 |
-
$message = "";
|
126 |
if (isset($_POST['order-submit'])) {
|
127 |
customtaxorder_update_order();
|
128 |
} ?>
|
@@ -149,9 +148,9 @@ function customtaxorder() {
|
|
149 |
<h2 class="widget-top"><?php _e( $tax_label) ?> | <small><?php _e('Order the taxonomies by dragging and dropping them into the desired order.', 'custom-taxonomy-order-ne') ?></small></h2>
|
150 |
<div class="misc-pub-section">
|
151 |
<ul id="custom-order-list">
|
152 |
-
<?php foreach ( $terms as $term )
|
153 |
<li id="id_<?php echo $term->term_id; ?>" class="lineitem"><?php echo $term->name; ?></li>
|
154 |
-
<?php
|
155 |
</ul>
|
156 |
</div>
|
157 |
<div class="misc-pub-section misc-pub-section-last">
|
@@ -170,9 +169,11 @@ function customtaxorder() {
|
|
170 |
<input type="hidden" id="hidden-parent-id" name="hidden-parent-id" value="<?php echo $parent_ID; ?>" />
|
171 |
<input type="hidden" id="hidden-parent-id-order" name="hidden-parent-id-order" value="<?php echo $parent_ID_order; ?>" />
|
172 |
</div>
|
173 |
-
<?php
|
|
|
|
|
174 |
<div class="widget order-widget">
|
175 |
-
<h2 class="widget-top"><?php print(__('Sub-', 'custom-taxonomy-order-ne')
|
176 |
<div class="misc-pub-section misc-pub-section-last">
|
177 |
<select id="sub-posts" name="sub-posts">
|
178 |
<?php echo $dropdown; ?>
|
61 |
// Set your custom capability through this filter.
|
62 |
$custom_cap = apply_filters( 'customtaxorder_custom_cap', 'manage_categories' );
|
63 |
|
64 |
+
if ( function_exists('current_user_can') && ! current_user_can( $custom_cap ) ) {
|
65 |
die(__( 'Cheatin’ uh?', 'custom-taxonomy-order-ne' ));
|
66 |
}
|
67 |
|
68 |
?>
|
69 |
+
<h1>Custom Taxonomy Order</h1>
|
70 |
<div class="order-widget">
|
71 |
<p><?php _e('The ordering of categories and custom taxonomy terms through a simple drag-and-drop interface.', 'custom-taxonomy-order-ne'); ?></p>
|
72 |
<?php
|
73 |
+
if ( ! empty( $taxonomies ) ) {
|
74 |
+
echo '<h2>' . __('Taxonomies', 'custom-taxonomy-order-ne') . '</h2><ul>';
|
75 |
$taxonomies = customtaxorder_sort_taxonomies( $taxonomies );
|
76 |
echo '<li class="lineitem"><a href="' . admin_url( 'admin.php?page=customtaxorder-taxonomies' ) . '">' . __('Taxonomies', 'custom-taxonomy-order-ne') . '</a></li>
|
77 |
';
|
78 |
foreach ( $taxonomies as $taxonomy ) {
|
79 |
+
echo '<li class="lineitem"><a href="' . admin_url( 'admin.php?page=customtaxorder-' . $taxonomy->name ) . '">' . $taxonomy->label . '</a> (' . $taxonomy->name . ')</li>
|
80 |
';
|
81 |
}
|
82 |
}
|
83 |
echo '</ul></div></div><!-- #wrap -->';
|
84 |
return;
|
85 |
} else {
|
86 |
+
if ( ! empty( $taxonomies ) ) {
|
87 |
foreach ( $taxonomies as $taxonomy ) {
|
88 |
$com_page = 'customtaxorder-'.$taxonomy->name;
|
89 |
+
if ( ! isset($options[$taxonomy->name]) ) {
|
90 |
$options[$taxonomy->name] = 0; // default if not set in options yet
|
91 |
}
|
92 |
if ( $_GET['page'] == $com_page ) {
|
99 |
$tax_label = $taxonomy->label;
|
100 |
$tax = $taxonomy->name;
|
101 |
} else {
|
102 |
+
if ( ! isset($options[$taxonomy->name]) ) {
|
103 |
$options[$taxonomy->name] = 0; // default if not set in options yet
|
104 |
}
|
105 |
$settings .= '<input name="customtaxorder_settings[' . $taxonomy->name . ']" type="hidden" value="' . $options[$taxonomy->name] . '" />';
|
122 |
$parent_term = get_term($_POST['hidden-parent-id'], $tax);
|
123 |
$parent_ID = $parent_term->parent;
|
124 |
}
|
|
|
125 |
if (isset($_POST['order-submit'])) {
|
126 |
customtaxorder_update_order();
|
127 |
} ?>
|
148 |
<h2 class="widget-top"><?php _e( $tax_label) ?> | <small><?php _e('Order the taxonomies by dragging and dropping them into the desired order.', 'custom-taxonomy-order-ne') ?></small></h2>
|
149 |
<div class="misc-pub-section">
|
150 |
<ul id="custom-order-list">
|
151 |
+
<?php foreach ( $terms as $term ) { ?>
|
152 |
<li id="id_<?php echo $term->term_id; ?>" class="lineitem"><?php echo $term->name; ?></li>
|
153 |
+
<?php } ?>
|
154 |
</ul>
|
155 |
</div>
|
156 |
<div class="misc-pub-section misc-pub-section-last">
|
169 |
<input type="hidden" id="hidden-parent-id" name="hidden-parent-id" value="<?php echo $parent_ID; ?>" />
|
170 |
<input type="hidden" id="hidden-parent-id-order" name="hidden-parent-id-order" value="<?php echo $parent_ID_order; ?>" />
|
171 |
</div>
|
172 |
+
<?php
|
173 |
+
$dropdown = customtaxorder_sub_query( $terms, $tax );
|
174 |
+
if( ! empty($dropdown) ) { ?>
|
175 |
<div class="widget order-widget">
|
176 |
+
<h2 class="widget-top"><?php print(__('Sub-', 'custom-taxonomy-order-ne') . $tax_label); ?> | <small><?php _e('Choose a term from the drop down to order its sub-terms.', 'custom-taxonomy-order-ne'); ?></small></h2>
|
177 |
<div class="misc-pub-section misc-pub-section-last">
|
178 |
<select id="sub-posts" name="sub-posts">
|
179 |
<?php echo $dropdown; ?>
|
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: 4.9
|
6 |
-
Stable tag: 2.
|
7 |
License: GPLv2 or later
|
8 |
|
9 |
|
@@ -148,6 +148,11 @@ The left metabox lists the toplevel terms. Right (or below) are the sub-terms.
|
|
148 |
|
149 |
== Changelog ==
|
150 |
|
|
|
|
|
|
|
|
|
|
|
151 |
= 2.9.5 =
|
152 |
* 2018-09-07
|
153 |
* Add support for Dark Mode beta plugin.
|
3 |
Tags: term order, category order, taxonomy order, order
|
4 |
Requires at least: 3.7
|
5 |
Tested up to: 4.9
|
6 |
+
Stable tag: 2.10.0
|
7 |
License: GPLv2 or later
|
8 |
|
9 |
|
148 |
|
149 |
== Changelog ==
|
150 |
|
151 |
+
= 2.10.0 =
|
152 |
+
* 2018-10-17
|
153 |
+
* Sort attributes for WooCommerce automatically.
|
154 |
+
* Show name and label of taxonomy in the lists.
|
155 |
+
|
156 |
= 2.9.5 =
|
157 |
* 2018-09-07
|
158 |
* Add support for Dark Mode beta plugin.
|
taxonomies.php
CHANGED
@@ -53,8 +53,8 @@ function custom_taxonomy_order() {
|
|
53 |
<ul id="custom-taxonomy-list">
|
54 |
<?php
|
55 |
foreach ( $taxonomies_ordered as $taxonomy ) { ?>
|
56 |
-
<li id="<?php echo $taxonomy->name; ?>" class="lineitem"><?php echo $taxonomy->name
|
57 |
-
|
58 |
} ?>
|
59 |
</ul>
|
60 |
</div>
|
@@ -142,3 +142,31 @@ function customtaxorder_sort_taxonomies( $taxonomies = array() ) {
|
|
142 |
|
143 |
return $taxonomies_ordered;
|
144 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
<ul id="custom-taxonomy-list">
|
54 |
<?php
|
55 |
foreach ( $taxonomies_ordered as $taxonomy ) { ?>
|
56 |
+
<li id="<?php echo $taxonomy->name; ?>" class="lineitem"><?php echo $taxonomy->label . ' (' . $taxonomy->name . ')';?></li>
|
57 |
+
<?php
|
58 |
} ?>
|
59 |
</ul>
|
60 |
</div>
|
142 |
|
143 |
return $taxonomies_ordered;
|
144 |
}
|
145 |
+
|
146 |
+
|
147 |
+
/*
|
148 |
+
* Sort the taxonomies for WooCommerce
|
149 |
+
*
|
150 |
+
* Parameter: $taxonomies, array with a list of taxonomy objects of WC_Product_Attribute.
|
151 |
+
*
|
152 |
+
* Returns: array with list of taxonomies, ordered correctly.
|
153 |
+
*
|
154 |
+
* @since: 2.10.0
|
155 |
+
*
|
156 |
+
*/
|
157 |
+
function customtaxorder_sort_woocommerce_taxonomies( $attributes ) {
|
158 |
+
if ( is_array( $attributes ) && ! empty( $attributes ) ) {
|
159 |
+
foreach ( $attributes as $attribute ) {
|
160 |
+
if ( is_object( $attribute ) && is_a( $attribute, 'WC_Product_Attribute' ) ) {
|
161 |
+
// nothing to do
|
162 |
+
} else {
|
163 |
+
return $attributes; // not an attribute we are looking for.
|
164 |
+
}
|
165 |
+
}
|
166 |
+
// We have the correct data.
|
167 |
+
$attributes = customtaxorder_sort_taxonomies( $attributes );
|
168 |
+
}
|
169 |
+
|
170 |
+
return $attributes;
|
171 |
+
}
|
172 |
+
add_filter( 'woocommerce_product_get_attributes', 'customtaxorder_sort_woocommerce_taxonomies' );
|