bb_admin_add_menu

The BuddyPress bb admin add menu function.

Description

bb_admin_add_menu( (string) $display_name, $capability, (string) $file_name, (constant) $menu_position = false, (string) $class = '', (string) $id = '' ); 

Parameters (6)

0. $display_name (string)
The display name.
1. $capability
The capability.
2. $file_name (string)
The file name.
3. $menu_position — Optional. (constant) => false
The menu position.
4. $class — Optional. (string) => ''
The class.
5. $id — Optional. (string) => ''
The id.

Usage

  1. if ( !function_exists( 'bb_admin_add_menu' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-admin/includes/functions.bb-admin.php'; 
  3.  
  4. // The display name. 
  5. $display_name = ''; 
  6.  
  7. // The capability. 
  8. $capability = null; 
  9.  
  10. // The file name. 
  11. $file_name = ''; 
  12.  
  13. // The menu position. 
  14. $menu_position = false; 
  15.  
  16. // The class. 
  17. $class = ''; 
  18.  
  19. // The id. 
  20. $id = ''; 
  21.  
  22. // NOTICE! Understand what this does before running. 
  23. $result = bb_admin_add_menu($display_name, $capability, $file_name, $menu_position, $class, $id); 
  24.  

Defined (1)

The function is defined in the following location(s).

/bp-forums/bbpress/bb-admin/includes/functions.bb-admin.php  
  1. function bb_admin_add_menu( $display_name, $capability, $file_name, $menu_position = false, $class = '', $id = '' ) 
  2. global $bb_menu; 
  3. global $bb_registered_plugin_callbacks; 
  4. if ( empty( $bb_registered_plugin_callbacks ) ) { 
  5. $bb_registered_plugin_callbacks = array(); 
  6.  
  7. if ( $display_name && $capability && $file_name ) { 
  8. // Get an array of the keys 
  9. $menu_keys = array_keys( $bb_menu ); 
  10.  
  11. if ( $menu_position ) { 
  12. if ( is_numeric( $menu_position ) ) { 
  13. if ( !isset( $bb_menu[$menu_position] ) ) { 
  14. $plugin_menu_next = $menu_position; 
  15. } else { 
  16. return bb_admin_add_menu( $display_name, $capability, $file_name, ( $menu_position + 1 ), $class, $id ); 
  17. } else { 
  18. // Set the bounds for different menu groups (main or side) 
  19. switch ( $menu_position ) { 
  20. case 'dash': 
  21. $lower = 50; 
  22. $upper = 100; 
  23. break; 
  24. case 'main': 
  25. $lower = 200; 
  26. $upper = 250; 
  27. break; 
  28. default: 
  29. $lower = 350; 
  30. $upper = 500; 
  31. break; 
  32.  
  33. // Get an array of all plugin added keys 
  34. $plugin_menu_keys = array_filter( $menu_keys, create_function( '$v', 'if ($v >= ' . $lower . ' && $v < ' . $upper . ') { return $v; }' ) ); 
  35.  
  36. // If there is an array of keys 
  37. if ( is_array( $plugin_menu_keys ) && count( $plugin_menu_keys ) ) { 
  38. // Get the highest key value and add one 
  39. $plugin_menu_next = max( $plugin_menu_keys ) + 1; 
  40. } else { 
  41. // It's the first one 
  42. $plugin_menu_next = $lower; 
  43. } else { 
  44. $plugin_menu_next = max( array_keys( $bb_menu ) ) + 1; 
  45. $bb_menu[$plugin_menu_next] = array( '', 'read', 'separator' ); 
  46. $plugin_menu_next++; 
  47.  
  48. if ( strpos( $file_name, '.php' ) === false ) { 
  49. $bb_registered_plugin_callbacks[] = $file_name; 
  50.  
  51. // Add the menu item at the given key 
  52. $bb_menu[$plugin_menu_next] = array( $display_name, $capability, $file_name, $class, $id ); 
  53.  
  54. ksort( $bb_menu ); 
  55.  
  56. return $plugin_menu_next; 
  57.  
  58. return false;