View difference between Paste ID: TA4vGHT5 and
SHOW:
|
|
- or go back to the newest paste.
1 | - | |
1 | + | <?php |
2 | ||
3 | /* | |
4 | Plugin Name: Add All Nav Links to BP Adminbar (bp-wp-navbar) | |
5 | Requires at least: WordPress 2.9.2 / BuddyPress 1.2.3 | |
6 | Tested up to: WordPress 3.0 / BuddyPress 1.2.5.2 (Should work anyway. Be sure to read the readme file for more on this.) | |
7 | Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates | |
8 | Description: This plugin aggregates all Buddypress directory and Wordpress page links into the BP Adminbar. All BP pages are collected in a Community dropdown, and all WP pages appear in dropdowns that respect whatever page order you have set in your WP backend. | |
9 | Version: 1.1 (Initial release) | |
10 | Author: Patrick Cohen (pcwriter) | |
11 | Author URI: http://nowrecovery.com/members/admin/ | |
12 | ||
13 | Thanks and props to hnla for invaluable collaboration and tutoring on this plugin; to David Lewis, Chau kar, Jens Wedin, and r-a-y for some great contributions; and to all for helping me learn basic stuff and iron out the kinks in this code (whether they know it or not). | |
14 | ||
15 | License : GPL2 | |
16 | Copyright 2010 Patrick Cohen (email : info@nowrecovery.com) | |
17 | ||
18 | This program is free software; you can redistribute it and/or modify | |
19 | it under the terms of the GNU General Public License, version 2, as | |
20 | published by the Free Software Foundation. | |
21 | ||
22 | This program is distributed in the hope that it will be useful, | |
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 | GNU General Public License for more details. | |
26 | ||
27 | You should have received a copy of the GNU General Public License | |
28 | along with this program; if not, write to the Free Software | |
29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
30 | */ | |
31 | ||
32 | /*-------------------------- USER CONFIG OPTIONS --------------------------*/ | |
33 | ||
34 | // configure wp_list_pages nav as horizontal(false) or vertical dropdown(true) | |
35 | $pageLinkDropdown = true; // set true for dropdown | |
36 | ||
37 | //configure top level Nav bar labels | |
38 | $wpListPagesLabel = 'Pages'; | |
39 | ||
40 | // configure labels for wp_nav_menu dropdowns | |
41 | $adminbarPages1 = 'Pages'; | |
42 | $adminbarPages2 = 'pages 2'; | |
43 | ||
44 | // hide the main site navigation - default = false(show) set to true to hide | |
45 | $hideMainNav = false; | |
46 | ||
47 | /*-------------------------- END USER CONFIG -----------------------------*/ | |
48 | ||
49 | // Register WP 3.0 nav menus regions | |
50 | // Create regions for each user menu type | |
51 | if ( function_exists( 'register_nav_menus' ) ) { | |
52 | register_nav_menus( array( | |
53 | 'bp_adminbar_pages1' => __( 'Adminbar pages 1'), | |
54 | 'bp_adminbar_pages2' => __( 'Adminbar pages 2 ') | |
55 | ) ); | |
56 | } | |
57 | ||
58 | ||
59 | // Begin 'pages' function | |
60 | ||
61 | function pages(){ | |
62 | global $current_blog, $wpListPagesLabel, $wpListPagesLabel, $adminbarPages1, | |
63 | $adminbarPages2, $hideMainNav; | |
64 | ||
65 | ?> | |
66 | ||
67 | <?php if($current_blog->blog_id == '1') : ?> | |
68 | ||
69 | ||
70 | <!-- Community Drop Down --> | |
71 | <li | |
72 | <?php if (bp_is_page( BP_ACTIVITY_SLUG ) || | |
73 | bp_is_page( BP_MEMBERS_SLUG ) || bp_is_member() || | |
74 | bp_is_page( BP_GROUPS_SLUG ) || bp_is_group() || | |
75 | bp_is_page( BP_FORUMS_SLUG ) || | |
76 | bp_is_page( BP_BLOGS_SLUG ) ) : ?> class="selected"<?php endif; ?>> | |
77 | ||
78 | <a href="<?php echo site_url() ?>/<?php echo BP_ACTIVITY_SLUG ?>/" title="<?php _e( '', 'buddypress' ) ?>"><?php _e( 'Community', 'buddypress' ) ?></a> | |
79 | ||
80 | <ul> | |
81 | ||
82 | <?php if ( bp_is_active( 'activity' ) ) : ?> | |
83 | <li<?php if ( bp_is_page( BP_ACTIVITY_SLUG ) ) : ?> class="selected"<?php endif; ?>> | |
84 | <a href="<?php echo site_url() ?>/<?php echo BP_ACTIVITY_SLUG ?>/" title="<?php _e( 'Activity', 'buddypress' ) ?>"><?php _e( 'Activity', 'buddypress' ) ?></a> | |
85 | </li> | |
86 | <?php endif; ?> | |
87 | ||
88 | <li<?php if ( bp_is_page( BP_MEMBERS_SLUG ) || bp_is_member() ) : ?> class="selected"<?php endif; ?>> | |
89 | <a href="<?php echo site_url() ?>/<?php echo BP_MEMBERS_SLUG ?>/" title="<?php _e( 'Members', 'buddypress' ) ?>"><?php _e( 'Members', 'buddypress' ) ?></a> | |
90 | </li> | |
91 | ||
92 | <?php if ( bp_is_active( 'blogs' ) && bp_core_is_multisite() ) : ?> | |
93 | <li<?php if ( bp_is_page( BP_BLOGS_SLUG ) ) : ?> class="selected"<?php endif; ?>> | |
94 | <a href="<?php echo site_url() ?>/<?php echo BP_BLOGS_SLUG ?>/" title="<?php _e( 'Member Blogs', 'buddypress' ) ?>"><?php _e( 'Member Blogs', 'buddypress' ) ?></a> | |
95 | </li> | |
96 | <?php endif; ?> | |
97 | ||
98 | <?php if ( bp_is_active( 'groups' ) ) : ?> | |
99 | <li<?php if ( bp_is_page( BP_GROUPS_SLUG ) || bp_is_group() ) : ?> class="selected"<?php endif; ?>> | |
100 | <a href="<?php echo site_url() ?>/<?php echo BP_GROUPS_SLUG ?>/" title="<?php _e( 'Groups', 'buddypress' ) ?>"><?php _e( 'Groups', 'buddypress' ) ?></a> | |
101 | </li> | |
102 | ||
103 | <?php if ( bp_is_active( 'forums' ) && bp_is_active( 'groups' ) && ( function_exists( 'bp_forums_is_installed_correctly' ) && !(int) get_site_option( 'bp-disable-forum-directory' ) ) && bp_forums_is_installed_correctly() ) : ?> | |
104 | <li<?php if ( bp_is_page( BP_FORUMS_SLUG ) ) : ?> class="selected"<?php endif; ?>> | |
105 | <a href="<?php echo site_url() ?>/<?php echo BP_FORUMS_SLUG ?>/" title="<?php _e( 'Group Forums', 'buddypress' ) ?>"><?php _e( 'Group Forums', 'buddypress' ) ?></a> | |
106 | </li> | |
107 | <?php endif; ?> | |
108 | <?php endif; ?> | |
109 | ||
110 | <?php do_action( 'bp_nav_items' ); ?> | |
111 | ||
112 | </ul> | |
113 | ||
114 | </li> | |
115 | <?php if(!function_exists( 'wp_nav_menu' ) ): ?> | |
116 | <?php ### Don't show wp_list_pages if WP 3.0 use New wp_nav_menus instead ### ?> | |
117 | <?php if($pageLinkDropdown) : ?> | |
118 | <li><a href="/"><?php echo $wpListPagesLabel; ?></a> | |
119 | <ul> | |
120 | <?php endif; ?> | |
121 | ||
122 | <li> | |
123 | <?php wp_list_pages( 'title_li=&depth=20&exclude=' ); ?> | |
124 | </li> | |
125 | ||
126 | <?php if($pageLinkDropdown) : ?> | |
127 | </ul> | |
128 | </li> | |
129 | <?php endif; ?> | |
130 | <?php endif; ?> | |
131 | ||
132 | <?php ##################### Add call to WP Nav Menus ####################### ?> | |
133 | <?php if ( function_exists( 'wp_nav_menu' ) ): ?> | |
134 | <?php if(has_nav_menu('bp_adminbar_pages1')): ?> | |
135 | <li><a href="<?php site_url() ?>"><?php echo $adminbarPages1; ?></a> | |
136 | <?php wp_nav_menu(array('sort_column' => 'menu_order', 'container' => '', 'fallback_cb' => '', 'theme_location' => 'bp_adminbar_pages1')) ?> | |
137 | </li> | |
138 | <?php endif; ?> | |
139 | ||
140 | <?php if(has_nav_menu('bp_adminbar_pages2')): ?> | |
141 | <li><a href="<?php site_url() ?>"><?php echo $adminbarPages2; ?></a> | |
142 | <?php wp_nav_menu(array('sort_column' => 'menu_order', 'container' => '', 'fallback_cb' => '', 'theme_location' => 'bp_adminbar_pages2')) ?> | |
143 | </li> | |
144 | <?php endif; ?> | |
145 | ||
146 | <?php endif; // end check for wp 3.0 ?> | |
147 | <?php ################# end WP 3.0 wp_nav_menus ########################### ?> | |
148 | ||
149 | <?php endif; ?> | |
150 | ||
151 | <?php | |
152 | } | |
153 | ||
154 | add_action( 'bp_adminbar_menus', 'pages', 15 ); | |
155 | ||
156 | if ( $hideMainNav ): | |
157 | function hide_main_nav() { ?> | |
158 | <style type="text/css"> | |
159 | /*<![CDATA[*/ | |
160 | /* bp-wp-navbar - hide main site navigation */ | |
161 | ul#nav {display:none;} | |
162 | /*]]>*/ | |
163 | </style> | |
164 | <?php } | |
165 | add_action('wp_head', 'hide_main_nav'); | |
166 | endif; | |
167 | ?> |