BP_Core

Creates the Core component.

Defined (1)

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

/bp-core/classes/class-bp-core.php  
  1. class BP_Core extends BP_Component { 
  2.  
  3. /** 
  4. * Start the members component creation process. 
  5. * @since 1.5.0 
  6. */ 
  7. public function __construct() { 
  8. parent::start( 
  9. 'core',  
  10. __( 'BuddyPress Core', 'buddypress' ),  
  11. buddypress()->plugin_dir 
  12. ); 
  13.  
  14. $this->bootstrap(); 
  15.  
  16. /** 
  17. * Populate the global data needed before BuddyPress can continue. 
  18. * This involves figuring out the currently required, activated, deactivated,  
  19. * and optional components. 
  20. * @since 1.5.0 
  21. */ 
  22. private function bootstrap() { 
  23. $bp = buddypress(); 
  24.  
  25. /** 
  26. * Fires before the loading of individual components and after BuddyPress Core. 
  27. * Allows plugins to run code ahead of the other components. 
  28. * @since 1.2.0 
  29. */ 
  30. do_action( 'bp_core_loaded' ); 
  31.  
  32. /** Components ******************************************************* 
  33. */ 
  34.  
  35. /** 
  36. * Filters the included and optional components. 
  37. * @since 1.5.0 
  38. * @param array $value Array of included and optional components. 
  39. */ 
  40. $bp->optional_components = apply_filters( 'bp_optional_components', array( 'activity', 'blogs', 'forums', 'friends', 'groups', 'messages', 'notifications', 'settings', 'xprofile' ) ); 
  41.  
  42. /** 
  43. * Filters the required components. 
  44. * @since 1.5.0 
  45. * @param array $value Array of required components. 
  46. */ 
  47. $bp->required_components = apply_filters( 'bp_required_components', array( 'members' ) ); 
  48.  
  49. // Get a list of activated components. 
  50. if ( $active_components = bp_get_option( 'bp-active-components' ) ) { 
  51.  
  52. /** This filter is documented in bp-core/admin/bp-core-admin-components.php */ 
  53. $bp->active_components = apply_filters( 'bp_active_components', $active_components ); 
  54.  
  55. /** 
  56. * Filters the deactivated components. 
  57. * @since 1.0.0 
  58. * @param array $value Array of deactivated components. 
  59. */ 
  60. $bp->deactivated_components = apply_filters( 'bp_deactivated_components', array_values( array_diff( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), array_keys( $bp->active_components ) ) ) ); 
  61.  
  62. // Pre 1.5 Backwards compatibility. 
  63. } elseif ( $deactivated_components = bp_get_option( 'bp-deactivated-components' ) ) { 
  64.  
  65. // Trim off namespace and filename. 
  66. foreach ( array_keys( (array) $deactivated_components ) as $component ) { 
  67. $trimmed[] = str_replace( '.php', '', str_replace( 'bp-', '', $component ) ); 
  68.  
  69. /** This filter is documented in bp-core/bp-core-loader.php */ 
  70. $bp->deactivated_components = apply_filters( 'bp_deactivated_components', $trimmed ); 
  71.  
  72. // Setup the active components. 
  73. $active_components = array_fill_keys( array_diff( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), array_values( $bp->deactivated_components ) ), '1' ); 
  74.  
  75. /** This filter is documented in bp-core/admin/bp-core-admin-components.php */ 
  76. $bp->active_components = apply_filters( 'bp_active_components', $bp->active_components ); 
  77.  
  78. // Default to all components active. 
  79. } else { 
  80.  
  81. // Set globals. 
  82. $bp->deactivated_components = array(); 
  83.  
  84. // Setup the active components. 
  85. $active_components = array_fill_keys( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), '1' ); 
  86.  
  87. /** This filter is documented in bp-core/admin/bp-core-admin-components.php */ 
  88. $bp->active_components = apply_filters( 'bp_active_components', $bp->active_components ); 
  89.  
  90. // Loop through optional components. 
  91. foreach( $bp->optional_components as $component ) { 
  92. if ( bp_is_active( $component ) && file_exists( $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' ) ) { 
  93. include( $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' ); 
  94.  
  95. // Loop through required components. 
  96. foreach( $bp->required_components as $component ) { 
  97. if ( file_exists( $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' ) ) { 
  98. include( $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' ); 
  99.  
  100. // Add Core to required components. 
  101. $bp->required_components[] = 'core'; 
  102.  
  103. /** 
  104. * Fires after the loading of individual components. 
  105. * @since 2.0.0 
  106. */ 
  107. do_action( 'bp_core_components_included' ); 
  108.  
  109. /** 
  110. * Include bp-core files. 
  111. * @since 1.6.0 
  112. * @see BP_Component::includes() for description of parameters. 
  113. * @param array $includes See {@link BP_Component::includes()}. 
  114. */ 
  115. public function includes( $includes = array() ) { 
  116.  
  117. if ( ! is_admin() ) { 
  118. return; 
  119.  
  120. $includes = array( 
  121. 'admin' 
  122. ); 
  123.  
  124. parent::includes( $includes ); 
  125.  
  126. /** 
  127. * Set up bp-core global settings. 
  128. * Sets up a majority of the BuddyPress globals that require a minimal 
  129. * amount of processing, meaning they cannot be set in the BuddyPress class. 
  130. * @since 1.5.0 
  131. * @see BP_Component::setup_globals() for description of parameters. 
  132. * @param array $args See {@link BP_Component::setup_globals()}. 
  133. */ 
  134. public function setup_globals( $args = array() ) { 
  135. $bp = buddypress(); 
  136.  
  137. /** Database ********************************************************* 
  138. */ 
  139.  
  140. // Get the base database prefix. 
  141. if ( empty( $bp->table_prefix ) ) { 
  142. $bp->table_prefix = bp_core_get_table_prefix(); 
  143.  
  144. // The domain for the root of the site where the main blog resides. 
  145. if ( empty( $bp->root_domain ) ) { 
  146. $bp->root_domain = bp_core_get_root_domain(); 
  147.  
  148. // Fetches all of the core BuddyPress settings in one fell swoop. 
  149. if ( empty( $bp->site_options ) ) { 
  150. $bp->site_options = bp_core_get_root_options(); 
  151.  
  152. // The names of the core WordPress pages used to display BuddyPress content. 
  153. if ( empty( $bp->pages ) ) { 
  154. $bp->pages = bp_core_get_directory_pages(); 
  155.  
  156. /** Basic current user data ****************************************** 
  157. */ 
  158.  
  159. // Logged in user is the 'current_user'. 
  160. $current_user = wp_get_current_user(); 
  161.  
  162. // The user ID of the user who is currently logged in. 
  163. $bp->loggedin_user = new stdClass; 
  164. $bp->loggedin_user->id = isset( $current_user->ID ) ? $current_user->ID : 0; 
  165.  
  166. /** Avatars ********************************************************** 
  167. */ 
  168.  
  169. // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar. 
  170. $bp->grav_default = new stdClass; 
  171.  
  172. /** 
  173. * Filters the default user Gravatar. 
  174. * @since 1.1.0 
  175. * @param string $value Default user Gravatar. 
  176. */ 
  177. $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', $bp->site_options['avatar_default'] ); 
  178.  
  179. /** 
  180. * Filters the default group Gravatar. 
  181. * @since 1.1.0 
  182. * @param string $value Default group Gravatar. 
  183. */ 
  184. $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', $bp->grav_default->user ); 
  185.  
  186. /** 
  187. * Filters the default blog Gravatar. 
  188. * @since 1.1.0 
  189. * @param string $value Default blog Gravatar. 
  190. */ 
  191. $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', $bp->grav_default->user ); 
  192.  
  193. // Notifications table. Included here for legacy purposes. Use 
  194. // bp-notifications instead. 
  195. $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications'; 
  196.  
  197. // Backward compatibility for plugins modifying the legacy bp_nav and bp_options_nav global properties. 
  198. $bp->bp_nav = new BP_Core_BP_Nav_BackCompat(); 
  199. $bp->bp_options_nav = new BP_Core_BP_Options_Nav_BackCompat(); 
  200.  
  201. /** 
  202. * Used to determine if user has admin rights on current content. If the 
  203. * logged in user is viewing their own profile and wants to delete 
  204. * something, is_item_admin is used. This is a generic variable so it 
  205. * can be used by other components. It can also be modified, so when 
  206. * viewing a group 'is_item_admin' would be 'true' if they are a group 
  207. * admin, and 'false' if they are not. 
  208. */ 
  209. bp_update_is_item_admin( bp_user_has_access(), 'core' ); 
  210.  
  211. // Is the logged in user is a mod for the current item? 
  212. bp_update_is_item_mod( false, 'core' ); 
  213.  
  214. /** 
  215. * Fires at the end of the setup of bp-core globals setting. 
  216. * @since 1.1.0 
  217. */ 
  218. do_action( 'bp_core_setup_globals' ); 
  219.  
  220. /** 
  221. * Setup cache groups 
  222. * @since 2.2.0 
  223. */ 
  224. public function setup_cache_groups() { 
  225.  
  226. // Global groups. 
  227. wp_cache_add_global_groups( array( 
  228. 'bp' 
  229. ) ); 
  230.  
  231. parent::setup_cache_groups(); 
  232.  
  233. /** 
  234. * Set up post types. 
  235. * @since BuddyPress (2.4.0) 
  236. */ 
  237. public function register_post_types() { 
  238.  
  239. // Emails 
  240. if ( bp_is_root_blog() && ! is_network_admin() ) { 
  241. register_post_type( 
  242. bp_get_email_post_type(),  
  243. apply_filters( 'bp_register_email_post_type', array( 
  244. 'description' => _x( 'BuddyPress emails', 'email post type description', 'buddypress' ),  
  245. 'labels' => bp_get_email_post_type_labels(),  
  246. 'menu_icon' => 'dashicons-email',  
  247. 'public' => false,  
  248. 'publicly_queryable' => bp_current_user_can( 'bp_moderate' ),  
  249. 'query_var' => false,  
  250. 'rewrite' => false,  
  251. 'show_in_admin_bar' => false,  
  252. 'show_ui' => bp_current_user_can( 'bp_moderate' ),  
  253. 'supports' => bp_get_email_post_type_supports(),  
  254. ) ) 
  255. ); 
  256.  
  257. parent::register_post_types();