Post Types Order - Version 1.8.9

Version Description

  • Add Nonce for admin settings
    • Update queries to use prepare
    • Drag & Drop Sortable within Post Type archive interface
    • Code cleanup
    • Set time limit for ajax calls to attempt a code execution extend
Download this release

Release Info

Developer nsp-code
Plugin Icon 128x128 Post Types Order
Version 1.8.9
Comparing to
See all releases

Code changes from version 1.8.7 to 1.8.9

css/cpt-archive-dd.css ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ #the-list.ui-sortable tr:hover { cursor: move;}
2
+ #the-list.ui-sortable tr.alternate { background-color: #F9F9F9; }
3
+ #the-list.ui-sortable tr.ui-sortable-helper { background-color: #ffffff; outline: 1px solid #dfdfdf;}
css/cpt.css CHANGED
@@ -6,7 +6,7 @@
6
  #order-post-type #sortable li.placeholder{border: dashed 2px #ccc;height:18px; background-color: #FFF;}
7
 
8
  #icon-settings {background-image:url("../images/admin-icon-settings.gif");background-repeat:no-repeat;}
9
- h2.subtitle {font-size: 15px; font-style: italic; font-weight: bold}
10
  .wrap .example { color: #666666; font-size: 11px; font-weight: bold}
11
 
12
  #cpto #cpt_info_box {padding: 0 10px; border: 1px dashed #6aadcc; background-color: #FFF; margin-top: 10px;
6
  #order-post-type #sortable li.placeholder{border: dashed 2px #ccc;height:18px; background-color: #FFF;}
7
 
8
  #icon-settings {background-image:url("../images/admin-icon-settings.gif");background-repeat:no-repeat;}
9
+ #cpto h2.subtitle {font-size: 15px; font-style: italic; font-weight: bold; padding-left: 0px}
10
  .wrap .example { color: #666666; font-size: 11px; font-weight: bold}
11
 
12
  #cpto #cpt_info_box {padding: 0 10px; border: 1px dashed #6aadcc; background-color: #FFF; margin-top: 10px;
include/cpto-class.php CHANGED
@@ -6,15 +6,70 @@
6
 
7
  function __construct()
8
  {
9
- add_action( 'admin_init', array(&$this, 'registerFiles'), 11 );
10
- add_action( 'admin_init', array(&$this, 'checkPost'), 10 );
11
- add_action( 'admin_menu', array(&$this, 'addMenu') );
12
 
 
 
13
 
14
-
15
- add_action( 'wp_ajax_update-custom-type-order', array(&$this, 'saveAjaxOrder') );
16
  }
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  function registerFiles()
19
  {
20
  if ( $this->current_post_type != null )
@@ -39,8 +94,16 @@
39
  }
40
  }
41
 
 
 
 
 
 
42
  function saveAjaxOrder()
43
  {
 
 
 
44
  global $wpdb;
45
 
46
  parse_str($_POST['order'], $data);
@@ -70,6 +133,68 @@
70
  }
71
  }
72
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
 
75
  function addMenu()
6
 
7
  function __construct()
8
  {
9
+ add_action( 'admin_init', array(&$this, 'registerFiles'), 11 );
10
+ add_action( 'admin_init', array(&$this, 'checkPost'), 10 );
11
+ add_action( 'admin_menu', array(&$this, 'addMenu') );
12
 
13
+ //load archive drag&drop sorting dependencies
14
+ add_action( 'admin_enqueue_scripts', array(&$this, 'archiveDragDrop'), 10 );
15
 
16
+ add_action( 'wp_ajax_update-custom-type-order', array(&$this, 'saveAjaxOrder') );
17
+ add_action( 'wp_ajax_update-custom-type-order-archive', array(&$this, 'saveArchiveAjaxOrder') );
18
  }
19
 
