Version Description
Download this release
Release Info
| Developer | hsameerc |
| Plugin | |
| Version | 2.2 |
| Comparing to | |
| See all releases | |
Code changes from version 2.1 to 2.2
- assets/scporder.js +13 -13
- readme.txt +11 -5
- screenshot-2.png +0 -0
- settings.php +17 -30
- simple-custom-post-order.php +123 -257
assets/scporder.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
'items': 'tr',
|
| 4 |
'axis': 'y',
|
| 5 |
'helper': fixHelper,
|
| 6 |
'update' : function(e, ui) {
|
| 7 |
-
|
| 8 |
action: 'update-menu-order',
|
| 9 |
-
order:
|
| 10 |
});
|
| 11 |
}
|
| 12 |
-
});
|
| 13 |
-
|
| 14 |
-
});
|
| 15 |
|
| 16 |
-
var fixHelper = function(e, ui) {
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
};
|
|
|
|
|
|
| 1 |
+
(function($){
|
| 2 |
+
$("#the-list").sortable({
|
| 3 |
'items': 'tr',
|
| 4 |
'axis': 'y',
|
| 5 |
'helper': fixHelper,
|
| 6 |
'update' : function(e, ui) {
|
| 7 |
+
$.post( ajaxurl, {
|
| 8 |
action: 'update-menu-order',
|
| 9 |
+
order: $("#the-list").sortable("serialize"),
|
| 10 |
});
|
| 11 |
}
|
| 12 |
+
});
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
var fixHelper = function(e, ui) {
|
| 15 |
+
ui.children().children().each(function() {
|
| 16 |
+
$(this).width($(this).width());
|
| 17 |
+
});
|
| 18 |
+
return ui;
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
})(jQuery)
|
readme.txt
CHANGED
|
@@ -1,17 +1,17 @@
|
|
| 1 |
=== Simple Custom Post Order ===
|
| 2 |
Contributors: hsameerc
|
| 3 |
-
Tags: custom post order, post order, js post order, page order,
|
| 4 |
Requires at least: 3.0.0
|
| 5 |
-
Tested up to: 3.
|
| 6 |
-
Stable tag: 3.
|
| 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
|
| 11 |
|
| 12 |
== Description ==
|
| 13 |
|
| 14 |
-
Order posts(posts, any custom post types
|
| 15 |
Excluding custom query which uses order or orderby parameters, in get_posts or query_posts and so on.
|
| 16 |
|
| 17 |
== Installation ==
|
|
@@ -45,3 +45,9 @@ An answer to that question.
|
|
| 45 |
|
| 46 |
= Version 2.1 (31-12-2013) =
|
| 47 |
* Prevent Breaking autocomplete
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
=== Simple Custom Post Order ===
|
| 2 |
Contributors: hsameerc
|
| 3 |
+
Tags: custom post order, post order, js post order, page order, posts order, category order, sort posts, sort pages, sort custom posts
|
| 4 |
Requires at least: 3.0.0
|
| 5 |
+
Tested up to: 3.9.1
|
| 6 |
+
Stable tag: 3.9.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 ==
|
| 45 |
|
| 46 |
= Version 2.1 (31-12-2013) =
|
| 47 |
* Prevent Breaking autocomplete
|
| 48 |
+
|
| 49 |
+
= Version 2.2 (02-07-2014) =
|
| 50 |
+
* Fixed bug: Custom Query which uses 'order' or 'orderby' parameters is preferred
|
| 51 |
+
* It does not depend on the designation manner of arguments( Parameters ). ( $args = 'orderby=&order=' or $args = array( 'orderby' => '', 'order' => '' ) )
|
| 52 |
+
* Previous Versions Issues were Improved.
|
| 53 |
+
* Removed Taxonomy Sort( Will add in next Version :) )
|
screenshot-2.png
ADDED
|
Binary file
|
settings.php
CHANGED
|
@@ -17,34 +17,23 @@ $objects = $scporder_options['objects'];
|
|
| 17 |
</div>
|
| 18 |
<?php endif; ?>
|
| 19 |
<form method="post">
|
| 20 |
-
<table class="form-table">
|
| 21 |
<tbody>
|
| 22 |
<tr valign="top">
|
| 23 |
<th scope="row"><label for="blogname"><?php _e( 'Sortable Objects', 'scporder' ) ?></label></th>
|
| 24 |
<td>
|
| 25 |
<input type="hidden" name="msg" value="true" />
|
| 26 |
<?php if ( function_exists( 'wp_nonce_field' ) ) wp_nonce_field( 'nonce_scporder' ); ?>
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
<?php
|
| 31 |
$post_types = get_post_types( array(
|
| 32 |
'public' => true
|
| 33 |
), 'objects' );
|
| 34 |
?>
|
| 35 |
-
|
| 36 |
<?php
|
| 37 |
foreach ( $post_types as $post_type ) {
|
| 38 |
if ( $post_type->name != 'attachment' ) {
|
| 39 |
?>
|
| 40 |
-
<label><input type="checkbox" name="objects[]" value="<?php echo $post_type->name; ?>" <?php
|
| 41 |
-
if ( isset( $objects ) && is_array( $objects ) ) {
|
| 42 |
-
if ( in_array( $post_type->name, $objects ) ) {
|
| 43 |
-
echo 'checked="checked"';
|
| 44 |
-
}
|
| 45 |
-
}
|
| 46 |
-
?> /> <?php echo $post_type->label; ?></label><br />
|
| 47 |
-
|
| 48 |
<?php
|
| 49 |
}
|
| 50 |
}
|
|
@@ -53,23 +42,21 @@ $objects = $scporder_options['objects'];
|
|
| 53 |
</tr>
|
| 54 |
</tbody>
|
| 55 |
</table>
|
| 56 |
-
|
| 57 |
<p class="submit">
|
| 58 |
-
<input type="submit" class="button-primary" name="scporder_submit" value="<?php _e( 'Update', '
|
| 59 |
</p>
|
| 60 |
-
|
| 61 |
</form>
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
}
|
| 17 |
</div>
|
| 18 |
<?php endif; ?>
|
| 19 |
<form method="post">
|
| 20 |
+
<table id="scporder_select_objects" class="form-table">
|
| 21 |
<tbody>
|
| 22 |
<tr valign="top">
|
| 23 |
<th scope="row"><label for="blogname"><?php _e( 'Sortable Objects', 'scporder' ) ?></label></th>
|
| 24 |
<td>
|
| 25 |
<input type="hidden" name="msg" value="true" />
|
| 26 |
<?php if ( function_exists( 'wp_nonce_field' ) ) wp_nonce_field( 'nonce_scporder' ); ?>
|
|
|
|
|
|
|
|
|
|
| 27 |
<?php
|
| 28 |
$post_types = get_post_types( array(
|
| 29 |
'public' => true
|
| 30 |
), 'objects' );
|
| 31 |
?>
|
|
|
|
| 32 |
<?php
|
| 33 |
foreach ( $post_types as $post_type ) {
|
| 34 |
if ( $post_type->name != 'attachment' ) {
|
| 35 |
?>
|
| 36 |
+
<label><input type="checkbox" name="objects[]" value="<?php echo $post_type->name; ?>" <?php if ( isset($objects) && is_array($objects) ) { if ( in_array($post_type->name, $objects )) { echo 'checked="checked"'; } } ?>/> <?php echo $post_type->label; ?></label><br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
<?php
|
| 38 |
}
|
| 39 |
}
|
| 42 |
</tr>
|
| 43 |
</tbody>
|
| 44 |
</table>
|
| 45 |
+
<label><input type="checkbox" id="checkall_scp"> <?php _e('Check All', 'scporder') ?></label>
|
| 46 |
<p class="submit">
|
| 47 |
+
<input type="submit" class="button-primary" name="scporder_submit" value="<?php _e( 'Update', 'scporder' ); ?>" />
|
| 48 |
</p>
|
|
|
|
| 49 |
</form>
|
| 50 |
+
</div>
|
| 51 |
+
<script>
|
| 52 |
+
(function($){
|
| 53 |
+
$("#checkall_scp").on('click', function(){
|
| 54 |
+
var items = $("#scporder_select_objects input");
|
| 55 |
+
if ( $(this).is(':checked') ) {
|
| 56 |
+
$(items).prop('checked', true);
|
| 57 |
+
} else {
|
| 58 |
+
$(items).prop('checked', false);
|
| 59 |
+
}
|
| 60 |
+
});
|
| 61 |
+
})(jQuery)
|
| 62 |
+
</script>
|
|
|
simple-custom-post-order.php
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 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: 2.
|
| 8 |
Author: Sameer Humagain
|
| 9 |
Author URI: http://hsameer.com.np/
|
| 10 |
*/
|
|
@@ -32,7 +32,7 @@ class SCPO_Engine {
|
|
| 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( '
|
| 36 |
|
| 37 |
add_action( 'wp_ajax_update-menu-order', array( &$this, 'update_menu_order' ) );
|
| 38 |
|
|
@@ -97,121 +97,119 @@ class SCPO_Engine {
|
|
| 97 |
require SCPO_DIR . 'settings.php';
|
| 98 |
}
|
| 99 |
|
| 100 |
-
function
|
|
|
|
|
|
|
|
|
|
| 101 |
$scporder_options = get_option( 'scporder_options' );
|
| 102 |
-
$objects = $scporder_options['objects'];
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
$active = true;
|
| 116 |
}
|
| 117 |
}
|
| 118 |
-
|
| 119 |
-
if ( $active ) {
|
| 120 |
-
$this->load_script_css();
|
| 121 |
-
}
|
| 122 |
}
|
|
|
|
| 123 |
}
|
| 124 |
|
| 125 |
function load_script_css() {
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
wp_enqueue_script( 'scporderjs', SCPO_URL . '/assets/scporder.js', array( 'jquery' ), null, true );
|
| 133 |
-
// load CSS
|
| 134 |
-
wp_enqueue_style( 'scporder', SCPO_URL . '/assets/scporder.css', array( ), null );
|
| 135 |
}
|
| 136 |
|
| 137 |
-
function refresh()
|
| 138 |
-
|
|
|
|
| 139 |
global $wpdb;
|
| 140 |
-
|
| 141 |
$scporder_options = get_option( 'scporder_options' );
|
| 142 |
-
$objects = $scporder_options['objects'];
|
| 143 |
-
|
| 144 |
if ( is_array( $objects ) ) {
|
| 145 |
-
foreach
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
$results = $wpdb->get_results( $sql );
|
| 158 |
-
|
| 159 |
-
foreach ( $results as $key => $result ) {
|
| 160 |
-
$wpdb->update( $wpdb->posts, array( 'menu_order' => $key + 1 ), array( 'ID' => $result->ID ) );
|
| 161 |
}
|
| 162 |
}
|
| 163 |
}
|
| 164 |
}
|
| 165 |
|
| 166 |
-
function update_menu_order()
|
|
|
|
| 167 |
global $wpdb;
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
$id_arr = array( );
|
| 175 |
-
foreach ( $data as $key => $values ) {
|
| 176 |
-
foreach ( $values as $position => $id ) {
|
| 177 |
$id_arr[] = $id;
|
| 178 |
}
|
| 179 |
}
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
$results = $wpdb->get_results( "SELECT menu_order FROM $wpdb->posts WHERE ID = " . $id );
|
| 185 |
-
foreach ( $results as $result ) {
|
| 186 |
$menu_order_arr[] = $result->menu_order;
|
| 187 |
}
|
| 188 |
-
}
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
foreach ( $data as $key => $values ) {
|
| 193 |
-
foreach ( $values as $position => $id ) {
|
| 194 |
$wpdb->update( $wpdb->posts, array( 'menu_order' => $menu_order_arr[$position] ), array( 'ID' => $id ) );
|
| 195 |
}
|
| 196 |
}
|
| 197 |
}
|
| 198 |
}
|
| 199 |
|
| 200 |
-
function update_options()
|
|
|
|
|
|
|
| 201 |
if ( isset( $_POST['scporder_submit'] ) ) {
|
| 202 |
-
|
| 203 |
check_admin_referer( 'nonce_scporder' );
|
| 204 |
-
|
| 205 |
if ( isset( $_POST['objects'] ) ) {
|
| 206 |
$input_options = array( 'objects' => $_POST['objects'] );
|
| 207 |
} else {
|
| 208 |
$input_options = array( 'objects' => '' );
|
| 209 |
}
|
| 210 |
-
|
| 211 |
update_option( 'scporder_options', $input_options );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
wp_redirect( 'admin.php?page=scporder-settings&msg=update' );
|
| 213 |
}
|
| 214 |
-
}
|
| 215 |
|
| 216 |
function scporder_previous_post_where( $where ) {
|
| 217 |
global $post;
|
|
@@ -265,213 +263,81 @@ class SCPO_Engine {
|
|
| 265 |
|
| 266 |
function scporder_filter_active( $wp_query ) {
|
| 267 |
|
| 268 |
-
if ( isset(
|
| 269 |
-
|
| 270 |
-
if ( isset( $wp_query->query_vars['suppress_filters'] ) )
|
| 271 |
-
$wp_query->query_vars['suppress_filters'] = false;
|
| 272 |
return $wp_query;
|
| 273 |
}
|
| 274 |
|
| 275 |
function scporder_pre_get_posts( $wp_query ) {
|
|
|
|
| 276 |
$scporder_options = get_option( 'scporder_options' );
|
| 277 |
$objects = $scporder_options['objects'];
|
| 278 |
-
|
| 279 |
if ( is_array( $objects ) ) {
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
if ( is_admin() && !defined( 'DOING_AJAX' ) ) {
|
| 284 |
-
|
| 285 |
-
|
| 286 |
if ( isset( $wp_query->query['post_type'] ) ) {
|
| 287 |
if ( in_array( $wp_query->query['post_type'], $objects ) ) {
|
| 288 |
$wp_query->set( 'orderby', 'menu_order' );
|
| 289 |
$wp_query->set( 'order', 'ASC' );
|
| 290 |
}
|
| 291 |
}
|
|
|
|
|
|
|
| 292 |
} else {
|
| 293 |
-
|
|
|
|
| 294 |
$active = false;
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
$
|
| 301 |
-
|
| 302 |
-
} else {
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
if ( isset( $wp_query->query['suppress_filters'] ) ) {
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
if ( is_array( $wp_query->query['post_type'] ) ) {
|
| 310 |
-
$post_types = $wp_query->query['post_type'];
|
| 311 |
-
foreach ( $post_types as $post_type ) {
|
| 312 |
-
if ( in_array( $post_type, $objects ) ) {
|
| 313 |
-
$active = true;
|
| 314 |
-
}
|
| 315 |
-
}
|
| 316 |
-
} else {
|
| 317 |
-
if ( in_array( $wp_query->query['post_type'], $objects ) ) {
|
| 318 |
$active = true;
|
| 319 |
}
|
| 320 |
}
|
| 321 |
} else {
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
}
|
|
|
|
|
|
|
|
|
|
| 339 |
} else {
|
| 340 |
-
if (
|
| 341 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
}
|
| 343 |
}
|
| 344 |
-
}
|
| 345 |
-
}
|
| 346 |
-
|
| 347 |
-
if ( $active ) {
|
| 348 |
-
if ( !isset( $wp_query->query['orderby'] ) || $wp_query->query['orderby'] == 'post_date' )
|
| 349 |
$wp_query->set( 'orderby', 'menu_order' );
|
| 350 |
-
if ( !isset( $wp_query->query['order'] ) || $wp_query->query['order'] == 'DESC' )
|
| 351 |
$wp_query->set( 'order', 'ASC' );
|
|
|
|
| 352 |
}
|
| 353 |
}
|
| 354 |
}
|
| 355 |
-
}
|
| 356 |
-
|
| 357 |
-
}
|
| 358 |
-
|
| 359 |
-
/* =============================================================================================================
|
| 360 |
-
* Taxonomy Sort
|
| 361 |
-
=============================================================================================================== */
|
| 362 |
-
class Taxonomy_Order_Engine {
|
| 363 |
-
|
| 364 |
-
/**
|
| 365 |
-
* Simple class constructor
|
| 366 |
-
*/
|
| 367 |
-
function __construct() {
|
| 368 |
-
// admin initialize
|
| 369 |
-
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
| 370 |
-
|
| 371 |
-
// front-end initialize
|
| 372 |
-
add_action( 'init', array( $this, 'init' ) );
|
| 373 |
-
}
|
| 374 |
-
|
| 375 |
-
/**
|
| 376 |
-
* Initialize administration
|
| 377 |
-
*/
|
| 378 |
-
function admin_init() {
|
| 379 |
-
// load scripts
|
| 380 |
-
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
// ajax to save the sorting
|
| 384 |
-
add_action( 'wp_ajax_get_inline_boxes', array( $this, 'inline_edit_boxes' ) );
|
| 385 |
-
|
| 386 |
-
// reorder terms when someone tries to get terms
|
| 387 |
-
add_filter( 'get_terms', array( $this, 'reorder_terms' ) );
|
| 388 |
-
}
|
| 389 |
-
|
| 390 |
-
/**
|
| 391 |
-
* Initialize front-page
|
| 392 |
-
*
|
| 393 |
-
*/
|
| 394 |
-
function init() {
|
| 395 |
-
// reorder terms when someone tries to get terms
|
| 396 |
-
add_filter( 'get_terms', array( $this, 'reorder_terms' ) );
|
| 397 |
-
}
|
| 398 |
-
|
| 399 |
-
/**
|
| 400 |
-
* Load scripts
|
| 401 |
-
*/
|
| 402 |
-
function enqueue_scripts() {
|
| 403 |
-
// allow enqueue only on tags/taxonomy page
|
| 404 |
-
if ( get_current_screen()->base != 'edit-tags' )
|
| 405 |
-
return;
|
| 406 |
-
// load jquery and plugin's script
|
| 407 |
-
wp_enqueue_script( 'jquery' );
|
| 408 |
-
wp_enqueue_script( 'taxonomyorder', plugins_url( 'assets/taxonomy_order.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable' ) );
|
| 409 |
-
|
| 410 |
-
wp_enqueue_style( 'scporder', SCPO_URL . '/assets/scporder.css', array( ), null );
|
| 411 |
-
}
|
| 412 |
-
|
| 413 |
-
/**
|
| 414 |
-
* Do the sorting
|
| 415 |
-
*/
|
| 416 |
-
function inline_edit_boxes() {
|
| 417 |
-
// loop through rows
|
| 418 |
-
foreach ( $_POST['rows'] as $key => $row ) {
|
| 419 |
-
// skip empty
|
| 420 |
-
if ( !isset( $row ) || $row == "" )
|
| 421 |
-
continue;
|
| 422 |
-
|
| 423 |
-
// update order
|
| 424 |
-
update_post_meta( $row, 'thets_order', ( $key + 1 ) );
|
| 425 |
-
}
|
| 426 |
-
|
| 427 |
-
// kill it for ajax
|
| 428 |
-
exit;
|
| 429 |
-
}
|
| 430 |
-
|
| 431 |
-
/**
|
| 432 |
-
* Order terms
|
| 433 |
-
*/
|
| 434 |
-
function reorder_terms( $objects ) {
|
| 435 |
-
// we do not need empty objects
|
| 436 |
-
if ( empty( $objects ) )
|
| 437 |
-
return $objects;
|
| 438 |
-
|
| 439 |
-
// do not apply ordering to list that contains just names
|
| 440 |
-
if ( !is_object( $objects[0] ) )
|
| 441 |
-
return $objects;
|
| 442 |
-
|
| 443 |
-
// placeholder for ordered objects
|
| 444 |
-
$placeholder = array( );
|
| 445 |
-
|
| 446 |
-
// invalid key counter (if key is not set)
|
| 447 |
-
$invalid_key = 9000;
|
| 448 |
-
|
| 449 |
-
// loop through objects
|
| 450 |
-
foreach ( $objects as $key => $object ) {
|
| 451 |
-
// increase invalid key count
|
| 452 |
-
$invalid_key++;
|
| 453 |
-
|
| 454 |
-
// continue if no term_id
|
| 455 |
-
if ( !isset( $object->term_id ) )
|
| 456 |
-
continue;
|
| 457 |
-
|
| 458 |
-
// get the order key
|
| 459 |
-
$term_order = get_post_meta( $object->term_id, 'thets_order', true );
|
| 460 |
-
|
| 461 |
-
// use order key if exists, invalid key if not
|
| 462 |
-
$term_key = ( $term_order != "" && $term_order != 0 ) ? (int) $term_order : $invalid_key;
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
$placeholder[$term_key] = $object;
|
| 466 |
-
}
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
ksort( $placeholder );
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
return $placeholder;
|
| 473 |
-
}
|
| 474 |
|
| 475 |
}
|
| 476 |
-
|
| 477 |
-
new Taxonomy_Order_Engine;
|
| 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: 2.2
|
| 8 |
Author: Sameer Humagain
|
| 9 |
Author URI: http://hsameer.com.np/
|
| 10 |
*/
|
| 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( 'admin_init', array( &$this, 'load_script_css' ) );
|
| 36 |
|
| 37 |
add_action( 'wp_ajax_update-menu-order', array( &$this, 'update_menu_order' ) );
|
| 38 |
|
| 97 |
require SCPO_DIR . 'settings.php';
|
| 98 |
}
|
| 99 |
|
| 100 |
+
function _check_load_script_css() {
|
| 101 |
+
|
| 102 |
+
$active = false;
|
| 103 |
+
|
| 104 |
$scporder_options = get_option( 'scporder_options' );
|
| 105 |
+
$objects = $scporder_options['objects'];
|
| 106 |
+
|
| 107 |
+
if ( is_array( $objects ) ) {
|
| 108 |
+
if ( !strstr( $_SERVER["REQUEST_URI"], 'action=edit' ) && !strstr( $_SERVER["REQUEST_URI"], 'wp-admin/post-new.php' ) ) {
|
| 109 |
+
|
| 110 |
+
if ( isset( $_GET['post_type'] ) ) {
|
| 111 |
+
if ( in_array( $_GET['post_type'], $objects ) ) {
|
| 112 |
+
$active = true;
|
| 113 |
+
}
|
| 114 |
+
} else if ( strstr( $_SERVER["REQUEST_URI"], 'wp-admin/edit.php' ) ) {
|
| 115 |
+
if ( in_array( 'post', $objects ) ) {
|
| 116 |
+
$active = true;
|
| 117 |
+
}
|
|
|
|
| 118 |
}
|
| 119 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
}
|
| 121 |
+
return $active;
|
| 122 |
}
|
| 123 |
|
| 124 |
function load_script_css() {
|
| 125 |
+
if ( $this->_check_load_script_css() ) {
|
| 126 |
+
wp_enqueue_script( 'jQuery' );
|
| 127 |
+
wp_enqueue_script( 'jquery-ui-sortable' );
|
| 128 |
+
wp_enqueue_script( 'scporderjs', SCPO_URL . '/assets/scporder.js', array( 'jquery' ), null, true );
|
| 129 |
+
wp_enqueue_style( 'scporder', SCPO_URL . '/assets/scporder.css', array( ), null );
|
| 130 |
+
}
|
|
|
|
|
|
|
|
|
|
| 131 |
}
|
| 132 |
|
| 133 |
+
function refresh()
|
| 134 |
+
{
|
| 135 |
+
|
| 136 |
global $wpdb;
|
|
|
|
| 137 |
$scporder_options = get_option( 'scporder_options' );
|
| 138 |
+
$objects = $scporder_options['objects'];
|
| 139 |
+
|
| 140 |
if ( is_array( $objects ) ) {
|
| 141 |
+
foreach( $objects as $object) {
|
| 142 |
+
|
| 143 |
+
$result = $wpdb->get_results( "SELECT count(*) as cnt, max(menu_order) as max, min(menu_order) as min FROM $wpdb->posts WHERE post_type = '".$object."' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')" );
|
| 144 |
+
if ( count( $result ) > 0 && $result[0]->cnt == $result[0]->max && $result[0]->min != 0 ) {
|
| 145 |
+
continue;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
$results = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type = '".$object."' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future') ORDER BY menu_order ASC" );
|
| 149 |
+
|
| 150 |
+
foreach( $results as $key => $result ) {
|
| 151 |
+
$wpdb->update( $wpdb->posts, array( 'menu_order' => $key+1 ), array( 'ID' => $result->ID ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
}
|
| 153 |
}
|
| 154 |
}
|
| 155 |
}
|
| 156 |
|
| 157 |
+
function update_menu_order()
|
| 158 |
+
{
|
| 159 |
global $wpdb;
|
| 160 |
+
parse_str($_POST['order'], $data);
|
| 161 |
+
if ( is_array($data) ) {
|
| 162 |
+
$id_arr = array();
|
| 163 |
+
foreach( $data as $key => $values ) {
|
| 164 |
+
foreach( $values as $position => $id ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
$id_arr[] = $id;
|
| 166 |
}
|
| 167 |
}
|
| 168 |
+
$menu_order_arr = array();
|
| 169 |
+
foreach( $id_arr as $key => $id ) {
|
| 170 |
+
$results = $wpdb->get_results( "SELECT menu_order FROM $wpdb->posts WHERE ID = ".$id );
|
| 171 |
+
foreach( $results as $result ) {
|
|
|
|
|
|
|
| 172 |
$menu_order_arr[] = $result->menu_order;
|
| 173 |
}
|
| 174 |
+
}
|
| 175 |
+
sort($menu_order_arr);
|
| 176 |
+
foreach( $data as $key => $values ) {
|
| 177 |
+
foreach( $values as $position => $id ) {
|
|
|
|
|
|
|
| 178 |
$wpdb->update( $wpdb->posts, array( 'menu_order' => $menu_order_arr[$position] ), array( 'ID' => $id ) );
|
| 179 |
}
|
| 180 |
}
|
| 181 |
}
|
| 182 |
}
|
| 183 |
|
| 184 |
+
function update_options()
|
| 185 |
+
{
|
| 186 |
+
global $wpdb;
|
| 187 |
if ( isset( $_POST['scporder_submit'] ) ) {
|
|
|
|
| 188 |
check_admin_referer( 'nonce_scporder' );
|
|
|
|
| 189 |
if ( isset( $_POST['objects'] ) ) {
|
| 190 |
$input_options = array( 'objects' => $_POST['objects'] );
|
| 191 |
} else {
|
| 192 |
$input_options = array( 'objects' => '' );
|
| 193 |
}
|
|
|
|
| 194 |
update_option( 'scporder_options', $input_options );
|
| 195 |
+
$scporder_options = get_option( 'scporder_options' );
|
| 196 |
+
$objects = $scporder_options['objects'];
|
| 197 |
+
|
| 198 |
+
if ( !empty( $objects ) ) {
|
| 199 |
+
foreach( $objects as $object) {
|
| 200 |
+
$result = $wpdb->get_results( "SELECT count(*) as cnt, max(menu_order) as max, min(menu_order) as min FROM $wpdb->posts WHERE post_type = '".$object."' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')" );
|
| 201 |
+
if ( count( $result ) > 0 && $result[0]->max == 0 ) {
|
| 202 |
+
$results = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type = '".$object."' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future') ORDER BY post_date DESC" );
|
| 203 |
+
foreach( $results as $key => $result ) {
|
| 204 |
+
$wpdb->update( $wpdb->posts, array( 'menu_order' => $key+1 ), array( 'ID' => $result->ID ) );
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
wp_redirect( 'admin.php?page=scporder-settings&msg=update' );
|
| 211 |
}
|
| 212 |
+
}
|
| 213 |
|
| 214 |
function scporder_previous_post_where( $where ) {
|
| 215 |
global $post;
|
| 263 |
|
| 264 |
function scporder_filter_active( $wp_query ) {
|
| 265 |
|
| 266 |
+
if ( isset($wp_query->query['suppress_filters']) ) $wp_query->query['suppress_filters'] = false;
|
| 267 |
+
if ( isset($wp_query->query_vars['suppress_filters']) ) $wp_query->query_vars['suppress_filters'] = false;
|
|
|
|
|
|
|
| 268 |
return $wp_query;
|
| 269 |
}
|
| 270 |
|
| 271 |
function scporder_pre_get_posts( $wp_query ) {
|
| 272 |
+
global $args;
|
| 273 |
$scporder_options = get_option( 'scporder_options' );
|
| 274 |
$objects = $scporder_options['objects'];
|
| 275 |
+
|
| 276 |
if ( is_array( $objects ) ) {
|
| 277 |
+
|
| 278 |
+
|
|
|
|
| 279 |
if ( is_admin() && !defined( 'DOING_AJAX' ) ) {
|
| 280 |
+
|
| 281 |
+
|
| 282 |
if ( isset( $wp_query->query['post_type'] ) ) {
|
| 283 |
if ( in_array( $wp_query->query['post_type'], $objects ) ) {
|
| 284 |
$wp_query->set( 'orderby', 'menu_order' );
|
| 285 |
$wp_query->set( 'order', 'ASC' );
|
| 286 |
}
|
| 287 |
}
|
| 288 |
+
|
| 289 |
+
|
| 290 |
} else {
|
| 291 |
+
|
| 292 |
+
|
| 293 |
$active = false;
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
if ( isset( $wp_query->query['post_type'] ) ) {
|
| 297 |
+
if ( is_array( $wp_query->query['post_type'] ) ) {
|
| 298 |
+
$post_types = $wp_query->query['post_type'];
|
| 299 |
+
foreach( $post_types as $post_type ) {
|
| 300 |
+
if ( in_array( $post_type, $objects ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
$active = true;
|
| 302 |
}
|
| 303 |
}
|
| 304 |
} else {
|
| 305 |
+
if ( in_array( $wp_query->query['post_type'], $objects ) ) {
|
| 306 |
+
$active = true;
|
| 307 |
+
}
|
| 308 |
+
}
|
| 309 |
+
} else {
|
| 310 |
+
if ( in_array( 'post', $objects ) ) {
|
| 311 |
+
$active = true;
|
| 312 |
+
}
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
if ( $active ) {
|
| 316 |
+
|
| 317 |
+
if ( isset( $args ) ) {
|
| 318 |
+
if ( is_array( $args ) ) {
|
| 319 |
+
if ( !isset( $args['orderby'] ) ) {
|
| 320 |
+
$wp_query->set( 'orderby', 'menu_order' );
|
| 321 |
}
|
| 322 |
+
if ( !isset( $args['order'] ) ) {
|
| 323 |
+
$wp_query->set( 'order', 'ASC' );
|
| 324 |
+
}
|
| 325 |
} else {
|
| 326 |
+
if ( !strstr( $args, 'orderby=' ) ) {
|
| 327 |
+
$wp_query->set( 'orderby', 'menu_order' );
|
| 328 |
+
}
|
| 329 |
+
if ( !strstr( $args, 'order=' ) ) {
|
| 330 |
+
$wp_query->set( 'order', 'ASC' );
|
| 331 |
+
|
| 332 |
}
|
| 333 |
}
|
| 334 |
+
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
$wp_query->set( 'orderby', 'menu_order' );
|
|
|
|
| 336 |
$wp_query->set( 'order', 'ASC' );
|
| 337 |
+
}
|
| 338 |
}
|
| 339 |
}
|
| 340 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
|
| 342 |
}
|
| 343 |
+
}
|
|
|
