From 3a2b927d4b52eb8fc7d730eeff5ca7bdfc0f8343 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 20 Dec 2017 13:37:02 -0500 Subject: [PATCH] Lock down menus. Creating function to get the correct page ids for public menu. This will check to see if the page has password protection also. --- functions.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/functions.php b/functions.php index 6eaf7e7..30c6523 100644 --- a/functions.php +++ b/functions.php @@ -50,6 +50,7 @@ function glm_page_menu($parent = 0, $class = '') 'parent' => $parent, 'number' => '', 'exclude' => "$frontPageId,702", + 'include' => glm_get_visable_page_ids(), 'post_status' => 'publish', 'sort_order' => 'asc', 'sort_column' => 'menu_order' @@ -95,6 +96,24 @@ function SearchFilter($query) { } add_filter('pre_get_posts','SearchFilter'); +function glm_get_visable_page_ids() +{ + $publishPageIds = array(); + // Find all pages marked published + $publishedPages = get_pages( + array( + 'post_type' => 'page', + 'post_status' => 'publish', + ) + ); + foreach ( $publishedPages as $page ) { + if ( !$page->post_password ) { + $publishPageIds[] = $page->ID; + } + } + return $publishPageIds; +} + /** * glm_offcanvas_menu * @@ -103,9 +122,10 @@ add_filter('pre_get_posts','SearchFilter'); function glm_offcanvas_menu() { wp_page_menu(array( - 'depth' => 0, + 'depth' => 0, 'sort_column' => 'menu_order', - 'menu_class' => 'left-off-canvas-list' + 'menu_class' => 'left-off-canvas-list', + 'include' => glm_get_visable_page_ids(), )); } -- 2.17.1