Changeset 6274
- Timestamp:
- 02/02/2017 11:08:01 PM (7 years ago)
- Location:
- trunk/src/includes/admin
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/actions.php
r6186 r6274 47 47 add_action( 'current_screen', 'bbp_current_screen' ); 48 48 add_action( 'wpmu_new_blog', 'bbp_new_site', 10, 6 ); 49 add_action( 'tool_box', 'bbp_admin_tool_box' ); 49 50 50 51 // Hook on to admin_init … … 89 90 add_action( 'load-tools_page_bbp-repair', 'bbp_admin_repair_handler' ); 90 91 add_action( 'load-tools_page_bbp-reset', 'bbp_admin_reset_handler' ); 92 add_action( 'bbp_admin_tool_box', 'bbp_admin_tools_box' ); 91 93 92 94 // Add sample permalink filter … … 266 268 267 269 /** 270 * Dedicated action to output admin tools.php sections 271 * 272 * @since 2.6.0 bbPress (r6273) 273 * 274 * @uses do_action() Calls 'bbp_admin_tool_box' 275 */ 276 function bbp_admin_tool_box() { 277 do_action( 'bbp_admin_tool_box' ); 278 } 279 280 /** 268 281 * Dedicated action to hook into the current screen 269 282 * -
trunk/src/includes/admin/admin.php
r6250 r6274 202 202 $hooks = array(); 203 203 204 // These are later removed in admin_head 205 if ( current_user_can( 'bbp_tools_page' ) ) { 206 if ( current_user_can( 'bbp_tools_repair_page' ) ) { 207 $hooks[] = add_management_page( 208 __( 'Repair Forums', 'bbpress' ), 209 __( 'Forum Repair', 'bbpress' ), 210 $this->minimum_capability, 211 'bbp-repair', 212 'bbp_admin_repair' 213 ); 204 // Get the tools pages 205 $tools = bbp_get_tools_admin_pages(); 206 207 // Loop through tools and check 208 foreach ( $tools as $tool ) { 209 210 // Try to add the admin page 211 $page = add_management_page( 212 $tool['name'], 213 $tool['name'], 214 $tool['cap'], 215 $tool['page'], 216 $tool['func'] 217 ); 218 219 // Add page to hook if user can view it 220 if ( false !== $page ) { 221 $hooks[] = $page; 214 222 } 215 216 if ( current_user_can( 'bbp_tools_import_page' ) ) { 217 $hooks[] = add_management_page( 218 __( 'Import Forums', 'bbpress' ), 219 __( 'Forum Import', 'bbpress' ), 220 $this->minimum_capability, 221 'bbp-converter', 222 'bbp_converter_settings' 223 ); 224 } 225 226 if ( current_user_can( 'bbp_tools_reset_page' ) ) { 227 $hooks[] = add_management_page( 228 __( 'Reset Forums', 'bbpress' ), 229 __( 'Forum Reset', 'bbpress' ), 230 $this->minimum_capability, 231 'bbp-reset', 232 'bbp_admin_reset' 233 ); 234 } 235 236 // Fudge the highlighted subnav item when on a bbPress admin page 237 foreach ( $hooks as $hook ) { 238 add_action( "admin_head-$hook", 'bbp_tools_modify_menu_highlight' ); 239 } 240 241 // Forums Tools Root 242 add_management_page( 243 __( 'Forums', 'bbpress' ), 244 __( 'Forums', 'bbpress' ), 245 $this->minimum_capability, 246 'bbp-repair', 247 'bbp_admin_repair' 248 ); 249 } 223 } 224 225 // Fudge the highlighted subnav item when on a bbPress admin page 226 foreach ( $hooks as $hook ) { 227 add_action( "admin_head-{$hook}", 'bbp_tools_modify_menu_highlight' ); 228 } 229 230 // Forums Tools Root 231 add_management_page( 232 __( 'Forums', 'bbpress' ), 233 __( 'Forums', 'bbpress' ), 234 'bbp_tools_page', 235 'bbp-repair', 236 'bbp_admin_repair' 237 ); 250 238 251 239 // Are settings enabled? 252 if ( ! bbp_settings_integration() && current_user_can( 'bbp_settings_page' )) {240 if ( ! bbp_settings_integration() ) { 253 241 add_options_page( 254 242 __( 'Forums', 'bbpress' ), 255 243 __( 'Forums', 'bbpress' ), 256 $this->minimum_capability,244 'bbp_settings_page', 257 245 'bbpress', 258 246 'bbp_admin_settings' … … 267 255 __( 'Welcome to bbPress', 'bbpress' ), 268 256 __( 'Welcome to bbPress', 'bbpress' ), 269 $this->minimum_capability,257 'bbp_about_page', 270 258 'bbp-about', 271 259 array( $this, 'about_screen' ) … … 276 264 __( 'Welcome to bbPress', 'bbpress' ), 277 265 __( 'Welcome to bbPress', 'bbpress' ), 278 $this->minimum_capability,266 'bbp_about_page', 279 267 'bbp-credits', 280 268 array( $this, 'credits_screen' ) -
trunk/src/includes/admin/functions.php
r6115 r6274 278 278 279 279 // Setup core admin tabs 280 $tabs = apply_filters( 'bbp_tools_admin_tabs', array( 281 '0' => array( 282 'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-repair' ), 'tools.php' ) ), 283 'name' => __( 'Repair Forums', 'bbpress' ) 284 ), 285 '1' => array( 286 'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-converter' ), 'tools.php' ) ), 287 'name' => __( 'Import Forums', 'bbpress' ) 288 ), 289 '2' => array( 290 'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-reset' ), 'tools.php' ) ), 291 'name' => __( 'Reset Forums', 'bbpress' ) 292 ) 293 ) ); 280 $tabs = bbp_get_tools_admin_pages(); 294 281 295 282 // Loop through tabs and build navigation 296 foreach ( array_values( $tabs ) as $tab_data ) { 297 $is_current = (bool) ( $tab_data['name'] == $active_tab ); 283 foreach ( $tabs as $tab ) { 284 285 // Skip if user cannot visit page 286 if ( ! current_user_can( $tab['cap'] ) ) { 287 continue; 288 } 289 290 // Setup tab HTML 291 $is_current = (bool) ( $tab['name'] == $active_tab ); 298 292 $tab_class = $is_current ? $active_class : $idle_class; 299 $tabs_html .= '<a href="' . esc_url( $tab_data['href'] ) . '" class="' . esc_attr( $tab_class ) . '">' . esc_html( $tab_data['name'] ) . '</a>'; 293 $tab_url = get_admin_url( '', add_query_arg( array( 'page' => $tab['page'] ), 'tools.php' ) ); 294 $tabs_html .= '<a href="' . esc_url( $tab_url ) . '" class="' . esc_attr( $tab_class ) . '">' . esc_html( $tab['name'] ) . '</a>'; 300 295 } 301 296 … … 303 298 return $tabs_html; 304 299 } 300 301 /** 302 * Return possible tools pages 303 * 304 * @since 2.6.0 (r6273) 305 * 306 * @return array 307 */ 308 function bbp_get_tools_admin_pages() { 309 return apply_filters( 'bbp_tools_admin_tabs', array( 310 array( 311 'page' => 'bbp-repair', 312 'func' => 'bbp_admin_repair', 313 'cap' => 'bbp_tools_repair_page', 314 'name' => esc_html__( 'Repair Forums', 'bbpress' ), 315 316 // Deprecated 2.6.0 317 'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-repair' ), 'tools.php' ) ) 318 ), 319 array( 320 'page' => 'bbp-converter', 321 'func' => 'bbp_converter_settings', 322 'cap' => 'bbp_tools_import_page', 323 'name' => esc_html__( 'Import Forums', 'bbpress' ), 324 325 // Deprecated 2.6.0 326 'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-converter' ), 'tools.php' ) ) 327 ), 328 array( 329 'page' => 'bbp-reset', 330 'func' => 'bbp_admin_reset', 331 'cap' => 'bbp_tools_reset_page', 332 'name' => esc_html__( 'Reset Forums', 'bbpress' ), 333 334 // Deprecated 2.6.0 335 'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-reset' ), 'tools.php' ) ) 336 ) 337 ) ); 338 } -
trunk/src/includes/admin/tools.php
r6257 r6274 10 10 // Exit if accessed directly 11 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Output a bbPress specific tools box 15 * 16 * @since 2.6.0 bbPress (r6273) 17 */ 18 function bbp_admin_tools_box() { 19 20 // Bail if user cannot access tools page 21 if ( ! current_user_can( 'bbp_tools_page' ) ) { 22 return; 23 } 24 25 // Get the tools pages 26 $links = array(); 27 $tools = bbp_get_tools_admin_pages(); ?> 28 29 <div class="card"> 30 <h3 class="title"><?php _e( 'Forums', 'bbpress' ) ?></h3> 31 <p><?php esc_html_e( 'bbPress provides the following tools to help you manage your forums:', 'bbpress' ); ?></p> 32 33 <?php 34 35 // Loop through tools and create links 36 foreach ( $tools as $tool ) { 37 38 // Skip if user cannot see this page 39 if ( ! current_user_can( $tool['cap'] ) ) { 40 continue; 41 } 42 43 // Add link to array 44 $links[] = sprintf( '<a href="%s">%s</a>', get_admin_url( '', add_query_arg( array( 'page' => $tool['page'] ), 'tools.php' ) ), $tool['name'] ); 45 } 46 47 // Output links 48 echo '<p class="bbp-tools-links">' . implode( ' · ', $links ) . '</p>'; 49 50 ?></div> 51 52 <?php 53 } 12 54 13 55 /** Repair ********************************************************************/
Note: See TracChangeset
for help on using the changeset viewer.