PluginProbe
bbPress / 2.1-rc1
bbPress v2.1-rc1
trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.2.2 All 71 releases
bbpress / bbp-admin / bbp-functions.php

bbp-functions.php in bbPress 2.1-rc1, at bbp-admin/bbp-functions.php

213 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Admin Functions
5 *
6 * @package bbPress
7 * @subpackage Administration
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 /** Admin Menus ***************************************************************/
14
15 /**
16 * Add a separator to the WordPress admin menus
17 *
18 * @since bbPress (r2957)
19 */
20 function bbp_admin_separator() {
21
22 // Prevent duplicate separators when no new menu items exist
23 if ( !current_user_can( 'edit_replies' ) )
24 return;
25
26 // Prevent duplicate separators when no core menu items exist
27 if ( !current_user_can( 'manage_options' ) )
28 return;
29
30 global $menu;
31
32 $menu[] = array( '', 'read', 'separator-bbpress', '', 'wp-menu-separator bbpress' );
33 }
34
35 /**
36 * Tell WordPress we have a custom menu order
37 *
38 * @since bbPress (r2957)
39 *
40 * @param bool $menu_order Menu order
41 * @return bool Always true
42 */
43 function bbp_admin_custom_menu_order( $menu_order ) {
44 if ( !current_user_can( 'edit_replies' ) )
45 return $menu_order;
46
47 return true;
48 }
49
50 /**
51 * Move our custom separator above our custom post types
52 *
53 * @since bbPress (r2957)
54 *
55 * @param array $menu_order Menu Order
56 * @uses bbp_get_forum_post_type() To get the forum post type
57 * @return array Modified menu order
58 */
59 function bbp_admin_menu_order( $menu_order ) {
60
61 // Initialize our custom order array
62 $bbp_menu_order = array();
63
64 // Get the index of our custom separator
65 $bbp_separator = array_search( 'separator-bbpress', $menu_order );
66
67 // Forums
68 if ( current_user_can( 'edit_forums' ) ) {
69 $top_menu_type = bbp_get_forum_post_type();
70
71 // Topics
72 } elseif ( current_user_can( 'edit_topics' ) ) {
73 $top_menu_type = bbp_get_topic_post_type();
74
75 // Replies
76 } elseif ( current_user_can( 'edit_replies' ) ) {
77 $top_menu_type = bbp_get_reply_post_type();
78
79 // Bail if there are no bbPress menus present
80 } else {
81 return;
82 }
83
84 // Loop through menu order and do some rearranging
85 foreach ( $menu_order as $index => $item ) {
86
87 // Current item is ours, so set our separator here
88 if ( ( ( 'edit.php?post_type=' . $top_menu_type ) == $item ) ) {
89 $bbp_menu_order[] = 'separator-bbpress';
90 unset( $menu_order[$bbp_separator] );
91 }
92
93 // Skip our separator
94 if ( !in_array( $item, array( 'separator-bbpress' ) ) ) {
95 $bbp_menu_order[] = $item;
96 }
97 }
98
99 // Return our custom order
100 return $bbp_menu_order;
101 }
102
103 /**
104 * Filter sample permalinks so that certain languages display properly.
105 *
106 * @since bbPress (r3336)
107 *
108 * @param string $post_link Custom post type permalink
109 * @param object $_post Post data object
110 * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
111 * @param bool $sample Optional, defaults to false. Is it a sample permalink.
112 *
113 * @uses is_admin() To make sure we're on an admin page
114 * @uses bbp_is_custom_post_type() To get the forum post type
115 *
116 * @return string The custom post type permalink
117 */
118 function bbp_filter_sample_permalink( $post_link, $_post, $leavename = false, $sample = false ) {
119
120 // Bail if not on an admin page and not getting a sample permalink
121 if ( !empty( $sample ) && is_admin() && bbp_is_custom_post_type() )
122 return urldecode( $post_link );
123
124 // Return post link
125 return $post_link;
126 }
127
128 /**
129 * Uninstall all bbPress options and capabilities from a specific site.
130 *
131 * @since bbPress (r3765)
132 * @param type $site_id
133 */
134 function bbp_do_uninstall( $site_id = 0 ) {
135 if ( empty( $site_id ) )
136 $site_id = get_current_blog_id();
137
138 switch_to_blog( $site_id );
139 bbp_delete_options();
140 bbp_remove_caps();
141 flush_rewrite_rules();
142 restore_current_blog();
143 }
144
145 /**
146 * This tells WP to highlight the Tools > Forums menu item,
147 * regardless of which actual bbPress Tools screen we are on.
148 *
149 * The conditional prevents the override when the user is viewing settings or
150 * any third-party plugins.
151 *
152 * @since bbPress (r3888)
153 * @global string $plugin_page
154 * @global array $submenu_file
155 */
156 function bbp_tools_modify_menu_highlight() {
157 global $plugin_page, $submenu_file;
158
159 // This tweaks the Tools subnav menu to only show one bbPress menu item
160 if ( ! in_array( $plugin_page, array( 'bbp-settings' ) ) )
161 $submenu_file = 'bbp-repair';
162 }
163
164 /**
165 * Output the tabs in the admin area
166 *
167 * @since bbPress (r3872)
168 * @param string $active_tab Name of the tab that is active
169 */
170 function bbp_tools_admin_tabs( $active_tab = '' ) {
171 echo bbp_get_tools_admin_tabs( $active_tab );
172 }
173
174 /**
175 * Output the tabs in the admin area
176 *
177 * @since bbPress (r3872)
178 * @param string $active_tab Name of the tab that is active
179 */
180 function bbp_get_tools_admin_tabs( $active_tab = '' ) {
181
182 // Declare local variables
183 $tabs_html = '';
184 $idle_class = 'nav-tab';
185 $active_class = 'nav-tab nav-tab-active';
186
187 // Setup core admin tabs
188 $tabs = apply_filters( 'bbp_tools_admin_tabs', array(
189 '0' => array(
190 'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-repair' ), 'tools.php' ) ),
191 'name' => __( 'Repair Forums', 'bbpress' )
192 ),
193 '1' => array(
194 'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-converter' ), 'tools.php' ) ),
195 'name' => __( 'Import Forums', 'bbpress' )
196 ),
197 '2' => array(
198 'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-reset' ), 'tools.php' ) ),
199 'name' => __( 'Reset Forums', 'bbpress' )
200 )
201 ) );
202
203 // Loop through tabs and build navigation
204 foreach( $tabs as $tab_id => $tab_data ) {
205 $is_current = (bool) ( $tab_data['name'] == $active_tab );
206 $tab_class = $is_current ? $active_class : $idle_class;
207 $tabs_html .= '<a href="' . $tab_data['href'] . '" class="' . $tab_class . '">' . $tab_data['name'] . '</a>';
208 }
209
210 // Output the tabs
211 return $tabs_html;
212 }
213