View difference between Paste ID: Mnsxaa4y 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 label (wp_list_pages as vertical dropdown) | |
38 | $wpListPagesLabel = 'Pages'; | |
39 | ||
40 | // Configure label for 'Community' links default = 'Community' | |
41 | $bpCommunityLinks = 'Community'; | |
42 | ||
43 | // Configure labels for wp_nav_menu dropdowns | |
44 | $adminbarPages1 = 'Pages'; | |
45 | $adminbarPages2 = 'pages 2'; | |
46 | ||
47 | // hide the main site navigation - default = false(show) set to true to hide | |
48 | $hideMainNav = false; // set true to hide main site links | |
49 | ||
50 | /*-------------------------- END USER CONFIG -----------------------------*/ | |
51 | ||
52 | // Register WP 3.0 nav menus regions | |
53 | // Create regions for each user menu type | |
54 | if ( function_exists( 'register_nav_menus' ) ) { | |
55 | register_nav_menus( array( | |
56 | 'bp_adminbar_pages1' => __( 'Adminbar pages 1'), | |
57 | 'bp_adminbar_pages2' => __( 'Adminbar pages 2 ') | |
58 | ) ); | |
59 | } | |
60 | ||
61 | ||
62 | // Begin 'pages' function | |
63 | ||
64 | function pages(){ | |
65 | global $current_blog, $pageLinkDropdown, $wpListPagesLabel, $bpCommunityLinks, $adminbarPages1, | |
66 | $adminbarPages2 ; | |
67 | ||
68 | ?> | |
69 | ||
70 | <?php if($current_blog->blog_id == '1') : ?> | |
71 | ||
72 | ||
73 | <!-- Community Drop Down --> | |
74 | <li | |
75 | <?php if (bp_is_page( BP_ACTIVITY_SLUG ) || | |
76 | bp_is_page( BP_MEMBERS_SLUG ) || bp_is_member() || | |
77 | bp_is_page( BP_GROUPS_SLUG ) || bp_is_group() || | |
78 | bp_is_page( BP_FORUMS_SLUG ) || | |
79 | bp_is_page( BP_BLOGS_SLUG ) ) : ?> class="selected"<?php endif; ?>> | |
80 | ||
81 | <a href="<?php echo site_url() ?>/<?php echo BP_ACTIVITY_SLUG ?>/" title="<?php _e( '', 'buddypress' ) ?>"><?php _e( $bpCommunityLinks, 'buddypress' ) ?></a> | |
82 | ||
83 | <ul> | |
84 | ||
85 | <?php if ( bp_is_active( 'activity' ) ) : ?> | |
86 | <li<?php if ( bp_is_page( BP_ACTIVITY_SLUG ) ) : ?> class="selected"<?php endif; ?>> | |
87 | <a href="<?php echo site_url() ?>/<?php echo BP_ACTIVITY_SLUG ?>/" title="<?php _e( 'Activity', 'buddypress' ) ?>"><?php _e( 'Activity', 'buddypress' ) ?></a> | |
88 | </li> | |
89 | <?php endif; ?> | |
90 | ||
91 | <li<?php if ( bp_is_page( BP_MEMBERS_SLUG ) || bp_is_member() ) : ?> class="selected"<?php endif; ?>> | |
92 | <a href="<?php echo site_url() ?>/<?php echo BP_MEMBERS_SLUG ?>/" title="<?php _e( 'Members', 'buddypress' ) ?>"><?php _e( 'Members', 'buddypress' ) ?></a> | |
93 | </li> | |
94 | ||
95 | <?php if ( bp_is_active( 'blogs' ) && bp_core_is_multisite() ) : ?> | |
96 | <li<?php if ( bp_is_page( BP_BLOGS_SLUG ) ) : ?> class="selected"<?php endif; ?>> | |
97 | <a href="<?php echo site_url() ?>/<?php echo BP_BLOGS_SLUG ?>/" title="<?php _e( 'Member Blogs', 'buddypress' ) ?>"><?php _e( 'Member Blogs', 'buddypress' ) ?></a> | |
98 | </li> | |
99 | <?php endif; ?> | |
100 | ||
101 | <?php if ( bp_is_active( 'groups' ) ) : ?> | |
102 | <li<?php if ( bp_is_page( BP_GROUPS_SLUG ) || bp_is_group() ) : ?> class="selected"<?php endif; ?>> | |
103 | <a href="<?php echo site_url() ?>/<?php echo BP_GROUPS_SLUG ?>/" title="<?php _e( 'Groups', 'buddypress' ) ?>"><?php _e( 'Groups', 'buddypress' ) ?></a> | |
104 | </li> | |
105 | ||
106 | <?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() ) : ?> | |
107 | <li<?php if ( bp_is_page( BP_FORUMS_SLUG ) ) : ?> class="selected"<?php endif; ?>> | |
108 | <a href="<?php echo site_url() ?>/<?php echo BP_FORUMS_SLUG ?>/" title="<?php _e( 'Group Forums', 'buddypress' ) ?>"><?php _e( 'Group Forums', 'buddypress' ) ?></a> | |
109 | </li> | |
110 | <?php endif; ?> | |
111 | <?php endif; ?> | |
112 | ||
113 | <?php do_action( 'bp_nav_items' ); ?> | |
114 | ||
115 | </ul> | |
116 | ||
117 | </li> | |
118 | <?php if(!function_exists( 'wp_nav_menu' ) ): ?> | |
119 | <?php ### Don't show wp_list_pages if WP 3.0 use New wp_nav_menus instead ### ?> | |
120 | <?php if($pageLinkDropdown) : ?> | |
121 | <li><a href="/"><?php echo $wpListPagesLabel; ?></a> | |
122 | <ul> | |
123 | <?php endif; ?> | |
124 | ||
125 | <li> | |
126 | <?php wp_list_pages( 'title_li=&depth=20&exclude=' ); ?> | |
127 | </li> | |
128 | ||
129 | <?php if($pageLinkDropdown) : ?> | |
130 | </ul> | |
131 | </li> | |
132 | <?php endif; ?> | |
133 | <?php endif; ?> | |
134 | ||
135 | <?php ##################### Add call to WP Nav Menus ####################### ?> | |
136 | <?php if ( function_exists( 'wp_nav_menu' ) ): ?> | |
137 | <?php if(has_nav_menu('bp_adminbar_pages1')): ?> | |
138 | <li><a href="<?php site_url() ?>"><?php echo $adminbarPages1; ?></a> | |
139 | <?php wp_nav_menu(array('sort_column' => 'menu_order', 'container' => '', 'fallback_cb' => '', 'theme_location' => 'bp_adminbar_pages1')) ?> | |
140 | </li> | |
141 | <?php endif; ?> | |
142 | ||
143 | <?php if(has_nav_menu('bp_adminbar_pages2')): ?> | |
144 | <li><a href="<?php site_url() ?>"><?php echo $adminbarPages2; ?></a> | |
145 | <?php wp_nav_menu(array('sort_column' => 'menu_order', 'container' => '', 'fallback_cb' => '', 'theme_location' => 'bp_adminbar_pages2')) ?> | |
146 | </li> | |
147 | <?php endif; ?> | |
148 | ||
149 | <?php endif; // end check for wp 3.0 ?> | |
150 | <?php ################# end WP 3.0 wp_nav_menus ########################### ?> | |
151 | ||
152 | <?php endif; ?> | |
153 | ||
154 | <?php | |
155 | } | |
156 | ||
157 | add_action( 'bp_adminbar_menus', 'pages', 15 ); | |
158 | ||
159 | if ( $hideMainNav ): | |
160 | function hide_main_nav() { ?> | |
161 | <style type="text/css"> | |
162 | /*<![CDATA[*/ | |
163 | /* bp-wp-navbar - hide main site navigation */ | |
164 | ul#nav {display:none;} | |
165 | /*]]>*/ | |
166 | </style> | |
167 | <?php } | |
168 | add_action('wp_head', 'hide_main_nav'); | |
169 | endif; | |
170 | ?> |