20
+
21
+ /**
22
+ * Load archive drag&drop sorting dependencies
23
+ *
24
+ * Since version 1.8.8
25
+ */
26
+ function archiveDragDrop()
27
+ {
28
+ $options = cpt_get_options();
29
+
30
+ //if functionality turned off, continue
31
+ if( $options['archive_drag_drop'] != '1')
32
+ return;
33
+
34
+ //if adminsort turned off no need to continue
35
+ if( $options['adminsort'] != '1')
36
+ return;
37
+
38
+ $screen = get_current_screen();
39
+
40
+ //check if the right interface
41
+ if(!isset($screen->post_type) || empty($screen->post_type))
42
+ return;
43
+
44
+ //check if post type is sortable
45
+ if(isset($options['show_reorder_interfaces'][$screen->post_type]) && $options['show_reorder_interfaces'][$screen->post_type] != 'show')
46
+ return;
47
+
48
+ //if is taxonomy term filter return
49
+ if(is_category() || is_tax())
50
+ return;
51
+
52
+ //return if use orderby columns
53
+ if (isset($_GET['orderby']) && $_GET['orderby'] != 'menu_order')
54
+ return false;
55
+
56
+ //return if post status filtering
57
+ if (isset($_GET['post_status']))
58
+ return false;
59
+
60
+ //return if post author filtering
61
+ if (isset($_GET['author']))
62
+ return false;
63
+
64
+ //load required dependencies
65
+ wp_enqueue_style('cpt-archive-dd', CPTURL . '/css/cpt-archive-dd.css');
66
+
67
+ wp_enqueue_script('jquery');
68
+ wp_enqueue_script('jquery-ui-sortable');
69
+ wp_enqueue_script('cpt', CPTURL . '/js/cpt.js', array('jquery'));
70
+
71
+ }
72
+
73
  function registerFiles()
74
  {
75
  if ( $this->current_post_type != null )
94
  }
95
  }
96
 
97
+
98
+ /**
99
+ * Save the order set through separate interface
100
+ *
101
+ */
102
  function saveAjaxOrder()
103
  {
104
+
105
+ set_time_limit(600);
106
+
107
  global $wpdb;
108
 
109
  parse_str($_POST['order'], $data);
133
  }
134
  }
135
  }
