Forked from stephanieleary/wp_private_page_filters.php
Last active
January 4, 2016 02:29
-
-
Save KoenRijpstra/8555554 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Enable unpublished pages in page lists and dropdowns | |
* | |
* @param array $args | |
* @return array $args | |
*/ | |
function scl_list_pages_args( $args ) { | |
$args['post_status'] = array( 'publish', 'private' ); | |
return $args; | |
} | |
add_filter( 'wp_list_pages_args', 'scl_list_pages_args' ); | |
add_filter( 'wp_dropdown_pages_args', 'scl_list_pages_args' ); | |
/** | |
* Add private/draft/future/pending pages to parent dropdown in page attributes metabox and Quick Edit | |
* | |
* @param array $dropdown_args | |
* @param object $post (Optional) | |
* @return array $dropdown_args | |
*/ | |
function page_attributes_metabox_add_parents( $dropdown_args, $post = NULL ) { | |
$dropdown_args['post_status'] = array('publish', 'draft', 'pending', 'future', 'private'); | |
return $dropdown_args; | |
} | |
add_filter( 'page_attributes_dropdown_pages_args', 'page_attributes_metabox_add_parents', 10, 2 ); | |
add_filter( 'quick_edit_dropdown_pages_args', 'page_attributes_metabox_add_parents', 10); | |
/** | |
* Add (status) to titles in page parent dropdowns | |
* | |
* @param string $title | |
* @param object $page | |
* @return string $title | |
*/ | |
function page_parent_status_filter( $title, $page ) { | |
$status = $page->post_status; | |
if ($status != __('publish')) | |
$title .= " ($status)"; | |
return $title; | |
} | |
add_filter( 'list_pages', 'page_parent_status_filter', 10, 2); | |
/** | |
* Filter public page queries to include privately published ones. | |
* Filter pages metabox on menu admin screen to include all built-in statuses. | |
* | |
* @param object $query | |
* @return object $query | |
*/ | |
function private_page_query_filter($query) { | |
if ( is_admin() ) { | |
$screen = get_current_screen(); | |
if ( 'nav-menus' == $screen->base ) | |
$query->set( 'post_status', 'publish,private,future,pending,draft' ); | |
} | |
else { | |
$query->set( 'post_status', 'publish,private' ); | |
} | |
return $query; | |
} | |
add_filter('pre_get_posts', 'private_page_query_filter'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment