function to_plugin_options() { $options = get_option('tto_options'); if (isset($_POST['to_form_submit']) && wp_verify_nonce($_POST['to_form_nonce'], 'to_form_submit')) { $options['capability'] = sanitize_key($_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"> <div id="icon-settings" class="icon32"></div> <h2><?php _e("General Settings", 'taxonomy-terms-order'); ?> </h2> <?php tto_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 _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="install_plugins" <?php if (!isset($options['capability']) || empty($options['capability']) || isset($options['capability']) && $options['capability'] == "install_plugins") { echo 'selected="selected"'; } ?> ><?php _e('Administrator', 'taxonomy-terms-order'); ?> </option> </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="role" 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> *(<?php _e("global setting", 'taxonomy-terms-order'); ?> ) <?php _e("Additional description and details at ", 'taxonomy-terms-order'); ?> <a target="_blank" href="http://www.nsp-code.com/taxonomy-terms-order-and-auto-sort-admin-sort-description-an-usage/"><?php _e("Auto Sort Description", 'taxonomy-terms-order'); ?> </a> </td> </tr> <tr valign="top"> <th scope="row" style="text-align: right;"><label><?php _e("Admin Sort", 'taxonomy-terms-order'); ?> </label></th> <td> <input id="adminsort" type="checkbox" <?php if ($options['adminsort'] == "1") { echo ' checked="checked"'; } ?> value="1" name="adminsort"> <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="http://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>'; }
function TOPluginInterface() { global $wpdb, $wp_locale; $taxonomy = isset($_GET['taxonomy']) ? $_GET['taxonomy'] : ''; $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post'; $post_type_data = get_post_type_object($post_type); if (!taxonomy_exists($taxonomy)) { $taxonomy = ''; } ?> <div class="wrap"> <div class="icon32" id="icon-edit"><br></div> <h2><?php _e("Taxonomy Order", 'to'); ?> </h2> <?php tto_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.", 'to'); ?> </p> </div> </noscript> <div class="clear"></div> <form action="edit.php" method="get" id="to_form"> <input type="hidden" name="page" value="to-interface-<?php echo $post_type; ?> " /> <?php if ($post_type != 'post') { echo '<input type="hidden" name="post_type" value="' . $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", 'to'); ?> </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", 'to'); ?> </th><th style="" class="manage-column" id="categories" scope="col"><?php _e("Total Posts", 'to'); ?> </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; $taxonomy_terms = get_terms($key); ?> <tr valign="top" class="<?php if ($alternate === TRUE) { echo 'alternate '; } ?> " id="taxonomy-<?php echo $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 /><br /> <?php } ?> <div id="order-terms"> <div id="post-body"> <ul class="sortable" id="tto_sortable"> <?php 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", 'to'); ?> </a> </p> </div> </div> </form> <script type="text/javascript"> jQuery(document).ready(function() { var NestedSortableSerializedData; 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 = serialize(mySortable); jQuery.post( ajaxurl, { action:'update-taxonomy-order', order: serialize_data, taxonomy : '<?php echo $taxonomy; ?> ' }, function() { jQuery("#ajax-response").html('<div class="message updated fade"><p><?php _e("Items Order Updates", 'to'); ?> </p></div>'); jQuery("#ajax-response div").delay(3000).hide("slow"); }); }); </script> </div> <?php }
function to_plugin_options() { $options = get_option('tto_options'); if (isset($_POST['form_submit'])) { $options['level'] = $_POST['level']; $options['autosort'] = isset($_POST['autosort']) ? $_POST['autosort'] : ''; $options['adminsort'] = isset($_POST['adminsort']) ? $_POST['adminsort'] : ''; ?> <div class="updated fade"><p><?php _e('Settings Saved', 'to'); ?> </p></div><?php update_option('tto_options', $options); } ?> <div class="wrap"> <div id="icon-settings" class="icon32"></div> <h2><?php _e("General Settings", 'to'); ?> </h2> <?php tto_info_box(); ?> <form id="form_data" name="form" method="post"> <br /> <h2 class="subtitle"><?php _e("General", 'to'); ?> </h2> <table class="form-table"> <tbody> <tr valign="top"> <th scope="row" style="text-align: right;"><label><?php _e("Minimum Level to use this plugin", 'to'); ?> </label></th> <td> <select id="role" name="level"> <option value="0" <?php if ($options['level'] == "0") { echo 'selected="selected"'; } ?> ><?php _e('Subscriber', 'tto'); ?> </option> <option value="1" <?php if ($options['level'] == "1") { echo 'selected="selected"'; } ?> ><?php _e('Contributor', 'tto'); ?> </option> <option value="2" <?php if ($options['level'] == "2") { echo 'selected="selected"'; } ?> ><?php _e('Author', 'tto'); ?> </option> <option value="5" <?php if ($options['level'] == "5") { echo 'selected="selected"'; } ?> ><?php _e('Editor', 'tto'); ?> </option> <option value="8" <?php if ($options['level'] == "8") { echo 'selected="selected"'; } ?> ><?php _e('Administrator', 'tto'); ?> </option> </select> </td> </tr> <tr valign="top"> <th scope="row" style="text-align: right;"><label><?php _e("Auto Sort", 'to'); ?> </label></th> <td> <select id="role" name="autosort"> <option value="0" <?php if ($options['autosort'] == "0") { echo 'selected="selected"'; } ?> ><?php _e('OFF', 'tto'); ?> </option> <option value="1" <?php if ($options['autosort'] == "1") { echo 'selected="selected"'; } ?> ><?php _e('ON', 'tto'); ?> </option> </select> *(<?php _e("global setting", 'to'); ?> ) </td> </tr> <tr valign="top"> <th scope="row" style="text-align: right;"><label><?php _e("Admin Sort", 'to'); ?> </label></th> <td> <label for="users_can_register"> <input type="checkbox" <?php if ($options['adminsort'] == "1") { echo ' checked="checked"'; } ?> value="1" name="adminsort"> <?php _e("This will change the order of terms within the admin interface", 'to'); ?> .</label> </td> </tr> <tr valign="top"> <th scope="row" style="text-align: right;"></th> <td> <br /><br /><br /> <p><b><u><?php _e("Autosort OFF", 'to'); ?> </u></b></p> <p class="example"><?php _e('No query will be changed, the terms will appear in the original order. To retrieve the terms in the required order you must use the term_order on the orderby parameter', 'to'); ?> :</p> <pre class="example"> $argv = array( 'orderby' => 'term_order', 'hide_empty' => false ); get_terms('category', $argv); </pre> <p><?php _e("See more info on the get_terms usage", 'to'); ?> <a href="http://codex.wordpress.org/Function_Reference/get_terms" target="_blank"><?php _e("here", 'to'); ?> </a></p> <p><b><u><?php _e("Autosort ON", 'to'); ?> </u></b></p> <p class="example"><?php _e('The queries will be updated, all terms will appear in the order you manually defined. This is recommended if you don\'t want to change any theme code to apply the terms order', 'to'); ?> </p> </td> </tr> </tbody> </table> <p class="submit"> <input type="submit" name="Submit" class="button-primary" value="<?php _e('Save Settings', 'to'); ?> "> </p> <input type="hidden" name="form_submit" value="true" /> </form> <?php echo '</div>'; }