136
+
137
+
138
+ /**
139
+ * Save the order set throgh the Archive
140
+ *
141
+ */
142
+ function saveArchiveAjaxOrder()
143
+ {
144
+
145
+ set_time_limit(600);
146
+
147
+ global $wpdb;
148
+
149
+ $post_type = filter_var ( $_POST['post_type'], FILTER_SANITIZE_STRING);
150
+ $paged = filter_var ( $_POST['paged'], FILTER_SANITIZE_NUMBER_INT);
151
+ parse_str($_POST['order'], $data);
152
+
153
+ if (!is_array($data) || count($data) < 1)
154
+ die();
155
+
156
+ //retrieve a list of all objects
157
+ $mysql_query = $wpdb->prepare("SELECT ID FROM ". $wpdb->posts ."
158
+ WHERE post_type = %s AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
159
+ ORDER BY menu_order, post_date DESC", $post_type);
160
+ $results = $wpdb->get_results($mysql_query);
161
+
162
+ if (!is_array($results) || count($results) < 1)
163
+ die();
164
+
165
+ //create the list of ID's
166
+ $objects_ids = array();
167
+ foreach($results as $result)
168
+ {
169
+ $objects_ids[] = $result->ID;
170
+ }
171
+
172
+ global $userdata;
173
+ $objects_per_page = get_user_meta($userdata->ID ,'edit_post_per_page', TRUE);
174
+
175
+ $edit_start_at = $paged * $objects_per_page - $objects_per_page;
176
+ $index = 0;
177
+ for($i = $edit_start_at; $i < ($edit_start_at + $objects_per_page); $i++)
178
+ {
179
+ if(!isset($objects_ids[$i]))
180
+ break;
181
+
182
+ $objects_ids[$i] = $data['post'][$index];
183
+ $index++;
184
+ }
185
+
186
+ //update the menu_order within database
187
+ foreach( $objects_ids as $menu_order => $id )
188
+ {
189
+ $data = array(
190
+ 'menu_order' => $menu_order
191
+ );
192
+ $data = apply_filters('post-types-order_save-ajax-order', $data, $menu_order, $id);
193
+
194
+ $wpdb->update( $wpdb->posts, $data, array('ID' => $id) );
195
+ }
196
+
197
+ }
198
 
199
 
200
  function addMenu()
include/functions.php CHANGED
@@ -36,6 +36,7 @@
36
  'show_reorder_interfaces' => array(),
37
  'autosort' => 1,
38
  'adminsort' => 1,
 
39
  'capability' => 'install_plugins',
40
  'navigation_sort_apply' => 1,
41
 
@@ -83,13 +84,22 @@
83
  </div>
84
 
85
  <div id="donate_form">
86
- <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
87
- <input type="hidden" name="cmd" value="_s-xclick">
88
- <input type="hidden" name="hosted_button_id" value="CU22TFDKJMLAE">
89
- <input type="hidden" name="custom" value="PostTypesOrder">
90
- <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
91
- <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
 
 
 
 
 
 
 
 
92
  </form>
 
93
  </div>
94
  </div>
95
 
36
  'show_reorder_interfaces' => array(),
37
  'autosort' => 1,
38
  'adminsort' => 1,
39
+ 'archive_drag_drop' => 1,
40
  'capability' => 'install_plugins',
41
  'navigation_sort_apply' => 1,
42
 
84
  </div>
85
 
86
  <div id="donate_form">
87
+ <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
88
+ <input type="hidden" name="cmd" value="_donations">
89
+ <input type="hidden" name="business" value="electronice_delphi@yahoo.com">
90
+ <input type="hidden" name="lc" value="RO">
91
+ <input type="hidden" name="item_name" value="Nsp-Code">
92
+ <input type="hidden" name="item_number" value="post-types-order">
93
+ <input type="hidden" name="no_note" value="0">
94
+ <input type="hidden" name="cn" value="Add special instructions to the seller:">
95
+ <input type="hidden" name="no_shipping" value="2">
96
+ <input type="hidden" name="cancel_return" value="http://nsp-code.com/donate.php">
97
+ <input type="hidden" name="currency_code" value="USD">
98
+ <input type="hidden" name="bn" value="PP-DonationsBF:btn_donateCC_LG.gif:NonHosted">
99
+ <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
100
+ <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
101
  </form>
102
+
103
  </div>
104
  </div>
105
 
include/options.php CHANGED
@@ -5,8 +5,9 @@ function cpt_plugin_options()
5
  {
6
  $options = cpt_get_options();
7
 
8
- if (isset($_POST['form_submit']))
9
  {
 
10
  $options['show_reorder_interfaces'] = (array) $_POST['show_reorder_interfaces'];
11
  $options['show_reorder_interfaces'] = array_map( 'sanitize_key', $options['show_reorder_interfaces'] );
12
 
@@ -14,6 +15,7 @@ function cpt_plugin_options()
14
 
15
  $options['autosort'] = isset($_POST['autosort']) ? intval($_POST['autosort']) : '';
16
  $options['adminsort'] = isset($_POST['adminsort']) ? intval($_POST['adminsort']) : '';
 
17
 
18
  $options['navigation_sort_apply'] = isset($_POST['navigation_sort_apply']) ? intval($_POST['navigation_sort_apply']) : '';
19
 
@@ -26,114 +28,123 @@ function cpt_plugin_options()
26
 
27
  $queue_data = get_option('ce_queue');
28
 
29
- ?>
30
- <div id="cpto" class="wrap">
31
- <div id="icon-settings" class="icon32"></div>
32
- <h2><?php _e('General Settings', 'post-types-order') ?></h2>
33
-
34
- <?php cpt_info_box(); ?>
35
-
36
- <form id="form_data" name="form" method="post">
37
- <br />
38
- <h2 class="subtitle"><?php _e('General', 'post-types-order') ?></h2>
39
- <table class="form-table">
40
- <tbody>
41
- <tr valign="top">
42
- <th scope="row" style="text-align: right;"><label><?php _e('Show / Hide re-order interface', 'post-types-order') ?></label></th>
43
- <td>
44
- <?php
45
-
46
- $post_types = get_post_types();
47
- foreach( $post_types as $post_type_name )
48
- {
49
- //ignore list
50
- $ignore_post_types = array(
51
- 'reply',
52
- 'topic',
53
- 'report',
54
- 'status'
55
- );
56
-
57
- if(in_array($post_type_name, $ignore_post_types))
58
- continue;
59
-
60
- if(is_post_type_hierarchical($post_type_name))
61
- continue;
62
-
63
- $post_type_data = get_post_type_object( $post_type_name );
64
- if($post_type_data->show_ui === FALSE)
65
- continue;
66
- ?>
67
- <p><label>
68
- <select name="show_reorder_interfaces[<?php echo $post_type_name ?>]">
69
- <option value="show" <?php if(isset($options['show_reorder_interfaces'][$post_type_name]) && $options['show_reorder_interfaces'][$post_type_name] == 'show') {echo ' selected="selected"';} ?>><?php _e( "Show", 'post-types-order' ) ?></option>
70
- <option value="hide" <?php if(isset($options['show_reorder_interfaces'][$post_type_name]) && $options['show_reorder_interfaces'][$post_type_name] == 'hide') {echo ' selected="selected"';} ?>><?php _e( "Hide", 'post-types-order' ) ?></option>
71
- </select> &nbsp;&nbsp;<?php echo $post_type_data->labels->singular_name ?>
72
- </label><br />&nbsp;</p>
73
- <?php } ?>
74
- </td>
75
- </tr>
76
- <tr valign="top">
77
- <th scope="row" style="text-align: right;"><label><?php _e('Minimum Level to use this plugin', 'post-types-order') ?></label></th>
78
- <td>
79
- <select id="role" name="capability">
80
- <option value="read" <?php if (isset($options['capability']) && $options['capability'] == "read") echo 'selected="selected"'?>><?php _e('Subscriber', 'post-types-order') ?></option>
81
- <option value="edit_posts" <?php if (isset($options['capability']) && $options['capability'] == "edit_posts") echo 'selected="selected"'?>><?php _e('Contributor', 'post-types-order') ?></option>
82
- <option value="publish_posts" <?php if (isset($options['capability']) && $options['capability'] == "publish_posts") echo 'selected="selected"'?>><?php _e('Author', 'post-types-order') ?></option>
83
- <option value="publish_pages" <?php if (isset($options['capability']) && $options['capability'] == "publish_pages") echo 'selected="selected"'?>><?php _e('Editor', 'post-types-order') ?></option>
84
- <option value="switch_themes" <?php if (!isset($options['capability']) || empty($options['capability']) || (isset($options['capability']) && $options['capability'] == "switch_themes")) echo 'selected="selected"'?>><?php _e('Administrator', 'post-types-order') ?></option>
85
- </select>
86
- </td>
87
- </tr>
88
-
89
- <tr valign="top">
90
- <th scope="row" style="text-align: right;"><label for="autosort"><?php _e('Auto Sort', 'post-types-order') ?></label></th>
91
- <td>
92
- <p><input type="checkbox" <?php if ($options['autosort'] == "1") {echo ' checked="checked"';} ?> id="autosort" value="1" name="autosort"> <?php _e("If checked, the plug-in automatically update the WordPress queries to use the new order (<b>No code update is necessarily</b>)", 'post-types-order'); ?></p>
93
- <p class="description"><?php _e("If only certain queries need to use the custom sort, keep this unchecked and include 'orderby' => 'menu_order' into query parameters", 'post-types-order') ?>.
94
- <br />
95
- <a href="http://www.nsp-code.com/sample-code-on-how-to-apply-the-sort-for-post-types-order-plugin/" target="_blank"><?php _e('Additional Description and Examples', 'post-types-order') ?></a></p>
96
-
97
- </td>
98
- </tr>
99
-
100
-
101
- <tr valign="top">
102
- <th scope="row" style="text-align: right;"><label for="adminsort"><?php _e('Admin Sort', 'post-types-order') ?></label></th>
103
- <td>
104
- <p>
105
- <input type="checkbox" <?php if ($options['adminsort'] == "1") {echo ' checked="checked"';} ?> id="adminsort" value="1" name="adminsort">
106
- <?php _e("To affect the admin interface, to see the post types per your new sort, this need to be checked", 'post-types-order') ?>.</p>
107
- </td>
108
- </tr>
109
 
110
- <tr valign="top">
111
- <th scope="row" style="text-align: right;"><label for="navigation_sort_apply"><?php _e('Next / Previous Apply', 'post-types-order') ?></label></th>
112
- <td>
113
- <p>
114
- <input type="checkbox" <?php if ($options['navigation_sort_apply'] == "1") {echo ' checked="checked"';} ?> id="navigation_sort_apply" value="1" name="navigation_sort_apply">
115
- <?php _e("Apply the sort on Next / Previous site-wide navigation.", 'post-types-order') ?> <?php _e('This can also be controlled through', 'post-types-order') ?> <a href="http://www.nsp-code.com/apply-custom-sorting-for-next-previous-site-wide-navigation/" target="_blank"><?php _e('code', 'post-types-order') ?></a></p>
116
- </td>
117
- </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
- </tbody>
120
- </table>
121
-
122
- <p class="submit">
123
- <input type="submit" name="Submit" class="button-primary" value="<?php
124
- _e('Save Settings', 'post-types-order') ?>">
125
- </p>
126
-
127
- <input type="hidden" name="form_submit" value="true" />
 
 
 
128
 
 
 
 
 
 
 
 
 
129
 
130
- </form>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
 
132
- <br />
133
-
134
- <?php
135
- echo '</div>';
136
-
137
 
138
  }
139
 
5
  {
6
  $options = cpt_get_options();
7
 
8
+ if (isset($_POST['form_submit']) && wp_verify_nonce($_POST['cpto_form_nonce'],'cpto_form_submit'))
9
  {
10
+
11
  $options['show_reorder_interfaces'] = (array) $_POST['show_reorder_interfaces'];
12
  $options['show_reorder_interfaces'] = array_map( 'sanitize_key', $options['show_reorder_interfaces'] );
13
 
15
 
16
  $options['autosort'] = isset($_POST['autosort']) ? intval($_POST['autosort']) : '';
17
  $options['adminsort'] = isset($_POST['adminsort']) ? intval($_POST['adminsort']) : '';
18
+ $options['archive_drag_drop'] = isset($_POST['archive_drag_drop']) ? intval($_POST['archive_drag_drop']) : '';
19
 
20
  $options['navigation_sort_apply'] = isset($_POST['navigation_sort_apply']) ? intval($_POST['navigation_sort_apply']) : '';
21
 
28
 
29
  $queue_data = get_option('ce_queue');
30
 
31
+ ?>
32
+ <div id="cpto" class="wrap">
33
+ <div id="icon-settings" class="icon32"></div>
34
+ <h2><?php _e('General Settings', 'post-types-order') ?></h2>
35
+
36
+ <?php cpt_info_box(); ?>
37
+
38
+ <form id="form_data" name="form" method="post">
39
+ <br />
40
+ <h2 class="subtitle"><?php _e('General', 'post-types-order') ?></h2>
41
+ <table class="form-table">
42
+ <tbody>
43
+ <tr valign="top">
44
+ <th scope="row" style="text-align: right;"><label><?php _e('Show / Hide re-order interface', 'post-types-order') ?></label></th>
45
+ <td>
46
+ <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
+ $post_types = get_post_types();
49
+ foreach( $post_types as $post_type_name )
50
+ {
51
+ //ignore list
52
+ $ignore_post_types = array(
53
+ 'reply',
54
+ 'topic',
55
+ 'report',
56
+ 'status'
57
+ );
58
+
59
+ if(in_array($post_type_name, $ignore_post_types))
60
+ continue;
61
+
62
+ if(is_post_type_hierarchical($post_type_name))
63
+ continue;
64
+
65
+ $post_type_data = get_post_type_object( $post_type_name );
66
+ if($post_type_data->show_ui === FALSE)
67
+ continue;
68
+ ?>
69
+ <p><label>
70
+ <select name="show_reorder_interfaces[<?php echo $post_type_name ?>]">
71
+ <option value="show" <?php if(isset($options['show_reorder_interfaces'][$post_type_name]) && $options['show_reorder_interfaces'][$post_type_name] == 'show') {echo ' selected="selected"';} ?>><?php _e( "Show", 'post-types-order' ) ?></option>
72
+ <option value="hide" <?php if(isset($options['show_reorder_interfaces'][$post_type_name]) && $options['show_reorder_interfaces'][$post_type_name] == 'hide') {echo ' selected="selected"';} ?>><?php _e( "Hide", 'post-types-order' ) ?></option>
73
+ </select> &nbsp;&nbsp;<?php echo $post_type_data->labels->singular_name ?>
74
+ </label><br />&nbsp;</p>
75
+ <?php } ?>
76
+ </td>
77
+ </tr>
78
+ <tr valign="top">
79
+ <th scope="row" style="text-align: right;"><label><?php _e('Minimum Level to use this plugin', 'post-types-order') ?></label></th>
80
+ <td>
81
+ <select id="role" name="capability">
82
+ <option value="read" <?php if (isset($options['capability']) && $options['capability'] == "read") echo 'selected="selected"'?>><?php _e('Subscriber', 'post-types-order') ?></option>
83
+ <option value="edit_posts" <?php if (isset($options['capability']) && $options['capability'] == "edit_posts") echo 'selected="selected"'?>><?php _e('Contributor', 'post-types-order') ?></option>
84
+ <option value="publish_posts" <?php if (isset($options['capability']) && $options['capability'] == "publish_posts") echo 'selected="selected"'?>><?php _e('Author', 'post-types-order') ?></option>
85
+ <option value="publish_pages" <?php if (isset($options['capability']) && $options['capability'] == "publish_pages") echo 'selected="selected"'?>><?php _e('Editor', 'post-types-order') ?></option>
86
+ <option value="switch_themes" <?php if (!isset($options['capability']) || empty($options['capability']) || (isset($options['capability']) && $options['capability'] == "switch_themes")) echo 'selected="selected"'?>><?php _e('Administrator', 'post-types-order') ?></option>
87
+ </select>
88
+ </td>
89
+ </tr>
90
+
91
+ <tr valign="top">
92
+ <th scope="row" style="text-align: right;"><label for="autosort"><?php _e('Auto Sort', 'post-types-order') ?></label></th>
93
+ <td>
94
+ <p><input type="checkbox" <?php checked( '1', $options['autosort'] ); ?> id="autosort" value="1" name="autosort"> <?php _e("If checked, the plug-in automatically update the WordPress queries to use the new order (<b>No code update is necessarily</b>)", 'post-types-order'); ?></p>
95
+ <p class="description"><?php _e("If only certain queries need to use the custom sort, keep this unchecked and include 'orderby' => 'menu_order' into query parameters", 'post-types-order') ?>.
96
+ <br />
97
+ <a href="http://www.nsp-code.com/sample-code-on-how-to-apply-the-sort-for-post-types-order-plugin/" target="_blank"><?php _e('Additional Description and Examples', 'post-types-order') ?></a></p>
98
 
99
+ </td>
100
+ </tr>
101
+
102
+
103
+ <tr valign="top">
104
+ <th scope="row" style="text-align: right;"><label for="adminsort"><?php _e('Admin Sort', 'post-types-order') ?></label></th>
105
+ <td>
106
+ <p>
107
+ <input type="checkbox" <?php checked( '1', $options['adminsort'] ); ?> id="adminsort" value="1" name="adminsort">
108
+ <?php _e("To affect the admin interface, to see the post types per your new sort, this need to be checked", 'post-types-order') ?>.</p>
109
+ </td>
110
+ </tr>
111
 
112
+ <tr valign="top">
113
+ <th scope="row" style="text-align: right;"><label for="archive_drag_drop"><?php _e('Archive Drag&Drop ', 'post-types-order') ?></label></th>
114
+ <td>
115
+ <p>
116
+ <input type="checkbox" <?php checked( '1', $options['archive_drag_drop'] ); ?> id="archive_drag_drop" value="1" name="archive_drag_drop">
117
+ <?php _e("Allow sortable drag & drop functionality within default WordPress post type archive. Admin Sort need to be active.", 'post-types-order') ?>.</p>
118
+ </td>
119
+ </tr>
120
 
121
+ <tr valign="top">
122
+ <th scope="row" style="text-align: right;"><label for="navigation_sort_apply"><?php _e('Next / Previous Apply', 'post-types-order') ?></label></th>
123
+ <td>
124
+ <p>
125
+ <input type="checkbox" <?php checked( '1', $options['navigation_sort_apply'] ); ?> id="navigation_sort_apply" value="1" name="navigation_sort_apply">
126
+ <?php _e("Apply the sort on Next / Previous site-wide navigation.", 'post-types-order') ?> <?php _e('This can also be controlled through', 'post-types-order') ?> <a href="http://www.nsp-code.com/apply-custom-sorting-for-next-previous-site-wide-navigation/" target="_blank"><?php _e('code', 'post-types-order') ?></a></p>
127
+ </td>
128
+ </tr>
129
+
130
+ </tbody>
131
+ </table>
132
+
133
+ <p class="submit">
134
+ <input type="submit" name="Submit" class="button-primary" value="<?php
135
+ _e('Save Settings', 'post-types-order') ?>">
136
+ </p>
137
+
138
+
139
+ <?php wp_nonce_field('cpto_form_submit','cpto_form_nonce'); ?>
140
+ <input type="hidden" name="form_submit" value="true" />
141
+
142
+
143
+ </form>
144
 
145
+ <br />
146
+ </div>
147
+ <?php
 
 
148
 
149
  }
150
 
js/cpt.js ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ var getUrlParameter = function getUrlParameter(sParam) {
4
+ var sPageURL = decodeURIComponent(window.location.search.substring(1)),
5
+ sURLVariables = sPageURL.split('&'),
6
+ sParameterName,
7
+ i;
8
+
9
+ for (i = 0; i < sURLVariables.length; i++) {
10
+ sParameterName = sURLVariables[i].split('=');
11
+
12
+ if (sParameterName[0] === sParam) {
13
+ return sParameterName[1] === undefined ? true : sParameterName[1];
14
+ }
15
+ }
16
+ };
17
+
18
+ jQuery(document).ready(function()
19
+ {
20
+
21
+ jQuery('table.posts #the-list').sortable({
22
+ 'items': 'tr',
23
+ 'axis': 'y',
24
+ 'update' : function(e, ui) {
25
+
26
+ var post_type = jQuery('input[name="post_type"]').val();
27
+ var order = jQuery('#the-list').sortable('serialize');
28
+
29
+ var paged = getUrlParameter('paged');
30
+ if(typeof paged === 'undefined')
31
+ paged = 1;
32
+
33
+ var queryString = { "action": "update-custom-type-order-archive", "post_type" : post_type, "order" : order ,"paged": paged};
34
+ //send the data through ajax
35
+ jQuery.ajax({
36
+ type: 'POST',
37
+ url: ajaxurl,
38
+ data: queryString,
39
+ cache: false,
40
+ dataType: "html",
41
+ success: function(data){
42
+
43
+ },
44
+ error: function(html){
45
+
46
+ }
47
+ });
48
+
49
+ }
50
+ });
51
+
52
+
53
+ });
post-types-order.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.nsp-code.com
5
  Description: Posts Order and Post Types Objects Order using a Drag and Drop Sortable javascript capability
6
  Author: Nsp Code
7
  Author URI: http://www.nsp-code.com
8
- Version: 1.8.7
9
  Text Domain: post-types-order
10
  Domain Path: /languages/
11
  */
@@ -269,14 +269,14 @@ Domain Path: /languages/
269
 
270
  $current_menu_order = $post->menu_order;
271
 
272
- $query = "SELECT p.* FROM $wpdb->posts AS p
273
  $_join
274
- WHERE p.post_date < '". $post->post_date ."' AND p.menu_order = '".$current_menu_order."' AND p.post_type = '". $post->post_type ."' AND p.post_status = 'publish' $_where";
275
  $results = $wpdb->get_results($query);
276
 
277
  if (count($results) > 0)
278
  {
279
- $where .= " AND p.menu_order = '".$current_menu_order."'";
280
  }
281
  else
282
  {
@@ -349,14 +349,14 @@ Domain Path: /languages/
349
  $current_menu_order = $post->menu_order;
350
 
351
  //check if there are more posts with lower menu_order
352
- $query = "SELECT p.* FROM $wpdb->posts AS p
353
  $_join
354
- WHERE p.post_date > '". $post->post_date ."' AND p.menu_order = '".$current_menu_order."' AND p.post_type = '". $post->post_type ."' AND p.post_status = 'publish' $_where";
355
  $results = $wpdb->get_results($query);
356
 
357
  if (count($results) > 0)
358
  {
359
- $where .= " AND p.menu_order = '".$current_menu_order."'";
360
  }
361
  else
362
  {
5
  Description: Posts Order and Post Types Objects Order using a Drag and Drop Sortable javascript capability
6
  Author: Nsp Code
7
  Author URI: http://www.nsp-code.com
8
+ Version: 1.8.9
9
  Text Domain: post-types-order
10
  Domain Path: /languages/
11
  */
269
 
270
  $current_menu_order = $post->menu_order;
271
 
272
+ $query = $wpdb->prepare( "SELECT p.* FROM $wpdb->posts AS p
273
  $_join
274
+ WHERE p.post_date < %s AND p.menu_order = %d AND p.post_type = %s AND p.post_status = 'publish' $_where" , $post->post_date, $current_menu_order, $post->post_type);
275
  $results = $wpdb->get_results($query);
276
 
277
  if (count($results) > 0)
278
  {
279
+ $where .= $wpdb->prepare( " AND p.menu_order = %d". $current_menu_order );
280
  }
281
  else
282
  {
349
  $current_menu_order = $post->menu_order;
350
 
351
  //check if there are more posts with lower menu_order
352
+ $query = $wpdb->prepare( "SELECT p.* FROM $wpdb->posts AS p
353
  $_join
354
+ WHERE p.post_date > %s AND p.menu_order = %d AND p.post_type = %s AND p.post_status = 'publish' $_where", $post->post_date, $current_menu_order, $post->post_type );
355
  $results = $wpdb->get_results($query);
356
 
357
  if (count($results) > 0)
358
  {
359
+ $where .= $wpdb->prepare(" AND p.menu_order = %d", $current_menu_order );
360
  }
361
  else
362
  {
readme.txt CHANGED
@@ -3,16 +3,16 @@ Contributors: nsp-code
3
  Donate link: http://www.nsp-code.com/donate.php
4
  Tags: post order, posts order, sort, post sort, posts sort, post type order, custom order, admin posts order
5
  Requires at least: 2.8
6
- Tested up to: 4.5
7
- Stable tag: 1.8.7
8
 
9
- Post Order and custom Post Type Objects (posts, any custom post types) using a Drag and Drop Sortable JavaScript AJAX interface.
10
 
11
  == Description ==
12
 
13
- <strong>Over 1.500.000 DOWNLOADS and near PERFECT ratting out of 150 REVIEWS</strong>. <br />
14
- A powerful plugin, Order Posts and Post Types Objects using a Drag and Drop Sortable JavaScript capability.
15
- It allow to reorder the posts for any custom post types you defined, including the default Posts. Also you can have the admin posts interface sorted per your new sort. Post Order has never been easier.
16
 
17
  = Usage =
18
  This was built considering for everyone to be able to use no matter the WordPress experience, so it's very easy:
@@ -54,7 +54,11 @@ Feel free to contact us at electronice_delphi@yahoo.com
54
 
55
  = I have no PHP knowledge at all, i will still be able to use this plugin? =
56
 
57
- Absolutely you can! Unlike many other plugins, you don't have to do any code changes to make your post order to change accordingly to custom defined post order. There is an option to autoupdate the WordPress queries so the posts order will be returned in the required order. Anyway this can be turned off to allow customized code usage.
 
 
 
 
58
 
59
  = What kind of posts/pages this plugin allow me to sort? =
60
 
@@ -82,6 +86,14 @@ Consider upgrading to our advanced version of this plugin at a very resonable pr
82
 
83
 
84
  == Change Log ==
 
 
 
 
 
 
 
 
85
  = 1.8.7 =
86
  - Admin Post / Page Gallery items order fix
87
  - New filter pto/posts_orderby to ignore sort apply
@@ -231,6 +243,5 @@ Make sure you get the latest version.
231
 
232
  == Localization ==
233
 
234
- Available in English, Brazilian Portuguese, Spanish, Romanian, Italian, Dusth, Hebrew, German, Norwegian (norsk), Turkish (t?rk?e), Swedish, Hungarian, Portuguese, Chinese, Czech
235
  Want to contribute with a translation to your language? Please check at https://translate.wordpress.org/projects/wp-plugins/post-types-order
236
  http://www.nsp-code.com
3
  Donate link: http://www.nsp-code.com/donate.php
4
  Tags: post order, posts order, sort, post sort, posts sort, post type order, custom order, admin posts order
5
  Requires at least: 2.8
6
+ Tested up to: 4.5.2
7
+ Stable tag: 1.8.9
8
 
9
+ Post Order and custom Post Type Objects (posts, any custom post types) using a Drag and Drop Sortable JavaScript AJAX interface or within default WordPress post type archive.
10
 
11
  == Description ==
12
 
13
+ <strong>Over 1.700.000 DOWNLOADS and near PERFECT rating out of 150 REVIEWS</strong>. <br />
14
+ A powerful plugin, Order Posts and Post Types Objects using a Drag and Drop Sortable JavaScript capability. The order can be customized within default WordPress post type archive list page or a separate Re-Order interface which display all objects.
15
+ It allow to reorder the posts for any custom post types you defined, including the default Posts. Also you can display the posts within admin interface sorted per your new sort. Post Order has never been easier.
16
 
17
  = Usage =
18
  This was built considering for everyone to be able to use no matter the WordPress experience, so it's very easy:
54
 
55
  = I have no PHP knowledge at all, i will still be able to use this plugin? =
56
 
57
+ Absolutely you can! Unlike many other plugins, you don't have to do any code changes to make your post order to change accordingly to custom defined post order. There is an option to autoupdate the WordPress queries so the posts order will be returned in the required order. Anyway this can be turned off (Autosort) to allow customized code usage.
58
+
59
+ = How to manually apply the sort on queries =
60
+
61
+ Include a 'orderby' => 'menu_order' property within your custom query.
62
 
63
  = What kind of posts/pages this plugin allow me to sort? =
64
 
86
 
87
 
88
  == Change Log ==
89
+
90
+ = 1.8.9 =
91
+ - Add Nonce for admin settings
92
+ - Update queries to use prepare
93
+ - Drag & Drop Sortable within Post Type archive interface
94
+ - Code cleanup
95
+ - Set time limit for ajax calls to attempt a code execution extend
96
+
97
  = 1.8.7 =
98
  - Admin Post / Page Gallery items order fix
99
  - New filter pto/posts_orderby to ignore sort apply
243
 
244
  == Localization ==
245
 
 
246
  Want to contribute with a translation to your language? Please check at https://translate.wordpress.org/projects/wp-plugins/post-types-order
247
  http://www.nsp-code.com
screenshot-1.png CHANGED
Binary file
screenshot-2.png ADDED
Binary file