Reorder Posts - Version 2.5.0

Version Description

  • Released 2020-11-18
  • Fixing sortable script with newer versions of jQuery.
Download this release

Release Info

Developer ronalfy
Plugin Icon 128x128 Reorder Posts
Version 2.5.0
Comparing to
See all releases

Code changes from version 2.4.1 to 2.5.0

Files changed (4) hide show
  1. class-reorder.php +1 -1
  2. index.php +1 -1
  3. readme.txt +8 -10
  4. scripts/sort.js +90 -79
class-reorder.php CHANGED
@@ -336,7 +336,7 @@ final class MN_Reorder {
336
  wp_enqueue_script( 'jquery-ui-touch-punch', REORDER_URL . '/scripts/jquery.ui.touch-punch.js', array( 'jquery-ui-sortable' ), '0.2.3', true );
337
  wp_register_script( 'reorder_nested', REORDER_URL . '/scripts/jquery.mjs.nestedSortable.js', array( 'jquery-ui-touch-punch' ), '2.0.0', true );
338
 
339
- wp_enqueue_script( 'reorder_posts', REORDER_URL . '/scripts/sort.js', array( 'reorder_nested' ), '20160813', true );
340
  wp_localize_script( 'reorder_posts', 'reorder_posts', array(
341
  'action' => 'post_sort',
342
  'expand' => esc_js( __( 'Expand', 'metronet-reorder-posts' ) ),
336
  wp_enqueue_script( 'jquery-ui-touch-punch', REORDER_URL . '/scripts/jquery.ui.touch-punch.js', array( 'jquery-ui-sortable' ), '0.2.3', true );
337
  wp_register_script( 'reorder_nested', REORDER_URL . '/scripts/jquery.mjs.nestedSortable.js', array( 'jquery-ui-touch-punch' ), '2.0.0', true );
338
 
339
+ wp_enqueue_script( 'reorder_posts', REORDER_URL . '/scripts/sort.js', array( 'reorder_nested' ), '20201118', true );
340
  wp_localize_script( 'reorder_posts', 'reorder_posts', array(
341
  'action' => 'post_sort',
342
  'expand' => esc_js( __( 'Expand', 'metronet-reorder-posts' ) ),
index.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Reorder Posts
4
  Plugin URI: https://wordpress.org/plugins/metronet-reorder-posts/
5
  Description: Easily reorder posts and pages in WordPress
6
- Version: 2.4.1
7
  Author: Ryan Hellyer, Ronald Huereca, Scott Basgaard
8
  Author URI: https://github.com/ronalfy/reorder-posts
9
  Text Domain: metronet-reorder-posts
3
  Plugin Name: Reorder Posts
4
  Plugin URI: https://wordpress.org/plugins/metronet-reorder-posts/
5
  Description: Easily reorder posts and pages in WordPress
6
+ Version: 2.5.0
7
  Author: Ryan Hellyer, Ronald Huereca, Scott Basgaard
8
  Author URI: https://github.com/ronalfy/reorder-posts
9
  Text Domain: metronet-reorder-posts
readme.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: ryanhellyer, ronalfy, scottbasgaard
3
  Author URI: https://github.com/ronalfy/reorder-posts
4
  Plugin URL: https://wordpress.org/plugins/metronet-reorder-posts/
5
  Requires at Least: 3.7
6
- Tested up to: 5.1
7
  Tags: reorder, reorder posts
8
- Stable tag: 2.4.1
9
  License: GPLv3 or later
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
@@ -129,6 +129,10 @@ No, but there is an add-on for this plugin called <a href="https://wordpress.org
129
 
130
  == Changelog ==
131
 
 
 
 
 
132
  = 2.4.1 =
133
  * Released 2019-02-16
134
  * Added query to reorder posts for an example
@@ -239,11 +243,5 @@ No, but there is an add-on for this plugin called <a href="https://wordpress.org
239
 
240
  == Upgrade Notice ==
241
 
242
- = 2.4.1 =
243
- Added query to reorder posts for an example. Option to turn off query output.
244
-
245
- = 2.4.0 =
246
- Major CSS overhaul inspired by the Nested Pages plugin and the plugin is now mobile friendly.
247
-
248
- = 2.3.0 =
249
- Added screen options to set the number of posts displayed
3
  Author URI: https://github.com/ronalfy/reorder-posts
4
  Plugin URL: https://wordpress.org/plugins/metronet-reorder-posts/
5
  Requires at Least: 3.7
6
+ Tested up to: 5.8
7
  Tags: reorder, reorder posts
8
+ Stable tag: 2.5.0
9
  License: GPLv3 or later
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
129
 
130
  == Changelog ==
131
 
132
+ = 2.5.0 =
133
+ * Released 2020-11-18
134
+ * Fixing sortable script with newer versions of jQuery.
135
+
136
  = 2.4.1 =
137
  * Released 2019-02-16
138
  * Added query to reorder posts for an example
243
 
244
  == Upgrade Notice ==
245
 
246
+ = 2.5.0 =
247
+ Fixing sortable script with newer versions of jQuery.
 
 
 
 
 
 
scripts/sort.js CHANGED
@@ -1,106 +1,103 @@
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
  var callback = false;
9
  var sort_start = {};
10
  var sort_end = {};
11
- postList.nestedSortable( {
12
  forcePlaceholderSize: true,
13
  handle: 'div',
14
- helper: 'clone',
15
  items: 'li',
16
  maxLevels: max_levels,
17
- opacity: .6,
18
  placeholder: 'ui-sortable-placeholder',
19
  revert: 250,
20
  tabSize: 25,
21
  tolerance: 'pointer',
22
  toleranceElement: '> div',
23
  listType: 'ul',
24
- update: function( event, ui ) {
25
  reorder_row_nesting();
26
- $loading_animation = jQuery( '#loading-animation' );
27
- var reorder_ajax_callback = function( response ) {
28
- response = jQuery.parseJSON( response );
29
- if ( true == response.more_posts ) {
30
- $.post( ajaxurl, response, reorder_ajax_callback );
31
  } else {
32
- if ( false != callback ) {
33
  var callback_ajax_args = callback;
34
  callback = false;
35
- $.post( ajaxurl, callback_ajax_args, reorder_ajax_callback );
36
  } else {
37
-
38
  $('#loading-animation').hide();
39
  }
40
  }
41
- };
42
- ui.item.find( 'div.row-content:first' ).append( $loading_animation );
43
-
44
  $loading_animation.show();
45
-
46
  //Get the end items where the post was placed
47
  sort_end.item = ui.item;
48
- sort_end.prev = ui.item.prev( ':not(".placeholder")' );
49
- sort_end.next = ui.item.next( ':not(".placeholder")' );
50
-
51
  //Get starting post parent
52
- var start_post_parent = parseInt( sort_start.item.attr( 'data-parent' ) );
53
-
54
  //Get ending post parent
55
  var end_post_parent = 0;
56
- if( sort_end.prev.length > 0 || sort_end.next.length > 0 ) {
57
- if ( sort_end.prev.length > 0 ) {
58
- end_post_parent = parseInt( sort_end.prev.attr( 'data-parent' ) );
59
- } else if ( sort_end.next.length > 0 ) {
60
- end_post_parent = parseInt( sort_end.next.attr( 'data-parent' ) );
61
- }
62
- } else if ( sort_end.prev.length == 0 && sort_end.next.length == 0 ) {
63
  //We're the only child :(
64
- end_post_parent = ui.item.parents( 'li:first' ).attr( 'data-id' );
65
  }
66
-
67
  //Update post parent in DOM
68
- sort_end.item.attr( 'data-parent', end_post_parent );
69
-
70
-
71
-
72
  //Find the menu order and update dom accordingly
73
  var list_offset = 0;
74
- if( end_post_parent == 0 ) {
75
- var offset = $( '#reorder-offset' ).val();
76
-
77
  //Get index in list order and update dom
78
  list_offset = parseInt(offset) + parseInt(sort_end.item.index());
79
  } else {
80
  list_offset = parseInt(sort_end.item.index());
81
  }
82
- sort_end.item.attr( 'data-menu-order', list_offset );
83
-
84
  //Get attributes
85
  var attributes = {};
86
- $.each( sort_end.item[0].attributes, function() {
87
- attributes [ this.name ] = this.value;
88
- } );
89
-
90
  //Perform Ajax Call
91
  var parent_ajax_args = {
92
  action: reorder_posts.action,
93
  post_parent: end_post_parent,
94
  start: 0,
95
  nonce: reorder_posts.sortnonce,
96
- post_id: sort_end.item.attr( 'data-id' ),
97
- menu_order: sort_end.item.attr( 'data-menu-order' ),
98
  excluded: {},
99
- post_type: sort_start.item.attr( 'data-post-type' ),
100
- attributes: attributes
101
  };
102
  //Determine if we need to sort child nodes - if post_parent ids don't match and there are any remaining child nodes, we need to reorder those
103
- if ( start_post_parent != end_post_parent ) {
104
  //Determine if there are any remaining child nodes
105
  callback = {
106
  action: reorder_posts.action,
@@ -110,43 +107,57 @@ jQuery(document).ready(function($) {
110
  post_id: 0,
111
  menu_order: 0,
112
  excluded: {},
113
- post_type: sort_start.item.attr( 'data-post-type' ),
114
- attributes: attributes
115
  };
116
  }
117
-
118
- $.post( ajaxurl, parent_ajax_args, reorder_ajax_callback );
119
  },
120
- start: function( event, ui ) {
121
  sort_start.item = ui.item;
122
- sort_start.prev = ui.item.prev( ':not(".placeholder")' );
123
- sort_start.next = ui.item.next( ':not(".placeholder")' );
124
- }
125
  });
126
-
127
  function reorder_row_nesting() {
128
  // Add Nesting capabilities
129
- $( '.row-content' ).each( function() {
130
- var parents_count = $( this ).parents( 'ul' ).length;
131
  var padding = 30;
132
- if ( parents_count > 1 ) {
133
  var new_padding = parents_count * 20 + padding;
134
- $( this ).css('padding-left', new_padding + 'px');
135
  } else {
136
- $( this ).css('padding-left', padding + 'px');
137
  }
138
- } );
139
  }
140
-
141
- reorder_row_nesting()
142
-
143
- $( "#post-list .expand span" ).toggle( function() {
144
- $( this ).removeClass( 'dashicons-arrow-right' ).addClass( 'dashicons-arrow-down' );
145
- $( this ).parent().parent().next( '.children' ).fadeIn( "fast" );
146
- return false;
147
- }, function() {
148
- $( this ).removeClass( 'dashicons-arrow-down' ).addClass( 'dashicons-arrow-right' );
149
- $( this ).parent().parent().next( '.children' ).fadeOut( "fast" );
150
- return false;
151
- } );
152
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
  var callback = false;
9
  var sort_start = {};
10
  var sort_end = {};
11
+ postList.nestedSortable({
12
  forcePlaceholderSize: true,
13
  handle: 'div',
14
+ helper: 'clone',
15
  items: 'li',
16
  maxLevels: max_levels,
17
+ opacity: 0.6,
18
  placeholder: 'ui-sortable-placeholder',
19
  revert: 250,
20
  tabSize: 25,
21
  tolerance: 'pointer',
22
  toleranceElement: '> div',
23
  listType: 'ul',
24
+ update: function (event, ui) {
25
  reorder_row_nesting();
26
+ $loading_animation = jQuery('#loading-animation');
27
+ var reorder_ajax_callback = function (response) {
28
+ response = JSON.parse(response);
29
+ if (true == response.more_posts) {
30
+ $.post(ajaxurl, response, reorder_ajax_callback);
31
  } else {
32
+ if (false != callback) {
33
  var callback_ajax_args = callback;
34
  callback = false;
35
+ $.post(ajaxurl, callback_ajax_args, reorder_ajax_callback);
36
  } else {
 
37
  $('#loading-animation').hide();
38
  }
39
  }
40
+ };
41
+ ui.item.find('div.row-content:first').append($loading_animation);
42
+
43
  $loading_animation.show();
44
+
45
  //Get the end items where the post was placed
46
  sort_end.item = ui.item;
47
+ sort_end.prev = ui.item.prev(':not(".placeholder")');
48
+ sort_end.next = ui.item.next(':not(".placeholder")');
49
+
50
  //Get starting post parent
51
+ var start_post_parent = parseInt(sort_start.item.attr('data-parent'));
52
+
53
  //Get ending post parent
54
  var end_post_parent = 0;
55
+ if (sort_end.prev.length > 0 || sort_end.next.length > 0) {
56
+ if (sort_end.prev.length > 0) {
57
+ end_post_parent = parseInt(sort_end.prev.attr('data-parent'));
58
+ } else if (sort_end.next.length > 0) {
59
+ end_post_parent = parseInt(sort_end.next.attr('data-parent'));
60
+ }
61
+ } else if (sort_end.prev.length == 0 && sort_end.next.length == 0) {
62
  //We're the only child :(
63
+ end_post_parent = ui.item.parents('li:first').attr('data-id');
64
  }
65
+
66
  //Update post parent in DOM
67
+ sort_end.item.attr('data-parent', end_post_parent);
68
+
 
 
69
  //Find the menu order and update dom accordingly
70
  var list_offset = 0;
71
+ if (end_post_parent == 0) {
72
+ var offset = $('#reorder-offset').val();
73
+
74
  //Get index in list order and update dom
75
  list_offset = parseInt(offset) + parseInt(sort_end.item.index());
76
  } else {
77
  list_offset = parseInt(sort_end.item.index());
78
  }
79
+ sort_end.item.attr('data-menu-order', list_offset);
80
+
81
  //Get attributes
82
  var attributes = {};
83
+ $.each(sort_end.item[0].attributes, function () {
84
+ attributes[this.name] = this.value;
85
+ });
86
+
87
  //Perform Ajax Call
88
  var parent_ajax_args = {
89
  action: reorder_posts.action,
90
  post_parent: end_post_parent,
91
  start: 0,
92
  nonce: reorder_posts.sortnonce,
93
+ post_id: sort_end.item.attr('data-id'),
94
+ menu_order: sort_end.item.attr('data-menu-order'),
95
  excluded: {},
96
+ post_type: sort_start.item.attr('data-post-type'),
97
+ attributes: attributes,
98
  };
99
  //Determine if we need to sort child nodes - if post_parent ids don't match and there are any remaining child nodes, we need to reorder those
100
+ if (start_post_parent != end_post_parent) {
101
  //Determine if there are any remaining child nodes
102
  callback = {
103
  action: reorder_posts.action,
107
  post_id: 0,
108
  menu_order: 0,
109
  excluded: {},
110
+ post_type: sort_start.item.attr('data-post-type'),
111
+ attributes: attributes,
112
  };
113
  }
114
+
115
+ $.post(ajaxurl, parent_ajax_args, reorder_ajax_callback);
116
  },
117
+ start: function (event, ui) {
118
  sort_start.item = ui.item;
119
+ sort_start.prev = ui.item.prev(':not(".placeholder")');
120
+ sort_start.next = ui.item.next(':not(".placeholder")');
121
+ },
122
  });
123
+
124
  function reorder_row_nesting() {
125
  // Add Nesting capabilities
126
+ $('.row-content').each(function () {
127
+ var parents_count = $(this).parents('ul').length;
128
  var padding = 30;
129
+ if (parents_count > 1) {
130
  var new_padding = parents_count * 20 + padding;
131
+ $(this).css('padding-left', new_padding + 'px');
132
  } else {
133
+ $(this).css('padding-left', padding + 'px');
134
  }
135
+ });
136
  }
137
+
138
+ reorder_row_nesting();
139
+
140
+ $('#post-list .expand span').on('click', function (e) {
141
+ e.preventDefault();
142
+
143
+ var state = $(this).data('state');
144
+
145
+ switch (state) {
146
+ case 1:
147
+ case undefined:
148
+ $(this)
149
+ .removeClass('dashicons-arrow-right')
150
+ .addClass('dashicons-arrow-down');
151
+ $(this).parent().parent().next('.children').fadeIn('fast');
152
+ $(this).data('state', 2);
153
+ break;
154
+ case 2:
155
+ $(this)
156
+ .removeClass('dashicons-arrow-down')
157
+ .addClass('dashicons-arrow-right');
158
+ $(this).parent().parent().next('.children').fadeOut('fast');
159
+ $(this).data('state', 1);
160
+ break;
161
+ }
162
+ });
163
+ });