/includes/core/sub-actions.php

  1. <?php 
  2.  
  3. /** 
  4. * Plugin Dependency 
  5. * 
  6. * The purpose of the following hooks is to mimic the behavior of something 
  7. * called 'plugin dependency' which enables a plugin to have plugins of their 
  8. * own in a safe and reliable way. 
  9. * 
  10. * We do this in bbPress by mirroring existing WordPress hookss in many places 
  11. * allowing dependant plugins to hook into the bbPress specific ones, thus 
  12. * guaranteeing proper code execution only when bbPress is active. 
  13. * 
  14. * The following functions are wrappers for hookss, allowing them to be 
  15. * manually called and/or piggy-backed on top of other hooks if needed. 
  16. * 
  17. * @todo use anonymous functions when PHP minimun requirement allows (5.3) 
  18. */ 
  19.  
  20. /** Activation Actions ********************************************************/ 
  21.  
  22. /** 
  23. * Runs on bbPress activation 
  24. * 
  25. * @since bbPress (r2509) 
  26. * @uses register_uninstall_hook() To register our own uninstall hook 
  27. * @uses do_action() Calls 'bbp_activation' hook 
  28. */ 
  29. function bbp_activation() { 
  30. do_action( 'bbp_activation' ); 
  31.  
  32. /** 
  33. * Runs on bbPress deactivation 
  34. * 
  35. * @since bbPress (r2509) 
  36. * @uses do_action() Calls 'bbp_deactivation' hook 
  37. */ 
  38. function bbp_deactivation() { 
  39. do_action( 'bbp_deactivation' ); 
  40.  
  41. /** 
  42. * Runs when uninstalling bbPress 
  43. * 
  44. * @since bbPress (r2509) 
  45. * @uses do_action() Calls 'bbp_uninstall' hook 
  46. */ 
  47. function bbp_uninstall() { 
  48. do_action( 'bbp_uninstall' ); 
  49.  
  50. /** Main Actions **************************************************************/ 
  51.  
  52. /** 
  53. * Main action responsible for constants, globals, and includes 
  54. * 
  55. * @since bbPress (r2599) 
  56. * @uses do_action() Calls 'bbp_loaded' 
  57. */ 
  58. function bbp_loaded() { 
  59. do_action( 'bbp_loaded' ); 
  60.  
  61. /** 
  62. * Setup constants 
  63. * 
  64. * @since bbPress (r2599) 
  65. * @uses do_action() Calls 'bbp_constants' 
  66. */ 
  67. function bbp_constants() { 
  68. do_action( 'bbp_constants' ); 
  69.  
  70. /** 
  71. * Setup globals BEFORE includes 
  72. * 
  73. * @since bbPress (r2599) 
  74. * @uses do_action() Calls 'bbp_boot_strap_globals' 
  75. */ 
  76. function bbp_boot_strap_globals() { 
  77. do_action( 'bbp_boot_strap_globals' ); 
  78.  
  79. /** 
  80. * Include files 
  81. * 
  82. * @since bbPress (r2599) 
  83. * @uses do_action() Calls 'bbp_includes' 
  84. */ 
  85. function bbp_includes() { 
  86. do_action( 'bbp_includes' ); 
  87.  
  88. /** 
  89. * Setup globals AFTER includes 
  90. * 
  91. * @since bbPress (r2599) 
  92. * @uses do_action() Calls 'bbp_setup_globals' 
  93. */ 
  94. function bbp_setup_globals() { 
  95. do_action( 'bbp_setup_globals' ); 
  96.  
  97. /** 
  98. * Register any objects before anything is initialized 
  99. * 
  100. * @since bbPress (r4180) 
  101. * @uses do_action() Calls 'bbp_register' 
  102. */ 
  103. function bbp_register() { 
  104. do_action( 'bbp_register' ); 
  105.  
  106. /** 
  107. * Initialize any code after everything has been loaded 
  108. * 
  109. * @since bbPress (r2599) 
  110. * @uses do_action() Calls 'bbp_init' 
  111. */ 
  112. function bbp_init() { 
  113. do_action( 'bbp_init' ); 
  114.  
  115. /** 
  116. * Initialize widgets 
  117. * 
  118. * @since bbPress (r3389) 
  119. * @uses do_action() Calls 'bbp_widgets_init' 
  120. */ 
  121. function bbp_widgets_init() { 
  122. do_action( 'bbp_widgets_init' ); 
  123.  
  124. /** 
  125. * Setup the currently logged-in user 
  126. * 
  127. * @since bbPress (r2695) 
  128. * @uses did_action() To make sure the user isn't loaded out of order 
  129. * @uses do_action() Calls 'bbp_setup_current_user' 
  130. */ 
  131. function bbp_setup_current_user() { 
  132.  
  133. // If the current user is being setup before the "init" action has fired,  
  134. // strange (and difficult to debug) role/capability issues will occur. 
  135. if ( ! did_action( 'after_setup_theme' ) ) { 
  136. _doing_it_wrong( __FUNCTION__, __( 'The current user is being initialized without using $wp->init().', 'bbpress' ), '2.3' ); 
  137.  
  138. do_action( 'bbp_setup_current_user' ); 
  139.  
  140. /** Supplemental Actions ******************************************************/ 
  141.  
  142. /** 
  143. * Load translations for current language 
  144. * 
  145. * @since bbPress (r2599) 
  146. * @uses do_action() Calls 'bbp_load_textdomain' 
  147. */ 
  148. function bbp_load_textdomain() { 
  149. do_action( 'bbp_load_textdomain' ); 
  150.  
  151. /** 
  152. * Setup the post types 
  153. * 
  154. * @since bbPress (r2464) 
  155. * @uses do_action() Calls 'bbp_register_post_type' 
  156. */ 
  157. function bbp_register_post_types() { 
  158. do_action( 'bbp_register_post_types' ); 
  159.  
  160. /** 
  161. * Setup the post statuses 
  162. * 
  163. * @since bbPress (r2727) 
  164. * @uses do_action() Calls 'bbp_register_post_statuses' 
  165. */ 
  166. function bbp_register_post_statuses() { 
  167. do_action( 'bbp_register_post_statuses' ); 
  168.  
  169. /** 
  170. * Register the built in bbPress taxonomies 
  171. * 
  172. * @since bbPress (r2464) 
  173. * @uses do_action() Calls 'bbp_register_taxonomies' 
  174. */ 
  175. function bbp_register_taxonomies() { 
  176. do_action( 'bbp_register_taxonomies' ); 
  177.  
  178. /** 
  179. * Register the default bbPress views 
  180. * 
  181. * @since bbPress (r2789) 
  182. * @uses do_action() Calls 'bbp_register_views' 
  183. */ 
  184. function bbp_register_views() { 
  185. do_action( 'bbp_register_views' ); 
  186.  
  187. /** 
  188. * Register the default bbPress shortcodes 
  189. * 
  190. * @since bbPress (r4211) 
  191. * @uses do_action() Calls 'bbp_register_shortcodes' 
  192. */ 
  193. function bbp_register_shortcodes() { 
  194. do_action( 'bbp_register_shortcodes' ); 
  195.  
  196. /** 
  197. * Enqueue bbPress specific CSS and JS 
  198. * 
  199. * @since bbPress (r3373) 
  200. * @uses do_action() Calls 'bbp_enqueue_scripts' 
  201. */ 
  202. function bbp_enqueue_scripts() { 
  203. do_action( 'bbp_enqueue_scripts' ); 
  204.  
  205. /** 
  206. * Add the bbPress-specific rewrite tags 
  207. * 
  208. * @since bbPress (r2753) 
  209. * @uses do_action() Calls 'bbp_add_rewrite_tags' 
  210. */ 
  211. function bbp_add_rewrite_tags() { 
  212. do_action( 'bbp_add_rewrite_tags' ); 
  213.  
  214. /** 
  215. * Add the bbPress-specific rewrite rules 
  216. * 
  217. * @since bbPress (r4918) 
  218. * @uses do_action() Calls 'bbp_add_rewrite_rules' 
  219. */ 
  220. function bbp_add_rewrite_rules() { 
  221. do_action( 'bbp_add_rewrite_rules' ); 
  222.  
  223. /** 
  224. * Add the bbPress-specific permalink structures 
  225. * 
  226. * @since bbPress (r4918) 
  227. * @uses do_action() Calls 'bbp_add_permastructs' 
  228. */ 
  229. function bbp_add_permastructs() { 
  230. do_action( 'bbp_add_permastructs' ); 
  231.  
  232. /** 
  233. * Add the bbPress-specific login forum action 
  234. * 
  235. * @since bbPress (r2753) 
  236. * @uses do_action() Calls 'bbp_login_form_login' 
  237. */ 
  238. function bbp_login_form_login() { 
  239. do_action( 'bbp_login_form_login' ); 
  240.  
  241. /** User Actions **************************************************************/ 
  242.  
  243. /** 
  244. * The main action for hooking into when a user account is updated 
  245. * 
  246. * @since bbPress (r4304) 
  247. * 
  248. * @param int $user_id ID of user being edited 
  249. * @param array $old_user_data The old, unmodified user data 
  250. * @uses do_action() Calls 'bbp_profile_update' 
  251. */ 
  252. function bbp_profile_update( $user_id = 0, $old_user_data = array() ) { 
  253. do_action( 'bbp_profile_update', $user_id, $old_user_data ); 
  254.  
  255. /** 
  256. * The main action for hooking into a user being registered 
  257. * 
  258. * @since bbPress (r4304) 
  259. * @param int $user_id ID of user being edited 
  260. * @uses do_action() Calls 'bbp_user_register' 
  261. */ 
  262. function bbp_user_register( $user_id = 0 ) { 
  263. do_action( 'bbp_user_register', $user_id ); 
  264.  
  265. /** Final Action **************************************************************/ 
  266.  
  267. /** 
  268. * bbPress has loaded and initialized everything, and is okay to go 
  269. * 
  270. * @since bbPress (r2618) 
  271. * @uses do_action() Calls 'bbp_ready' 
  272. */ 
  273. function bbp_ready() { 
  274. do_action( 'bbp_ready' ); 
  275.  
  276. /** Theme Permissions *********************************************************/ 
  277.  
  278. /** 
  279. * The main action used for redirecting bbPress theme actions that are not 
  280. * permitted by the current_user 
  281. * 
  282. * @since bbPress (r3605) 
  283. * @uses do_action() 
  284. */ 
  285. function bbp_template_redirect() { 
  286. do_action( 'bbp_template_redirect' ); 
  287.  
  288. /** Theme Helpers *************************************************************/ 
  289.  
  290. /** 
  291. * The main action used for executing code before the theme has been setup 
  292. * 
  293. * @since bbPress (r3829) 
  294. * @uses do_action() 
  295. */ 
  296. function bbp_register_theme_packages() { 
  297. do_action( 'bbp_register_theme_packages' ); 
  298.  
  299. /** 
  300. * The main action used for executing code before the theme has been setup 
  301. * 
  302. * @since bbPress (r3732) 
  303. * @uses do_action() 
  304. */ 
  305. function bbp_setup_theme() { 
  306. do_action( 'bbp_setup_theme' ); 
  307.  
  308. /** 
  309. * The main action used for executing code after the theme has been setup 
  310. * 
  311. * @since bbPress (r3732) 
  312. * @uses do_action() 
  313. */ 
  314. function bbp_after_setup_theme() { 
  315. do_action( 'bbp_after_setup_theme' ); 
  316.  
  317. /** 
  318. * The main action used for handling theme-side POST requests 
  319. * 
  320. * @since bbPress (r4550) 
  321. * @uses do_action() 
  322. */ 
  323. function bbp_post_request() { 
  324.  
  325. // Bail if not a POST action 
  326. if ( ! bbp_is_post_request() ) 
  327. return; 
  328.  
  329. // Bail if no action 
  330. if ( empty( $_POST['action'] ) ) 
  331. return; 
  332.  
  333. // This dynamic action is probably the one you want to use. It narrows down 
  334. // the scope of the 'action' without needing to check it in your function. 
  335. do_action( 'bbp_post_request_' . $_POST['action'] ); 
  336.  
  337. // Use this static action if you don't mind checking the 'action' yourself. 
  338. do_action( 'bbp_post_request', $_POST['action'] ); 
  339.  
  340. /** 
  341. * The main action used for handling theme-side GET requests 
  342. * 
  343. * @since bbPress (r4550) 
  344. * @uses do_action() 
  345. */ 
  346. function bbp_get_request() { 
  347.  
  348. // Bail if not a POST action 
  349. if ( ! bbp_is_get_request() ) 
  350. return; 
  351.  
  352. // Bail if no action 
  353. if ( empty( $_GET['action'] ) ) 
  354. return; 
  355.  
  356. // This dynamic action is probably the one you want to use. It narrows down 
  357. // the scope of the 'action' without needing to check it in your function. 
  358. do_action( 'bbp_get_request_' . $_GET['action'] ); 
  359.  
  360. // Use this static action if you don't mind checking the 'action' yourself. 
  361. do_action( 'bbp_get_request', $_GET['action'] ); 
  362.  
  363. /** Filters *******************************************************************/ 
  364.  
  365. /** 
  366. * Filter the plugin locale and domain. 
  367. * 
  368. * @since bbPress (r4213) 
  369. * 
  370. * @param string $locale 
  371. * @param string $domain 
  372. */ 
  373. function bbp_plugin_locale( $locale = '', $domain = '' ) { 
  374. return apply_filters( 'bbp_plugin_locale', $locale, $domain ); 
  375.  
  376. /** 
  377. * Piggy back filter for WordPress's 'request' filter 
  378. * 
  379. * @since bbPress (r3758) 
  380. * @param array $query_vars 
  381. * @return array 
  382. */ 
  383. function bbp_request( $query_vars = array() ) { 
  384. return apply_filters( 'bbp_request', $query_vars ); 
  385.  
  386. /** 
  387. * The main filter used for theme compatibility and displaying custom bbPress 
  388. * theme files. 
  389. * 
  390. * @since bbPress (r3311) 
  391. * @uses apply_filters() 
  392. * @param string $template 
  393. * @return string Template file to use 
  394. */ 
  395. function bbp_template_include( $template = '' ) { 
  396. return apply_filters( 'bbp_template_include', $template ); 
  397.  
  398. /** 
  399. * Generate bbPress-specific rewrite rules 
  400. * 
  401. * @since bbPress (r2688) 
  402. * @deprecated since bbPress (r4918) 
  403. * @param WP_Rewrite $wp_rewrite 
  404. * @uses do_action() Calls 'bbp_generate_rewrite_rules' with {@link WP_Rewrite} 
  405. */ 
  406. function bbp_generate_rewrite_rules( $wp_rewrite ) { 
  407. do_action_ref_array( 'bbp_generate_rewrite_rules', array( &$wp_rewrite ) ); 
  408.  
  409. /** 
  410. * Filter the allowed themes list for bbPress specific themes 
  411. * 
  412. * @since bbPress (r2944) 
  413. * @uses apply_filters() Calls 'bbp_allowed_themes' with the allowed themes list 
  414. */ 
  415. function bbp_allowed_themes( $themes ) { 
  416. return apply_filters( 'bbp_allowed_themes', $themes ); 
  417.  
  418. /** 
  419. * Maps forum/topic/reply caps to built in WordPress caps 
  420. * 
  421. * @since bbPress (r2593) 
  422. * 
  423. * @param array $caps Capabilities for meta capability 
  424. * @param string $cap Capability name 
  425. * @param int $user_id User id 
  426. * @param mixed $args Arguments 
  427. */ 
  428. function bbp_map_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) { 
  429. return apply_filters( 'bbp_map_meta_caps', $caps, $cap, $user_id, $args ); 
.