public
Created

Patch to add custom post type support to CMS Page Order plugin

  • Download Gist
gistfile1.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
Index: cms-page-order.php
===================================================================
--- cms-page-order.php (revision 439171)
+++ cms-page-order.php (working copy)
@@ -36,8 +36,11 @@
/** Setup Page, Styles and Scripts */
function cmspo_admin_menu() {
load_plugin_textdomain( 'cms-page-order', false, '/cms-page-order/locale/');
- $page = add_submenu_page( 'edit.php?post_type=page', __( 'Page Order', 'cms-page-order' ), __( 'Page Order', 'cms-page-order' ), 'edit_pages', 'order', 'cmspo_menu_order_page' );
- add_action( 'admin_print_styles-' . $page, 'cmspo_print_styles' );
+ $post_types = apply_filters( 'cmspo_post_types', array( 'page' ) );
+ foreach( $post_types as $post_type ) {
+ $page = add_submenu_page( 'edit.php?post_type=' . $post_type, __( 'Page Order', 'cms-page-order' ), __( 'Page Order', 'cms-page-order' ), 'edit_pages', 'order', 'cmspo_menu_order_page' );
+ add_action( 'admin_print_styles-' . $page, 'cmspo_print_styles' );
+ }
$help = '<p>'.__( 'Rearrange the pages by dragging and dropping.', 'cms-page-order' );
if ( ( $max_levels = apply_filters( 'cmspo_max_levels', 0 ) - 1 ) && $max_levels > 0 )
@@ -176,7 +179,8 @@
<?php
printf( _n( 'Item moved to the Trash.', '%s items moved to the Trash.', $_REQUEST['trashed'] ), number_format_i18n( $_REQUEST['trashed'] ) );
$ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0;
- echo ' <a href="' . esc_url( wp_nonce_url( "edit.php?post_type=page&doaction=undo&action=untrash&ids=$ids", "bulk-posts" ) ) . '">' . __('Undo') . '</a><br />';
+ $post_type = esc_attr( $_GET['post_type'] );
+ echo ' <a href="' . esc_url( wp_nonce_url( "edit.php?post_type=$post_type&doaction=undo&action=untrash&ids=$ids", "bulk-posts" ) ) . '">' . __('Undo') . '</a><br />';
unset($_REQUEST['trashed']);
?>
</p></div>
@@ -225,11 +229,12 @@
GROUP BY t.language_code
");
+ $post_type = esc_attr( $_GET['post_type'] );
foreach ( $res as $r ) {
if ( $r->code == ICL_LANGUAGE_CODE )
$langs[] = '<span class="po-sel">'.$r->name.' <span class="po-count">('.$r->count.')</span>';
else
- $langs[] = '<span><a href="?post_type=page&page=order&lang='.$r->code.'">'.$r->name.'</a> <span class="po-count">('.$r->count.')</span>';
+ $langs[] = '<span><a href="?post_type=' . $post_type . '&page=order&lang='.$r->code.'">'.$r->name.'</a> <span class="po-count">('.$r->count.')</span>';
}
echo implode( ' | </span>', $langs ) . '</span>';
}
@@ -243,8 +248,9 @@
function cmspo_list_pages($args = null, $count = false) {
// no array in post_status until 3.2
+ $post_type = esc_attr( $_GET['post_type'] );
$defaults = array(
- 'post_type' => 'page',
+ 'post_type' => $post_type,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
@@ -351,8 +357,9 @@
elseif ( in_array($state, array('draft', 'pending', 'future')) )
$title = __( 'Publish page', 'cms-page-order' );
+ $post_type = esc_attr( $_GET['post_type'] );
if ( in_array( $state, array( 'draft', 'pending', 'future', 'private', 'password' ) ) )
- $action_url = wp_nonce_url( '?post_type=page&page=order&post='.$page->ID.'&action=remove_label&state='.$state, 'cms-page-order' );
+ $action_url = wp_nonce_url( '?post_type=' . $post_type . '&page=order&post='.$page->ID.'&action=remove_label&state='.$state, 'cms-page-order' );
if ( $state == 'private' && !current_user_can( 'edit_private_pages' ) )
$action_url = null;
else

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.