Version Description
Download this release
Release Info
| Developer | hsameerc |
| Plugin | |
| Version | 1.5 |
| Comparing to | |
| See all releases | |
Code changes from version 1.0 to 1.5
- assets/scporder.css +1 -0
- assets/taxonomy_order.js +54 -0
- readme.txt +11 -11
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- settings.php +76 -44
- simple-custom-post-order.php +291 -181
assets/scporder.css
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
.ui-sortable tr:hover {
|
| 2 |
cursor: move;
|
| 3 |
}
|
| 1 |
+
.wp-list-table.tags td:hover{ cursor: move; }
|
| 2 |
.ui-sortable tr:hover {
|
| 3 |
cursor: move;
|
| 4 |
}
|
assets/taxonomy_order.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
jQuery( document ).ready( function( $ )
|
| 2 |
+
{
|
| 3 |
+
// if it is taxonomy page
|
| 4 |
+
if( adminpage == 'edit-tags-php' )
|
| 5 |
+
{
|
| 6 |
+
// make table rows sortable
|
| 7 |
+
$( '.wp-list-table.tags tbody' ).sortable({
|
| 8 |
+
items: 'tr:not(.inline-edit-row)',
|
| 9 |
+
cursor: 'move',
|
| 10 |
+
axis: 'y',
|
| 11 |
+
containment: 'table.widefat',
|
| 12 |
+
scrollSensitivity: 40,
|
| 13 |
+
stop: function( event, ui ) {
|
| 14 |
+
// array for the ids and positions
|
| 15 |
+
var rows = new Array([]);
|
| 16 |
+
|
| 17 |
+
// show "activity" with spinner
|
| 18 |
+
hsam_taxonomy_sort_activity_spinner( true );
|
| 19 |
+
|
| 20 |
+
$( '.wp-list-table.tags tbody tr:not(.inline-edit-row)' ).each( function( i, e ) {
|
| 21 |
+
var rowID = parseInt( $( e ).attr( 'id' ).substr( 4 ) );
|
| 22 |
+
rows[i] = rowID;
|
| 23 |
+
} );
|
| 24 |
+
|
| 25 |
+
// post rows for sorting
|
| 26 |
+
$.post( ajaxurl, { 'rows' : rows, 'action' : 'get_inline_boxes' }, function(response) {
|
| 27 |
+
// stop activity spinner
|
| 28 |
+
hsam_taxonomy_sort_activity_spinner( false );
|
| 29 |
+
});
|
| 30 |
+
}
|
| 31 |
+
});
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* Adds, shows or hides the activity status spinner
|
| 36 |
+
|
| 37 |
+
*/
|
| 38 |
+
function hsam_taxonomy_sort_activity_spinner( status ) {
|
| 39 |
+
var actions_table = $( '.tablenav .actions' );
|
| 40 |
+
|
| 41 |
+
if( actions_table.find( '.spinner' ).length === 0 && status === true ) {
|
| 42 |
+
// add spinner
|
| 43 |
+
actions_table.prepend( '<div class="spinner" style="display: inline;" />' );
|
| 44 |
+
}
|
| 45 |
+
else if ( status === true ) {
|
| 46 |
+
// show spinner
|
| 47 |
+
actions_table.find( '.spinner' ).show();
|
| 48 |
+
}
|
| 49 |
+
else {
|
| 50 |
+
// hide spinner
|
| 51 |
+
actions_table.find( '.spinner' ).hide();
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
} );
|
readme.txt
CHANGED
|
@@ -1,24 +1,23 @@
|
|
| 1 |
=== Simple Custom Post Order ===
|
| 2 |
Contributors: hsameerc
|
| 3 |
-
Tags: custom post order, post order,
|
| 4 |
Requires at least: 3.0.0
|
| 5 |
Tested up to: 3.5.1
|
| 6 |
Stable tag: 3.5.1
|
| 7 |
License: GPLv2 or later
|
| 8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 9 |
|
| 10 |
-
Order posts(posts, any custom post types) using a Drag and Drop Sortable JavaScript. Configuration is unnecessary.
|
| 11 |
|
| 12 |
== Description ==
|
| 13 |
|
| 14 |
-
Order posts(posts, any custom post types) using a Drag and Drop Sortable JavaScript. Configuration is unnecessary. You can do directly on default WordPress administration.
|
| 15 |
Excluding custom query which uses order or orderby parameters, in get_posts or query_posts and so on.
|
| 16 |
|
| 17 |
== Installation ==
|
| 18 |
|
| 19 |
1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
|
| 20 |
-
1. Activate the plugin through the 'Plugins' menu in WordPress
|
| 21 |
-
1. Place `<?php do_action('plugin_name_hook'); ?>` in your templates
|
| 22 |
|
| 23 |
== Frequently asked questions ==
|
| 24 |
|
|
@@ -32,11 +31,12 @@ An answer to that question.
|
|
| 32 |
2. screenshot-2
|
| 33 |
|
| 34 |
== Changelog ==
|
|
|
|
|
|
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
== Upgrade notice ==
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
== Arbitrary section 1 ==
|
| 1 |
=== Simple Custom Post Order ===
|
| 2 |
Contributors: hsameerc
|
| 3 |
+
Tags: custom post order, post order, js post order, page order, taxonomy order, posts order, category order, sort posts, sort pages, sort custom posts
|
| 4 |
Requires at least: 3.0.0
|
| 5 |
Tested up to: 3.5.1
|
| 6 |
Stable tag: 3.5.1
|
| 7 |
License: GPLv2 or later
|
| 8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 9 |
|
| 10 |
+
Order posts(posts, any custom post types,any taxonomy) using a Drag and Drop Sortable JavaScript. Configuration is unnecessary.
|
| 11 |
|
| 12 |
== Description ==
|
| 13 |
|
| 14 |
+
Order posts(posts, any custom post types,any taxonomy) using a Drag and Drop Sortable JavaScript. Configuration is unnecessary. You can do directly on default WordPress administration.
|
| 15 |
Excluding custom query which uses order or orderby parameters, in get_posts or query_posts and so on.
|
| 16 |
|
| 17 |
== Installation ==
|
| 18 |
|
| 19 |
1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
|
| 20 |
+
1. Activate the plugin through the 'Plugins' menu in WordPress
|
|
|
|
| 21 |
|
| 22 |
== Frequently asked questions ==
|
| 23 |
|
| 31 |
2. screenshot-2
|
| 32 |
|
| 33 |
== Changelog ==
|
| 34 |
+
= Version 1.0 (20-07-2013) =
|
| 35 |
+
* Initial release.
|
| 36 |
|
| 37 |
+
= Version 1.5 (25-07-2013) =
|
| 38 |
+
* Fix : fix errors
|
| 39 |
+
* Added Taxonomy Sort
|
| 40 |
+
* Added Taxonomy Sort option In setting Page
|
| 41 |
|
| 42 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
screenshot-1.png
DELETED
|
Binary file
|
screenshot-2.png
DELETED
|
Binary file
|
settings.php
CHANGED
|
@@ -1,55 +1,87 @@
|
|
| 1 |
<?php
|
| 2 |
-
|
| 3 |
-
$scporder_options = get_option('scporder_options');
|
| 4 |
$objects = $scporder_options['objects'];
|
| 5 |
-
|
| 6 |
?>
|
| 7 |
|
| 8 |
<div class="wrapper">
|
| 9 |
|
| 10 |
-
<?php screen_icon( 'plugins' ); ?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
<h2><?php _e('Simple Custom Post Order Settings', 'scporder'); ?></h2>
|
| 13 |
|
| 14 |
-
<?php if ( isset($_GET['msg'] )) : ?>
|
| 15 |
-
<div id="message" class="updated below-h2">
|
| 16 |
-
<?php if ( $_GET['msg'] == 'update') : ?>
|
| 17 |
-
<p><?php _e('Settings saved.', 'scporder'); ?></p>
|
| 18 |
-
<?php endif; ?>
|
| 19 |
-
</div>
|
| 20 |
-
<?php endif; ?>
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
</div>
|
| 1 |
<?php
|
| 2 |
+
$scporder_options = get_option( 'scporder_options' );
|
|
|
|
| 3 |
$objects = $scporder_options['objects'];
|
|
|
|
| 4 |
?>
|
| 5 |
|
| 6 |
<div class="wrapper">
|
| 7 |
|
| 8 |
+
<?php screen_icon( 'plugins' ); ?>
|
| 9 |
+
|
| 10 |
+
<h2><?php _e( 'Simple Custom Post Order Settings', 'scporder' ); ?></h2>
|
| 11 |
+
<?php
|
| 12 |
+
if ( $_POST['msg'] == 'true' ) {
|
| 13 |
+
taxonomy_order_update();
|
| 14 |
+
?>
|
| 15 |
+
<br>
|
| 16 |
+
<div id="message" class="updated below-h2">
|
| 17 |
+
<p><?php _e( 'Settings saved.', 'scporder' ); ?></p>
|
| 18 |
+
</div>
|
| 19 |
+
<?php
|
| 20 |
+
}
|
| 21 |
+
?>
|
| 22 |
+
<?php if ( isset( $_GET['msg'] ) ) : ?>
|
| 23 |
+
<br>
|
| 24 |
+
<div id="message" class="updated below-h2">
|
| 25 |
+
<?php if ( $_GET['msg'] == 'update' ) : ?>
|
| 26 |
+
<p><?php _e( 'Settings saved.', 'scporder' ); ?></p>
|
| 27 |
+
<?php endif; ?>
|
| 28 |
+
</div>
|
| 29 |
+
<?php endif; ?>
|
| 30 |
+
<form method="post">
|
| 31 |
+
<table class="form-table">
|
| 32 |
+
<tbody>
|
| 33 |
+
<tr valign="top">
|
| 34 |
+
<th scope="row"><label for="blogname"><?php _e( 'Sortable Objects', 'scporder' ) ?></label></th>
|
| 35 |
+
<td>
|
| 36 |
+
<input type="hidden" name="msg" value="true" />
|
| 37 |
+
<label><input type="checkbox" name="taxonomy_order" id="display_sidebar" <?php echo get_option( 'order_taxonomy' ); ?> /> Enable Taxonomy Order <br></label>
|
| 38 |
+
<?php if ( function_exists( 'wp_nonce_field' ) ) wp_nonce_field( 'nonce_scporder' ); ?>
|
| 39 |
|
|
|
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
<?php
|
| 43 |
+
$post_types = get_post_types( array(
|
| 44 |
+
'public' => true
|
| 45 |
+
), 'objects' );
|
| 46 |
+
?>
|
| 47 |
|
| 48 |
+
<?php
|
| 49 |
+
foreach ( $post_types as $post_type ) {
|
| 50 |
+
if ( $post_type->name != 'attachment' ) {
|
| 51 |
+
?>
|
| 52 |
+
<label><input type="checkbox" name="objects[]" value="<?php echo $post_type->name; ?>" <?php
|
| 53 |
+
if ( isset( $objects ) && is_array( $objects ) ) {
|
| 54 |
+
if ( in_array( $post_type->name, $objects ) ) {
|
| 55 |
+
echo 'checked="checked"';
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
?> /> <?php echo $post_type->label; ?></label><br />
|
| 59 |
|
| 60 |
+
<?php
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
?>
|
| 64 |
+
</td>
|
| 65 |
+
</tr>
|
| 66 |
+
</tbody>
|
| 67 |
+
</table>
|
| 68 |
+
|
| 69 |
+
<p class="submit">
|
| 70 |
+
<input type="submit" class="button-primary" name="scporder_submit" value="<?php _e( 'Update', 'scpo' ); ?>" />
|
| 71 |
+
</p>
|
| 72 |
+
|
| 73 |
+
</form>
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
</div>
|
| 77 |
+
|
| 78 |
+
<?php
|
| 79 |
+
|
| 80 |
+
function taxonomy_order_update() {
|
| 81 |
+
if ( $_POST['taxonomy_order'] == 'on' ) {
|
| 82 |
+
$display = 'checked';
|
| 83 |
+
} else {
|
| 84 |
+
$display = '';
|
| 85 |
+
}
|
| 86 |
+
update_option( 'order_taxonomy', $display );
|
| 87 |
+
}
|
|
|
|
|
|
simple-custom-post-order.php
CHANGED
|
@@ -1,269 +1,265 @@
|
|
| 1 |
<?php
|
|
|
|
| 2 |
/*
|
| 3 |
-
Plugin Name: Simple Custom Post Order
|
| 4 |
-
Plugin URI: http://hsameer.com.np/simple-custom-post-order/
|
| 5 |
-
Description: Order Items (Posts, Pages, and Custom Post Types) using a Drag and Drop Sortable JavaScript.
|
| 6 |
-
Version: 1.
|
| 7 |
-
Author: Sameer Humagain
|
| 8 |
-
Author URI: http://hsameer.com.np/
|
| 9 |
-
*/
|
| 10 |
-
|
| 11 |
|
| 12 |
-
/*====================================================================
|
| 13 |
-
Define
|
| 14 |
-
====================================================================*/
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
$scporder = new SCPO_Engine();
|
| 24 |
|
| 25 |
-
class SCPO_Engine
|
| 26 |
-
|
| 27 |
-
function __construct()
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
add_action( 'admin_menu', array( &$this, 'admin_menu') );
|
| 32 |
-
|
| 33 |
add_action( 'admin_init', array( &$this, 'refresh' ) );
|
| 34 |
-
add_action( 'admin_init', array( &$this, 'update_options') );
|
| 35 |
add_action( 'init', array( &$this, 'enable_objects' ) );
|
| 36 |
-
|
| 37 |
add_action( 'wp_ajax_update-menu-order', array( &$this, 'update_menu_order' ) );
|
| 38 |
-
|
| 39 |
-
|
| 40 |
add_filter( 'pre_get_posts', array( &$this, 'scporder_filter_active' ) );
|
| 41 |
add_filter( 'pre_get_posts', array( &$this, 'scporder_pre_get_posts' ) );
|
| 42 |
-
|
| 43 |
-
|
| 44 |
add_filter( 'get_previous_post_where', array( &$this, 'scporder_previous_post_where' ) );
|
| 45 |
add_filter( 'get_previous_post_sort', array( &$this, 'scporder_previous_post_sort' ) );
|
| 46 |
add_filter( 'get_next_post_where', array( &$this, 'scporder_next_post_where' ) );
|
| 47 |
add_filter( 'get_next_post_sort', array( &$this, 'scporder_next_post_sort' ) );
|
| 48 |
}
|
| 49 |
-
|
| 50 |
-
function scporder_install()
|
| 51 |
-
{
|
| 52 |
global $wpdb;
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
$post_types = get_post_types( array
|
| 57 |
'public' => true
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
foreach ($post_types as $post_type ) {
|
| 61 |
$init_objects[] = $post_type->name;
|
| 62 |
}
|
| 63 |
$input_options = array( 'objects' => $init_objects );
|
| 64 |
-
|
| 65 |
update_option( 'scporder_options', $input_options );
|
| 66 |
-
|
| 67 |
-
|
| 68 |
// Initialize : menu_order from date_post
|
| 69 |
-
|
| 70 |
$scporder_options = get_option( 'scporder_options' );
|
| 71 |
$objects = $scporder_options['objects'];
|
| 72 |
-
|
| 73 |
-
foreach( $objects as $object) {
|
| 74 |
$sql = "SELECT
|
| 75 |
ID
|
| 76 |
FROM
|
| 77 |
$wpdb->posts
|
| 78 |
WHERE
|
| 79 |
-
post_type = '"
|
| 80 |
AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
|
| 81 |
ORDER BY
|
| 82 |
post_date DESC
|
| 83 |
";
|
| 84 |
-
|
| 85 |
-
$results = $wpdb->get_results($sql);
|
| 86 |
-
|
| 87 |
-
foreach( $results as $key => $result ) {
|
| 88 |
-
$wpdb->update( $wpdb->posts, array( 'menu_order' => $key+1 ), array( 'ID' => $result->ID ) );
|
| 89 |
}
|
| 90 |
}
|
| 91 |
}
|
| 92 |
-
|
| 93 |
-
function admin_menu()
|
| 94 |
-
|
| 95 |
-
add_options_page( __('SCPOrder', 'scporder'), __('SCPOrder', 'scporder'), 'manage_options', 'scporder-settings', array( &$this,'admin_page' ));
|
| 96 |
}
|
| 97 |
-
|
| 98 |
-
function admin_page()
|
| 99 |
-
|
| 100 |
-
require SCPO_DIR.'settings.php';
|
| 101 |
}
|
| 102 |
-
|
| 103 |
-
function enable_objects()
|
| 104 |
-
{
|
| 105 |
$scporder_options = get_option( 'scporder_options' );
|
| 106 |
$objects = $scporder_options['objects'];
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
if ( is_array( $objects ) ) {
|
| 109 |
$active = false;
|
| 110 |
-
|
| 111 |
// for Pages or Custom Post Types
|
| 112 |
-
if ( isset($_GET['post_type']) ) {
|
| 113 |
if ( in_array( $_GET['post_type'], $objects ) ) {
|
| 114 |
$active = true;
|
| 115 |
}
|
| 116 |
-
|
| 117 |
} else {
|
| 118 |
$post_list = strstr( $_SERVER["REQUEST_URI"], 'wp-admin/edit.php' );
|
| 119 |
if ( $post_list && in_array( 'post', $objects ) ) {
|
| 120 |
$active = true;
|
| 121 |
}
|
| 122 |
}
|
| 123 |
-
|
| 124 |
if ( $active ) {
|
| 125 |
-
$this->load_script_css();
|
| 126 |
}
|
| 127 |
}
|
| 128 |
}
|
| 129 |
-
|
| 130 |
function load_script_css() {
|
|
|
|
|
|
|
|
|
|
| 131 |
// load JavaScript
|
| 132 |
wp_enqueue_script( 'jQuery' );
|
| 133 |
wp_enqueue_script( 'jquery-ui-sortable' );
|
| 134 |
-
wp_enqueue_script( 'scporderjs', SCPO_URL.'/assets/scporder.js', array( 'jquery' ), null, true );
|
| 135 |
// load CSS
|
| 136 |
-
wp_enqueue_style( 'scporder', SCPO_URL.'/assets/scporder.css', array(), null );
|
| 137 |
}
|
| 138 |
-
|
| 139 |
-
function refresh()
|
| 140 |
-
|
| 141 |
-
|
| 142 |
global $wpdb;
|
| 143 |
-
|
| 144 |
$scporder_options = get_option( 'scporder_options' );
|
| 145 |
$objects = $scporder_options['objects'];
|
| 146 |
-
|
| 147 |
if ( is_array( $objects ) ) {
|
| 148 |
-
foreach( $objects as $object) {
|
| 149 |
$sql = "SELECT
|
| 150 |
ID
|
| 151 |
FROM
|
| 152 |
$wpdb->posts
|
| 153 |
WHERE
|
| 154 |
-
post_type = '"
|
| 155 |
AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
|
| 156 |
ORDER BY
|
| 157 |
menu_order ASC
|
| 158 |
";
|
| 159 |
-
|
| 160 |
-
$results = $wpdb->get_results($sql);
|
| 161 |
-
|
| 162 |
-
foreach( $results as $key => $result ) {
|
| 163 |
-
|
| 164 |
}
|
| 165 |
}
|
| 166 |
}
|
| 167 |
}
|
| 168 |
-
|
| 169 |
-
function update_menu_order()
|
| 170 |
-
{
|
| 171 |
global $wpdb;
|
| 172 |
-
|
| 173 |
-
parse_str($_POST['order'], $data);
|
| 174 |
-
|
| 175 |
-
if ( is_array($data) ) {
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
$id_arr = array();
|
| 179 |
-
foreach( $data as $key => $values ) {
|
| 180 |
-
foreach( $values as $position => $id ) {
|
| 181 |
$id_arr[] = $id;
|
| 182 |
}
|
| 183 |
}
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
$menu_order_arr = array();
|
| 187 |
-
foreach( $id_arr as $key => $id ) {
|
| 188 |
-
$results = $wpdb->get_results("SELECT menu_order FROM $wpdb->posts WHERE ID = "
|
| 189 |
-
foreach( $results as $result ) {
|
| 190 |
$menu_order_arr[] = $result->menu_order;
|
| 191 |
}
|
| 192 |
}
|
| 193 |
-
|
| 194 |
-
sort($menu_order_arr);
|
| 195 |
-
|
| 196 |
-
foreach( $data as $key => $values ) {
|
| 197 |
-
foreach( $values as $position => $id ) {
|
| 198 |
$wpdb->update( $wpdb->posts, array( 'menu_order' => $menu_order_arr[$position] ), array( 'ID' => $id ) );
|
| 199 |
}
|
| 200 |
}
|
| 201 |
}
|
| 202 |
}
|
| 203 |
-
|
| 204 |
-
function update_options()
|
| 205 |
-
{
|
| 206 |
if ( isset( $_POST['scporder_submit'] ) ) {
|
| 207 |
-
|
| 208 |
check_admin_referer( 'nonce_scporder' );
|
| 209 |
-
|
| 210 |
if ( isset( $_POST['objects'] ) ) {
|
| 211 |
$input_options = array( 'objects' => $_POST['objects'] );
|
| 212 |
} else {
|
| 213 |
$input_options = array( 'objects' => '' );
|
| 214 |
}
|
| 215 |
-
|
| 216 |
update_option( 'scporder_options', $input_options );
|
| 217 |
wp_redirect( 'admin.php?page=scporder-settings&msg=update' );
|
| 218 |
}
|
| 219 |
}
|
| 220 |
-
|
| 221 |
-
function scporder_previous_post_where( $where )
|
| 222 |
-
{
|
| 223 |
global $post;
|
| 224 |
|
| 225 |
-
$scporder_options = get_option('scporder_options');
|
| 226 |
$objects = $scporder_options['objects'];
|
| 227 |
-
|
| 228 |
if ( in_array( $post->post_type, $objects ) ) {
|
| 229 |
$current_menu_order = $post->menu_order;
|
| 230 |
-
$where = "WHERE p.menu_order > '"
|
| 231 |
-
}
|
| 232 |
return $where;
|
| 233 |
}
|
| 234 |
-
|
| 235 |
-
function scporder_previous_post_sort( $orderby )
|
| 236 |
-
{
|
| 237 |
global $post;
|
| 238 |
|
| 239 |
-
$scporder_options = get_option('scporder_options');
|
| 240 |
$objects = $scporder_options['objects'];
|
| 241 |
-
|
| 242 |
if ( in_array( $post->post_type, $objects ) ) {
|
| 243 |
$orderby = 'ORDER BY p.menu_order ASC LIMIT 1';
|
| 244 |
}
|
| 245 |
return $orderby;
|
| 246 |
}
|
| 247 |
-
|
| 248 |
-
function scporder_next_post_where( $where )
|
| 249 |
-
{
|
| 250 |
global $post;
|
| 251 |
|
| 252 |
-
$scporder_options = get_option('scporder_options');
|
| 253 |
$objects = $scporder_options['objects'];
|
| 254 |
-
|
| 255 |
if ( in_array( $post->post_type, $objects ) ) {
|
| 256 |
$current_menu_order = $post->menu_order;
|
| 257 |
-
$where = "WHERE p.menu_order < '"
|
| 258 |
}
|
| 259 |
return $where;
|
| 260 |
}
|
| 261 |
-
|
| 262 |
-
function scporder_next_post_sort( $orderby )
|
| 263 |
-
{
|
| 264 |
global $post;
|
| 265 |
-
|
| 266 |
-
$scporder_options = get_option('scporder_options');
|
| 267 |
$objects = $scporder_options['objects'];
|
| 268 |
|
| 269 |
if ( in_array( $post->post_type, $objects ) ) {
|
|
@@ -271,56 +267,53 @@ class SCPO_Engine
|
|
| 271 |
}
|
| 272 |
return $orderby;
|
| 273 |
}
|
| 274 |
-
|
| 275 |
-
function scporder_filter_active( $wp_query )
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
if ( isset($wp_query->query_vars['suppress_filters']) )
|
|
|
|
| 280 |
return $wp_query;
|
| 281 |
}
|
| 282 |
-
|
| 283 |
-
function scporder_pre_get_posts( $wp_query )
|
| 284 |
-
|
| 285 |
-
$scporder_options = get_option('scporder_options');
|
| 286 |
$objects = $scporder_options['objects'];
|
| 287 |
-
|
| 288 |
if ( is_array( $objects ) ) {
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
if ( is_admin() && !defined( 'DOING_AJAX' ) ) {
|
| 293 |
-
|
| 294 |
-
|
| 295 |
if ( isset( $wp_query->query['post_type'] ) ) {
|
| 296 |
if ( in_array( $wp_query->query['post_type'], $objects ) ) {
|
| 297 |
$wp_query->set( 'orderby', 'menu_order' );
|
| 298 |
$wp_query->set( 'order', 'ASC' );
|
| 299 |
}
|
| 300 |
}
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
} else {
|
| 305 |
-
|
| 306 |
$active = false;
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
if ( empty( $wp_query->query ) ) {
|
| 311 |
if ( in_array( 'post', $objects ) ) {
|
| 312 |
$active = true;
|
| 313 |
}
|
| 314 |
} else {
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
if ( isset($wp_query->query['suppress_filters']) ) {
|
| 319 |
-
|
| 320 |
-
|
| 321 |
if ( is_array( $wp_query->query['post_type'] ) ) {
|
| 322 |
$post_types = $wp_query->query['post_type'];
|
| 323 |
-
foreach( $post_types as $post_type ) {
|
| 324 |
if ( in_array( $post_type, $objects ) ) {
|
| 325 |
$active = true;
|
| 326 |
}
|
|
@@ -330,17 +323,15 @@ class SCPO_Engine
|
|
| 330 |
$active = true;
|
| 331 |
}
|
| 332 |
}
|
| 333 |
-
|
| 334 |
-
|
| 335 |
} else {
|
| 336 |
-
|
| 337 |
-
|
| 338 |
if ( isset( $wp_query->query['post_type'] ) ) {
|
| 339 |
-
|
| 340 |
-
|
| 341 |
if ( is_array( $wp_query->query['post_type'] ) ) {
|
| 342 |
$post_types = $wp_query->query['post_type'];
|
| 343 |
-
foreach( $post_types as $post_type ) {
|
| 344 |
if ( in_array( $post_type, $objects ) ) {
|
| 345 |
$active = true;
|
| 346 |
}
|
|
@@ -350,23 +341,142 @@ class SCPO_Engine
|
|
| 350 |
$active = true;
|
| 351 |
}
|
| 352 |
}
|
| 353 |
-
|
| 354 |
} else {
|
| 355 |
if ( in_array( 'post', $objects ) ) {
|
| 356 |
$active = true;
|
| 357 |
}
|
| 358 |
}
|
| 359 |
-
}
|
| 360 |
}
|
| 361 |
-
|
| 362 |
if ( $active ) {
|
| 363 |
-
if ( !isset( $wp_query->query['orderby'] ) || $wp_query->query['orderby'] == 'post_date' )
|
| 364 |
-
|
| 365 |
-
|
|
|
|
|
|
|
| 366 |
}
|
| 367 |
}
|
| 368 |
}
|
|
|
|
| 369 |
}
|
| 370 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
|
| 372 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<?php
|
| 2 |
+
|
| 3 |
/*
|
| 4 |
+
Plugin Name: Simple Custom Post Order
|
| 5 |
+
Plugin URI: http://hsameer.com.np/simple-custom-post-order/
|
| 6 |
+
Description: Order Items (Posts, Pages, and Custom Post Types) using a Drag and Drop Sortable JavaScript.
|
| 7 |
+
Version: 1.5
|
| 8 |
+
Author: Sameer Humagain
|
| 9 |
+
Author URI: http://hsameer.com.np/
|
| 10 |
+
*/
|
|
|
|
| 11 |
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
/* ====================================================================
|
| 14 |
+
Define
|
| 15 |
+
==================================================================== */
|
| 16 |
|
| 17 |
+
define( 'SCPO_URL', plugins_url( '', __FILE__ ) );
|
| 18 |
+
define( 'SCPO_DIR', plugin_dir_path( __FILE__ ) );
|
| 19 |
+
|
| 20 |
+
/* ====================================================================
|
| 21 |
+
Class & Method
|
| 22 |
+
==================================================================== */
|
| 23 |
|
| 24 |
$scporder = new SCPO_Engine();
|
| 25 |
|
| 26 |
+
class SCPO_Engine {
|
| 27 |
+
|
| 28 |
+
function __construct() {
|
| 29 |
+
if ( !get_option( 'scporder_options' ) )
|
| 30 |
+
$this->scporder_install();
|
| 31 |
+
|
| 32 |
+
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
|
|
|
|
| 33 |
add_action( 'admin_init', array( &$this, 'refresh' ) );
|
| 34 |
+
add_action( 'admin_init', array( &$this, 'update_options' ) );
|
| 35 |
add_action( 'init', array( &$this, 'enable_objects' ) );
|
| 36 |
+
|
| 37 |
add_action( 'wp_ajax_update-menu-order', array( &$this, 'update_menu_order' ) );
|
| 38 |
+
|
| 39 |
+
|
| 40 |
add_filter( 'pre_get_posts', array( &$this, 'scporder_filter_active' ) );
|
| 41 |
add_filter( 'pre_get_posts', array( &$this, 'scporder_pre_get_posts' ) );
|
| 42 |
+
|
| 43 |
+
|
| 44 |
add_filter( 'get_previous_post_where', array( &$this, 'scporder_previous_post_where' ) );
|
| 45 |
add_filter( 'get_previous_post_sort', array( &$this, 'scporder_previous_post_sort' ) );
|
| 46 |
add_filter( 'get_next_post_where', array( &$this, 'scporder_next_post_where' ) );
|
| 47 |
add_filter( 'get_next_post_sort', array( &$this, 'scporder_next_post_sort' ) );
|
| 48 |
}
|
| 49 |
+
|
| 50 |
+
function scporder_install() {
|
|
|
|
| 51 |
global $wpdb;
|
| 52 |
+
|
| 53 |
+
//Initialize Options
|
| 54 |
+
|
| 55 |
+
$post_types = get_post_types( array(
|
| 56 |
'public' => true
|
| 57 |
+
), 'objects' );
|
| 58 |
+
|
| 59 |
+
foreach ( $post_types as $post_type ) {
|
| 60 |
$init_objects[] = $post_type->name;
|
| 61 |
}
|
| 62 |
$input_options = array( 'objects' => $init_objects );
|
| 63 |
+
|
| 64 |
update_option( 'scporder_options', $input_options );
|
| 65 |
+
|
| 66 |
+
|
| 67 |
// Initialize : menu_order from date_post
|
| 68 |
+
|
| 69 |
$scporder_options = get_option( 'scporder_options' );
|
| 70 |
$objects = $scporder_options['objects'];
|
| 71 |
+
|
| 72 |
+
foreach ( $objects as $object ) {
|
| 73 |
$sql = "SELECT
|
| 74 |
ID
|
| 75 |
FROM
|
| 76 |
$wpdb->posts
|
| 77 |
WHERE
|
| 78 |
+
post_type = '" . $object . "'
|
| 79 |
AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
|
| 80 |
ORDER BY
|
| 81 |
post_date DESC
|
| 82 |
";
|
| 83 |
+
|
| 84 |
+
$results = $wpdb->get_results( $sql );
|
| 85 |
+
|
| 86 |
+
foreach ( $results as $key => $result ) {
|
| 87 |
+
$wpdb->update( $wpdb->posts, array( 'menu_order' => $key + 1 ), array( 'ID' => $result->ID ) );
|
| 88 |
}
|
| 89 |
}
|
| 90 |
}
|
| 91 |
+
|
| 92 |
+
function admin_menu() {
|
| 93 |
+
add_options_page( __( 'SCPOrder', 'scporder' ), __( 'SCPOrder', 'scporder' ), 'manage_options', 'scporder-settings', array( &$this, 'admin_page' ) );
|
|
|
|
| 94 |
}
|
| 95 |
+
|
| 96 |
+
function admin_page() {
|
| 97 |
+
require SCPO_DIR . 'settings.php';
|
|
|
|
| 98 |
}
|
| 99 |
+
|
| 100 |
+
function enable_objects() {
|
|
|
|
| 101 |
$scporder_options = get_option( 'scporder_options' );
|
| 102 |
$objects = $scporder_options['objects'];
|
| 103 |
+
$tex = $scporder_options['taxonomy'];
|
| 104 |
+
if ( is_array( $tex ) ) {
|
| 105 |
+
$active = true;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
if ( is_array( $objects ) ) {
|
| 109 |
$active = false;
|
| 110 |
+
|
| 111 |
// for Pages or Custom Post Types
|
| 112 |
+
if ( isset( $_GET['post_type'] ) ) {
|
| 113 |
if ( in_array( $_GET['post_type'], $objects ) ) {
|
| 114 |
$active = true;
|
| 115 |
}
|
| 116 |
+
// for Posts
|
| 117 |
} else {
|
| 118 |
$post_list = strstr( $_SERVER["REQUEST_URI"], 'wp-admin/edit.php' );
|
| 119 |
if ( $post_list && in_array( 'post', $objects ) ) {
|
| 120 |
$active = true;
|
| 121 |
}
|
| 122 |
}
|
| 123 |
+
|
| 124 |
if ( $active ) {
|
| 125 |
+
$this->load_script_css();
|
| 126 |
}
|
| 127 |
}
|
| 128 |
}
|
| 129 |
+
|
| 130 |
function load_script_css() {
|
| 131 |
+
global $pagenow;
|
| 132 |
+
if ( is_admin() && $pagenow == 'edit-tags.php' )
|
| 133 |
+
return;
|
| 134 |
// load JavaScript
|
| 135 |
wp_enqueue_script( 'jQuery' );
|
| 136 |
wp_enqueue_script( 'jquery-ui-sortable' );
|
| 137 |
+
wp_enqueue_script( 'scporderjs', SCPO_URL . '/assets/scporder.js', array( 'jquery' ), null, true );
|
| 138 |
// load CSS
|
| 139 |
+
wp_enqueue_style( 'scporder', SCPO_URL . '/assets/scporder.css', array( ), null );
|
| 140 |
}
|
| 141 |
+
|
| 142 |
+
function refresh() {
|
| 143 |
+
|
|
|
|
| 144 |
global $wpdb;
|
| 145 |
+
|
| 146 |
$scporder_options = get_option( 'scporder_options' );
|
| 147 |
$objects = $scporder_options['objects'];
|
| 148 |
+
|
| 149 |
if ( is_array( $objects ) ) {
|
| 150 |
+
foreach ( $objects as $object ) {
|
| 151 |
$sql = "SELECT
|
| 152 |
ID
|
| 153 |
FROM
|
| 154 |
$wpdb->posts
|
| 155 |
WHERE
|
| 156 |
+
post_type = '" . $object . "'
|
| 157 |
AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
|
| 158 |
ORDER BY
|
| 159 |
menu_order ASC
|
| 160 |
";
|
| 161 |
+
|
| 162 |
+
$results = $wpdb->get_results( $sql );
|
| 163 |
+
|
| 164 |
+
foreach ( $results as $key => $result ) {
|
| 165 |
+
$wpdb->update( $wpdb->posts, array( 'menu_order' => $key + 1 ), array( 'ID' => $result->ID ) );
|
| 166 |
}
|
| 167 |
}
|
| 168 |
}
|
| 169 |
}
|
| 170 |
+
|
| 171 |
+
function update_menu_order() {
|
|
|
|
| 172 |
global $wpdb;
|
| 173 |
+
|
| 174 |
+
parse_str( $_POST['order'], $data );
|
| 175 |
+
|
| 176 |
+
if ( is_array( $data ) ) {
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
$id_arr = array( );
|
| 180 |
+
foreach ( $data as $key => $values ) {
|
| 181 |
+
foreach ( $values as $position => $id ) {
|
| 182 |
$id_arr[] = $id;
|
| 183 |
}
|
| 184 |
}
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
$menu_order_arr = array( );
|
| 188 |
+
foreach ( $id_arr as $key => $id ) {
|
| 189 |
+
$results = $wpdb->get_results( "SELECT menu_order FROM $wpdb->posts WHERE ID = " . $id );
|
| 190 |
+
foreach ( $results as $result ) {
|
| 191 |
$menu_order_arr[] = $result->menu_order;
|
| 192 |
}
|
| 193 |
}
|
| 194 |
+
|
| 195 |
+
sort( $menu_order_arr );
|
| 196 |
+
|
| 197 |
+
foreach ( $data as $key => $values ) {
|
| 198 |
+
foreach ( $values as $position => $id ) {
|
| 199 |
$wpdb->update( $wpdb->posts, array( 'menu_order' => $menu_order_arr[$position] ), array( 'ID' => $id ) );
|
| 200 |
}
|
| 201 |
}
|
| 202 |
}
|
| 203 |
}
|
| 204 |
+
|
| 205 |
+
function update_options() {
|
|
|
|
| 206 |
if ( isset( $_POST['scporder_submit'] ) ) {
|
| 207 |
+
|
| 208 |
check_admin_referer( 'nonce_scporder' );
|
| 209 |
+
|
| 210 |
if ( isset( $_POST['objects'] ) ) {
|
| 211 |
$input_options = array( 'objects' => $_POST['objects'] );
|
| 212 |
} else {
|
| 213 |
$input_options = array( 'objects' => '' );
|
| 214 |
}
|
| 215 |
+
|
| 216 |
update_option( 'scporder_options', $input_options );
|
| 217 |
wp_redirect( 'admin.php?page=scporder-settings&msg=update' );
|
| 218 |
}
|
| 219 |
}
|
| 220 |
+
|
| 221 |
+
function scporder_previous_post_where( $where ) {
|
|
|
|
| 222 |
global $post;
|
| 223 |
|
| 224 |
+
$scporder_options = get_option( 'scporder_options' );
|
| 225 |
$objects = $scporder_options['objects'];
|
| 226 |
+
|
| 227 |
if ( in_array( $post->post_type, $objects ) ) {
|
| 228 |
$current_menu_order = $post->menu_order;
|
| 229 |
+
$where = "WHERE p.menu_order > '" . $current_menu_order . "' AND p.post_type = '" . $post->post_type . "' AND p.post_status = 'publish'";
|
| 230 |
+
}
|
| 231 |
return $where;
|
| 232 |
}
|
| 233 |
+
|
| 234 |
+
function scporder_previous_post_sort( $orderby ) {
|
|
|
|
| 235 |
global $post;
|
| 236 |
|
| 237 |
+
$scporder_options = get_option( 'scporder_options' );
|
| 238 |
$objects = $scporder_options['objects'];
|
| 239 |
+
|
| 240 |
if ( in_array( $post->post_type, $objects ) ) {
|
| 241 |
$orderby = 'ORDER BY p.menu_order ASC LIMIT 1';
|
| 242 |
}
|
| 243 |
return $orderby;
|
| 244 |
}
|
| 245 |
+
|
| 246 |
+
function scporder_next_post_where( $where ) {
|
|
|
|
| 247 |
global $post;
|
| 248 |
|
| 249 |
+
$scporder_options = get_option( 'scporder_options' );
|
| 250 |
$objects = $scporder_options['objects'];
|
| 251 |
+
|
| 252 |
if ( in_array( $post->post_type, $objects ) ) {
|
| 253 |
$current_menu_order = $post->menu_order;
|
| 254 |
+
$where = "WHERE p.menu_order < '" . $current_menu_order . "' AND p.post_type = '" . $post->post_type . "' AND p.post_status = 'publish'";
|
| 255 |
}
|
| 256 |
return $where;
|
| 257 |
}
|
| 258 |
+
|
| 259 |
+
function scporder_next_post_sort( $orderby ) {
|
|
|
|
| 260 |
global $post;
|
| 261 |
+
|
| 262 |
+
$scporder_options = get_option( 'scporder_options' );
|
| 263 |
$objects = $scporder_options['objects'];
|
| 264 |
|
| 265 |
if ( in_array( $post->post_type, $objects ) ) {
|
| 267 |
}
|
| 268 |
return $orderby;
|
| 269 |
}
|
| 270 |
+
|
| 271 |
+
function scporder_filter_active( $wp_query ) {
|
| 272 |
+
|
| 273 |
+
if ( isset( $wp_query->query['suppress_filters'] ) )
|
| 274 |
+
$wp_query->query['suppress_filters'] = false;
|
| 275 |
+
if ( isset( $wp_query->query_vars['suppress_filters'] ) )
|
| 276 |
+
$wp_query->query_vars['suppress_filters'] = false;
|
| 277 |
return $wp_query;
|
| 278 |
}
|
| 279 |
+
|
| 280 |
+
function scporder_pre_get_posts( $wp_query ) {
|
| 281 |
+
$scporder_options = get_option( 'scporder_options' );
|
|
|
|
| 282 |
$objects = $scporder_options['objects'];
|
| 283 |
+
|
| 284 |
if ( is_array( $objects ) ) {
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
|
| 288 |
if ( is_admin() && !defined( 'DOING_AJAX' ) ) {
|
| 289 |
+
|
| 290 |
+
|
| 291 |
if ( isset( $wp_query->query['post_type'] ) ) {
|
| 292 |
if ( in_array( $wp_query->query['post_type'], $objects ) ) {
|
| 293 |
$wp_query->set( 'orderby', 'menu_order' );
|
| 294 |
$wp_query->set( 'order', 'ASC' );
|
| 295 |
}
|
| 296 |
}
|
|
|
|
|
|
|
|
|
|
| 297 |
} else {
|
| 298 |
+
|
| 299 |
$active = false;
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
|
| 303 |
if ( empty( $wp_query->query ) ) {
|
| 304 |
if ( in_array( 'post', $objects ) ) {
|
| 305 |
$active = true;
|
| 306 |
}
|
| 307 |
} else {
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
if ( isset( $wp_query->query['suppress_filters'] ) ) {
|
| 312 |
+
|
| 313 |
+
|
| 314 |
if ( is_array( $wp_query->query['post_type'] ) ) {
|
| 315 |
$post_types = $wp_query->query['post_type'];
|
| 316 |
+
foreach ( $post_types as $post_type ) {
|
| 317 |
if ( in_array( $post_type, $objects ) ) {
|
| 318 |
$active = true;
|
| 319 |
}
|
| 323 |
$active = true;
|
| 324 |
}
|
| 325 |
}
|
|
|
|
|
|
|
| 326 |
} else {
|
| 327 |
+
|
| 328 |
+
|
| 329 |
if ( isset( $wp_query->query['post_type'] ) ) {
|
| 330 |
+
|
| 331 |
+
|
| 332 |
if ( is_array( $wp_query->query['post_type'] ) ) {
|
| 333 |
$post_types = $wp_query->query['post_type'];
|
| 334 |
+
foreach ( $post_types as $post_type ) {
|
| 335 |
if ( in_array( $post_type, $objects ) ) {
|
| 336 |
$active = true;
|
| 337 |
}
|
| 341 |
$active = true;
|
| 342 |
}
|
| 343 |
}
|
|
|
|
| 344 |
} else {
|
| 345 |
if ( in_array( 'post', $objects ) ) {
|
| 346 |
$active = true;
|
| 347 |
}
|
| 348 |
}
|
| 349 |
+
}
|
| 350 |
}
|
| 351 |
+
|
| 352 |
if ( $active ) {
|
| 353 |
+
if ( !isset( $wp_query->query['orderby'] ) || $wp_query->query['orderby'] == 'post_date' )
|
| 354 |
+
$wp_query->set( 'orderby', 'menu_order' );
|
| 355 |
+
if ( !isset( $wp_query->query['order'] ) || $wp_query->query['order'] == 'DESC' )
|
| 356 |
+
$wp_query->set( 'order', 'ASC' );
|
| 357 |
+
}
|
| 358 |
}
|
| 359 |
}
|
| 360 |
}
|
| 361 |
+
|
| 362 |
}
|
| 363 |
|
| 364 |
+
/* =============================================================================================================
|
| 365 |
+
* Taxonomy Sort
|
| 366 |
+
=============================================================================================================== */
|
| 367 |
+
if ( get_option( 'order_taxonomy' ) == 'checked' ) {
|
| 368 |
+
|
| 369 |
+
class Taxonomy_Order_Engine {
|
| 370 |
+
|
| 371 |
+
/**
|
| 372 |
+
* Simple class constructor
|
| 373 |
+
*/
|
| 374 |
+
function __construct() {
|
| 375 |
+
// admin initialize
|
| 376 |
+
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
| 377 |
+
|
| 378 |
+
// front-end initialize
|
| 379 |
+
add_action( 'init', array( $this, 'init' ) );
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
/**
|
| 383 |
+
* Initialize administration
|
| 384 |
+
*/
|
| 385 |
+
function admin_init() {
|
| 386 |
+
// load scripts
|
| 387 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
| 388 |
+
|
| 389 |
|
| 390 |
+
// ajax to save the sorting
|
| 391 |
+
add_action( 'wp_ajax_get_inline_boxes', array( $this, 'inline_edit_boxes' ) );
|
| 392 |
+
|
| 393 |
+
// reorder terms when someone tries to get terms
|
| 394 |
+
add_filter( 'get_terms', array( $this, 'reorder_terms' ) );
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
/**
|
| 398 |
+
* Initialize front-page
|
| 399 |
+
*
|
| 400 |
+
*/
|
| 401 |
+
function init() {
|
| 402 |
+
// reorder terms when someone tries to get terms
|
| 403 |
+
add_filter( 'get_terms', array( $this, 'reorder_terms' ) );
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
/**
|
| 407 |
+
* Load scripts
|
| 408 |
+
*/
|
| 409 |
+
function enqueue_scripts() {
|
| 410 |
+
// allow enqueue only on tags/taxonomy page
|
| 411 |
+
if ( get_current_screen()->base != 'edit-tags' )
|
| 412 |
+
return;
|
| 413 |
+
// load jquery and plugin's script
|
| 414 |
+
wp_enqueue_script( 'jquery' );
|
| 415 |
+
wp_enqueue_script( 'taxonomyorder', plugins_url( 'assets/taxonomy_order.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable' ) );
|
| 416 |
+
|
| 417 |
+
wp_enqueue_style( 'scporder', SCPO_URL . '/assets/scporder.css', array( ), null );
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
/**
|
| 421 |
+
* Do the sorting
|
| 422 |
+
*/
|
| 423 |
+
function inline_edit_boxes() {
|
| 424 |
+
// loop through rows
|
| 425 |
+
foreach ( $_POST['rows'] as $key => $row ) {
|
| 426 |
+
// skip empty
|
| 427 |
+
if ( !isset( $row ) || $row == "" )
|
| 428 |
+
continue;
|
| 429 |
+
|
| 430 |
+
// update order
|
| 431 |
+
update_post_meta( $row, 'thets_order', ( $key + 1 ) );
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
// kill it for ajax
|
| 435 |
+
exit;
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
/**
|
| 439 |
+
* Order terms
|
| 440 |
+
*/
|
| 441 |
+
function reorder_terms( $objects ) {
|
| 442 |
+
// we do not need empty objects
|
| 443 |
+
if ( empty( $objects ) )
|
| 444 |
+
return $objects;
|
| 445 |
+
|
| 446 |
+
// placeholder for ordered objects
|
| 447 |
+
$placeholder = array( );
|
| 448 |
+
|
| 449 |
+
// invalid key counter (if key is not set)
|
| 450 |
+
$invalid_key = 9000;
|
| 451 |
+
|
| 452 |
+
// loop through objects
|
| 453 |
+
foreach ( $objects as $key => $object ) {
|
| 454 |
+
// increase invalid key count
|
| 455 |
+
$invalid_key++;
|
| 456 |
+
|
| 457 |
+
// continue if no term_id
|
| 458 |
+
if ( !isset( $object->term_id ) )
|
| 459 |
+
continue;
|
| 460 |
+
|
| 461 |
+
// get the order key
|
| 462 |
+
$term_order = get_post_meta( $object->term_id, 'thets_order', true );
|
| 463 |
+
|
| 464 |
+
// use order key if exists, invalid key if not
|
| 465 |
+
$term_key = ( $term_order != "" && $term_order != 0 ) ? (int) $term_order : $invalid_key;
|
| 466 |
+
|
| 467 |
+
|
| 468 |
+
$placeholder[$term_key] = $object;
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
|
| 472 |
+
ksort( $placeholder );
|
| 473 |
+
|
| 474 |
+
|
| 475 |
+
return $placeholder;
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
|
| 481 |
+
new Taxonomy_Order_Engine;
|
| 482 |
+
}
|
