/svntrunk/bp-core/bp-core-dependency.php

https://bitbucket.org/simplemediacode/bptrunk · PHP · 281 lines · 86 code · 33 blank · 162 comment · 2 complexity · 6bd3b7af87f6f39035c11c676feeb5ae MD5 · raw file

  1. <?php
  2. /**
  3. * Plugin Dependency
  4. *
  5. * The purpose of the following hooks is to mimic the behavior of something
  6. * called 'plugin dependency' which enables a plugin to have plugins of their
  7. * own in a safe and reliable way.
  8. *
  9. * We do this in BuddyPress by mirroring existing WordPress hookss in many places
  10. * allowing dependant plugins to hook into the BuddyPress specific ones, thus
  11. * guaranteeing proper code execution only when BuddyPress is active.
  12. *
  13. * The following functions are wrappers for hookss, allowing them to be
  14. * manually called and/or piggy-backed on top of other hooks if needed.
  15. *
  16. * @todo use anonymous functions when PHP minimun requirement allows (5.3)
  17. */
  18. /**
  19. * Include files on this action
  20. */
  21. function bp_include() {
  22. do_action( 'bp_include' );
  23. }
  24. /**
  25. * Include files on this action
  26. */
  27. function bp_setup_components() {
  28. do_action( 'bp_setup_components' );
  29. }
  30. /**
  31. * Setup global variables and objects
  32. */
  33. function bp_setup_globals() {
  34. do_action( 'bp_setup_globals' );
  35. }
  36. /**
  37. * Set navigation elements
  38. */
  39. function bp_setup_nav() {
  40. do_action( 'bp_setup_nav' );
  41. }
  42. /**
  43. * Set up BuddyPress implementation of the WP Toolbar
  44. */
  45. function bp_setup_admin_bar() {
  46. if ( bp_use_wp_admin_bar() )
  47. do_action( 'bp_setup_admin_bar' );
  48. }
  49. /**
  50. * Set the page title
  51. */
  52. function bp_setup_title() {
  53. do_action( 'bp_setup_title' );
  54. }
  55. /**
  56. * Register widgets
  57. */
  58. function bp_setup_widgets() {
  59. do_action( 'bp_register_widgets' );
  60. }
  61. /**
  62. * Setup the currently logged-in user
  63. *
  64. * @uses did_action() To make sure the user isn't loaded out of order
  65. * @uses do_action() Calls 'bp_setup_current_user'
  66. */
  67. function bp_setup_current_user() {
  68. // If the current user is being setup before the "init" action has fired,
  69. // strange (and difficult to debug) role/capability issues will occur.
  70. if ( ! did_action( 'after_setup_theme' ) ) {
  71. _doing_it_wrong( __FUNCTION__, __( 'The current user is being initialized without using $wp->init().', 'buddypress' ), '1.7' );
  72. }
  73. do_action( 'bp_setup_current_user' );
  74. }
  75. /**
  76. * Initlialize code
  77. */
  78. function bp_init() {
  79. do_action( 'bp_init' );
  80. }
  81. /**
  82. * Attached to plugins_loaded
  83. */
  84. function bp_loaded() {
  85. do_action( 'bp_loaded' );
  86. }
  87. /**
  88. * Attached to wp
  89. */
  90. function bp_ready() {
  91. do_action( 'bp_ready' );
  92. }
  93. /**
  94. * Attach potential template actions
  95. */
  96. function bp_actions() {
  97. do_action( 'bp_actions' );
  98. }
  99. /**
  100. * Attach potential template screens
  101. */
  102. function bp_screens() {
  103. do_action( 'bp_screens' );
  104. }
  105. /**
  106. * Initialize widgets
  107. */
  108. function bp_widgets_init() {
  109. do_action ( 'bp_widgets_init' );
  110. }
  111. /**
  112. * BuddyPress head scripts
  113. */
  114. function bp_head() {
  115. do_action ( 'bp_head' );
  116. }
  117. /** Theme Permissions *********************************************************/
  118. /**
  119. * The main action used for redirecting BuddyPress theme actions that are not
  120. * permitted by the current_user
  121. *
  122. * @since BuddyPress (1.6)
  123. *
  124. * @uses do_action()
  125. */
  126. function bp_template_redirect() {
  127. do_action( 'bp_template_redirect' );
  128. }
  129. /** Theme Helpers *************************************************************/
  130. /**
  131. * The main action used registering theme directory
  132. *
  133. * @since BuddyPress (1.5)
  134. * @uses do_action()
  135. */
  136. function bp_register_theme_directory() {
  137. do_action( 'bp_register_theme_directory' );
  138. }
  139. /**
  140. * The main action used registering theme packages
  141. *
  142. * @since BuddyPress (1.7)
  143. * @uses do_action()
  144. */
  145. function bp_register_theme_packages() {
  146. do_action( 'bp_register_theme_packages' );
  147. }
  148. /**
  149. * Enqueue BuddyPress specific CSS and JS
  150. *
  151. * @since BuddyPress (1.6)
  152. *
  153. * @uses do_action() Calls 'bp_enqueue_scripts'
  154. */
  155. function bp_enqueue_scripts() {
  156. do_action ( 'bp_enqueue_scripts' );
  157. }
  158. /**
  159. * Add the BuddyPress-specific rewrite tags
  160. *
  161. * @since BuddyPress (1.8)
  162. * @uses do_action() Calls 'bp_add_rewrite_tags'
  163. */
  164. function bp_add_rewrite_tags() {
  165. do_action( 'bp_add_rewrite_tags' );
  166. }
  167. /**
  168. * Piggy back action for BuddyPress sepecific theme actions before the theme has
  169. * been setup and the theme's functions.php has loaded.
  170. *
  171. * @since BuddyPress (1.6)
  172. *
  173. * @uses do_action() Calls 'bp_setup_theme'
  174. */
  175. function bp_setup_theme() {
  176. do_action ( 'bp_setup_theme' );
  177. }
  178. /**
  179. * Piggy back action for BuddyPress sepecific theme actions once the theme has
  180. * been setup and the theme's functions.php has loaded.
  181. *
  182. * Hooked to 'after_setup_theme' with a priority of 100. This allows plenty of
  183. * time for other themes to load their features, such as BuddyPress support,
  184. * before our theme compatibility layer kicks in.
  185. *
  186. * @since BuddyPress (1.6)
  187. *
  188. * @uses do_action() Calls 'bp_after_setup_theme'
  189. */
  190. function bp_after_setup_theme() {
  191. do_action ( 'bp_after_setup_theme' );
  192. }
  193. /** Theme Compatibility Filter ************************************************/
  194. /**
  195. * Piggy back filter for WordPress's 'request' filter
  196. *
  197. * @since BuddyPress (1.7)
  198. * @param array $query_vars
  199. * @return array
  200. */
  201. function bp_request( $query_vars = array() ) {
  202. return apply_filters( 'bp_request', $query_vars );
  203. }
  204. /**
  205. * Piggy back filter to handle login redirects.
  206. *
  207. * @since BuddyPress (1.7)
  208. *
  209. * @param string $redirect_to
  210. * @param string $redirect_to_raw
  211. * @param string $user
  212. */
  213. function bp_login_redirect( $redirect_to = '', $redirect_to_raw = '', $user = false ) {
  214. return apply_filters( 'bp_login_redirect', $redirect_to, $redirect_to_raw, $user );
  215. }
  216. /**
  217. * The main filter used for theme compatibility and displaying custom BuddyPress
  218. * theme files.
  219. *
  220. * @since BuddyPress (1.6)
  221. *
  222. * @uses apply_filters()
  223. *
  224. * @param string $template
  225. * @return string Template file to use
  226. */
  227. function bp_template_include( $template = '' ) {
  228. return apply_filters( 'bp_template_include', $template );
  229. }
  230. /**
  231. * Generate BuddyPress-specific rewrite rules
  232. *
  233. * @since BuddyPress (1.7)
  234. * @param WP_Rewrite $wp_rewrite
  235. * @uses do_action() Calls 'bp_generate_rewrite_rules' with {@link WP_Rewrite}
  236. */
  237. function bp_generate_rewrite_rules( $wp_rewrite ) {
  238. do_action_ref_array( 'bp_generate_rewrite_rules', array( &$wp_rewrite ) );
  239. }
  240. /**
  241. * Filter the allowed themes list for BuddyPress specific themes
  242. *
  243. * @since BuddyPress (1.7)
  244. * @uses apply_filters() Calls 'bp_allowed_themes' with the allowed themes list
  245. */
  246. function bp_allowed_themes( $themes ) {
  247. return apply_filters( 'bp_allowed_themes', $themes );
  248. }