Members only appearance/Menu auto-creation
authorLaury GvR <laury@gaslightmedia.com>
Thu, 28 Apr 2016 19:17:08 +0000 (15:17 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Thu, 28 Apr 2016 19:17:08 +0000 (15:17 -0400)
setup/adminHooks.php

index 8eb9333..5a8d143 100644 (file)
@@ -28,7 +28,7 @@
 
 
 // Add content to member detail page
-add_filter('glm-member-db-admin-management-hoooksHelp', function($content) {
+add_filter('glm-member-db-admin-management-hooksHelp', function($content) {
 
         // Read in this plugin/addon hook help file
         $fname = GLM_MEMBERS_PLUGIN_PATH.'/setup/hooksHelp.html';
@@ -43,5 +43,58 @@ add_filter('glm-member-db-admin-management-hoooksHelp', function($content) {
     10,
     2
 );
+        
+$menuName = "Members Only";
+$menuSlug = "members-only";
+// Does the menu exist already?
+register_nav_menu($menuSlug, $menuName);
+    
+$menuExists = wp_get_nav_menu_object( $menuName );
+
+// If it doesn't exist, let's create it.
+if( !$menuExists){
+    
+    $membersOnlyPageID = get_option('glm_members_database_members_only_id');
+    //
+    $menu_id = wp_create_nav_menu($menuName);
+
+    // Set up default members only link and add it to the menu.
+    wp_update_nav_menu_item($menu_id, 0, array(
+        'menu-item-title' =>  __('Members Only'),
+        'menu-item-object-id' => get_option('glm_members_database_members_only_id'),
+        'menu-item-parent-id' => 0,
+        'menu-item-position'  => 0,
+        'menu-item-object'    => 'page',
+        'menu-item-type'      => 'post_type',
+        'menu-item-classes'   => 'members-only',
+        'menu-item-status'    => 'publish'));
+}
+
+$locations = get_theme_mod( 'nav_menu_locations' );
+if(!empty($locations))
+{
+    $menu = get_term_by('name', $menuName, 'nav_menu');
+    $locations[$menuSlug] = $menu->term_id;
+    set_theme_mod('nav_menu_locations', $locations);
+}
+
+if ( ! function_exists( 'glm_theme_members_only_menu' ) && function_exists('Glm_Theme_Top_Bar_Walker')) {
+    function glm_theme_members_only_menu() {
+        wp_nav_menu(array(
+            'container' => false,                           // remove nav container
+            'container_class' => 'members-only1',                        // class of container
+            'menu' => '',                                   // menu name
+            'menu_class' => 'members-only2',                             // adding custom nav class
+            'theme_location' => 'members-only',             // where it's located in the theme
+            'before' => '',                                 // before each link <a>
+            'after' => '',                                  // after each link </a>
+            'link_before' => '',                            // before each link text
+            'link_after' => '',                             // after each link text
+            'depth' => 2,                                   // limit the depth of the nav
+            'fallback_cb' => false,                         // fallback function (see below)
+            'walker' => new Glm_Theme_Top_Bar_Walker()
+        ));
+    }
+}
 
 ?>
\ No newline at end of file