first commit
This commit is contained in:
103
wp-content/plugins/taxonomy-terms-order/include/class.addons.php
Normal file
103
wp-content/plugins/taxonomy-terms-order/include/class.addons.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
class TTO_addons
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
add_action ('to/get_terms_orderby/ignore', array ( $this, 'to_get_terms_orderby_ignore_coauthors' ), 10, 3 );
|
||||
add_action ('to/get_terms_orderby/ignore', array ( $this, 'to_get_terms_orderby_ignore_polylang' ), 10, 3);
|
||||
add_action ('to/get_terms_orderby/ignore', array ( $this, 'to_get_terms_orderby_ignore_woocommerce' ), 10, 3);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Co-Authors Plus fix
|
||||
*
|
||||
* @param mixed $ignore
|
||||
* @param mixed $orderby
|
||||
* @param mixed $args
|
||||
*/
|
||||
function to_get_terms_orderby_ignore_coauthors( $ignore, $orderby, $args )
|
||||
{
|
||||
if( !function_exists('is_plugin_active') )
|
||||
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
||||
|
||||
if( ! is_plugin_active( 'co-authors-plus/co-authors-plus.php' ))
|
||||
return $ignore;
|
||||
|
||||
if ( ! isset($args['taxonomy']) || count($args['taxonomy']) !== 1 || array_search('author', $args['taxonomy']) === FALSE )
|
||||
return $ignore;
|
||||
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Polylang fix
|
||||
*
|
||||
* @param mixed $ignore
|
||||
* @param mixed $orderby
|
||||
* @param mixed $args
|
||||
*/
|
||||
function to_get_terms_orderby_ignore_polylang( $ignore, $orderby, $args )
|
||||
{
|
||||
if( !function_exists('is_plugin_active') )
|
||||
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
||||
|
||||
if( ! is_plugin_active( 'polylang/polylang.php' ))
|
||||
return $ignore;
|
||||
|
||||
if ( ! isset( $args['taxonomy'] ) || count( $args['taxonomy'] ) < 1 )
|
||||
return $ignore;
|
||||
|
||||
if( in_array( 'language', $args['taxonomy'] ) )
|
||||
return TRUE;
|
||||
|
||||
return $ignore;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* WooCommerce Attribute order
|
||||
*
|
||||
* @param mixed $ignore
|
||||
* @param mixed $orderby
|
||||
* @param mixed $args
|
||||
*/
|
||||
function to_get_terms_orderby_ignore_woocommerce( $ignore, $orderby, $args )
|
||||
{
|
||||
if( !function_exists('is_plugin_active') )
|
||||
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
||||
|
||||
if( ! is_plugin_active( 'woocommerce/woocommerce.php' ))
|
||||
return $ignore;
|
||||
|
||||
if ( ! function_exists ( 'wc_get_attribute_taxonomies' ) )
|
||||
return $ignore;
|
||||
|
||||
//create a list of attribute taxonomies
|
||||
$attributes = wc_get_attribute_taxonomies();
|
||||
$found_attributex_tax = array();
|
||||
foreach ( $attributes as $attribute )
|
||||
{
|
||||
$found_attributex_tax[] = 'pa_' . $attribute->attribute_name;
|
||||
}
|
||||
|
||||
if ( ! isset($args['taxonomy']) || count($args['taxonomy']) !== 1 )
|
||||
return $ignore;
|
||||
|
||||
if ( count ( array_intersect( $found_attributex_tax, $args['taxonomy']) ) < 1 )
|
||||
return $ignore;
|
||||
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
new TTO_addons();
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
class TTO_functions
|
||||
{
|
||||
/**
|
||||
* Return default plugin options
|
||||
*
|
||||
*/
|
||||
static public function get_settings()
|
||||
{
|
||||
|
||||
$settings = get_option('tto_options');
|
||||
|
||||
$defaults = array (
|
||||
'show_reorder_interfaces' => array(),
|
||||
'capability' => 'manage_options',
|
||||
'autosort' => '1',
|
||||
'adminsort' => '1'
|
||||
);
|
||||
$settings = wp_parse_args( $settings, $defaults );
|
||||
|
||||
return $settings;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @desc
|
||||
*
|
||||
* Return UserLevel
|
||||
*
|
||||
*/
|
||||
static public function userdata_get_user_level($return_as_numeric = FALSE)
|
||||
{
|
||||
global $userdata;
|
||||
|
||||
$user_level = '';
|
||||
for ($i=10; $i >= 0;$i--)
|
||||
{
|
||||
if (current_user_can('level_' . $i) === TRUE)
|
||||
{
|
||||
$user_level = $i;
|
||||
if ($return_as_numeric === FALSE)
|
||||
$user_level = 'level_'.$i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ($user_level);
|
||||
}
|
||||
|
||||
|
||||
static public function check_table_column()
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
//check if the menu_order column exists;
|
||||
$query = "SHOW COLUMNS FROM $wpdb->terms
|
||||
LIKE 'term_order'";
|
||||
$result = $wpdb->query($query);
|
||||
|
||||
if ($result == 0)
|
||||
{
|
||||
$query = "ALTER TABLE $wpdb->terms ADD `term_order` INT( 4 ) NULL DEFAULT '0'";
|
||||
$result = $wpdb->query($query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public function info_box()
|
||||
{
|
||||
?>
|
||||
<div id="cpt_info_box">
|
||||
<p><?php _e( "Did you find this plugin useful? Please support our work with a donation or write an article about this plugin in your blog with a link to our site", 'taxonomy-terms-order' ) ?> <strong>https://www.nsp-code.com/</strong></p>
|
||||
<h4><?php _e( "Did you know there is an Advanced Version of this plug-in?", 'taxonomy-terms-order' ) ?> <a target="_blank" href="https://www.nsp-code.com/premium-plugins/advanced-taxonomy-terms-order/"><?php _e( "Read more", 'taxonomy-terms-order' ) ?></a></h4>
|
||||
<p><?php _e( "Check our", 'taxonomy-terms-order' ) ?> <a target="_blank" href="https://wordpress.org/plugins/post-types-order/">Post Types Order</a> <?php _e( "plugin which allows to custom sort all posts, pages, custom post types", 'taxonomy-terms-order' ) ?> </p>
|
||||
<p><?php _e('Check our', 'taxonomy-terms-order') ?> <a target="_blank" href="https://wordpress.org/plugins/post-terms-order/">Post Terms Order</a> <?php _e('plugin which allows to custom sort categories and custom taxonomies terms per post basis', 'taxonomy-terms-order') ?> </p>
|
||||
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
|
||||
class TTO_Interface
|
||||
{
|
||||
|
||||
function Interface()
|
||||
{
|
||||
global $wpdb, $wp_locale;
|
||||
|
||||
$taxonomy = isset($_GET['taxonomy']) ? sanitize_key($_GET['taxonomy']) : '';
|
||||
$post_type = isset($_GET['post_type']) ? sanitize_key($_GET['post_type']) : '';
|
||||
if(empty($post_type))
|
||||
{
|
||||
$screen = get_current_screen();
|
||||
|
||||
if(isset($screen->post_type) && !empty($screen->post_type))
|
||||
$post_type = $screen->post_type;
|
||||
else
|
||||
{
|
||||
switch($screen->parent_file)
|
||||
{
|
||||
case "upload.php" :
|
||||
$post_type = 'attachment';
|
||||
break;
|
||||
|
||||
default:
|
||||
$post_type = 'post';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$post_type_data = get_post_type_object($post_type);
|
||||
|
||||
if (!taxonomy_exists($taxonomy))
|
||||
$taxonomy = '';
|
||||
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h2><?php _e( "Taxonomy Order", 'taxonomy-terms-order' ) ?></h2>
|
||||
|
||||
<?php TTO_functions::info_box() ?>
|
||||
|
||||
<div id="ajax-response"></div>
|
||||
|
||||
<noscript>
|
||||
<div class="error message">
|
||||
<p><?php _e( "This plugin can't work without javascript, because it's use drag and drop and AJAX.", 'taxonomy-terms-order' ) ?></p>
|
||||
</div>
|
||||
</noscript>
|
||||
|
||||
<div class="clear"></div>
|
||||
|
||||
<?php
|
||||
|
||||
$current_section_parent_file = '';
|
||||
switch($post_type)
|
||||
{
|
||||
|
||||
case "attachment" :
|
||||
$current_section_parent_file = "upload.php";
|
||||
break;
|
||||
|
||||
default :
|
||||
$current_section_parent_file = "edit.php";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<form action="<?php echo $current_section_parent_file ?>" method="get" id="to_form">
|
||||
<input type="hidden" name="page" value="to-interface-<?php echo esc_attr($post_type) ?>" />
|
||||
<?php
|
||||
|
||||
if (!in_array($post_type, array('post', 'attachment')))
|
||||
echo '<input type="hidden" name="post_type" value="'. esc_attr($post_type) .'" />';
|
||||
|
||||
//output all available taxonomies for this post type
|
||||
|
||||
$post_type_taxonomies = get_object_taxonomies($post_type);
|
||||
|
||||
foreach ($post_type_taxonomies as $key => $taxonomy_name)
|
||||
{
|
||||
$taxonomy_info = get_taxonomy($taxonomy_name);
|
||||
if ($taxonomy_info->hierarchical !== TRUE)
|
||||
unset($post_type_taxonomies[$key]);
|
||||
}
|
||||
|
||||
//use the first taxonomy if emtpy taxonomy
|
||||
if ($taxonomy == '' || !taxonomy_exists($taxonomy))
|
||||
{
|
||||
reset($post_type_taxonomies);
|
||||
$taxonomy = current($post_type_taxonomies);
|
||||
}
|
||||
|
||||
if (count($post_type_taxonomies) > 1)
|
||||
{
|
||||
|
||||
?>
|
||||
|
||||
<h2 class="subtitle"><?php echo ucfirst($post_type_data->labels->name) ?> <?php _e( "Taxonomies", 'taxonomy-terms-order' ) ?></h2>
|
||||
<table cellspacing="0" class="wp-list-taxonomy">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="" class="column-cb check-column" id="cb" scope="col"> </th><th style="" class="" id="author" scope="col"><?php _e( "Taxonomy Title", 'taxonomy-terms-order' ) ?></th><th style="" class="manage-column" id="categories" scope="col"><?php _e( "Total Posts", 'taxonomy-terms-order' ) ?></th> </tr>
|
||||
</thead>
|
||||
|
||||
|
||||
<tbody id="the-list">
|
||||
<?php
|
||||
|
||||
$alternate = FALSE;
|
||||
foreach ($post_type_taxonomies as $post_type_taxonomy)
|
||||
{
|
||||
$taxonomy_info = get_taxonomy($post_type_taxonomy);
|
||||
|
||||
$alternate = $alternate === TRUE ? FALSE :TRUE;
|
||||
|
||||
$args = array(
|
||||
'hide_empty' => 0,
|
||||
'taxonomy' => $post_type_taxonomy
|
||||
);
|
||||
$taxonomy_terms = get_terms( $args );
|
||||
|
||||
?>
|
||||
<tr valign="top" class="<?php if ($alternate === TRUE) {echo 'alternate ';} ?>" id="taxonomy-<?php echo esc_attr($taxonomy) ?>">
|
||||
<th class="check-column" scope="row"><input type="radio" onclick="to_change_taxonomy(this)" value="<?php echo $post_type_taxonomy ?>" <?php if ($post_type_taxonomy == $taxonomy) {echo 'checked="checked"';} ?> name="taxonomy"> </th>
|
||||
<td class="categories column-categories"><b><?php echo $taxonomy_info->label ?></b> (<?php echo $taxonomy_info->labels->singular_name; ?>)</td>
|
||||
<td class="categories column-categories"><?php echo count($taxonomy_terms) ?></td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<br />
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<div id="order-terms">
|
||||
|
||||
<div id="post-body">
|
||||
|
||||
<ul class="sortable" id="tto_sortable">
|
||||
<?php
|
||||
$this->listTerms($taxonomy);
|
||||
?>
|
||||
</ul>
|
||||
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
|
||||
<div class="alignleft actions">
|
||||
<p class="submit">
|
||||
<a href="javascript:;" class="save-order button-primary"><?php _e( "Update", 'taxonomy-terms-order' ) ?></a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function() {
|
||||
|
||||
jQuery("ul.sortable").sortable({
|
||||
'tolerance':'intersect',
|
||||
'cursor':'pointer',
|
||||
'items':'> li',
|
||||
'axi': 'y',
|
||||
'placeholder':'placeholder',
|
||||
'nested': 'ul'
|
||||
});
|
||||
|
||||
jQuery(".save-order").bind( "click", function() {
|
||||
var mySortable = new Array();
|
||||
jQuery(".sortable").each( function(){
|
||||
|
||||
var serialized = jQuery(this).sortable("serialize");
|
||||
|
||||
var parent_tag = jQuery(this).parent().get(0).tagName;
|
||||
parent_tag = parent_tag.toLowerCase()
|
||||
if (parent_tag == 'li')
|
||||
{
|
||||
//
|
||||
var tag_id = jQuery(this).parent().attr('id');
|
||||
mySortable[tag_id] = serialized;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
mySortable[0] = serialized;
|
||||
}
|
||||
});
|
||||
|
||||
//serialize the array
|
||||
var serialize_data = JSON.stringify( convArrToObj(mySortable));
|
||||
|
||||
jQuery.post( ajaxurl, { action:'update-taxonomy-order', order: serialize_data, nonce : '<?php echo wp_create_nonce( 'update-taxonomy-order' ); ?>' }, function() {
|
||||
jQuery("#ajax-response").html('<div class="message updated fade"><p><?php esc_html_e ( "Items Order Updated", 'taxonomy-terms-order' ) ?></p></div>');
|
||||
jQuery("#ajax-response div").delay(3000).hide("slow");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function listTerms($taxonomy)
|
||||
{
|
||||
|
||||
// Query pages.
|
||||
$args = array(
|
||||
'orderby' => 'term_order',
|
||||
'depth' => 0,
|
||||
'child_of' => 0,
|
||||
'hide_empty' => 0
|
||||
);
|
||||
$taxonomy_terms = get_terms($taxonomy, $args);
|
||||
|
||||
$output = '';
|
||||
if (count($taxonomy_terms) > 0)
|
||||
{
|
||||
$output = $this->TOwalkTree($taxonomy_terms, $args['depth'], $args);
|
||||
}
|
||||
|
||||
echo $output;
|
||||
|
||||
}
|
||||
|
||||
function TOwalkTree($taxonomy_terms, $depth, $r)
|
||||
{
|
||||
$walker = new TO_Terms_Walker;
|
||||
$args = array($taxonomy_terms, $depth, $r);
|
||||
return call_user_func_array(array(&$walker, 'walk'), $args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
class TTO_plugin_options
|
||||
{
|
||||
|
||||
public function plugin_options()
|
||||
{
|
||||
$options = TTO_functions::get_settings();
|
||||
|
||||
if (isset($_POST['to_form_submit']) && wp_verify_nonce($_POST['to_form_nonce'],'to_form_submit') )
|
||||
{
|
||||
$options['show_reorder_interfaces'] = preg_replace( '/[^a-z]/', '', $_POST['show_reorder_interfaces'] );
|
||||
$options['capability'] = preg_replace( '/[^a-zA-Z0-9_\-]/', '', $_POST['capability'] );
|
||||
|
||||
$options['autosort'] = isset($_POST['autosort']) ? intval($_POST['autosort']) : '';
|
||||
$options['adminsort'] = isset($_POST['adminsort']) ? intval($_POST['adminsort']) : '';
|
||||
|
||||
?><div class="updated fade"><p><?php _e('Settings Saved', 'taxonomy-terms-order') ?></p></div><?php
|
||||
|
||||
update_option('tto_options', $options);
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="wrap">
|
||||
|
||||
<h2><?php _e( "General Settings", 'taxonomy-terms-order' ) ?></h2>
|
||||
|
||||
<?php TTO_functions::info_box() ?>
|
||||
|
||||
<form id="form_data" name="form" method="post">
|
||||
<br />
|
||||
<h2 class="subtitle"><?php _e( "General", 'taxonomy-terms-order' ) ?></h2>
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
|
||||
<tr valign="top">
|
||||
<th scope="row" style="text-align: right;"><label><?php esc_html_e('Show / Hide re-order interface', 'atto') ?></label></th>
|
||||
<td>
|
||||
<p><?php esc_html_e("Display the Taxonomy Order interface for the specified post types.", 'atto') ?></p>
|
||||
<br />
|
||||
<div class="pt-list">
|
||||
<?php
|
||||
|
||||
$post_types = get_post_types( array(), 'objects' );
|
||||
foreach( $post_types as $post_type )
|
||||
{
|
||||
|
||||
//check if there are any taxonomy for this post type
|
||||
$post_type_taxonomies = get_object_taxonomies( $post_type->name );
|
||||
|
||||
foreach ($post_type_taxonomies as $key => $taxonomy_name)
|
||||
{
|
||||
$taxonomy_info = get_taxonomy($taxonomy_name);
|
||||
if (empty($taxonomy_info->hierarchical) || $taxonomy_info->hierarchical !== TRUE)
|
||||
unset($post_type_taxonomies[$key]);
|
||||
}
|
||||
|
||||
if (count($post_type_taxonomies) == 0)
|
||||
continue;
|
||||
|
||||
|
||||
?>
|
||||
<p class="pt-item"><label>
|
||||
<select name="show_reorder_interfaces[<?php echo $post_type->name ?>]">
|
||||
<option value="show" <?php if(isset($options['show_reorder_interfaces'][$post_type->name]) && $options['show_reorder_interfaces'][$post_type->name] == 'show') {echo ' selected="selected"';} ?>><?php _e( "Show", 'atto' ) ?></option>
|
||||
<option value="hide" <?php if(isset($options['show_reorder_interfaces'][$post_type->name]) && $options['show_reorder_interfaces'][$post_type->name] == 'hide') {echo ' selected="selected"';} ?>><?php _e( "Hide", 'atto' ) ?></option>
|
||||
</select> <?php echo esc_html ( $post_type->label ); ?>
|
||||
</label><br /> </p>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
|
||||
<tr valign="top">
|
||||
<th scope="row" style="text-align: right;"><label><?php _e( "Minimum Level to use this plugin", 'taxonomy-terms-order' ) ?></label></th>
|
||||
<td>
|
||||
<select id="role" name="capability">
|
||||
<option value="read" <?php if (isset($options['capability']) && $options['capability'] == "read") echo 'selected="selected"'?>><?php _e('Subscriber', 'taxonomy-terms-order') ?></option>
|
||||
<option value="edit_posts" <?php if (isset($options['capability']) && $options['capability'] == "edit_posts") echo 'selected="selected"'?>><?php _e('Contributor', 'taxonomy-terms-order') ?></option>
|
||||
<option value="publish_posts" <?php if (isset($options['capability']) && $options['capability'] == "publish_posts") echo 'selected="selected"'?>><?php _e('Author', 'taxonomy-terms-order') ?></option>
|
||||
<option value="publish_pages" <?php if (isset($options['capability']) && $options['capability'] == "publish_pages") echo 'selected="selected"'?>><?php _e('Editor', 'taxonomy-terms-order') ?></option>
|
||||
<option value="manage_options" <?php if (!isset($options['capability']) || empty($options['capability']) || (isset($options['capability']) && $options['capability'] == "manage_options")) echo 'selected="selected"'?>><?php _e('Administrator', 'taxonomy-terms-order') ?></option>
|
||||
<?php do_action('tto/admin/plugin_options/capability') ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
<tr valign="top">
|
||||
<th scope="row" style="text-align: right;"><label><?php _e( "Auto Sort", 'taxonomy-terms-order' ) ?></label></th>
|
||||
<td>
|
||||
<select id="autosort" name="autosort">
|
||||
<option value="0" <?php if ($options['autosort'] == "0") echo 'selected="selected"'?>><?php _e('OFF', 'taxonomy-terms-order') ?></option>
|
||||
<option value="1" <?php if ($options['autosort'] == "1") echo 'selected="selected"'?>><?php _e('ON', 'taxonomy-terms-order') ?></option>
|
||||
</select>
|
||||
<label for="autosort"> *(<?php _e( "global setting", 'taxonomy-terms-order' ) ?>) <?php _e( "Additional description and details at ", 'taxonomy-terms-order' ) ?><a target="_blank" href="https://www.nsp-code.com/taxonomy-terms-order-and-auto-sort-admin-sort-description-an-usage/"><?php _e( "Auto Sort Description", 'taxonomy-terms-order' ) ?></a></label>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr valign="top">
|
||||
<th scope="row" style="text-align: right;"><label><?php _e( "Admin Sort", 'taxonomy-terms-order' ) ?></label></th>
|
||||
<td>
|
||||
<select id="adminsort" name="adminsort">
|
||||
<option value="0" <?php if ($options['adminsort'] == "0") echo 'selected="selected"'?>><?php _e('OFF', 'taxonomy-terms-order') ?></option>
|
||||
<option value="1" <?php if ($options['adminsort'] == "1") echo 'selected="selected"'?>><?php _e('ON', 'taxonomy-terms-order') ?></option>
|
||||
</select>
|
||||
<label for="adminsort"><?php _e("This will change the order of terms within the admin interface", 'taxonomy-terms-order') ?>. <?php _e( "Additional description and details at ", 'taxonomy-terms-order' ) ?><a target="_blank" href="https://www.nsp-code.com/taxonomy-terms-order-and-auto-sort-admin-sort-description-an-usage/"><?php _e( "Auto Sort Description", 'taxonomy-terms-order' ) ?></a></label>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<p class="submit">
|
||||
<input type="submit" name="Submit" class="button-primary" value="<?php _e('Save Settings', 'taxonomy-terms-order') ?>">
|
||||
</p>
|
||||
|
||||
<?php wp_nonce_field('to_form_submit','to_form_nonce'); ?>
|
||||
<input type="hidden" name="to_form_submit" value="true" />
|
||||
|
||||
</form>
|
||||
|
||||
<?php
|
||||
echo '</div>';
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
class TO_Terms_Walker extends Walker
|
||||
{
|
||||
|
||||
var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
|
||||
|
||||
|
||||
function start_lvl(&$output, $depth = 0, $args = array() )
|
||||
{
|
||||
extract($args, EXTR_SKIP);
|
||||
|
||||
$indent = str_repeat("\t", $depth);
|
||||
$output .= "\n$indent<ul class='children sortable'>\n";
|
||||
}
|
||||
|
||||
|
||||
function end_lvl(&$output, $depth = 0, $args = array())
|
||||
{
|
||||
extract($args, EXTR_SKIP);
|
||||
|
||||
$indent = str_repeat("\t", $depth);
|
||||
$output .= "$indent</ul>\n";
|
||||
}
|
||||
|
||||
|
||||
function start_el(&$output, $term, $depth = 0, $args = array(), $current_object_id = 0)
|
||||
{
|
||||
if ( $depth )
|
||||
$indent = str_repeat("\t", $depth);
|
||||
else
|
||||
$indent = '';
|
||||
|
||||
$currentScreen = get_current_screen();
|
||||
|
||||
$term_link = isset ( $currentScreen->post_type ) ? get_edit_term_link( $term, $term->taxonomy, $currentScreen->post_type ) : get_edit_term_link( $term );
|
||||
|
||||
$output .= $indent . '<li class="term_type_li" id="item_'.$term->term_id.'"><div class="item"><span class="title">'.apply_filters( 'to/term_title', $term->name, $term ).' </span> <span class="actions"><a href="' . $term_link .'"><span class="dashicons dashicons-edit"></span></a></span></div>';
|
||||
}
|
||||
|
||||
|
||||
function end_el(&$output, $object, $depth = 0, $args = array())
|
||||
{
|
||||
$output .= "</li>\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
224
wp-content/plugins/taxonomy-terms-order/include/class.tto.php
Normal file
224
wp-content/plugins/taxonomy-terms-order/include/class.tto.php
Normal file
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
class TTO
|
||||
{
|
||||
var $functions;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
add_action('admin_print_scripts', array ( $this, 'admin_print_scripts' ) );
|
||||
add_action('admin_print_styles', array ( $this, 'admin_print_styles' ) );
|
||||
add_action('admin_menu', array ( $this, 'admin_menu' ), 99);
|
||||
add_filter('terms_clauses', array ( $this, 'apply_order_filter' ), 10, 3);
|
||||
add_filter('get_terms_orderby', array ( $this, 'get_terms_orderby' ), 1, 2);
|
||||
|
||||
add_action( 'wp_ajax_update-taxonomy-order', array ( $this, 'saveAjaxOrder' ) );
|
||||
|
||||
if ( is_admin() )
|
||||
TTO_functions::check_table_column();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Admin Scripts
|
||||
*
|
||||
*/
|
||||
function admin_print_scripts()
|
||||
{
|
||||
wp_enqueue_script('jquery');
|
||||
|
||||
wp_enqueue_script('jquery-ui-sortable');
|
||||
|
||||
$myJsFile = TOURL . '/js/to-javascript.js';
|
||||
wp_register_script('to-javascript', $myJsFile);
|
||||
wp_enqueue_script( 'to-javascript');
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Admin styles
|
||||
*
|
||||
*/
|
||||
function admin_print_styles()
|
||||
{
|
||||
$myCssFile = TOURL . '/css/to.css';
|
||||
wp_register_style('to.css', $myCssFile);
|
||||
wp_enqueue_style( 'to.css');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Plugin menus
|
||||
*
|
||||
*/
|
||||
function admin_menu()
|
||||
{
|
||||
include (TOPATH . '/include/class.interface.php');
|
||||
include (TOPATH . '/include/class.terms_walker.php');
|
||||
include (TOPATH . '/include/class.options.php');
|
||||
|
||||
$TTO_plugin_options = new TTO_plugin_options();
|
||||
add_options_page('Taxonomy Terms Order', '<img class="menu_tto" src="'. TOURL .'/images/menu-icon.png" alt="" />' . __('Taxonomy Terms Order', 'taxonomy-terms-order'), 'manage_options', 'to-options', array ( $TTO_plugin_options, 'plugin_options' ) );
|
||||
|
||||
$options = TTO_functions::get_settings();
|
||||
|
||||
if(isset($options['capability']) && !empty($options['capability']))
|
||||
$capability = $options['capability'];
|
||||
else if (is_numeric($options['level']))
|
||||
{
|
||||
//maintain the old user level compatibility
|
||||
$capability = TTO_functions::userdata_get_user_level();
|
||||
}
|
||||
else
|
||||
{
|
||||
$capability = 'manage_options';
|
||||
}
|
||||
|
||||
//put a menu within all custom types if apply
|
||||
$post_types = get_post_types();
|
||||
foreach( $post_types as $post_type)
|
||||
{
|
||||
|
||||
//check if there are any taxonomy for this post type
|
||||
$post_type_taxonomies = get_object_taxonomies($post_type);
|
||||
|
||||
foreach ($post_type_taxonomies as $key => $taxonomy_name)
|
||||
{
|
||||
$taxonomy_info = get_taxonomy($taxonomy_name);
|
||||
if (empty($taxonomy_info->hierarchical) || $taxonomy_info->hierarchical !== TRUE)
|
||||
unset($post_type_taxonomies[$key]);
|
||||
}
|
||||
|
||||
if (count($post_type_taxonomies) == 0)
|
||||
continue;
|
||||
|
||||
if ( isset ( $options['show_reorder_interfaces'][ $post_type ]) && $options['show_reorder_interfaces'][ $post_type ] == 'hide' )
|
||||
continue;
|
||||
|
||||
$TTO_Interface = new TTO_Interface();
|
||||
|
||||
if ($post_type == 'post')
|
||||
add_submenu_page('edit.php', __('Taxonomy Order', 'taxonomy-terms-order'), __('Taxonomy Order', 'taxonomy-terms-order'), $capability, 'to-interface-'.$post_type, array ( $TTO_Interface, 'Interface' ) );
|
||||
elseif ($post_type == 'attachment')
|
||||
add_submenu_page('upload.php', __('Taxonomy Order', 'taxonomy-terms-order'), __('Taxonomy Order', 'taxonomy-terms-order'), $capability, 'to-interface-'.$post_type, array ( $TTO_Interface, 'Interface' ) );
|
||||
else
|
||||
add_submenu_page('edit.php?post_type='.$post_type, __('Taxonomy Order', 'taxonomy-terms-order'), __('Taxonomy Order', 'taxonomy-terms-order'), $capability, 'to-interface-'.$post_type, array ( $TTO_Interface, 'Interface' ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply order filter
|
||||
*
|
||||
* @param mixed $clauses
|
||||
* @param mixed $taxonomies
|
||||
* @param mixed $args
|
||||
*/
|
||||
function apply_order_filter( $clauses, $taxonomies, $args)
|
||||
{
|
||||
if ( apply_filters('to/get_terms_orderby/ignore', FALSE, $clauses['orderby'], $args) )
|
||||
return $clauses;
|
||||
|
||||
$options = TTO_functions::get_settings();
|
||||
|
||||
//if admin make sure use the admin setting
|
||||
if (is_admin())
|
||||
{
|
||||
|
||||
//return if use orderby columns
|
||||
if (isset($_GET['orderby']) && $_GET['orderby'] != 'term_order')
|
||||
return $clauses;
|
||||
|
||||
if ( $options['adminsort'] == "1" && (!isset($args['ignore_term_order']) || (isset($args['ignore_term_order']) && $args['ignore_term_order'] !== TRUE) ) )
|
||||
{
|
||||
if ( $clauses['orderby'] == 'ORDER BY t.name' )
|
||||
$clauses['orderby'] = 'ORDER BY t.term_order '. $clauses['order'] .', t.name';
|
||||
else
|
||||
$clauses['orderby'] = 'ORDER BY t.term_order';
|
||||
|
||||
}
|
||||
|
||||
return $clauses;
|
||||
}
|
||||
|
||||
//if autosort, then force the menu_order
|
||||
if ($options['autosort'] == "1" && (!isset($args['ignore_term_order']) || (isset($args['ignore_term_order']) && $args['ignore_term_order'] !== TRUE) ) )
|
||||
{
|
||||
$clauses['orderby'] = 'ORDER BY t.term_order';
|
||||
}
|
||||
|
||||
return $clauses;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get terms orderby
|
||||
*
|
||||
* @param mixed $orderby
|
||||
* @param mixed $args
|
||||
* @return mixed
|
||||
*/
|
||||
function get_terms_orderby($orderby, $args)
|
||||
{
|
||||
if ( apply_filters('to/get_terms_orderby/ignore', FALSE, $orderby, $args) )
|
||||
return $orderby;
|
||||
|
||||
if (isset($args['orderby']) && $args['orderby'] == "term_order" && $orderby != "term_order")
|
||||
return "t.term_order";
|
||||
|
||||
return $orderby;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save the AJAX order update
|
||||
*
|
||||
*/
|
||||
function saveAjaxOrder()
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
if ( ! wp_verify_nonce( $_POST['nonce'], 'update-taxonomy-order' ) )
|
||||
die();
|
||||
|
||||
$data = stripslashes($_POST['order']);
|
||||
$unserialised_data = json_decode($data, TRUE);
|
||||
|
||||
if (is_array($unserialised_data))
|
||||
foreach($unserialised_data as $key => $values )
|
||||
{
|
||||
//$key_parent = str_replace("item_", "", $key);
|
||||
$items = explode("&", $values);
|
||||
unset($item);
|
||||
foreach ($items as $item_key => $item_)
|
||||
{
|
||||
$items[$item_key] = trim(str_replace("item[]=", "",$item_));
|
||||
}
|
||||
|
||||
if (is_array($items) && count($items) > 0)
|
||||
{
|
||||
foreach( $items as $item_key => $term_id )
|
||||
{
|
||||
$wpdb->update( $wpdb->terms, array('term_order' => ($item_key + 1)), array('term_id' => $term_id) );
|
||||
}
|
||||
clean_term_cache($items);
|
||||
}
|
||||
}
|
||||
|
||||
do_action('tto/update-order');
|
||||
|
||||
wp_cache_flush();
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user