bp_get_the_body_class

Customize the body class, according to the currently displayed BP content.

Description

(array) bp_get_the_body_class( (array) $wp_classes = array(), (bool) $custom_classes = false ); 

Uses the above is_() functions to output a body class for each scenario.

Returns (array)

$classes The BP-adjusted body classes.

Parameters (2)

0. $wp_classes — Optional. (array) => array()
The body classes coming from WP.
1. $custom_classes — Optional. (bool) => false
Classes that were passed to get_body_class().

Usage

  1. if ( !function_exists( 'bp_get_the_body_class' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-template.php'; 
  3.  
  4. // The body classes coming from WP. 
  5. $wp_classes = array(); 
  6.  
  7. // Classes that were passed to get_body_class(). 
  8. $custom_classes = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_get_the_body_class($wp_classes, $custom_classes); 
  12.  

Defined (1)

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

/bp-core/bp-core-template.php  
  1. function bp_get_the_body_class( $wp_classes = array(), $custom_classes = false ) { 
  2.  
  3. $bp_classes = array(); 
  4.  
  5. /** Pages *************************************************************/ 
  6.  
  7. if ( is_front_page() ) { 
  8. $bp_classes[] = 'home-page'; 
  9.  
  10. if ( bp_is_directory() ) { 
  11. $bp_classes[] = 'directory'; 
  12.  
  13. if ( bp_is_single_item() ) { 
  14. $bp_classes[] = 'single-item'; 
  15.  
  16. /** Components ********************************************************/ 
  17.  
  18. if ( ! bp_is_blog_page() ) { 
  19. if ( bp_is_user_profile() ) { 
  20. $bp_classes[] = 'xprofile'; 
  21.  
  22. $bp_classes[] = 'activity'; 
  23.  
  24. if ( bp_is_blogs_component() ) { 
  25. $bp_classes[] = 'blogs'; 
  26.  
  27. $bp_classes[] = 'messages'; 
  28.  
  29. $bp_classes[] = 'friends'; 
  30.  
  31. $bp_classes[] = 'groups'; 
  32.  
  33. $bp_classes[] = 'settings'; 
  34.  
  35. /** User **************************************************************/ 
  36.  
  37. if ( bp_is_user() ) { 
  38. $bp_classes[] = 'bp-user'; 
  39.  
  40. // Add current user member types. 
  41. if ( $member_types = bp_get_member_type( bp_displayed_user_id(), false ) ) { 
  42. foreach( $member_types as $member_type ) { 
  43. $bp_classes[] = sprintf( 'member-type-%s', esc_attr( $member_type ) ); 
  44.  
  45. if ( ! bp_is_directory() ) { 
  46. if ( bp_is_user_blogs() ) { 
  47. $bp_classes[] = 'my-blogs'; 
  48.  
  49. if ( bp_is_user_groups() ) { 
  50. $bp_classes[] = 'my-groups'; 
  51.  
  52. if ( bp_is_user_activity() ) { 
  53. $bp_classes[] = 'my-activity'; 
  54. } else { 
  55. $bp_classes[] = 'type'; 
  56.  
  57. if ( bp_is_my_profile() ) { 
  58. $bp_classes[] = 'my-account'; 
  59.  
  60. if ( bp_is_user_profile() ) { 
  61. $bp_classes[] = 'my-profile'; 
  62.  
  63. if ( bp_is_user_friends() ) { 
  64. $bp_classes[] = 'my-friends'; 
  65.  
  66. if ( bp_is_user_messages() ) { 
  67. $bp_classes[] = 'my-messages'; 
  68.  
  69. $bp_classes[] = 'recent-comments'; 
  70.  
  71. $bp_classes[] = 'recent-posts'; 
  72.  
  73. $bp_classes[] = 'change-avatar'; 
  74.  
  75. $bp_classes[] = 'profile-edit'; 
  76.  
  77. $bp_classes[] = 'friends-activity'; 
  78.  
  79. $bp_classes[] = 'groups-activity'; 
  80.  
  81. /** Messages **********************************************************/ 
  82.  
  83. if ( bp_is_messages_inbox() ) { 
  84. $bp_classes[] = 'inbox'; 
  85.  
  86. $bp_classes[] = 'sentbox'; 
  87.  
  88. $bp_classes[] = 'compose'; 
  89.  
  90. if ( bp_is_notices() ) { 
  91. $bp_classes[] = 'notices'; 
  92.  
  93. $bp_classes[] = 'friend-requests'; 
  94.  
  95. if ( bp_is_create_blog() ) { 
  96. $bp_classes[] = 'create-blog'; 
  97.  
  98. /** Groups ************************************************************/ 
  99.  
  100. if ( bp_is_group() ) { 
  101. $bp_classes[] = 'group-' . groups_get_current_group()->slug; 
  102.  
  103. // Add current group types. 
  104. if ( $group_types = bp_groups_get_group_type( bp_get_current_group_id(), false ) ) { 
  105. foreach ( $group_types as $group_type ) { 
  106. $bp_classes[] = sprintf( 'group-type-%s', esc_attr( $group_type ) ); 
  107.  
  108. if ( bp_is_group_leave() ) { 
  109. $bp_classes[] = 'leave-group'; 
  110.  
  111. if ( bp_is_group_invites() ) { 
  112. $bp_classes[] = 'group-invites'; 
  113.  
  114. if ( bp_is_group_members() ) { 
  115. $bp_classes[] = 'group-members'; 
  116.  
  117. $bp_classes[] = 'group-forum-topic'; 
  118.  
  119. $bp_classes[] = 'group-forum-topic-edit'; 
  120.  
  121. if ( bp_is_group_forum() ) { 
  122. $bp_classes[] = 'group-forum'; 
  123.  
  124. $bp_classes[] = 'group-admin'; 
  125. $bp_classes[] = bp_get_group_current_admin_tab(); 
  126.  
  127. if ( bp_is_group_create() ) { 
  128. $bp_classes[] = 'group-create'; 
  129. $bp_classes[] = bp_get_groups_current_create_step(); 
  130.  
  131. if ( bp_is_group_home() ) { 
  132. $bp_classes[] = 'group-home'; 
  133.  
  134. if ( bp_is_single_activity() ) { 
  135. $bp_classes[] = 'activity-permalink'; 
  136.  
  137. /** Registration ******************************************************/ 
  138.  
  139. if ( bp_is_register_page() ) { 
  140. $bp_classes[] = 'registration'; 
  141.  
  142. if ( bp_is_activation_page() ) { 
  143. $bp_classes[] = 'activation'; 
  144.  
  145. /** Current Component & Action ****************************************/ 
  146.  
  147. if ( ! bp_is_blog_page() ) { 
  148. $bp_classes[] = bp_current_component(); 
  149. $bp_classes[] = bp_current_action(); 
  150.  
  151. /** Clean up ***********************************************************/ 
  152.  
  153. // Add BuddyPress class if we are within a BuddyPress page. 
  154. if ( ! bp_is_blog_page() ) { 
  155. $bp_classes[] = buddypress; 
  156.  
  157. // Merge WP classes with BuddyPress classes and remove any duplicates. 
  158. $classes = array_unique( array_merge( (array) $bp_classes, (array) $wp_classes ) ); 
  159.  
  160. /** 
  161. * Filters the BuddyPress classes to be added to body_class() 
  162. * @since 1.1.0 
  163. * @param array $classes Array of body classes to add. 
  164. * @param array $bp_classes Array of BuddyPress-based classes. 
  165. * @param array $wp_classes Array of WordPress-based classes. 
  166. * @param array $custom_classes Array of classes that were passed to get_body_class(). 
  167. */ 
  168. return apply_filters( 'bp_get_the_body_class', $classes, $bp_classes, $wp_classes, $custom_classes );