Version Description
- Released 2019-02-16
- Added query to reorder posts for an example
- Option to turn off query output
Download this release
Release Info
Developer | ronalfy |
Plugin | Reorder Posts |
Version | 2.4.1 |
Comparing to | |
See all releases |
Code changes from version 2.4.0 to 2.4.1
- class-reorder-admin.php +114 -85
- class-reorder.php +92 -67
- index.php +11 -12
- readme.txt +22 -11
class-reorder-admin.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Reorder posts
|
4 |
-
*
|
5 |
* @package WordPress
|
6 |
* @subpackage Metronet Reorder Posts plugin
|
7 |
*/
|
@@ -10,23 +10,23 @@
|
|
10 |
/**
|
11 |
* Reorder posts
|
12 |
* Adds drag and drop editor for reordering WordPress posts
|
13 |
-
*
|
14 |
* This class is self-instantiated and should not be used directly
|
15 |
-
*
|
16 |
* @license http://www.gnu.org/licenses/gpl.html GPL
|
17 |
* @author Ronald Huereca
|
18 |
* @since 2.0.0
|
19 |
*/
|
20 |
class MN_Reorder_Admin {
|
21 |
/**
|
22 |
-
* @var $instance
|
23 |
* @desc Instance of the admin class
|
24 |
* @access private
|
25 |
*/
|
26 |
private static $instance = null;
|
27 |
-
|
28 |
/**
|
29 |
-
* @var $options
|
30 |
* @desc WordPress options for access within this class
|
31 |
* @access private
|
32 |
*/
|
@@ -34,10 +34,10 @@ class MN_Reorder_Admin {
|
|
34 |
|
35 |
/**
|
36 |
* Class constructor
|
37 |
-
*
|
38 |
* Sets definitions
|
39 |
* Adds methods to appropriate hooks
|
40 |
-
*
|
41 |
* @author Ronald Huereca
|
42 |
* @since Reorder 1.1
|
43 |
* @access private
|
@@ -45,20 +45,20 @@ class MN_Reorder_Admin {
|
|
45 |
private function __construct( ) {
|
46 |
//Filter to hide the admin panel options
|
47 |
if ( !apply_filters( 'metronet_reorder_post_allow_admin', true ) ) return; //Use this filter if you want to disable the admin panel settings for this plugin, including disabling the menu order overrides
|
48 |
-
|
49 |
//Initialize actions
|
50 |
/* Dev note: If you know what you're doing code-wise, add the menu_order in get_posts, pre_get_posts, or WP_Query, disable these filters, and/or disable the admin settings (see above). */
|
51 |
add_filter( 'posts_orderby', array( $this, 'modify_menu_order_sql' ), 30, 2 );
|
52 |
add_action( 'pre_get_posts', array( $this, 'modify_menu_order_pre' ), 30, 1 );
|
53 |
-
|
54 |
//Admin Settings
|
55 |
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
|
56 |
add_action( 'admin_init', array( $this, 'init_admin_settings' ) );
|
57 |
-
|
58 |
//Plugin settings
|
59 |
add_filter( 'plugin_action_links_' . REORDER_BASENAME , array( $this, 'add_settings_link' ) );
|
60 |
}
|
61 |
-
|
62 |
//Singleton
|
63 |
public static function get_instance() {
|
64 |
if ( null == self::$instance ) {
|
@@ -66,7 +66,7 @@ class MN_Reorder_Admin {
|
|
66 |
}
|
67 |
return self::$instance;
|
68 |
} //end get_instance
|
69 |
-
|
70 |
/**
|
71 |
* Initialize options page
|
72 |
*
|
@@ -77,11 +77,35 @@ class MN_Reorder_Admin {
|
|
77 |
*
|
78 |
* @see init
|
79 |
*
|
80 |
-
*/
|
81 |
public function add_admin_menu() {
|
82 |
add_options_page( _x( 'Reorder Posts', 'Plugin Name - Settings Page Title', 'metronet-reorder-posts' ), _x( 'Reorder Posts', 'Plugin Name - Menu Item', 'metronet-reorder-posts' ), 'manage_options', 'metronet-reorder-posts', array( $this, 'options_page' ) );
|
83 |
}
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
/**
|
86 |
* Add post types to be overridden using menu_order
|
87 |
*
|
@@ -92,9 +116,9 @@ class MN_Reorder_Admin {
|
|
92 |
*
|
93 |
* @see init_admin_settings
|
94 |
*
|
95 |
-
* @param array $args {
|
96 |
@type string $desc Description for the setting.
|
97 |
-
|
98 |
}
|
99 |
*/
|
100 |
public function add_settings_field_menu_order( $args = array() ) {
|
@@ -102,30 +126,30 @@ class MN_Reorder_Admin {
|
|
102 |
$settings = $this->get_plugin_options();
|
103 |
$settings_menu_order = isset( $settings[ 'menu_order' ] ) ? $settings[ 'menu_order' ] : array();
|
104 |
$post_types = get_post_types( array(), 'object' );
|
105 |
-
|
106 |
//Foreach loop to show de awesome post types
|
107 |
foreach( $post_types as $post_type_name => $post_type ) {
|
108 |
-
|
109 |
//Determine whether to show this post type (show_ui = true)
|
110 |
$show_ui = (bool)isset( $post_type->show_ui ) ? $post_type->show_ui : false;
|
111 |
if ( !$show_ui || 'attachment' === $post_type_name ) continue;
|
112 |
-
|
113 |
//Get post type labels for checkbox
|
114 |
$post_type_value = isset( $settings_post_types[ $post_type_name ] ) ? $settings_post_types[ $post_type_name ] : 'on';
|
115 |
$post_type_label = isset( $post_type->label ) ? $post_type->label : $post_type_name;
|
116 |
printf( '<div id="metronet-reorder-posts-%s">', esc_attr( $post_type_name ) );
|
117 |
printf( '<h3>%s</h3>', esc_html( $post_type_label ) );
|
118 |
-
|
119 |
//Get menu order arguments
|
120 |
$menu_orderby = isset( $settings_menu_order[ $post_type_name ][ 'orderby' ] ) ? $settings_menu_order[ $post_type_name ][ 'orderby' ] : 'none';
|
121 |
-
|
122 |
//Output Menu Order Arguments
|
123 |
printf( '<p>%s</p>', esc_html__( 'Sort by:', 'metronet-reorder-posts' ) );
|
124 |
printf( '<select name="metronet-reorder-posts[menu_order][%1$s][orderby]">', esc_attr( $post_type_name ) );
|
125 |
printf( '<option value="none" %s>%s</option>', selected( 'none', $menu_orderby, false ), esc_html__( 'None', 'metronet-reorder-posts' ) );
|
126 |
printf( '<option value="menu_order" %s>%s</option>', selected( 'menu_order', $menu_orderby, false ), esc_html__( 'Menu Order', 'metronet-reorder-posts' ) );
|
127 |
echo '</select>';
|
128 |
-
|
129 |
//Get order arguments
|
130 |
$menu_order = isset( $settings_menu_order[ $post_type_name ][ 'order' ] ) ? $settings_menu_order[ $post_type_name ][ 'order' ] : 'DESC'; //DESC is WP_Query default
|
131 |
//Output Menu Order Arguments
|
@@ -134,12 +158,12 @@ class MN_Reorder_Admin {
|
|
134 |
printf( '<option value="ASC" %s>%s</option>', selected( 'ASC', $menu_order, false ), esc_html__( 'ASC', 'metronet-reorder-posts' ) );
|
135 |
printf( '<option value="DESC" %s>%s</option>', selected( 'DESC', $menu_order, false ), esc_html__( 'DESC', 'metronet-reorder-posts' ) );
|
136 |
echo '</select>';
|
137 |
-
|
138 |
//Output closing div
|
139 |
echo '</div>';
|
140 |
}
|
141 |
}
|
142 |
-
|
143 |
/**
|
144 |
* Add post types to be reordered using the plugin
|
145 |
*
|
@@ -150,9 +174,9 @@ class MN_Reorder_Admin {
|
|
150 |
*
|
151 |
* @see init_admin_settings
|
152 |
*
|
153 |
-
* @param array $args {
|
154 |
@type string $desc Description for the setting.
|
155 |
-
|
156 |
}
|
157 |
*/
|
158 |
public function add_settings_field_post_types( $args = array() ) {
|
@@ -160,29 +184,29 @@ class MN_Reorder_Admin {
|
|
160 |
$settings = $this->get_plugin_options();
|
161 |
$settings_post_types = isset( $settings[ 'post_types' ] ) ? $settings[ 'post_types' ] : array();
|
162 |
$post_types = get_post_types( array(), 'object' );
|
163 |
-
|
164 |
//Foreach loop to show de awesome post types
|
165 |
foreach( $post_types as $post_type_name => $post_type ) {
|
166 |
-
|
167 |
//Determine whether to show this post type (show_ui = true)
|
168 |
$show_ui = (bool)isset( $post_type->show_ui ) ? $post_type->show_ui : false;
|
169 |
if ( !$show_ui || 'attachment' === $post_type_name ) continue;
|
170 |
-
|
171 |
//Get post type labels for checkbox
|
172 |
$post_type_value = isset( $settings_post_types[ $post_type_name ] ) ? $settings_post_types[ $post_type_name ] : 'on';
|
173 |
$post_type_label = isset( $post_type->label ) ? $post_type->label : $post_type_name;
|
174 |
$checked = '';
|
175 |
if ( $post_type_value === 'on' ) {
|
176 |
$checked = checked( true, true, false );
|
177 |
-
}
|
178 |
-
|
179 |
//Output post type option
|
180 |
printf( '<div><input type="hidden" name="metronet-reorder-posts[post_types][%1$s]" value="off" /> <input type="checkbox" name="metronet-reorder-posts[post_types][%1$s]" id="post_type_%1$s" value="on" %2$s /><label for="post_type_%1$s"> %3$s</label></div>', esc_attr( $post_type_name ), $checked, esc_html( $post_type_label ) );
|
181 |
}
|
182 |
}
|
183 |
-
|
184 |
public function add_settings_heading_menu_order() {
|
185 |
-
printf( '<p>%s</p>', esc_html__( 'These are advanced options and you should only use these if you know what you are doing. These can overwrite the menu orders of custom queries (using get_posts or WP_Query), custom post type archives, and even the order your blog posts display.', 'metronet-reorder-posts' ) );
|
186 |
}
|
187 |
/**
|
188 |
* Add a settings link to the plugin's options.
|
@@ -197,12 +221,12 @@ class MN_Reorder_Admin {
|
|
197 |
* @param array $links Array of plugin options
|
198 |
* @return array $links Array of plugin options
|
199 |
*/
|
200 |
-
public function add_settings_link( $links ) {
|
201 |
-
$settings_link = sprintf( '<a href="%s">%s</a>', esc_url( admin_url( 'options-general.php?page=metronet-reorder-posts' ) ), _x( 'Settings', 'Plugin settings link on the plugins page', 'metronet-reorder-posts' ) );
|
202 |
-
array_unshift($links, $settings_link);
|
203 |
-
return $links;
|
204 |
}
|
205 |
-
|
206 |
/**
|
207 |
* Initialize and return plugin options.
|
208 |
*
|
@@ -217,15 +241,16 @@ class MN_Reorder_Admin {
|
|
217 |
*/
|
218 |
public function get_plugin_options() {
|
219 |
if ( false === $this->options ) {
|
220 |
-
$settings = get_option( 'metronet-reorder-posts' );
|
221 |
} else {
|
222 |
$settings = $this->options;
|
223 |
}
|
224 |
-
|
225 |
if ( false === $settings || !is_array( $settings ) ) {
|
226 |
$defaults = array(
|
227 |
'post_types' => array(),
|
228 |
'menu_order' => array(),
|
|
|
229 |
);
|
230 |
update_option( 'metronet-reorder-posts', $defaults );
|
231 |
return $defaults;
|
@@ -233,9 +258,9 @@ class MN_Reorder_Admin {
|
|
233 |
$this->options = $settings;
|
234 |
return $settings;
|
235 |
}
|
236 |
-
|
237 |
/**
|
238 |
-
* Initialize options
|
239 |
*
|
240 |
* Initialize page settings, fields, and sections and their callbacks
|
241 |
*
|
@@ -247,102 +272,106 @@ class MN_Reorder_Admin {
|
|
247 |
*/
|
248 |
public function init_admin_settings() {
|
249 |
register_setting( 'metronet-reorder-posts', 'metronet-reorder-posts', array( $this, 'sanitization' ) );
|
250 |
-
|
251 |
add_settings_section( 'mn-reorder-post-types', _x( 'Enable Post Types', 'plugin settings heading' , 'metronet-reorder-posts' ), '__return_empty_string', 'metronet-reorder-posts' );
|
252 |
-
|
253 |
add_settings_section( 'mn-reorder-menu-order', _x( 'Advanced', 'plugin settings heading' , 'metronet-reorder-posts' ), array( $this, 'add_settings_heading_menu_order' ), 'metronet-reorder-posts' );
|
254 |
-
|
|
|
|
|
255 |
add_settings_field( 'mn-post-types', __( 'Post Types', 'metronet-reorder-posts' ), array( $this, 'add_settings_field_post_types' ), 'metronet-reorder-posts', 'mn-reorder-post-types', array( 'desc' => __( 'Select the post types you would like this plugin enabled for.', 'metronet-reorder-posts' ) ) );
|
256 |
-
|
257 |
add_settings_field( 'mn-menu-order', __( 'Select the menu order arguments.', 'metronet-reorder-posts' ), array( $this, 'add_settings_field_menu_order' ), 'metronet-reorder-posts', 'mn-reorder-menu-order', array( 'desc' => __( 'Select the menu order for the post types.', 'metronet-reorder-posts' ) ) );
|
258 |
-
|
|
|
|
|
259 |
}
|
260 |
-
|
261 |
//Used for get_posts calls
|
262 |
public function modify_menu_order_pre( $query ) {
|
263 |
if( $query->is_main_query() || is_admin() || is_feed() ) return;
|
264 |
-
|
265 |
if ( !apply_filters( 'metronet_reorder_allow_menu_order', true ) ) return; //Return false to disable this completely
|
266 |
-
|
267 |
//Get main plugin options
|
268 |
$plugin_options = $this->get_plugin_options();
|
269 |
if ( !isset( $plugin_options[ 'menu_order' ] ) || !is_array( $plugin_options[ 'menu_order' ] ) || empty( $plugin_options[ 'menu_order' ] ) ) return;
|
270 |
$menu_order = $plugin_options[ 'menu_order' ];
|
271 |
-
|
272 |
//Get main post type
|
273 |
$main_query = $query->query;
|
274 |
$post_type = false;
|
275 |
if( isset( $main_query[ 'post_type' ] ) ) {
|
276 |
//Typically set on post type archives or custom WP_Query or get_posts instances
|
277 |
-
$post_type = $main_query[ 'post_type' ];
|
278 |
}
|
279 |
if ( !$post_type || is_array( $post_type ) ) return;
|
280 |
-
|
281 |
//See if suppress filters is on (using get_posts) (if it's not, use modify_menu_order_sql for that)
|
282 |
if ( !isset( $main_query[ 'suppress_filters' ] ) ) return;
|
283 |
-
|
284 |
if ( !apply_filters( 'metronet_reorder_allow_menu_order_' . $post_type, true ) ) return; //Return false to disable this for each individual post type as opposed to using a global filter above
|
285 |
-
|
286 |
//See if we're modifying the menu_order
|
287 |
$menu_order_orderby = isset( $menu_order[ $post_type ][ 'orderby' ] ) ? $menu_order[ $post_type ][ 'orderby' ] : 'none';
|
288 |
$menu_order_order = isset( $menu_order[ $post_type ][ 'order' ] ) ? $menu_order[ $post_type ][ 'order' ] : 'DESC';
|
289 |
-
|
290 |
//Return if post type is not be ordered
|
291 |
if ( $menu_order_orderby === 'none' ) return;
|
292 |
-
|
293 |
//Return of $menu_order_order is invalid
|
294 |
if ( $menu_order_order !== 'ASC' && $menu_order_order !== 'DESC' ) return;
|
295 |
-
|
296 |
//Overwrite the orderby clause
|
297 |
$query->set( 'orderby', 'menu_order' );
|
298 |
$query->set( 'order', $menu_order_order );
|
299 |
}
|
300 |
-
|
301 |
//Used on homepage archives, post type archives, or custom WP_Query calls
|
302 |
public function modify_menu_order_sql( $sql_orderby, $query ) {
|
303 |
if ( is_admin() || is_404() || is_feed() ) return $sql_orderby;
|
304 |
-
|
305 |
if ( !apply_filters( 'metronet_reorder_allow_menu_order', true ) ) return $sql_orderby; //Return false to disable this completely
|
306 |
-
|
307 |
//Get main plugin options
|
308 |
$plugin_options = $this->get_plugin_options();
|
309 |
if ( !isset( $plugin_options[ 'menu_order' ] ) || !is_array( $plugin_options[ 'menu_order' ] ) || empty( $plugin_options[ 'menu_order' ] ) ) return $sql_orderby;
|
310 |
-
|
311 |
$menu_order = $plugin_options[ 'menu_order' ];
|
312 |
-
|
313 |
$main_query = $query->query;
|
314 |
-
|
315 |
//Get main post type - Try to get post_type first, if not, see if we're on the main page showing blog posts
|
316 |
$post_type = false;
|
317 |
if( isset( $main_query[ 'post_type' ] ) ) {
|
318 |
//Typically set on post type archives or custom WP_Query or get_posts instances
|
319 |
-
$post_type = $main_query[ 'post_type' ];
|
320 |
} elseif ( is_home() ) {
|
321 |
$post_type = 'post';
|
322 |
-
}
|
323 |
if ( !$post_type || is_array( $post_type ) ) return $sql_orderby;
|
324 |
-
|
325 |
if ( !apply_filters( 'metronet_reorder_allow_menu_order_' . $post_type, true ) ) return $sql_orderby; //Return false to disable this for each individual post type as opposed to using a global filter above
|
326 |
-
|
327 |
//See if we're modifying the menu_order
|
328 |
$menu_order_orderby = isset( $menu_order[ $post_type ][ 'orderby' ] ) ? $menu_order[ $post_type ][ 'orderby' ] : 'none';
|
329 |
$menu_order_order = isset( $menu_order[ $post_type ][ 'order' ] ) ? $menu_order[ $post_type ][ 'order' ] : 'DESC';
|
330 |
-
|
331 |
//Return if post type is not be ordered
|
332 |
if ( $menu_order_orderby === 'none' ) return $sql_orderby;
|
333 |
-
|
334 |
//Return of $menu_order_order is invalid
|
335 |
if ( $menu_order_order !== 'ASC' && $menu_order_order !== 'DESC' ) return $sql_orderby;
|
336 |
-
|
337 |
//Overwrite the orderby clause
|
338 |
global $wpdb;
|
339 |
$sql_orderby = sprintf( '%s.menu_order %s', $wpdb->posts, $menu_order_order ); //for devs: no sanitization required as tablename is from $wpdb and $menu_order_order is set to match only ASC or DESC.
|
340 |
|
341 |
-
//Return
|
342 |
-
return $sql_orderby;
|
343 |
-
|
344 |
}
|
345 |
-
|
346 |
/**
|
347 |
* Output options page HTML.
|
348 |
*
|
@@ -366,7 +395,7 @@ class MN_Reorder_Admin {
|
|
366 |
</div>
|
367 |
<?php
|
368 |
}
|
369 |
-
|
370 |
/**
|
371 |
* Sanitize options before they are saved.
|
372 |
*
|
@@ -379,7 +408,7 @@ class MN_Reorder_Admin {
|
|
379 |
*
|
380 |
* @param array $input {
|
381 |
@type array $post_types
|
382 |
-
@type array $menu_order
|
383 |
}
|
384 |
* @return array Sanitized array of options
|
385 |
*/
|
@@ -389,12 +418,12 @@ class MN_Reorder_Admin {
|
|
389 |
if ( !empty( $post_types ) ) {
|
390 |
foreach( $post_types as $post_type_name => &$value ) {
|
391 |
if ( $value !== 'on' ) {
|
392 |
-
$value == 'off';
|
393 |
}
|
394 |
-
}
|
395 |
$input[ 'post_types' ] = $post_types;
|
396 |
}
|
397 |
-
|
398 |
//Get menu order options
|
399 |
$menu_order = $input[ 'menu_order' ];
|
400 |
if ( !empty( $menu_order ) ) {
|
@@ -403,18 +432,18 @@ class MN_Reorder_Admin {
|
|
403 |
if ( $orderby !== 'menu_order' ) {
|
404 |
$menu_order[ $post_type_name ][ 'orderby' ] == 'none';
|
405 |
}
|
406 |
-
|
407 |
$order = isset( $menu_order[ $post_type_name ][ 'order' ] ) ? $menu_order[ $post_type_name ] : 'DESC';
|
408 |
if ( $orderby !== 'ASC' ) {
|
409 |
-
$menu_order[ $post_type_name ][ 'order' ] == 'DESC';
|
410 |
}
|
411 |
}
|
412 |
$input[ 'menu_order' ] = $menu_order;
|
413 |
-
|
414 |
}
|
415 |
return $input;
|
416 |
}
|
417 |
-
|
418 |
} //end class Reorder_Admin
|
419 |
|
420 |
add_action( 'init', 'mn_reorder_admin_instantiate', 15 );
|
1 |
<?php
|
2 |
/**
|
3 |
* Reorder posts
|
4 |
+
*
|
5 |
* @package WordPress
|
6 |
* @subpackage Metronet Reorder Posts plugin
|
7 |
*/
|
10 |
/**
|
11 |
* Reorder posts
|
12 |
* Adds drag and drop editor for reordering WordPress posts
|
13 |
+
*
|
14 |
* This class is self-instantiated and should not be used directly
|
15 |
+
*
|
16 |
* @license http://www.gnu.org/licenses/gpl.html GPL
|
17 |
* @author Ronald Huereca
|
18 |
* @since 2.0.0
|
19 |
*/
|
20 |
class MN_Reorder_Admin {
|
21 |
/**
|
22 |
+
* @var $instance
|
23 |
* @desc Instance of the admin class
|
24 |
* @access private
|
25 |
*/
|
26 |
private static $instance = null;
|
27 |
+
|
28 |
/**
|
29 |
+
* @var $options
|
30 |
* @desc WordPress options for access within this class
|
31 |
* @access private
|
32 |
*/
|
34 |
|
35 |
/**
|
36 |
* Class constructor
|
37 |
+
*
|
38 |
* Sets definitions
|
39 |
* Adds methods to appropriate hooks
|
40 |
+
*
|
41 |
* @author Ronald Huereca
|
42 |
* @since Reorder 1.1
|
43 |
* @access private
|
45 |
private function __construct( ) {
|
46 |
//Filter to hide the admin panel options
|
47 |
if ( !apply_filters( 'metronet_reorder_post_allow_admin', true ) ) return; //Use this filter if you want to disable the admin panel settings for this plugin, including disabling the menu order overrides
|
48 |
+
|
49 |
//Initialize actions
|
50 |
/* Dev note: If you know what you're doing code-wise, add the menu_order in get_posts, pre_get_posts, or WP_Query, disable these filters, and/or disable the admin settings (see above). */
|
51 |
add_filter( 'posts_orderby', array( $this, 'modify_menu_order_sql' ), 30, 2 );
|
52 |
add_action( 'pre_get_posts', array( $this, 'modify_menu_order_pre' ), 30, 1 );
|
53 |
+
|
54 |
//Admin Settings
|
55 |
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
|
56 |
add_action( 'admin_init', array( $this, 'init_admin_settings' ) );
|
57 |
+
|
58 |
//Plugin settings
|
59 |
add_filter( 'plugin_action_links_' . REORDER_BASENAME , array( $this, 'add_settings_link' ) );
|
60 |
}
|
61 |
+
|
62 |
//Singleton
|
63 |
public static function get_instance() {
|
64 |
if ( null == self::$instance ) {
|
66 |
}
|
67 |
return self::$instance;
|
68 |
} //end get_instance
|
69 |
+
|
70 |
/**
|
71 |
* Initialize options page
|
72 |
*
|
77 |
*
|
78 |
* @see init
|
79 |
*
|
80 |
+
*/
|
81 |
public function add_admin_menu() {
|
82 |
add_options_page( _x( 'Reorder Posts', 'Plugin Name - Settings Page Title', 'metronet-reorder-posts' ), _x( 'Reorder Posts', 'Plugin Name - Menu Item', 'metronet-reorder-posts' ), 'manage_options', 'metronet-reorder-posts', array( $this, 'options_page' ) );
|
83 |
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Add query output
|
87 |
+
*
|
88 |
+
* Add query output
|
89 |
+
*
|
90 |
+
* @since 1.0.0
|
91 |
+
* @access public
|
92 |
+
*
|
93 |
+
* @see init_admin_settings
|
94 |
+
*
|
95 |
+
* @param array $args {
|
96 |
+
@type string $desc Description for the setting.
|
97 |
+
|
98 |
+
}
|
99 |
+
*/
|
100 |
+
public function add_settings_reorder_query( $args = array() ) {
|
101 |
+
//Get options/defaults
|
102 |
+
$settings = $this->get_plugin_options();
|
103 |
+
$settings_query = isset( $settings[ 'show_query' ] ) ? $settings[ 'show_query' ] : 'on';
|
104 |
+
|
105 |
+
printf( '<p><input type="radio" name="metronet-reorder-posts[show_query]" value="on" id="reorder_show_query_yes" %s /> <label for="reorder_show_query_yes">%s</label></p>', checked( 'on', $settings_query, false ), esc_html__( 'Yes', 'metronet-reorder-posts' ) );
|
106 |
+
printf( '<p><input type="radio" name="metronet-reorder-posts[show_query]" value="off" id="reorder_show_query_no" %s /> <label for="reorder_show_query_no">%s</label></p>', checked( 'off', $settings_query, false ), esc_html__( 'No', 'metronet-reorder-posts' ) );
|
107 |
+
}
|
108 |
+
|
109 |
/**
|
110 |
* Add post types to be overridden using menu_order
|
111 |
*
|
116 |
*
|
117 |
* @see init_admin_settings
|
118 |
*
|
119 |
+
* @param array $args {
|
120 |
@type string $desc Description for the setting.
|
121 |
+
|
122 |
}
|
123 |
*/
|
124 |
public function add_settings_field_menu_order( $args = array() ) {
|
126 |
$settings = $this->get_plugin_options();
|
127 |
$settings_menu_order = isset( $settings[ 'menu_order' ] ) ? $settings[ 'menu_order' ] : array();
|
128 |
$post_types = get_post_types( array(), 'object' );
|
129 |
+
|
130 |
//Foreach loop to show de awesome post types
|
131 |
foreach( $post_types as $post_type_name => $post_type ) {
|
132 |
+
|
133 |
//Determine whether to show this post type (show_ui = true)
|
134 |
$show_ui = (bool)isset( $post_type->show_ui ) ? $post_type->show_ui : false;
|
135 |
if ( !$show_ui || 'attachment' === $post_type_name ) continue;
|
136 |
+
|
137 |
//Get post type labels for checkbox
|
138 |
$post_type_value = isset( $settings_post_types[ $post_type_name ] ) ? $settings_post_types[ $post_type_name ] : 'on';
|
139 |
$post_type_label = isset( $post_type->label ) ? $post_type->label : $post_type_name;
|
140 |
printf( '<div id="metronet-reorder-posts-%s">', esc_attr( $post_type_name ) );
|
141 |
printf( '<h3>%s</h3>', esc_html( $post_type_label ) );
|
142 |
+
|
143 |
//Get menu order arguments
|
144 |
$menu_orderby = isset( $settings_menu_order[ $post_type_name ][ 'orderby' ] ) ? $settings_menu_order[ $post_type_name ][ 'orderby' ] : 'none';
|
145 |
+
|
146 |
//Output Menu Order Arguments
|
147 |
printf( '<p>%s</p>', esc_html__( 'Sort by:', 'metronet-reorder-posts' ) );
|
148 |
printf( '<select name="metronet-reorder-posts[menu_order][%1$s][orderby]">', esc_attr( $post_type_name ) );
|
149 |
printf( '<option value="none" %s>%s</option>', selected( 'none', $menu_orderby, false ), esc_html__( 'None', 'metronet-reorder-posts' ) );
|
150 |
printf( '<option value="menu_order" %s>%s</option>', selected( 'menu_order', $menu_orderby, false ), esc_html__( 'Menu Order', 'metronet-reorder-posts' ) );
|
151 |
echo '</select>';
|
152 |
+
|
153 |
//Get order arguments
|
154 |
$menu_order = isset( $settings_menu_order[ $post_type_name ][ 'order' ] ) ? $settings_menu_order[ $post_type_name ][ 'order' ] : 'DESC'; //DESC is WP_Query default
|
155 |
//Output Menu Order Arguments
|
158 |
printf( '<option value="ASC" %s>%s</option>', selected( 'ASC', $menu_order, false ), esc_html__( 'ASC', 'metronet-reorder-posts' ) );
|
159 |
printf( '<option value="DESC" %s>%s</option>', selected( 'DESC', $menu_order, false ), esc_html__( 'DESC', 'metronet-reorder-posts' ) );
|
160 |
echo '</select>';
|
161 |
+
|
162 |
//Output closing div
|
163 |
echo '</div>';
|
164 |
}
|
165 |
}
|
166 |
+
|
167 |
/**
|
168 |
* Add post types to be reordered using the plugin
|
169 |
*
|
174 |
*
|
175 |
* @see init_admin_settings
|
176 |
*
|
177 |
+
* @param array $args {
|
178 |
@type string $desc Description for the setting.
|
179 |
+
|
180 |
}
|
181 |
*/
|
182 |
public function add_settings_field_post_types( $args = array() ) {
|
184 |
$settings = $this->get_plugin_options();
|
185 |
$settings_post_types = isset( $settings[ 'post_types' ] ) ? $settings[ 'post_types' ] : array();
|
186 |
$post_types = get_post_types( array(), 'object' );
|
187 |
+
|
188 |
//Foreach loop to show de awesome post types
|
189 |
foreach( $post_types as $post_type_name => $post_type ) {
|
190 |
+
|
191 |
//Determine whether to show this post type (show_ui = true)
|
192 |
$show_ui = (bool)isset( $post_type->show_ui ) ? $post_type->show_ui : false;
|
193 |
if ( !$show_ui || 'attachment' === $post_type_name ) continue;
|
194 |
+
|
195 |
//Get post type labels for checkbox
|
196 |
$post_type_value = isset( $settings_post_types[ $post_type_name ] ) ? $settings_post_types[ $post_type_name ] : 'on';
|
197 |
$post_type_label = isset( $post_type->label ) ? $post_type->label : $post_type_name;
|
198 |
$checked = '';
|
199 |
if ( $post_type_value === 'on' ) {
|
200 |
$checked = checked( true, true, false );
|
201 |
+
}
|
202 |
+
|
203 |
//Output post type option
|
204 |
printf( '<div><input type="hidden" name="metronet-reorder-posts[post_types][%1$s]" value="off" /> <input type="checkbox" name="metronet-reorder-posts[post_types][%1$s]" id="post_type_%1$s" value="on" %2$s /><label for="post_type_%1$s"> %3$s</label></div>', esc_attr( $post_type_name ), $checked, esc_html( $post_type_label ) );
|
205 |
}
|
206 |
}
|
207 |
+
|
208 |
public function add_settings_heading_menu_order() {
|
209 |
+
printf( '<p>%s</p>', esc_html__( 'These are advanced options and you should only use these if you know what you are doing. These can overwrite the menu orders of custom queries (using get_posts or WP_Query), custom post type archives, and even the order your blog posts display.', 'metronet-reorder-posts' ) );
|
210 |
}
|
211 |
/**
|
212 |
* Add a settings link to the plugin's options.
|
221 |
* @param array $links Array of plugin options
|
222 |
* @return array $links Array of plugin options
|
223 |
*/
|
224 |
+
public function add_settings_link( $links ) {
|
225 |
+
$settings_link = sprintf( '<a href="%s">%s</a>', esc_url( admin_url( 'options-general.php?page=metronet-reorder-posts' ) ), _x( 'Settings', 'Plugin settings link on the plugins page', 'metronet-reorder-posts' ) );
|
226 |
+
array_unshift($links, $settings_link);
|
227 |
+
return $links;
|
228 |
}
|
229 |
+
|
230 |
/**
|
231 |
* Initialize and return plugin options.
|
232 |
*
|
241 |
*/
|
242 |
public function get_plugin_options() {
|
243 |
if ( false === $this->options ) {
|
244 |
+
$settings = get_option( 'metronet-reorder-posts' );
|
245 |
} else {
|
246 |
$settings = $this->options;
|
247 |
}
|
248 |
+
|
249 |
if ( false === $settings || !is_array( $settings ) ) {
|
250 |
$defaults = array(
|
251 |
'post_types' => array(),
|
252 |
'menu_order' => array(),
|
253 |
+
'show_query' => 'on'
|
254 |
);
|
255 |
update_option( 'metronet-reorder-posts', $defaults );
|
256 |
return $defaults;
|
258 |
$this->options = $settings;
|
259 |
return $settings;
|
260 |
}
|
261 |
+
|
262 |
/**
|
263 |
+
* Initialize options
|
264 |
*
|
265 |
* Initialize page settings, fields, and sections and their callbacks
|
266 |
*
|
272 |
*/
|
273 |
public function init_admin_settings() {
|
274 |
register_setting( 'metronet-reorder-posts', 'metronet-reorder-posts', array( $this, 'sanitization' ) );
|
275 |
+
|
276 |
add_settings_section( 'mn-reorder-post-types', _x( 'Enable Post Types', 'plugin settings heading' , 'metronet-reorder-posts' ), '__return_empty_string', 'metronet-reorder-posts' );
|
277 |
+
|
278 |
add_settings_section( 'mn-reorder-menu-order', _x( 'Advanced', 'plugin settings heading' , 'metronet-reorder-posts' ), array( $this, 'add_settings_heading_menu_order' ), 'metronet-reorder-posts' );
|
279 |
+
|
280 |
+
add_settings_section( 'mn-reorder-query', _x( 'Reorder Posts', 'plugin settings heading' , 'metronet-reorder-posts' ), '__return_empty_string', 'metronet-reorder-posts' );
|
281 |
+
|
282 |
add_settings_field( 'mn-post-types', __( 'Post Types', 'metronet-reorder-posts' ), array( $this, 'add_settings_field_post_types' ), 'metronet-reorder-posts', 'mn-reorder-post-types', array( 'desc' => __( 'Select the post types you would like this plugin enabled for.', 'metronet-reorder-posts' ) ) );
|
283 |
+
|
284 |
add_settings_field( 'mn-menu-order', __( 'Select the menu order arguments.', 'metronet-reorder-posts' ), array( $this, 'add_settings_field_menu_order' ), 'metronet-reorder-posts', 'mn-reorder-menu-order', array( 'desc' => __( 'Select the menu order for the post types.', 'metronet-reorder-posts' ) ) );
|
285 |
+
|
286 |
+
add_settings_field( 'mn-reorder-query', __( 'Show Posts Query', 'metronet-reorder-posts' ), array( $this, 'add_settings_reorder_query' ), 'metronet-reorder-posts', 'mn-reorder-query', array( 'desc' => __( 'Show a helpful sample query for Reorder posts.', 'metronet-reorder-posts' ) ) );
|
287 |
+
|
288 |
}
|
289 |
+
|
290 |
//Used for get_posts calls
|
291 |
public function modify_menu_order_pre( $query ) {
|
292 |
if( $query->is_main_query() || is_admin() || is_feed() ) return;
|
293 |
+
|
294 |
if ( !apply_filters( 'metronet_reorder_allow_menu_order', true ) ) return; //Return false to disable this completely
|
295 |
+
|
296 |
//Get main plugin options
|
297 |
$plugin_options = $this->get_plugin_options();
|
298 |
if ( !isset( $plugin_options[ 'menu_order' ] ) || !is_array( $plugin_options[ 'menu_order' ] ) || empty( $plugin_options[ 'menu_order' ] ) ) return;
|
299 |
$menu_order = $plugin_options[ 'menu_order' ];
|
300 |
+
|
301 |
//Get main post type
|
302 |
$main_query = $query->query;
|
303 |
$post_type = false;
|
304 |
if( isset( $main_query[ 'post_type' ] ) ) {
|
305 |
//Typically set on post type archives or custom WP_Query or get_posts instances
|
306 |
+
$post_type = $main_query[ 'post_type' ];
|
307 |
}
|
308 |
if ( !$post_type || is_array( $post_type ) ) return;
|
309 |
+
|
310 |
//See if suppress filters is on (using get_posts) (if it's not, use modify_menu_order_sql for that)
|
311 |
if ( !isset( $main_query[ 'suppress_filters' ] ) ) return;
|
312 |
+
|
313 |
if ( !apply_filters( 'metronet_reorder_allow_menu_order_' . $post_type, true ) ) return; //Return false to disable this for each individual post type as opposed to using a global filter above
|
314 |
+
|
315 |
//See if we're modifying the menu_order
|
316 |
$menu_order_orderby = isset( $menu_order[ $post_type ][ 'orderby' ] ) ? $menu_order[ $post_type ][ 'orderby' ] : 'none';
|
317 |
$menu_order_order = isset( $menu_order[ $post_type ][ 'order' ] ) ? $menu_order[ $post_type ][ 'order' ] : 'DESC';
|
318 |
+
|
319 |
//Return if post type is not be ordered
|
320 |
if ( $menu_order_orderby === 'none' ) return;
|
321 |
+
|
322 |
//Return of $menu_order_order is invalid
|
323 |
if ( $menu_order_order !== 'ASC' && $menu_order_order !== 'DESC' ) return;
|
324 |
+
|
325 |
//Overwrite the orderby clause
|
326 |
$query->set( 'orderby', 'menu_order' );
|
327 |
$query->set( 'order', $menu_order_order );
|
328 |
}
|
329 |
+
|
330 |
//Used on homepage archives, post type archives, or custom WP_Query calls
|
331 |
public function modify_menu_order_sql( $sql_orderby, $query ) {
|
332 |
if ( is_admin() || is_404() || is_feed() ) return $sql_orderby;
|
333 |
+
|
334 |
if ( !apply_filters( 'metronet_reorder_allow_menu_order', true ) ) return $sql_orderby; //Return false to disable this completely
|
335 |
+
|
336 |
//Get main plugin options
|
337 |
$plugin_options = $this->get_plugin_options();
|
338 |
if ( !isset( $plugin_options[ 'menu_order' ] ) || !is_array( $plugin_options[ 'menu_order' ] ) || empty( $plugin_options[ 'menu_order' ] ) ) return $sql_orderby;
|
339 |
+
|
340 |
$menu_order = $plugin_options[ 'menu_order' ];
|
341 |
+
|
342 |
$main_query = $query->query;
|
343 |
+
|
344 |
//Get main post type - Try to get post_type first, if not, see if we're on the main page showing blog posts
|
345 |
$post_type = false;
|
346 |
if( isset( $main_query[ 'post_type' ] ) ) {
|
347 |
//Typically set on post type archives or custom WP_Query or get_posts instances
|
348 |
+
$post_type = $main_query[ 'post_type' ];
|
349 |
} elseif ( is_home() ) {
|
350 |
$post_type = 'post';
|
351 |
+
}
|
352 |
if ( !$post_type || is_array( $post_type ) ) return $sql_orderby;
|
353 |
+
|
354 |
if ( !apply_filters( 'metronet_reorder_allow_menu_order_' . $post_type, true ) ) return $sql_orderby; //Return false to disable this for each individual post type as opposed to using a global filter above
|
355 |
+
|
356 |
//See if we're modifying the menu_order
|
357 |
$menu_order_orderby = isset( $menu_order[ $post_type ][ 'orderby' ] ) ? $menu_order[ $post_type ][ 'orderby' ] : 'none';
|
358 |
$menu_order_order = isset( $menu_order[ $post_type ][ 'order' ] ) ? $menu_order[ $post_type ][ 'order' ] : 'DESC';
|
359 |
+
|
360 |
//Return if post type is not be ordered
|
361 |
if ( $menu_order_orderby === 'none' ) return $sql_orderby;
|
362 |
+
|
363 |
//Return of $menu_order_order is invalid
|
364 |
if ( $menu_order_order !== 'ASC' && $menu_order_order !== 'DESC' ) return $sql_orderby;
|
365 |
+
|
366 |
//Overwrite the orderby clause
|
367 |
global $wpdb;
|
368 |
$sql_orderby = sprintf( '%s.menu_order %s', $wpdb->posts, $menu_order_order ); //for devs: no sanitization required as tablename is from $wpdb and $menu_order_order is set to match only ASC or DESC.
|
369 |
|
370 |
+
//Return
|
371 |
+
return $sql_orderby;
|
372 |
+
|
373 |
}
|
374 |
+
|
375 |
/**
|
376 |
* Output options page HTML.
|
377 |
*
|
395 |
</div>
|
396 |
<?php
|
397 |
}
|
398 |
+
|
399 |
/**
|
400 |
* Sanitize options before they are saved.
|
401 |
*
|
408 |
*
|
409 |
* @param array $input {
|
410 |
@type array $post_types
|
411 |
+
@type array $menu_order
|
412 |
}
|
413 |
* @return array Sanitized array of options
|
414 |
*/
|
418 |
if ( !empty( $post_types ) ) {
|
419 |
foreach( $post_types as $post_type_name => &$value ) {
|
420 |
if ( $value !== 'on' ) {
|
421 |
+
$value == 'off';
|
422 |
}
|
423 |
+
}
|
424 |
$input[ 'post_types' ] = $post_types;
|
425 |
}
|
426 |
+
|
427 |
//Get menu order options
|
428 |
$menu_order = $input[ 'menu_order' ];
|
429 |
if ( !empty( $menu_order ) ) {
|
432 |
if ( $orderby !== 'menu_order' ) {
|
433 |
$menu_order[ $post_type_name ][ 'orderby' ] == 'none';
|
434 |
}
|
435 |
+
|
436 |
$order = isset( $menu_order[ $post_type_name ][ 'order' ] ) ? $menu_order[ $post_type_name ] : 'DESC';
|
437 |
if ( $orderby !== 'ASC' ) {
|
438 |
+
$menu_order[ $post_type_name ][ 'order' ] == 'DESC';
|
439 |
}
|
440 |
}
|
441 |
$input[ 'menu_order' ] = $menu_order;
|
442 |
+
|
443 |
}
|
444 |
return $input;
|
445 |
}
|
446 |
+
|
447 |
} //end class Reorder_Admin
|
448 |
|
449 |
add_action( 'init', 'mn_reorder_admin_instantiate', 15 );
|
class-reorder.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Reorder posts
|
4 |
-
*
|
5 |
* @package WordPress
|
6 |
* @subpackage Metronet Reorder Posts plugin
|
7 |
*/
|
@@ -10,12 +10,12 @@
|
|
10 |
/**
|
11 |
* Reorder posts
|
12 |
* Adds drag and drop editor for reordering WordPress posts
|
13 |
-
*
|
14 |
* Based on work by Scott Basgaard and Ronald Huereca
|
15 |
-
*
|
16 |
* To use this class, simply instantiate it using an argument to set the post type as follows:
|
17 |
* new MN_Reorder( array( 'post_type' => 'post', 'order'=> 'ASC' ) );
|
18 |
-
*
|
19 |
* @copyright Copyright (c), Metronet
|
20 |
* @license http://www.gnu.org/licenses/gpl.html GPL
|
21 |
* @author Ryan Hellyer <ryan@metronet.no>
|
@@ -24,42 +24,42 @@
|
|
24 |
final class MN_Reorder {
|
25 |
|
26 |
/**
|
27 |
-
* @var $post_type
|
28 |
* @desc Post type to be reordered
|
29 |
* @access private
|
30 |
*/
|
31 |
private $post_type;
|
32 |
-
|
33 |
/**
|
34 |
-
* @var $posts_per_page
|
35 |
* @desc How many posts to show
|
36 |
* @access private
|
37 |
*/
|
38 |
private $posts_per_page;
|
39 |
-
|
40 |
/**
|
41 |
-
* @var $offset
|
42 |
* @desc How many posts to offset by
|
43 |
* @access private
|
44 |
*/
|
45 |
private $offset;
|
46 |
|
47 |
/**
|
48 |
-
* @var $heading
|
49 |
* @desc Admin page heading
|
50 |
* @access private
|
51 |
*/
|
52 |
private $heading;
|
53 |
|
54 |
/**
|
55 |
-
* @var $initial
|
56 |
* @desc HTML outputted at end of admin page
|
57 |
* @access private
|
58 |
*/
|
59 |
private $initial;
|
60 |
|
61 |
/**
|
62 |
-
* @var $final
|
63 |
* @desc HTML outputted at end of admin page
|
64 |
* @access private
|
65 |
*/
|
@@ -73,26 +73,26 @@ final class MN_Reorder {
|
|
73 |
private $post_status;
|
74 |
|
75 |
/**
|
76 |
-
* @var $menu_label
|
77 |
* @desc Admin page menu label
|
78 |
* @access private
|
79 |
*/
|
80 |
private $menu_label;
|
81 |
-
|
82 |
/**
|
83 |
-
* @var $order
|
84 |
* @desc ASC or DESC
|
85 |
* @access private
|
86 |
*/
|
87 |
private $order;
|
88 |
-
|
89 |
/**
|
90 |
-
* @var $reorder_page
|
91 |
* @desc Where the reorder interface is being added
|
92 |
* @access private
|
93 |
*/
|
94 |
private $reorder_page = '';
|
95 |
-
|
96 |
/**
|
97 |
* Get method for post status
|
98 |
*
|
@@ -102,9 +102,9 @@ final class MN_Reorder {
|
|
102 |
* @returns string $post_status Post Status of Posts
|
103 |
*/
|
104 |
public function get_post_status() {
|
105 |
-
return $this->post_status;
|
106 |
}
|
107 |
-
|
108 |
/**
|
109 |
* Get method for post order
|
110 |
*
|
@@ -114,9 +114,9 @@ final class MN_Reorder {
|
|
114 |
* @returns string $order Order of posts (ASC or DESC)
|
115 |
*/
|
116 |
public function get_post_order() {
|
117 |
-
return $this->order;
|
118 |
}
|
119 |
-
|
120 |
/**
|
121 |
* Get method for posts per page
|
122 |
*
|
@@ -126,9 +126,9 @@ final class MN_Reorder {
|
|
126 |
* @returns int $posts_per_page How many posts to display
|
127 |
*/
|
128 |
public function get_posts_per_page() {
|
129 |
-
return $this->posts_per_page;
|
130 |
}
|
131 |
-
|
132 |
/**
|
133 |
* Get method for post offset used in pagination
|
134 |
*
|
@@ -138,22 +138,22 @@ final class MN_Reorder {
|
|
138 |
* @returns int $offset Offset of posts
|
139 |
*/
|
140 |
public function get_offset() {
|
141 |
-
return $this->offset;
|
142 |
}
|
143 |
-
|
144 |
/**
|
145 |
* Class constructor
|
146 |
-
*
|
147 |
* Sets definitions
|
148 |
* Adds methods to appropriate hooks
|
149 |
-
*
|
150 |
* @author Ryan Hellyer <ryan@metronet.no>
|
151 |
* @since Reorder 1.0
|
152 |
* @access public
|
153 |
* @param array $args If not set, then uses $defaults instead
|
154 |
*/
|
155 |
public function __construct( $args = array() ) {
|
156 |
-
|
157 |
// Get posts per page
|
158 |
$user_id = get_current_user_id();
|
159 |
$posts_per_page = get_user_meta( $user_id, 'reorder_items_per_page', true );
|
@@ -161,7 +161,7 @@ final class MN_Reorder {
|
|
161 |
$posts_per_page = 50;
|
162 |
}
|
163 |
$offset = $posts_per_page - 2;
|
164 |
-
|
165 |
// Parse arguments
|
166 |
$defaults = array(
|
167 |
'post_type' => 'post', // Setting the post type to be reordered
|
@@ -175,7 +175,7 @@ final class MN_Reorder {
|
|
175 |
'posts_per_page' => $posts_per_page
|
176 |
);
|
177 |
$args = wp_parse_args( $args, $defaults );
|
178 |
-
|
179 |
// Set variables
|
180 |
$this->post_type = $args[ 'post_type' ];
|
181 |
$this->order = $args[ 'order' ];;
|
@@ -184,14 +184,14 @@ final class MN_Reorder {
|
|
184 |
$this->final = $args[ 'final' ];
|
185 |
$this->menu_label = $args[ 'menu_label' ];
|
186 |
$this->post_status = $args[ 'post_status' ];
|
187 |
-
|
188 |
//Get offset and posts_per_page
|
189 |
$this->posts_per_page = absint( $args[ 'posts_per_page' ] ); //todo - filterable?
|
190 |
$this->offset = absint( $args[ 'offset' ] ); //todo - filterable?
|
191 |
if ( $this->offset > $this->posts_per_page ) {
|
192 |
-
$this->offset = $this->posts_per_page;
|
193 |
}
|
194 |
-
|
195 |
// Add actions
|
196 |
add_filter( 'set-screen-option', array( $this, 'add_screen_option_save' ), 10, 3 );
|
197 |
add_action( 'wp_ajax_post_sort', array( $this, 'ajax_save_post_order' ) );
|
@@ -225,11 +225,11 @@ final class MN_Reorder {
|
|
225 |
*/
|
226 |
public function ajax_save_post_order() {
|
227 |
global $wpdb;
|
228 |
-
|
229 |
if ( !current_user_can( 'edit_pages' ) ) die( '' );
|
230 |
// Verify nonce value, for security purposes
|
231 |
if ( !wp_verify_nonce( $_POST['nonce'], 'sortnonce' ) ) die( '' );
|
232 |
-
|
233 |
//Get Ajax Vars
|
234 |
$post_parent = isset( $_POST[ 'post_parent' ] ) ? absint( $_POST[ 'post_parent' ] ) : 0;
|
235 |
$menu_order_start = isset( $_POST[ 'start' ] ) ? absint( $_POST[ 'start' ] ) : 0;
|
@@ -237,13 +237,13 @@ final class MN_Reorder {
|
|
237 |
$post_menu_order = isset( $_POST[ 'menu_order' ] ) ? absint( $_POST[ 'menu_order' ] ) : 0;
|
238 |
$posts_to_exclude = isset( $_POST[ 'excluded' ] ) ? array_filter( $_POST[ 'excluded' ], 'absint' ) : array();
|
239 |
$post_type = isset( $_POST[ 'post_type' ] ) ? sanitize_text_field( $_POST[ 'post_type' ] ) : false;
|
240 |
-
|
241 |
if ( !$post_type ) die( '' );
|
242 |
-
|
243 |
//Performance
|
244 |
remove_action( 'pre_post_update', 'wp_save_post_revision' );
|
245 |
-
|
246 |
-
//Build Initial Return
|
247 |
$return = array();
|
248 |
$return[ 'more_posts' ] = false;
|
249 |
$return[ 'action' ] = 'post_sort';
|
@@ -252,7 +252,7 @@ final class MN_Reorder {
|
|
252 |
$return[ 'post_id'] = $post_id;
|
253 |
$return[ 'menu_order' ] = $post_menu_order;
|
254 |
$return[ 'post_type' ] = $post_type;
|
255 |
-
|
256 |
//Update post if passed - Should run only on beginning of first iteration
|
257 |
if( $post_id > 0 && !isset( $_POST[ 'more_posts' ] ) ) {
|
258 |
$wpdb->update(
|
@@ -262,7 +262,7 @@ final class MN_Reorder {
|
|
262 |
clean_post_cache( $post_id );
|
263 |
$posts_to_exclude[] = $post_id;
|
264 |
}
|
265 |
-
|
266 |
//Build Query
|
267 |
$query_args = array(
|
268 |
'post_type' => $post_type,
|
@@ -278,15 +278,15 @@ final class MN_Reorder {
|
|
278 |
'update_post_meta_cache' => false
|
279 |
);
|
280 |
$posts = new WP_Query( $query_args );
|
281 |
-
|
282 |
$start = $menu_order_start;
|
283 |
if ( $posts->have_posts() ) {
|
284 |
foreach( $posts->posts as $post ) {
|
285 |
//Increment start if matches menu_order and there is a post to change
|
286 |
if ( $start == $post_menu_order && $post_id > 0 ) {
|
287 |
-
$start++;
|
288 |
}
|
289 |
-
|
290 |
if ( $post_id != $post->ID ) {
|
291 |
//Update post and counts
|
292 |
$wpdb->update(
|
@@ -302,9 +302,9 @@ final class MN_Reorder {
|
|
302 |
$return[ 'excluded' ] = $posts_to_exclude;
|
303 |
$return[ 'start' ] = $start;
|
304 |
if ( $posts->max_num_pages > 1 ) {
|
305 |
-
$return[ 'more_posts' ] = true;
|
306 |
} else {
|
307 |
-
$return[ 'more_posts' ] = false;
|
308 |
}
|
309 |
die( json_encode( $return ) );
|
310 |
} else {
|
@@ -335,7 +335,7 @@ final class MN_Reorder {
|
|
335 |
public function print_scripts() {
|
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',
|
@@ -383,7 +383,7 @@ final class MN_Reorder {
|
|
383 |
add_action( 'admin_print_styles-' . $hook, array( $this, 'print_styles' ) );
|
384 |
add_action( 'admin_print_scripts-' . $hook, array( $this, 'print_scripts' ) );
|
385 |
}
|
386 |
-
|
387 |
/**
|
388 |
* Add screen option for setting items per page
|
389 |
*
|
@@ -400,7 +400,7 @@ final class MN_Reorder {
|
|
400 |
|
401 |
add_screen_option( 'per_page', $args );
|
402 |
}
|
403 |
-
|
404 |
/**
|
405 |
* Saves the screen options setting
|
406 |
*
|
@@ -410,10 +410,10 @@ final class MN_Reorder {
|
|
410 |
*/
|
411 |
public function add_screen_option_save( $status, $option, $value ) {
|
412 |
if ( 'reorder_items_per_page' == $option ) return $value;
|
413 |
-
|
414 |
return $status;
|
415 |
}
|
416 |
-
|
417 |
/**
|
418 |
* Output the main Reorder Interface
|
419 |
*
|
@@ -437,7 +437,7 @@ final class MN_Reorder {
|
|
437 |
//Output non hierarchical posts
|
438 |
$page = isset( $_GET[ 'paged' ] ) ? absint( $_GET[ 'paged' ] ) : 0;
|
439 |
if ( $page == 0 || $page == 1 ) {
|
440 |
-
$offset = 0;
|
441 |
} elseif ( $page > 1 ) {
|
442 |
$offset = $this->offset * ( $page - 1 );
|
443 |
}
|
@@ -460,10 +460,10 @@ final class MN_Reorder {
|
|
460 |
while( $post_query->have_posts() ) {
|
461 |
global $post;
|
462 |
$post_query->the_post();
|
463 |
-
$this->output_row( $post );
|
464 |
}
|
465 |
echo '</ul><!-- #post-list -->';
|
466 |
-
|
467 |
//Show pagination links
|
468 |
if( $post_query->max_num_pages > 1 ) {
|
469 |
echo '<div id="reorder-pagination">';
|
@@ -477,10 +477,35 @@ final class MN_Reorder {
|
|
477 |
echo '</div>';
|
478 |
}
|
479 |
} else {
|
480 |
-
echo sprintf( '<h3>%s</h3> ', esc_html__( 'There is nothing to sort at this time', 'metronet-reorder-posts' ) );
|
481 |
}
|
482 |
-
echo esc_html( $this->final );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
483 |
}
|
|
|
484 |
/**
|
485 |
* Post Row Output
|
486 |
*
|
@@ -521,7 +546,7 @@ final class MN_Reorder {
|
|
521 |
?>
|
522 |
<div class="row">
|
523 |
<?php
|
524 |
-
$is_hierarchical = true;
|
525 |
if( is_post_type_hierarchical( $post->post_type ) ) {
|
526 |
?>
|
527 |
<div class="row-action">
|
@@ -537,7 +562,7 @@ final class MN_Reorder {
|
|
537 |
</div><!-- .row -->
|
538 |
<?php
|
539 |
}
|
540 |
-
|
541 |
if( $children->have_posts() ) {
|
542 |
echo '<ul class="children">';
|
543 |
while( $children->have_posts() ) {
|
@@ -546,12 +571,12 @@ final class MN_Reorder {
|
|
546 |
$this->output_row( $post );
|
547 |
}
|
548 |
echo '</ul>';
|
549 |
-
}
|
550 |
?>
|
551 |
</li>
|
552 |
<?php
|
553 |
} //end output_row
|
554 |
-
|
555 |
/**
|
556 |
* Initial HTML output
|
557 |
*
|
@@ -568,7 +593,7 @@ final class MN_Reorder {
|
|
568 |
<?php echo esc_html( $this->heading ); ?>
|
569 |
</h2>
|
570 |
<?php
|
571 |
-
$tabs =
|
572 |
array(
|
573 |
array(
|
574 |
'url' => $this->reorder_page /* URL to the tab */,
|
@@ -579,7 +604,7 @@ final class MN_Reorder {
|
|
579 |
);
|
580 |
$tabs = apply_filters( 'metronet_reorder_posts_tabs_' . $this->post_type, (array)$tabs );
|
581 |
$tabs_count = count( $tabs );
|
582 |
-
|
583 |
//Output tabs
|
584 |
$tab_html = '';
|
585 |
if ( $tabs && !empty( $tabs ) ) {
|
@@ -594,17 +619,17 @@ final class MN_Reorder {
|
|
594 |
$do_action = isset( $tab[ 'action' ] ) ? $tab[ 'action' ] : false;
|
595 |
}
|
596 |
$tab_url = isset( $tab[ 'url' ] ) ? $tab[ 'url' ] : '';
|
597 |
-
$tab_label = isset( $tab[ 'label' ] ) ? $tab[ 'label' ] : '';
|
598 |
$tab_html .= sprintf( '<a href="%s" class="%s">%s</a>', esc_url( $tab_url ), esc_attr( implode( ' ', $classes ) ), esc_html( $tab[ 'label' ] ) );
|
599 |
}
|
600 |
$tab_html .= '</h2>';
|
601 |
if ( $tabs_count > 1 ) {
|
602 |
-
echo $tab_html;
|
603 |
}
|
604 |
if ( $do_action ) {
|
605 |
-
do_action( $do_action );
|
606 |
}
|
607 |
-
}
|
608 |
?>
|
609 |
</div><!-- .wrap -->
|
610 |
<?php
|
1 |
<?php
|
2 |
/**
|
3 |
* Reorder posts
|
4 |
+
*
|
5 |
* @package WordPress
|
6 |
* @subpackage Metronet Reorder Posts plugin
|
7 |
*/
|
10 |
/**
|
11 |
* Reorder posts
|
12 |
* Adds drag and drop editor for reordering WordPress posts
|
13 |
+
*
|
14 |
* Based on work by Scott Basgaard and Ronald Huereca
|
15 |
+
*
|
16 |
* To use this class, simply instantiate it using an argument to set the post type as follows:
|
17 |
* new MN_Reorder( array( 'post_type' => 'post', 'order'=> 'ASC' ) );
|
18 |
+
*
|
19 |
* @copyright Copyright (c), Metronet
|
20 |
* @license http://www.gnu.org/licenses/gpl.html GPL
|
21 |
* @author Ryan Hellyer <ryan@metronet.no>
|
24 |
final class MN_Reorder {
|
25 |
|
26 |
/**
|
27 |
+
* @var $post_type
|
28 |
* @desc Post type to be reordered
|
29 |
* @access private
|
30 |
*/
|
31 |
private $post_type;
|
32 |
+
|
33 |
/**
|
34 |
+
* @var $posts_per_page
|
35 |
* @desc How many posts to show
|
36 |
* @access private
|
37 |
*/
|
38 |
private $posts_per_page;
|
39 |
+
|
40 |
/**
|
41 |
+
* @var $offset
|
42 |
* @desc How many posts to offset by
|
43 |
* @access private
|
44 |
*/
|
45 |
private $offset;
|
46 |
|
47 |
/**
|
48 |
+
* @var $heading
|
49 |
* @desc Admin page heading
|
50 |
* @access private
|
51 |
*/
|
52 |
private $heading;
|
53 |
|
54 |
/**
|
55 |
+
* @var $initial
|
56 |
* @desc HTML outputted at end of admin page
|
57 |
* @access private
|
58 |
*/
|
59 |
private $initial;
|
60 |
|
61 |
/**
|
62 |
+
* @var $final
|
63 |
* @desc HTML outputted at end of admin page
|
64 |
* @access private
|
65 |
*/
|
73 |
private $post_status;
|
74 |
|
75 |
/**
|
76 |
+
* @var $menu_label
|
77 |
* @desc Admin page menu label
|
78 |
* @access private
|
79 |
*/
|
80 |
private $menu_label;
|
81 |
+
|
82 |
/**
|
83 |
+
* @var $order
|
84 |
* @desc ASC or DESC
|
85 |
* @access private
|
86 |
*/
|
87 |
private $order;
|
88 |
+
|
89 |
/**
|
90 |
+
* @var $reorder_page
|
91 |
* @desc Where the reorder interface is being added
|
92 |
* @access private
|
93 |
*/
|
94 |
private $reorder_page = '';
|
95 |
+
|
96 |
/**
|
97 |
* Get method for post status
|
98 |
*
|
102 |
* @returns string $post_status Post Status of Posts
|
103 |
*/
|
104 |
public function get_post_status() {
|
105 |
+
return $this->post_status;
|
106 |
}
|
107 |
+
|
108 |
/**
|
109 |
* Get method for post order
|
110 |
*
|
114 |
* @returns string $order Order of posts (ASC or DESC)
|
115 |
*/
|
116 |
public function get_post_order() {
|
117 |
+
return $this->order;
|
118 |
}
|
119 |
+
|
120 |
/**
|
121 |
* Get method for posts per page
|
122 |
*
|
126 |
* @returns int $posts_per_page How many posts to display
|
127 |
*/
|
128 |
public function get_posts_per_page() {
|
129 |
+
return $this->posts_per_page;
|
130 |
}
|
131 |
+
|
132 |
/**
|
133 |
* Get method for post offset used in pagination
|
134 |
*
|
138 |
* @returns int $offset Offset of posts
|
139 |
*/
|
140 |
public function get_offset() {
|
141 |
+
return $this->offset;
|
142 |
}
|
143 |
+
|
144 |
/**
|
145 |
* Class constructor
|
146 |
+
*
|
147 |
* Sets definitions
|
148 |
* Adds methods to appropriate hooks
|
149 |
+
*
|
150 |
* @author Ryan Hellyer <ryan@metronet.no>
|
151 |
* @since Reorder 1.0
|
152 |
* @access public
|
153 |
* @param array $args If not set, then uses $defaults instead
|
154 |
*/
|
155 |
public function __construct( $args = array() ) {
|
156 |
+
|
157 |
// Get posts per page
|
158 |
$user_id = get_current_user_id();
|
159 |
$posts_per_page = get_user_meta( $user_id, 'reorder_items_per_page', true );
|
161 |
$posts_per_page = 50;
|
162 |
}
|
163 |
$offset = $posts_per_page - 2;
|
164 |
+
|
165 |
// Parse arguments
|
166 |
$defaults = array(
|
167 |
'post_type' => 'post', // Setting the post type to be reordered
|
175 |
'posts_per_page' => $posts_per_page
|
176 |
);
|
177 |
$args = wp_parse_args( $args, $defaults );
|
178 |
+
|
179 |
// Set variables
|
180 |
$this->post_type = $args[ 'post_type' ];
|
181 |
$this->order = $args[ 'order' ];;
|
184 |
$this->final = $args[ 'final' ];
|
185 |
$this->menu_label = $args[ 'menu_label' ];
|
186 |
$this->post_status = $args[ 'post_status' ];
|
187 |
+
|
188 |
//Get offset and posts_per_page
|
189 |
$this->posts_per_page = absint( $args[ 'posts_per_page' ] ); //todo - filterable?
|
190 |
$this->offset = absint( $args[ 'offset' ] ); //todo - filterable?
|
191 |
if ( $this->offset > $this->posts_per_page ) {
|
192 |
+
$this->offset = $this->posts_per_page;
|
193 |
}
|
194 |
+
|
195 |
// Add actions
|
196 |
add_filter( 'set-screen-option', array( $this, 'add_screen_option_save' ), 10, 3 );
|
197 |
add_action( 'wp_ajax_post_sort', array( $this, 'ajax_save_post_order' ) );
|
225 |
*/
|
226 |
public function ajax_save_post_order() {
|
227 |
global $wpdb;
|
228 |
+
|
229 |
if ( !current_user_can( 'edit_pages' ) ) die( '' );
|
230 |
// Verify nonce value, for security purposes
|
231 |
if ( !wp_verify_nonce( $_POST['nonce'], 'sortnonce' ) ) die( '' );
|
232 |
+
|
233 |
//Get Ajax Vars
|
234 |
$post_parent = isset( $_POST[ 'post_parent' ] ) ? absint( $_POST[ 'post_parent' ] ) : 0;
|
235 |
$menu_order_start = isset( $_POST[ 'start' ] ) ? absint( $_POST[ 'start' ] ) : 0;
|
237 |
$post_menu_order = isset( $_POST[ 'menu_order' ] ) ? absint( $_POST[ 'menu_order' ] ) : 0;
|
238 |
$posts_to_exclude = isset( $_POST[ 'excluded' ] ) ? array_filter( $_POST[ 'excluded' ], 'absint' ) : array();
|
239 |
$post_type = isset( $_POST[ 'post_type' ] ) ? sanitize_text_field( $_POST[ 'post_type' ] ) : false;
|
240 |
+
|
241 |
if ( !$post_type ) die( '' );
|
242 |
+
|
243 |
//Performance
|
244 |
remove_action( 'pre_post_update', 'wp_save_post_revision' );
|
245 |
+
|
246 |
+
//Build Initial Return
|
247 |
$return = array();
|
248 |
$return[ 'more_posts' ] = false;
|
249 |
$return[ 'action' ] = 'post_sort';
|
252 |
$return[ 'post_id'] = $post_id;
|
253 |
$return[ 'menu_order' ] = $post_menu_order;
|
254 |
$return[ 'post_type' ] = $post_type;
|
255 |
+
|
256 |
//Update post if passed - Should run only on beginning of first iteration
|
257 |
if( $post_id > 0 && !isset( $_POST[ 'more_posts' ] ) ) {
|
258 |
$wpdb->update(
|
262 |
clean_post_cache( $post_id );
|
263 |
$posts_to_exclude[] = $post_id;
|
264 |
}
|
265 |
+
|
266 |
//Build Query
|
267 |
$query_args = array(
|
268 |
'post_type' => $post_type,
|
278 |
'update_post_meta_cache' => false
|
279 |
);
|
280 |
$posts = new WP_Query( $query_args );
|
281 |
+
|
282 |
$start = $menu_order_start;
|
283 |
if ( $posts->have_posts() ) {
|
284 |
foreach( $posts->posts as $post ) {
|
285 |
//Increment start if matches menu_order and there is a post to change
|
286 |
if ( $start == $post_menu_order && $post_id > 0 ) {
|
287 |
+
$start++;
|
288 |
}
|
289 |
+
|
290 |
if ( $post_id != $post->ID ) {
|
291 |
//Update post and counts
|
292 |
$wpdb->update(
|
302 |
$return[ 'excluded' ] = $posts_to_exclude;
|
303 |
$return[ 'start' ] = $start;
|
304 |
if ( $posts->max_num_pages > 1 ) {
|
305 |
+
$return[ 'more_posts' ] = true;
|
306 |
} else {
|
307 |
+
$return[ 'more_posts' ] = false;
|
308 |
}
|
309 |
die( json_encode( $return ) );
|
310 |
} else {
|
335 |
public function print_scripts() {
|
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',
|
383 |
add_action( 'admin_print_styles-' . $hook, array( $this, 'print_styles' ) );
|
384 |
add_action( 'admin_print_scripts-' . $hook, array( $this, 'print_scripts' ) );
|
385 |
}
|
386 |
+
|
387 |
/**
|
388 |
* Add screen option for setting items per page
|
389 |
*
|
400 |
|
401 |
add_screen_option( 'per_page', $args );
|
402 |
}
|
403 |
+
|
404 |
/**
|
405 |
* Saves the screen options setting
|
406 |
*
|
410 |
*/
|
411 |
public function add_screen_option_save( $status, $option, $value ) {
|
412 |
if ( 'reorder_items_per_page' == $option ) return $value;
|
413 |
+
|
414 |
return $status;
|
415 |
}
|
416 |
+
|
417 |
/**
|
418 |
* Output the main Reorder Interface
|
419 |
*
|
437 |
//Output non hierarchical posts
|
438 |
$page = isset( $_GET[ 'paged' ] ) ? absint( $_GET[ 'paged' ] ) : 0;
|
439 |
if ( $page == 0 || $page == 1 ) {
|
440 |
+
$offset = 0;
|
441 |
} elseif ( $page > 1 ) {
|
442 |
$offset = $this->offset * ( $page - 1 );
|
443 |
}
|
460 |
while( $post_query->have_posts() ) {
|
461 |
global $post;
|
462 |
$post_query->the_post();
|
463 |
+
$this->output_row( $post );
|
464 |
}
|
465 |
echo '</ul><!-- #post-list -->';
|
466 |
+
|
467 |
//Show pagination links
|
468 |
if( $post_query->max_num_pages > 1 ) {
|
469 |
echo '<div id="reorder-pagination">';
|
477 |
echo '</div>';
|
478 |
}
|
479 |
} else {
|
480 |
+
echo sprintf( '<h3>%s</h3> ', esc_html__( 'There is nothing to sort at this time', 'metronet-reorder-posts' ) );
|
481 |
}
|
482 |
+
echo esc_html( $this->final );
|
483 |
+
$options = get_option( 'metronet-reorder-posts' );
|
484 |
+
|
485 |
+
if ( ! isset( $options[ 'show_query' ] ) || 'on' === $options[ 'show_query' ] ):
|
486 |
+
printf( '<h3>%s</h3>', esc_html__( 'Reorder Posts Query', 'metronet-reorder-posts' ) );
|
487 |
+
printf( '<p>%s</p>', esc_html__( 'You will need custom code to reorder posts. Here are some example query arguments for getting your content.', 'metronet-reorder-posts' ) );
|
488 |
+
$query = "
|
489 |
+
\$query = array(
|
490 |
+
'orderby' => 'menu_order',
|
491 |
+
'order' => 'ASC',
|
492 |
+
'post_status' => 'publish',
|
493 |
+
'post_type' => '{$this->post_type}',
|
494 |
+
'posts_per_page' => {$this->posts_per_page}
|
495 |
+
);
|
496 |
+
\$posts = get_posts( \$query );
|
497 |
+
if( ! empty( \$posts ) ) {
|
498 |
+
echo '<ul>';
|
499 |
+
foreach( \$posts as \$post ) {
|
500 |
+
printf( '<li><a href=\"%s\">%s</a></li>', esc_url( get_permalink( \$post->ID ) ), esc_html( \$post->post_title ) );
|
501 |
+
}
|
502 |
+
echo '</ul>';
|
503 |
+
}
|
504 |
+
";
|
505 |
+
printf( '<blockquote><pre><code>%s</code></pre></blockquote>', esc_html( print_r( $query, true ) ) );
|
506 |
+
endif;
|
507 |
}
|
508 |
+
|
509 |
/**
|
510 |
* Post Row Output
|
511 |
*
|
546 |
?>
|
547 |
<div class="row">
|
548 |
<?php
|
549 |
+
$is_hierarchical = true;
|
550 |
if( is_post_type_hierarchical( $post->post_type ) ) {
|
551 |
?>
|
552 |
<div class="row-action">
|
562 |
</div><!-- .row -->
|
563 |
<?php
|
564 |
}
|
565 |
+
|
566 |
if( $children->have_posts() ) {
|
567 |
echo '<ul class="children">';
|
568 |
while( $children->have_posts() ) {
|
571 |
$this->output_row( $post );
|
572 |
}
|
573 |
echo '</ul>';
|
574 |
+
}
|
575 |
?>
|
576 |
</li>
|
577 |
<?php
|
578 |
} //end output_row
|
579 |
+
|
580 |
/**
|
581 |
* Initial HTML output
|
582 |
*
|
593 |
<?php echo esc_html( $this->heading ); ?>
|
594 |
</h2>
|
595 |
<?php
|
596 |
+
$tabs =
|
597 |
array(
|
598 |
array(
|
599 |
'url' => $this->reorder_page /* URL to the tab */,
|
604 |
);
|
605 |
$tabs = apply_filters( 'metronet_reorder_posts_tabs_' . $this->post_type, (array)$tabs );
|
606 |
$tabs_count = count( $tabs );
|
607 |
+
|
608 |
//Output tabs
|
609 |
$tab_html = '';
|
610 |
if ( $tabs && !empty( $tabs ) ) {
|
619 |
$do_action = isset( $tab[ 'action' ] ) ? $tab[ 'action' ] : false;
|
620 |
}
|
621 |
$tab_url = isset( $tab[ 'url' ] ) ? $tab[ 'url' ] : '';
|
622 |
+
$tab_label = isset( $tab[ 'label' ] ) ? $tab[ 'label' ] : '';
|
623 |
$tab_html .= sprintf( '<a href="%s" class="%s">%s</a>', esc_url( $tab_url ), esc_attr( implode( ' ', $classes ) ), esc_html( $tab[ 'label' ] ) );
|
624 |
}
|
625 |
$tab_html .= '</h2>';
|
626 |
if ( $tabs_count > 1 ) {
|
627 |
+
echo $tab_html;
|
628 |
}
|
629 |
if ( $do_action ) {
|
630 |
+
do_action( $do_action );
|
631 |
}
|
632 |
+
}
|
633 |
?>
|
634 |
</div><!-- .wrap -->
|
635 |
<?php
|
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.
|
7 |
Author: Ryan Hellyer, Ronald Huereca, Scott Basgaard
|
8 |
Author URI: https://github.com/ronalfy/reorder-posts
|
9 |
Text Domain: metronet-reorder-posts
|
@@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
28 |
|
29 |
/**
|
30 |
* Do not continue processing since file was called directly
|
31 |
-
*
|
32 |
* @since 1.0
|
33 |
* @author Ryan Hellyer <ryan@metronet.no>
|
34 |
*/
|
@@ -37,7 +37,7 @@ if ( !defined( 'ABSPATH' ) )
|
|
37 |
|
38 |
/**
|
39 |
* Load classes
|
40 |
-
*
|
41 |
* @since 1.0
|
42 |
* @author Ryan Hellyer <ryan@metronet.no>
|
43 |
*/
|
@@ -46,7 +46,7 @@ require( 'class-reorder-admin.php' );
|
|
46 |
|
47 |
/**
|
48 |
* Define constants
|
49 |
-
*
|
50 |
* @since 1.0
|
51 |
* @author Ryan Hellyer <ryan@metronet.no>
|
52 |
*/
|
@@ -58,7 +58,7 @@ define( 'REORDER_BASENAME', plugin_basename(__FILE__) ); //Plugin basename
|
|
58 |
/**
|
59 |
* Instantiate admin panel
|
60 |
* Iterate through each specified post type and instantiate it's organiser
|
61 |
-
*
|
62 |
* @since 1.0
|
63 |
* @author Ryan Hellyer <ryan@metronet.no>
|
64 |
*/
|
@@ -66,27 +66,27 @@ add_action( 'wp_loaded', 'mn_reorder_posts_init', 100 ); //Load low priority in
|
|
66 |
function mn_reorder_posts_init() {
|
67 |
global $mn_reorder_instances;
|
68 |
$post_types = get_post_types( array(), 'names' );
|
69 |
-
|
70 |
//Get plugin options for post types and exclude as necessary
|
71 |
$plugin_options = get_option( 'metronet-reorder-posts', false );
|
72 |
if ( $plugin_options && isset( $plugin_options[ 'post_types' ] ) && is_array( $plugin_options[ 'post_types' ] ) ) {
|
73 |
foreach( $plugin_options[ 'post_types' ] as $post_type => $value ) {
|
74 |
if( $value === 'off' ) {
|
75 |
-
unset( $post_types[ $post_type ] );
|
76 |
}
|
77 |
}
|
78 |
}
|
79 |
-
|
80 |
// Add filter to allow users to control which post-types the plugin is used with via their theme
|
81 |
$post_types = array_unique( apply_filters( 'metronet_reorder_post_types', $post_types ) );
|
82 |
do_action( 'metronet_reorder_post_types_loaded', $post_types );
|
83 |
-
|
84 |
foreach ( $post_types as $post_type ) {
|
85 |
//Generate heading
|
86 |
$post_type_object = get_post_type_object( $post_type );
|
87 |
$post_type_label = isset( $post_type_object->label ) ? $post_type_object->label : __( 'Posts', 'metronet-reorder-posts' );
|
88 |
$heading = sprintf( __( 'Reorder %s', 'metronet-reorder-posts' ), $post_type_label );
|
89 |
-
|
90 |
// Instantiate new reordering
|
91 |
$mn_reorder_args = array(
|
92 |
'post_type' => $post_type,
|
@@ -97,7 +97,7 @@ function mn_reorder_posts_init() {
|
|
97 |
'menu_label' => __( 'Reorder', 'metronet-reorder-posts' ),
|
98 |
'post_status' => 'publish',
|
99 |
);
|
100 |
-
|
101 |
$mn_reorder_instances[ $post_type ] = new MN_Reorder(
|
102 |
$mn_reorder_args
|
103 |
);
|
@@ -113,4 +113,3 @@ function mn_reorder_init_language() {
|
|
113 |
/* Global variable for storing class instances */
|
114 |
global $mn_reorder_instances;
|
115 |
$mn_reorder_instances = array();
|
116 |
-
|
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
|
28 |
|
29 |
/**
|
30 |
* Do not continue processing since file was called directly
|
31 |
+
*
|
32 |
* @since 1.0
|
33 |
* @author Ryan Hellyer <ryan@metronet.no>
|
34 |
*/
|
37 |
|
38 |
/**
|
39 |
* Load classes
|
40 |
+
*
|
41 |
* @since 1.0
|
42 |
* @author Ryan Hellyer <ryan@metronet.no>
|
43 |
*/
|
46 |
|
47 |
/**
|
48 |
* Define constants
|
49 |
+
*
|
50 |
* @since 1.0
|
51 |
* @author Ryan Hellyer <ryan@metronet.no>
|
52 |
*/
|
58 |
/**
|
59 |
* Instantiate admin panel
|
60 |
* Iterate through each specified post type and instantiate it's organiser
|
61 |
+
*
|
62 |
* @since 1.0
|
63 |
* @author Ryan Hellyer <ryan@metronet.no>
|
64 |
*/
|
66 |
function mn_reorder_posts_init() {
|
67 |
global $mn_reorder_instances;
|
68 |
$post_types = get_post_types( array(), 'names' );
|
69 |
+
|
70 |
//Get plugin options for post types and exclude as necessary
|
71 |
$plugin_options = get_option( 'metronet-reorder-posts', false );
|
72 |
if ( $plugin_options && isset( $plugin_options[ 'post_types' ] ) && is_array( $plugin_options[ 'post_types' ] ) ) {
|
73 |
foreach( $plugin_options[ 'post_types' ] as $post_type => $value ) {
|
74 |
if( $value === 'off' ) {
|
75 |
+
unset( $post_types[ $post_type ] );
|
76 |
}
|
77 |
}
|
78 |
}
|
79 |
+
|
80 |
// Add filter to allow users to control which post-types the plugin is used with via their theme
|
81 |
$post_types = array_unique( apply_filters( 'metronet_reorder_post_types', $post_types ) );
|
82 |
do_action( 'metronet_reorder_post_types_loaded', $post_types );
|
83 |
+
|
84 |
foreach ( $post_types as $post_type ) {
|
85 |
//Generate heading
|
86 |
$post_type_object = get_post_type_object( $post_type );
|
87 |
$post_type_label = isset( $post_type_object->label ) ? $post_type_object->label : __( 'Posts', 'metronet-reorder-posts' );
|
88 |
$heading = sprintf( __( 'Reorder %s', 'metronet-reorder-posts' ), $post_type_label );
|
89 |
+
|
90 |
// Instantiate new reordering
|
91 |
$mn_reorder_args = array(
|
92 |
'post_type' => $post_type,
|
97 |
'menu_label' => __( 'Reorder', 'metronet-reorder-posts' ),
|
98 |
'post_status' => 'publish',
|
99 |
);
|
100 |
+
|
101 |
$mn_reorder_instances[ $post_type ] = new MN_Reorder(
|
102 |
$mn_reorder_args
|
103 |
);
|
113 |
/* Global variable for storing class instances */
|
114 |
global $mn_reorder_instances;
|
115 |
$mn_reorder_instances = array();
|
|
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:
|
7 |
-
Tags: reorder,
|
8 |
-
Stable tag: 2.4.
|
9 |
License: GPLv3 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
11 |
|
@@ -13,7 +13,7 @@ A simple and easy way to reorder your custom post types in WordPress.
|
|
13 |
|
14 |
== Description ==
|
15 |
|
16 |
-
A simple and easy way to reorder your custom post-type posts in WordPress. Adds drag and drop functionality for post ordering in the WordPress admin panel. Works with custom post-types and regular posts.
|
17 |
|
18 |
We consider Reorder Posts a <strong>developer tool</strong>. If you do not know what `menu_order` or custom queries are, then this plugin is likely not for you.
|
19 |
|
@@ -35,11 +35,13 @@ We consider Reorder Posts a <strong>developer tool</strong>. If you do not know
|
|
35 |
<li><a href="https://wordpress.org/plugins/reorder-terms/">Reorder Terms</a></li>
|
36 |
</ul>
|
37 |
|
|
|
|
|
38 |
<h3>Spread the Word</h3>
|
39 |
If you like this plugin, please help spread the word. Rate the plugin. Write about the plugin. Something :)
|
40 |
|
41 |
<h3>Translations</h3>
|
42 |
-
|
43 |
<ul>
|
44 |
<li>German</li>
|
45 |
</ul>
|
@@ -59,14 +61,14 @@ The plugin is now independently developed by <a href="https://geek.hellyer.kiwi/
|
|
59 |
|
60 |
== Installation ==
|
61 |
|
62 |
-
Either install the plugin via the WordPress admin panel, or ...
|
63 |
|
64 |
1. Upload `metronet-reorder-posts` to the `/wp-content/plugins/` directory.
|
65 |
2. Activate the plugin through the 'Plugins' menu in WordPress.
|
66 |
|
67 |
-
For each post type, you will see a new "Reorder" submenu. Simply navigate to "Reorder" to change the order of your post types. Changes are saved immediately, there is no need to click a save or update button.
|
68 |
|
69 |
-
By default, ordering is enabled for all post types. A settings panel is available for determining which post types to enable ordering for.
|
70 |
|
71 |
Advanced customization is allowed via hooks. See the <a href="https://github.com/ronalfy/reorder-posts#plugin-filters">Plugin Filters on GitHub</a>.
|
72 |
|
@@ -92,7 +94,7 @@ There isn't one. The changes are saved automatically.
|
|
92 |
|
93 |
Yes, and no. There are many ways to retrieve posts using the WordPress API, and if the code has a `menu_order` sort property, the changes should be reflected immediately.
|
94 |
|
95 |
-
Often, however, there is no `menu_order` argument. In the plugin's settings, there is an "Advanced" section which will attempt to override the `menu_order` property. Please use this with caution.
|
96 |
|
97 |
= Can I use this on a single post type? =
|
98 |
|
@@ -126,6 +128,12 @@ No, but there is an add-on for this plugin called <a href="https://wordpress.org
|
|
126 |
2. Admin panel settings
|
127 |
|
128 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
= 2.4.0 =
|
130 |
* Released 2016-08-14
|
131 |
* Major CSS overhaul inspired by the Nested Pages plugin
|
@@ -190,10 +198,10 @@ No, but there is an add-on for this plugin called <a href="https://wordpress.org
|
|
190 |
* Changed class names to be more unique.
|
191 |
|
192 |
= 2.0.0 =
|
193 |
-
* Released 2014-12-12
|
194 |
* Added settings panel for enabling/disabling the Reorder plugin for post types.
|
195 |
* Added advanced settings for overriding the menu order of post types.
|
196 |
-
* Added internationalization capabilities.
|
197 |
* Slightly adjusted the styles of the Reordering interface.
|
198 |
|
199 |
= 1.0.6 =
|
@@ -231,6 +239,9 @@ No, but there is an add-on for this plugin called <a href="https://wordpress.org
|
|
231 |
|
232 |
== Upgrade Notice ==
|
233 |
|
|
|
|
|
|
|
234 |
= 2.4.0 =
|
235 |
Major CSS overhaul inspired by the Nested Pages plugin and the plugin is now mobile friendly.
|
236 |
|
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 |
|
13 |
|
14 |
== Description ==
|
15 |
|
16 |
+
A simple and easy way to reorder your custom post-type posts in WordPress. Adds drag and drop functionality for post ordering in the WordPress admin panel. Works with custom post-types and regular posts.
|
17 |
|
18 |
We consider Reorder Posts a <strong>developer tool</strong>. If you do not know what `menu_order` or custom queries are, then this plugin is likely not for you.
|
19 |
|
35 |
<li><a href="https://wordpress.org/plugins/reorder-terms/">Reorder Terms</a></li>
|
36 |
</ul>
|
37 |
|
38 |
+
|
39 |
+
|
40 |
<h3>Spread the Word</h3>
|
41 |
If you like this plugin, please help spread the word. Rate the plugin. Write about the plugin. Something :)
|
42 |
|
43 |
<h3>Translations</h3>
|
44 |
+
|
45 |
<ul>
|
46 |
<li>German</li>
|
47 |
</ul>
|
61 |
|
62 |
== Installation ==
|
63 |
|
64 |
+
Either install the plugin via the WordPress admin panel, or ...
|
65 |
|
66 |
1. Upload `metronet-reorder-posts` to the `/wp-content/plugins/` directory.
|
67 |
2. Activate the plugin through the 'Plugins' menu in WordPress.
|
68 |
|
69 |
+
For each post type, you will see a new "Reorder" submenu. Simply navigate to "Reorder" to change the order of your post types. Changes are saved immediately, there is no need to click a save or update button.
|
70 |
|
71 |
+
By default, ordering is enabled for all post types. A settings panel is available for determining which post types to enable ordering for.
|
72 |
|
73 |
Advanced customization is allowed via hooks. See the <a href="https://github.com/ronalfy/reorder-posts#plugin-filters">Plugin Filters on GitHub</a>.
|
74 |
|
94 |
|
95 |
Yes, and no. There are many ways to retrieve posts using the WordPress API, and if the code has a `menu_order` sort property, the changes should be reflected immediately.
|
96 |
|
97 |
+
Often, however, there is no `menu_order` argument. In the plugin's settings, there is an "Advanced" section which will attempt to override the `menu_order` property. Please use this with caution.
|
98 |
|
99 |
= Can I use this on a single post type? =
|
100 |
|
128 |
2. Admin panel settings
|
129 |
|
130 |
== Changelog ==
|
131 |
+
|
132 |
+
= 2.4.1 =
|
133 |
+
* Released 2019-02-16
|
134 |
+
* Added query to reorder posts for an example
|
135 |
+
* Option to turn off query output
|
136 |
+
|
137 |
= 2.4.0 =
|
138 |
* Released 2016-08-14
|
139 |
* Major CSS overhaul inspired by the Nested Pages plugin
|
198 |
* Changed class names to be more unique.
|
199 |
|
200 |
= 2.0.0 =
|
201 |
+
* Released 2014-12-12
|
202 |
* Added settings panel for enabling/disabling the Reorder plugin for post types.
|
203 |
* Added advanced settings for overriding the menu order of post types.
|
204 |
+
* Added internationalization capabilities.
|
205 |
* Slightly adjusted the styles of the Reordering interface.
|
206 |
|
207 |
= 1.0.6 =
|
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 |
|