Lock down menus.
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 20 Dec 2017 18:37:02 +0000 (13:37 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 20 Dec 2017 18:37:02 +0000 (13:37 -0500)
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

index 6eaf7e7..30c6523 100644 (file)
@@ -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(),
     ));
 }