Changeset 822824
- Timestamp:
- 12/16/2013 02:04:02 AM (12 years ago)
- Location:
- menu-override/trunk
- Files:
-
- 2 edited
-
MenuOverride.php (modified) (5 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
menu-override/trunk/MenuOverride.php
r769237 r822824 4 4 Plugin URI: http://phillipshipley.com/wordpress/menu-override 5 5 Description: Override page level menus with this plugin. On a page by page basis you can leave your navigation menu the default, choose different menus for each page, or have a page inherit from its parent. This plugin is particularly useful when you want to have section level navigation menus but your theme does not support it. 6 Version: 0. 16 Version: 0.2 7 7 Author: fillup17 8 8 Author URI: http://phillipshipley.com/ … … 31 31 class MenuOverride 32 32 { 33 const formFieldPrefix = 'mo_menu_location_'; 34 33 35 public static function filterMenu($args = '') 34 36 { 35 37 global $post; 36 $current = get_post_meta($post->ID,'selectedMenu',true); 37 if($current == "PARENT"){ 38 $levels = 0; 39 while($current == "PARENT" && $levels < 5){ 40 $post = get_post($post->post_parent); 41 $current = get_post_meta($post->ID,'selectedMenu',true); 42 $levels++; 43 } 44 } 45 46 if($current == 'DEFAULT'){ 38 if($args['theme_location'] == ''){ 47 39 return $args; 48 40 } 41 $menuOverrideSelection = get_post_meta($post->ID,'menuOverrideSelection',true); 49 42 50 $args['theme_location'] = ''; 51 $args['menu'] = $current; 43 if(in_array($args['theme_location'],array_keys($menuOverrideSelection))){ 44 $current = $menuOverrideSelection[$args['theme_location']]; 45 if($current == "PARENT"){ 46 $levels = 0; 47 while($current == "PARENT" && $levels < 5){ 48 $post = get_post($post->post_parent); 49 $menuOverrideSelection = get_post_meta($post->ID,'menuOverrideSelection',true); 50 if(in_array($args['theme_location'],array_keys($menuOverrideSelection))){ 51 $current = $menuOverrideSelection[$args['theme_location']]; 52 } 53 $levels++; 54 } 55 } 56 57 if($current == 'DEFAULT'){ 58 return $args; 59 } 60 61 //$args['theme_location'] = ''; 62 $args['menu'] = $current; 63 } 52 64 53 65 return $args; … … 68 80 { 69 81 global $post; 70 $current = get_post_meta($post->ID,'selectedMenu',true);82 $currentMenu = get_post_meta($post->ID,'menuOverrideSelection',true); 71 83 $menus = self::getMenus(); 84 $locations = get_registered_nav_menus(); 85 72 86 wp_nonce_field('overridemenu_nonce', 'overridemenu_nonce' ); 73 87 ?> 74 <strong>You may override the menu used on this page by changing this dropdown:</strong><br /> 75 <select name="selectedMenu" id="selectedMenu"> 88 <strong>You may override any of the menus used on this page by selecting the location and the menu you wish to be displayed there:</strong><br /> 89 90 <?php 91 foreach($locations as $location => $temp){ 92 $field = self::formFieldPrefix . preg_replace('/ /','___',$location); 93 ?> 94 <br /><br />Location: <i><?php echo $location; ?></i><br /> 95 <select name="<?php echo $field; ?>" id="menuLocation<?php echo $location; ?>"> 76 96 <option value="DEFAULT">Use Default Menu</option> 77 <option value="PARENT" <?php if($current == 'PARENT'){ echo "selected='selected'"; }?>>Use Parent Page Menu</option>97 <option value="PARENT" <?php if($currentMenu[$location] == 'PARENT'){ echo "selected='selected'"; }?>>Use Parent Page Menu</option> 78 98 <?php 79 99 foreach($menus as $menu){ 80 100 ?> 81 101 <option value="<?php echo $menu->slug; ?>" 82 <?php if($menu->slug == $current ){ echo " selected='selected' ";} ?>><?php echo esc_attr($menu->name);?></option>102 <?php if($menu->slug == $currentMenu[$location]){ echo " selected='selected' ";} ?>><?php echo esc_attr($menu->name);?></option> 83 103 <?php 84 104 } … … 86 106 </select> 87 107 <?php 108 } 88 109 } 89 110 … … 96 117 // if our current user can't edit this post, bail 97 118 if( !current_user_can( 'edit_post' ) ) return; 119 120 $menuOverrideSelection = array(); 121 foreach($_POST as $key => $value){ 122 if(preg_match('/'.self::formFieldPrefix.'(.*)/', $key, $match)){ 123 $locName = preg_replace('/___/', ' ', $match[1]); 124 $menuOverrideSelection[$locName] = $value; 125 } 126 } 98 127 99 update_post_meta($post_id,' selectedMenu',$_POST['selectedMenu']);128 update_post_meta($post_id,'menuOverrideSelection',$menuOverrideSelection); 100 129 } 101 130 -
menu-override/trunk/readme.txt
r769237 r822824 3 3 Tags: menu override, custom menu, custom navigation 4 4 Requires at least: 3.5.1 5 Tested up to: 3. 65 Tested up to: 3.8 6 6 Stable tag: trunk 7 7 License: GPLv2 or later … … 22 22 == Changelog == 23 23 24 = 0.2 = 25 * Added ability to override multiple menu locations on a single page 26 24 27 = 0.1 = 25 28 * Initial Release … … 27 30 == Upgrade Notice == 28 31 32 = 0.2 = 33 * When upgrading, due to data structure changes, your current overrides will be lost, sorry. 34 29 35 = 0.1 = 30 36 * Initial Release
Note: See TracChangeset
for help on using the changeset viewer.