Version Description
- Added expand/collapse section for nested post types
- Added better page detection for scripts and styles
Download this release
Release Info
| Developer | ronalfy |
| Plugin | |
| Version | 1.0.5 |
| Comparing to | |
| See all releases | |
Code changes from version 1.0.4 to 1.0.5
- admin.css +3 -0
- class-reorder.php +23 -19
- index.php +1 -1
- readme.txt +6 -1
- scripts/sort.js +16 -4
admin.css
CHANGED
|
@@ -34,4 +34,7 @@
|
|
| 34 |
}
|
| 35 |
#loading-animation {
|
| 36 |
display: none;
|
|
|
|
|
|
|
|
|
|
| 37 |
}
|
| 34 |
}
|
| 35 |
#loading-animation {
|
| 36 |
display: none;
|
| 37 |
+
}
|
| 38 |
+
#post-list .children {
|
| 39 |
+
display: none;
|
| 40 |
}
|
class-reorder.php
CHANGED
|
@@ -29,6 +29,13 @@ class Reorder {
|
|
| 29 |
* @access private
|
| 30 |
*/
|
| 31 |
private $post_type;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
/**
|
| 34 |
* @var $direction
|
|
@@ -112,25 +119,13 @@ class Reorder {
|
|
| 112 |
$this->menu_label = $menu_label;
|
| 113 |
$this->icon = $icon;
|
| 114 |
$this->post_status = $post_status;
|
| 115 |
-
|
|
|
|
| 116 |
// Add actions
|
| 117 |
add_action( 'wp_ajax_post_sort', array( $this, 'ajax_save_post_order' ) );
|
| 118 |
-
add_action( 'admin_print_styles', array( $this, 'print_styles' ) );
|
| 119 |
-
add_action( 'admin_print_scripts', array( $this, 'print_scripts' ) );
|
| 120 |
add_action( 'admin_menu', array( $this, 'enable_post_sort' ), 10, 'page' );
|
| 121 |
-
add_action( 'admin_print_styles', array( $this, 'create_nonce' ) );
|
| 122 |
}
|
| 123 |
|
| 124 |
-
/**
|
| 125 |
-
* Creating the nonce value used within sort.js
|
| 126 |
-
*
|
| 127 |
-
* @author Ryan Hellyer <ryan@metronet.no>
|
| 128 |
-
* @since Reorder 1.0
|
| 129 |
-
* @access public
|
| 130 |
-
*/
|
| 131 |
-
public function create_nonce() {
|
| 132 |
-
echo "<script>var sortnonce = '" . wp_create_nonce( 'sortnonce' ) . "';</script>";
|
| 133 |
-
}
|
| 134 |
|
| 135 |
/**
|
| 136 |
* Saving the post oder for later use
|
|
@@ -211,12 +206,18 @@ class Reorder {
|
|
| 211 |
* @global string $pagenow Used internally by WordPress to designate what the current page is in the admin panel
|
| 212 |
*/
|
| 213 |
public function print_scripts() {
|
| 214 |
-
global $pagenow;
|
| 215 |
-
|
| 216 |
$pages = array( 'edit.php' );
|
|
|
|
| 217 |
if ( in_array( $pagenow, $pages ) ) {
|
| 218 |
wp_register_script( 'reorder_nested', REORDER_URL . '/scripts/jquery.mjs.nestedSortable.js', array( 'jquery-ui-sortable' ), '1.3.5', true );
|
| 219 |
wp_enqueue_script( 'reorder_posts', REORDER_URL . '/scripts/sort.js', array( 'reorder_nested' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
}
|
| 221 |
}
|
| 222 |
|
|
@@ -230,7 +231,8 @@ class Reorder {
|
|
| 230 |
public function enable_post_sort() {
|
| 231 |
$post_type = $this->post_type;
|
| 232 |
if ( 'post' != $post_type ) {
|
| 233 |
-
|
|
|
|
| 234 |
'edit.php?post_type=' . $post_type, // Parent slug
|
| 235 |
$this->heading, // Page title (unneeded since specified directly)
|
| 236 |
$this->menu_label, // Menu title
|
|
@@ -240,7 +242,7 @@ class Reorder {
|
|
| 240 |
);
|
| 241 |
}
|
| 242 |
else {
|
| 243 |
-
add_posts_page(
|
| 244 |
$this->heading, // Page title (unneeded since specified directly)
|
| 245 |
$this->menu_label, // Menu title
|
| 246 |
'edit_posts', // Capability
|
|
@@ -248,6 +250,8 @@ class Reorder {
|
|
| 248 |
array( $this, 'sort_posts' ) // Callback function
|
| 249 |
);
|
| 250 |
}
|
|
|
|
|
|
|
| 251 |
}
|
| 252 |
|
| 253 |
/**
|
|
@@ -284,7 +288,7 @@ class Reorder {
|
|
| 284 |
setup_postdata( $post );
|
| 285 |
?>
|
| 286 |
<li id="list_<?php the_id(); ?>">
|
| 287 |
-
<div><?php the_title(); ?></div>
|
| 288 |
<ul class='children'>
|
| 289 |
<?php $this->output_row_children( $post_children, $all_children ); ?>
|
| 290 |
</ul>
|
| 29 |
* @access private
|
| 30 |
*/
|
| 31 |
private $post_type;
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* @var $page_hook
|
| 35 |
+
* @desc Page hook to add reorder scripts/styles to
|
| 36 |
+
* @access private
|
| 37 |
+
*/
|
| 38 |
+
private $page_hook;
|
| 39 |
|
| 40 |
/**
|
| 41 |
* @var $direction
|
| 119 |
$this->menu_label = $menu_label;
|
| 120 |
$this->icon = $icon;
|
| 121 |
$this->post_status = $post_status;
|
| 122 |
+
$this->page_hook = $post_type . '_page_reorder-video';
|
| 123 |
+
|
| 124 |
// Add actions
|
| 125 |
add_action( 'wp_ajax_post_sort', array( $this, 'ajax_save_post_order' ) );
|
|
|
|
|
|
|
| 126 |
add_action( 'admin_menu', array( $this, 'enable_post_sort' ), 10, 'page' );
|
|
|
|
| 127 |
}
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
/**
|
| 131 |
* Saving the post oder for later use
|
| 206 |
* @global string $pagenow Used internally by WordPress to designate what the current page is in the admin panel
|
| 207 |
*/
|
| 208 |
public function print_scripts() {
|
| 209 |
+
global $pagenow, $hook_suffix;
|
|
|
|
| 210 |
$pages = array( 'edit.php' );
|
| 211 |
+
|
| 212 |
if ( in_array( $pagenow, $pages ) ) {
|
| 213 |
wp_register_script( 'reorder_nested', REORDER_URL . '/scripts/jquery.mjs.nestedSortable.js', array( 'jquery-ui-sortable' ), '1.3.5', true );
|
| 214 |
wp_enqueue_script( 'reorder_posts', REORDER_URL . '/scripts/sort.js', array( 'reorder_nested' ) );
|
| 215 |
+
wp_localize_script( 'reorder_posts', 'reorder_posts', array(
|
| 216 |
+
'expand' => esc_js( __( 'Expand', 'reorder' ) ),
|
| 217 |
+
'collapse' => esc_js( __( 'Collapse', 'reorder' ) ),
|
| 218 |
+
'sortnonce' => wp_create_nonce( 'sortnonce' ),
|
| 219 |
+
'hierarchical' => is_post_type_hierarchical( $this->post_type ) ? 'true' : 'false',
|
| 220 |
+
) );
|
| 221 |
}
|
| 222 |
}
|
| 223 |
|
| 231 |
public function enable_post_sort() {
|
| 232 |
$post_type = $this->post_type;
|
| 233 |
if ( 'post' != $post_type ) {
|
| 234 |
+
|
| 235 |
+
$hook = add_submenu_page(
|
| 236 |
'edit.php?post_type=' . $post_type, // Parent slug
|
| 237 |
$this->heading, // Page title (unneeded since specified directly)
|
| 238 |
$this->menu_label, // Menu title
|
| 242 |
);
|
| 243 |
}
|
| 244 |
else {
|
| 245 |
+
$hook = add_posts_page(
|
| 246 |
$this->heading, // Page title (unneeded since specified directly)
|
| 247 |
$this->menu_label, // Menu title
|
| 248 |
'edit_posts', // Capability
|
| 250 |
array( $this, 'sort_posts' ) // Callback function
|
| 251 |
);
|
| 252 |
}
|
| 253 |
+
add_action( 'admin_print_styles-' . $hook, array( $this, 'print_styles' ) );
|
| 254 |
+
add_action( 'admin_print_scripts-' . $hook, array( $this, 'print_scripts' ) );
|
| 255 |
}
|
| 256 |
|
| 257 |
/**
|
| 288 |
setup_postdata( $post );
|
| 289 |
?>
|
| 290 |
<li id="list_<?php the_id(); ?>">
|
| 291 |
+
<div><?php the_title(); ?> <a href='#' style="float: right"><?php esc_html_e( 'Expand', 'reorder' ); ?></a></div>
|
| 292 |
<ul class='children'>
|
| 293 |
<?php $this->output_row_children( $post_children, $all_children ); ?>
|
| 294 |
</ul>
|
index.php
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
Plugin Name: Metronet Reorder Posts
|
| 4 |
Plugin URI: http://metronet.no/
|
| 5 |
Description: Reorder posts
|
| 6 |
-
Version: 1.0.
|
| 7 |
Author: Ryan Hellyer / Metronet
|
| 8 |
Author URI: http://metronet.no/
|
| 9 |
|
| 3 |
Plugin Name: Metronet Reorder Posts
|
| 4 |
Plugin URI: http://metronet.no/
|
| 5 |
Description: Reorder posts
|
| 6 |
+
Version: 1.0.5
|
| 7 |
Author: Ryan Hellyer / Metronet
|
| 8 |
Author URI: http://metronet.no/
|
| 9 |
|
readme.txt
CHANGED
|
@@ -3,8 +3,9 @@ Contributors: ryanhellyer, metronet, ronalfy
|
|
| 3 |
Author URI: http://metronet.no/
|
| 4 |
Plugin URL: http://metronet.no/
|
| 5 |
Requires at Least: 3.3
|
|
|
|
| 6 |
Tags: reorder, posts, wordpress, post-type
|
| 7 |
-
Stable tag: 1.0.
|
| 8 |
|
| 9 |
A simple and easy way to reorder your custom post-type posts in WordPress.
|
| 10 |
|
|
@@ -49,6 +50,10 @@ Probably, but we only support the latest version of WordPress.
|
|
| 49 |
|
| 50 |
== Changelog ==
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
= 1.0.4 =
|
| 53 |
* Added support for hierarchical post types
|
| 54 |
|
| 3 |
Author URI: http://metronet.no/
|
| 4 |
Plugin URL: http://metronet.no/
|
| 5 |
Requires at Least: 3.3
|
| 6 |
+
Tested up to: 3.4.1
|
| 7 |
Tags: reorder, posts, wordpress, post-type
|
| 8 |
+
Stable tag: 1.0.5
|
| 9 |
|
| 10 |
A simple and easy way to reorder your custom post-type posts in WordPress.
|
| 11 |
|
| 50 |
|
| 51 |
== Changelog ==
|
| 52 |
|
| 53 |
+
= 1.0.5 =
|
| 54 |
+
* Added expand/collapse section for nested post types
|
| 55 |
+
* Added better page detection for scripts and styles
|
| 56 |
+
|
| 57 |
= 1.0.4 =
|
| 58 |
* Added support for hierarchical post types
|
| 59 |
|
scripts/sort.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
| 1 |
jQuery(document).ready(function($) {
|
| 2 |
//Variable sortnonce is declared globally
|
| 3 |
var postList = $('#post-list');
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
forcePlaceholderSize: true,
|
| 7 |
handle: 'div',
|
| 8 |
helper: 'clone',
|
| 9 |
items: 'li',
|
| 10 |
-
maxLevels:
|
| 11 |
opacity: .6,
|
| 12 |
placeholder: 'placeholder',
|
| 13 |
revert: 250,
|
|
@@ -20,11 +23,20 @@ jQuery(document).ready(function($) {
|
|
| 20 |
order = JSON.stringify( order , null, 2);
|
| 21 |
//console.log( order );
|
| 22 |
//return;
|
| 23 |
-
$.post( ajaxurl, { action: 'post_sort', nonce: sortnonce, data: order }, function( response ) {
|
| 24 |
}, 'json' );
|
| 25 |
|
| 26 |
}
|
| 27 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
/*
|
| 30 |
|
| 1 |
jQuery(document).ready(function($) {
|
| 2 |
//Variable sortnonce is declared globally
|
| 3 |
var postList = $('#post-list');
|
| 4 |
+
var max_levels = 6;
|
| 5 |
+
if ( reorder_posts.hierarchical == 'false' ) {
|
| 6 |
+
max_levels = 1;
|
| 7 |
+
}
|
| 8 |
+
postList.nestedSortable( {
|
| 9 |
forcePlaceholderSize: true,
|
| 10 |
handle: 'div',
|
| 11 |
helper: 'clone',
|
| 12 |
items: 'li',
|
| 13 |
+
maxLevels: max_levels,
|
| 14 |
opacity: .6,
|
| 15 |
placeholder: 'placeholder',
|
| 16 |
revert: 250,
|
| 23 |
order = JSON.stringify( order , null, 2);
|
| 24 |
//console.log( order );
|
| 25 |
//return;
|
| 26 |
+
$.post( ajaxurl, { action: 'post_sort', nonce: reorder_posts.sortnonce, data: order }, function( response ) {
|
| 27 |
}, 'json' );
|
| 28 |
|
| 29 |
}
|
| 30 |
});
|
| 31 |
+
$( "#post-list a" ).toggle( function() {
|
| 32 |
+
$( this ).html( reorder_posts.collapse );
|
| 33 |
+
$( this ).parent().next( '.children' ).slideDown( "slow" );
|
| 34 |
+
return false;
|
| 35 |
+
}, function() {
|
| 36 |
+
$( this ).html( reorder_posts.expand );
|
| 37 |
+
$( this ).parent().next( '.children' ).slideUp( "slow" );
|
| 38 |
+
return false;
|
| 39 |
+
} );
|
| 40 |
|
| 41 |
/*
|
| 42 |
|
