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

  1. <?php 
  2. /** 
  3. * Plugin Dependency Action Hooks. 
  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 hooks 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 hooks, allowing them to be 
  14. * manually called and/or piggy-backed on top of other hooks if needed. 
  15. * 
  16. * @package BuddyPress 
  17. * @subpackage Core 
  18. * @since 1.7.0 
  19. */ 
  20.  
  21. /** 
  22. * Fire the 'bp_include' action, where plugins should include files. 
  23. * 
  24. * @since 1.2.5 
  25. */ 
  26. function bp_include() { 
  27.  
  28. /** 
  29. * Fires inside the 'bp_include' function, where plugins should include files. 
  30. * 
  31. * @since 1.2.5 
  32. */ 
  33. do_action( 'bp_include' ); 
  34.  
  35. /** 
  36. * Fire the 'bp_setup_components' action, where plugins should initialize components. 
  37. * 
  38. * @since 1.6.0 
  39. */ 
  40. function bp_setup_components() { 
  41.  
  42. /** 
  43. * Fires inside the 'bp_setup_components' function, where plugins should initialize components. 
  44. * 
  45. * @since 1.6.0 
  46. */ 
  47. do_action( 'bp_setup_components' ); 
  48.  
  49. /** 
  50. * Fire the 'bp_setup_canonical_stack' action, where plugins should set up their canonical URL. 
  51. * 
  52. * @since 2.1.0 
  53. */ 
  54. function bp_setup_canonical_stack() { 
  55.  
  56. /** 
  57. * Fires inside the 'bp_setup_canonical_stack' function, where plugins should set up their canonical URL. 
  58. * 
  59. * @since 2.1.0 
  60. */ 
  61. do_action( 'bp_setup_canonical_stack' ); 
  62.  
  63. /** 
  64. * Fire the 'bp_register_taxonomies' action, where plugins should register taxonomies. 
  65. * 
  66. * @since 2.2.0 
  67. */ 
  68. function bp_register_taxonomies() { 
  69.  
  70. /** 
  71. * Fires inside the 'bp_register_taxonomies' function, where plugins should register taxonomies. 
  72. * 
  73. * @since 2.2.0 
  74. */ 
  75. do_action( 'bp_register_taxonomies' ); 
  76.  
  77. /** 
  78. * Fire the 'bp_register_post_types' action, where plugins should register post types. 
  79. * 
  80. * @since 2.5.0 
  81. */ 
  82. function bp_register_post_types() { 
  83.  
  84. /** 
  85. * Fires inside the 'bp_register_post_types' function, where plugins should register post types. 
  86. * 
  87. * @since 2.5.0 
  88. */ 
  89. do_action( 'bp_register_post_types' ); 
  90.  
  91. /** 
  92. * Fire the 'bp_setup_globals' action, where plugins should initialize global settings. 
  93. * 
  94. * @since 1.2.0 
  95. */ 
  96. function bp_setup_globals() { 
  97.  
  98. /** 
  99. * Fires inside the 'bp_setup_globals' function, where plugins should initialize global settings. 
  100. * 
  101. * @since 1.2.0 
  102. */ 
  103. do_action( 'bp_setup_globals' ); 
  104.  
  105. /** 
  106. * Fire the 'bp_setup_nav' action, where plugins should register their navigation items. 
  107. * 
  108. * @since 1.2.0 
  109. */ 
  110. function bp_setup_nav() { 
  111.  
  112. /** 
  113. * Fires inside the 'bp_setup_nav' function, where plugins should register their navigation items. 
  114. * 
  115. * @since 1.2.0 
  116. */ 
  117. do_action( 'bp_setup_nav' ); 
  118.  
  119. /** 
  120. * Fire the 'bp_setup_admin_bar' action, where plugins should add items to the WP admin bar. 
  121. * 
  122. * @since 1.5.0 
  123. */ 
  124. function bp_setup_admin_bar() { 
  125. if ( bp_use_wp_admin_bar() ) { 
  126.  
  127. /** 
  128. * Fires inside the 'bp_setup_admin_bar' function, where plugins should add items to the WP admin bar. 
  129. * 
  130. * This hook will only fire if bp_use_wp_admin_bar() returns true. 
  131. * 
  132. * @since 1.5.0 
  133. */ 
  134. do_action( 'bp_setup_admin_bar', array() ); 
  135.  
  136. /** 
  137. * Fire the 'bp_setup_title' action, where plugins should modify the page title. 
  138. * 
  139. * @since 1.5.0 
  140. */ 
  141. function bp_setup_title() { 
  142.  
  143. /** 
  144. * Fires inside the 'bp_setup_title' function, where plugins should modify the page title. 
  145. * 
  146. * @since 1.5.0 
  147. */ 
  148. do_action( 'bp_setup_title' ); 
  149.  
  150. /** 
  151. * Fire the 'bp_register_widgets' action, where plugins should register widgets. 
  152. * 
  153. * @since 1.2.0 
  154. */ 
  155. function bp_setup_widgets() { 
  156.  
  157. /** 
  158. * Fires inside the 'bp_register_widgets' function, where plugins should register widgets. 
  159. * 
  160. * @since 1.2.0 
  161. */ 
  162. do_action( 'bp_register_widgets' ); 
  163.  
  164. /** 
  165. * Fire the 'bp_register_member_types' action, where plugins should register member types. 
  166. * 
  167. * @since 2.3.0 
  168. */ 
  169. function bp_register_member_types() { 
  170.  
  171. /** 
  172. * Fires inside bp_register_member_types(), so plugins can register member types. 
  173. * 
  174. * @since 2.3.0 
  175. */ 
  176. do_action( 'bp_register_member_types' ); 
  177.  
  178. /** 
  179. * Fire the 'bp_setup_cache_groups' action, where cache groups are registered. 
  180. * 
  181. * @since 2.2.0 
  182. */ 
  183. function bp_setup_cache_groups() { 
  184.  
  185. /** 
  186. * Fires inside the 'bp_setup_cache_groups' function, where cache groups are registered. 
  187. * 
  188. * @since 2.2.0 
  189. */ 
  190. do_action( 'bp_setup_cache_groups' ); 
  191.  
  192. /** 
  193. * Set up the currently logged-in user. 
  194. * 
  195. * @since 1.7.0 
  196. * 
  197. * @link https://buddypress.trac.wordpress.org/ticket/6046 
  198. * @link https://core.trac.wordpress.org/ticket/24169 
  199. */ 
  200. function bp_setup_current_user() { 
  201.  
  202. /** 
  203. * Fires to set up the current user setup process. 
  204. * 
  205. * @since 1.7.0 
  206. */ 
  207. do_action( 'bp_setup_current_user' ); 
  208.  
  209. /** 
  210. * Fire the 'bp_init' action, BuddyPress's main initialization hook. 
  211. * 
  212. * @since 1.2.5 
  213. */ 
  214. function bp_init() { 
  215.  
  216. /** 
  217. * Fires inside the 'bp_init' function, BuddyPress' main initialization hook. 
  218. * 
  219. * @since 1.2.0 
  220. */ 
  221. do_action( 'bp_init' ); 
  222.  
  223. /** 
  224. * Fire the 'bp_rest_api_init' action, where BuddyPress registers REST API endpoints. 
  225. * 
  226. * @since 2.6.0 
  227. */ 
  228. function bp_rest_api_init() { 
  229.  
  230. /** 
  231. * Fires the 'bp_rest_api_init' function, where BuddyPress registers REST API endpoints. 
  232. * 
  233. * @since 2.6.0 
  234. */ 
  235. do_action( 'bp_rest_api_init' ); 
  236.  
  237. /** 
  238. * Fire the 'bp_customize_register' action when the Customizer has loaded,  
  239. * allowing scripts and styles to be initialized. 
  240. * 
  241. * @since 2.5.0 
  242. * 
  243. * @param WP_Customize_Manager $customizer Customizer instance. 
  244. */ 
  245. function bp_customize_register( WP_Customize_Manager $customizer ) { 
  246.  
  247. /** 
  248. * Fires once the Customizer has loaded, allow scripts and styles to be initialized. 
  249. * 
  250. * @since 2.5.0 
  251. * 
  252. * @param WP_Customize_Manager $customizer Customizer instance. 
  253. */ 
  254. do_action( 'bp_customize_register', $customizer ); 
  255.  
  256. /** 
  257. * Fire the 'bp_loaded' action, which fires after BP's core plugin files have been loaded. 
  258. * 
  259. * Attached to 'plugins_loaded'. 
  260. * 
  261. * @since 1.2.0 
  262. */ 
  263. function bp_loaded() { 
  264.  
  265. /** 
  266. * Fires inside the 'bp_loaded' function, which fires after BP's core plugin files have been loaded. 
  267. * 
  268. * @since 1.2.5 
  269. */ 
  270. do_action( 'bp_loaded' ); 
  271.  
  272. /** 
  273. * Fire the 'bp_ready' action, which runs after BP is set up and the page is about to render. 
  274. * 
  275. * Attached to 'wp'. 
  276. * 
  277. * @since 1.6.0 
  278. */ 
  279. function bp_ready() { 
  280.  
  281. /** 
  282. * Fires inside the 'bp_ready' function, which runs after BP is set up and the page is about to render. 
  283. * 
  284. * @since 1.6.0 
  285. */ 
  286. do_action( 'bp_ready' ); 
  287.  
  288. /** 
  289. * Fire the 'bp_actions' action, which runs just before rendering. 
  290. * 
  291. * Attach potential template actions, such as catching form requests or routing 
  292. * custom URLs. 
  293. * 
  294. * @since 1.5.0 
  295. */ 
  296. function bp_actions() { 
  297.  
  298. /** 
  299. * Fires inside the 'bp_actions' function, which runs just before rendering. 
  300. * 
  301. * @since 1.5.0 
  302. */ 
  303. do_action( 'bp_actions' ); 
  304.  
  305. /** 
  306. * Fire the 'bp_screens' action, which runs just before rendering. 
  307. * 
  308. * Runs just after 'bp_actions'. Use this hook to attach your template 
  309. * loaders. 
  310. * 
  311. * @since 1.5.0 
  312. */ 
  313. function bp_screens() { 
  314.  
  315. /** 
  316. * Fires inside the 'bp_screens' function, which runs just before rendering. 
  317. * 
  318. * Runs just after 'bp_actions'. Use this hook to attach your template loaders. 
  319. * 
  320. * @since 1.5.0 
  321. */ 
  322. do_action( 'bp_screens' ); 
  323.  
  324. /** 
  325. * Fire 'bp_widgets_init', which runs after widgets have been set up. 
  326. * 
  327. * Hooked to 'widgets_init'. 
  328. * 
  329. * @since 1.6.0 
  330. */ 
  331. function bp_widgets_init() { 
  332.  
  333. /** 
  334. * Fires inside the 'bp_widgets_init' function, which runs after widgets have been set up. 
  335. * 
  336. * Hooked to 'widgets_init'. 
  337. * 
  338. * @since 1.6.0 
  339. */ 
  340. do_action( 'bp_widgets_init' ); 
  341.  
  342. /** 
  343. * Fire 'bp_head', which is used to hook scripts and styles in the <head>. 
  344. * 
  345. * Hooked to 'wp_head'. 
  346. * 
  347. * @since 1.6.0 
  348. */ 
  349. function bp_head() { 
  350.  
  351. /** 
  352. * Fires inside the 'bp_head' function, which runs on 'wp_head'. 
  353. * 
  354. * @since 1.6.0 
  355. */ 
  356. do_action( 'bp_head' ); 
  357.  
  358. /** Theme Permissions *********************************************************/ 
  359.  
  360. /** 
  361. * Fire the 'bp_template_redirect' action. 
  362. * 
  363. * Run at 'template_redirect', just before WordPress selects and loads a theme 
  364. * template. The main purpose of this hook in BuddyPress is to redirect users 
  365. * who do not have the proper permission to access certain content. 
  366. * 
  367. * @since 1.6.0 
  368. */ 
  369. function bp_template_redirect() { 
  370.  
  371. /** 
  372. * Fires inside the 'bp_template_redirect' function. 
  373. * 
  374. * @since 1.6.0 
  375. */ 
  376. do_action( 'bp_template_redirect' ); 
  377.  
  378. /** Theme Helpers *************************************************************/ 
  379.  
  380. /** 
  381. * Fire the 'bp_register_theme_directory' action. 
  382. * 
  383. * The main action used registering theme directories. 
  384. * 
  385. * @since 1.5.0 
  386. */ 
  387. function bp_register_theme_directory() { 
  388.  
  389. /** 
  390. * Fires inside the 'bp_register_theme_directory' function. 
  391. * 
  392. * The main action used registering theme directories. 
  393. * 
  394. * @since 1.7.0 
  395. */ 
  396. do_action( 'bp_register_theme_directory' ); 
  397.  
  398. /** 
  399. * Fire the 'bp_register_theme_packages' action. 
  400. * 
  401. * The main action used registering theme packages. 
  402. * 
  403. * @since 1.7.0 
  404. */ 
  405. function bp_register_theme_packages() { 
  406.  
  407. /** 
  408. * Fires inside the 'bp_register_theme_packages' function. 
  409. * 
  410. * @since 1.7.0 
  411. */ 
  412. do_action( 'bp_register_theme_packages' ); 
  413.  
  414. /** 
  415. * Fire the 'bp_enqueue_scripts' action, where BP enqueues its CSS and JS. 
  416. * 
  417. * @since 1.6.0 
  418. */ 
  419. function bp_enqueue_scripts() { 
  420.  
  421. /** 
  422. * Fires inside the 'bp_enqueue_scripts' function, where BP enqueues its CSS and JS. 
  423. * 
  424. * @since 1.6.0 
  425. */ 
  426. do_action( 'bp_enqueue_scripts' ); 
  427.  
  428. /** 
  429. * Fires the 'bp_enqueue_embed_scripts' action in the <head> for BP oEmbeds. 
  430. * 
  431. * @since 2.6.0 
  432. */ 
  433. function bp_enqueue_embed_scripts() { 
  434. if ( ! is_buddypress() ) { 
  435. return; 
  436.  
  437. /** 
  438. * Enqueue CSS and JS files for BuddyPress embeds. 
  439. * 
  440. * @since 2.6.0 
  441. */ 
  442. do_action( 'bp_enqueue_embed_scripts' ); 
  443.  
  444. /** 
  445. * Fire the 'bp_add_rewrite_tag' action, where BP adds its custom rewrite tags. 
  446. * 
  447. * @since 1.8.0 
  448. */ 
  449. function bp_add_rewrite_tags() { 
  450.  
  451. /** 
  452. * Fires inside the 'bp_add_rewrite_tags' function, where BP adds its custom rewrite tags. 
  453. * 
  454. * @since 1.8.0 
  455. */ 
  456. do_action( 'bp_add_rewrite_tags' ); 
  457.  
  458. /** 
  459. * Fire the 'bp_add_rewrite_rules' action, where BP adds its custom rewrite rules. 
  460. * 
  461. * @since 1.9.0 
  462. */ 
  463. function bp_add_rewrite_rules() { 
  464.  
  465. /** 
  466. * Fires inside the 'bp_add_rewrite_rules' function, where BP adds its custom rewrite rules. 
  467. * 
  468. * @since 1.9.0 
  469. */ 
  470. do_action( 'bp_add_rewrite_rules' ); 
  471.  
  472. /** 
  473. * Fire the 'bp_add_permastructs' action, where BP adds its BP-specific permalink structure. 
  474. * 
  475. * @since 1.9.0 
  476. */ 
  477. function bp_add_permastructs() { 
  478.  
  479. /** 
  480. * Fires inside the 'bp_add_permastructs' function, where BP adds its BP-specific permalink structure. 
  481. * 
  482. * @since 1.9.0 
  483. */ 
  484. do_action( 'bp_add_permastructs' ); 
  485.  
  486. /** 
  487. * Fire the 'bp_setup_theme' action. 
  488. * 
  489. * The main purpose of 'bp_setup_theme' is give themes a place to load their 
  490. * BuddyPress-specific functionality. 
  491. * 
  492. * @since 1.6.0 
  493. */ 
  494. function bp_setup_theme() { 
  495.  
  496. /** 
  497. * Fires inside the 'bp_setup_theme' function. 
  498. * 
  499. * @since 1.6.0 
  500. */ 
  501. do_action( 'bp_setup_theme' ); 
  502.  
  503. /** 
  504. * Fire the 'bp_after_setup_theme' action. 
  505. * 
  506. * Piggy-back action for BuddyPress-specific theme actions once the theme has 
  507. * been set up and the theme's functions.php has loaded. 
  508. * 
  509. * Hooked to 'after_setup_theme' with a priority of 100. This allows plenty of 
  510. * time for other themes to load their features, such as BuddyPress support,  
  511. * before our theme compatibility layer kicks in. 
  512. * 
  513. * @since 1.6.0 
  514. */ 
  515. function bp_after_setup_theme() { 
  516.  
  517. /** 
  518. * Fires inside the 'bp_after_setup_theme' function. 
  519. * 
  520. * @since 1.7.0 
  521. */ 
  522. do_action( 'bp_after_setup_theme' ); 
  523.  
  524. /** Theme Compatibility Filter ************************************************/ 
  525.  
  526. /** 
  527. * Fire the 'bp_request' filter, a piggy-back of WP's 'request'. 
  528. * 
  529. * @since 1.7.0 
  530. * 
  531. * @see WP::parse_request() for a description of parameters. 
  532. * 
  533. * @param array $query_vars See {@link WP::parse_request()}. 
  534. * @return array $query_vars See {@link WP::parse_request()}. 
  535. */ 
  536. function bp_request( $query_vars = array() ) { 
  537.  
  538. /** 
  539. * Filters the query_vars for the current request. 
  540. * 
  541. * @since 1.7.0 
  542. * 
  543. * @param array $query_vars Array of query variables. 
  544. */ 
  545. return apply_filters( 'bp_request', $query_vars ); 
  546.  
  547. /** 
  548. * Fire the 'bp_login_redirect' filter, a piggy-back of WP's 'login_redirect'. 
  549. * 
  550. * @since 1.7.0 
  551. * 
  552. * @param string $redirect_to See 'login_redirect'. 
  553. * @param string $redirect_to_raw See 'login_redirect'. 
  554. * @param bool $user See 'login_redirect'. 
  555. * @return string 
  556. */ 
  557. function bp_login_redirect( $redirect_to = '', $redirect_to_raw = '', $user = false ) { 
  558.  
  559. /** 
  560. * Filters the URL to redirect to after login. 
  561. * 
  562. * @since 1.7.0 
  563. * 
  564. * @param string $redirect_to The redirect destination URL. 
  565. * @param string $redirect_to_raw The requested redirect destination URL passed as a parameter. 
  566. * @param WP_User|WP_Error $user WP_User object if login was successful, WP_Error object otherwise. 
  567. */ 
  568. return apply_filters( 'bp_login_redirect', $redirect_to, $redirect_to_raw, $user ); 
  569.  
  570. /** 
  571. * Fire 'bp_template_include', main filter used for theme compatibility and displaying custom BP theme files. 
  572. * 
  573. * Hooked to 'template_include'. 
  574. * 
  575. * @since 1.6.0 
  576. * 
  577. * @param string $template See 'template_include'. 
  578. * @return string Template file to use. 
  579. */ 
  580. function bp_template_include( $template = '' ) { 
  581.  
  582. /** 
  583. * Filters the template to use with template_include. 
  584. * 
  585. * @since 1.6.0 
  586. * 
  587. * @param string $template The path of the template to include. 
  588. */ 
  589. return apply_filters( 'bp_template_include', $template ); 
  590.  
  591. /** 
  592. * Fire the 'bp_generate_rewrite_rules' action, where BP generates its rewrite rules. 
  593. * 
  594. * @since 1.7.0 
  595. * 
  596. * @param WP_Rewrite $wp_rewrite See 'generate_rewrite_rules'. 
  597. */ 
  598. function bp_generate_rewrite_rules( $wp_rewrite ) { 
  599.  
  600. /** 
  601. * Fires inside the 'bp_generate_rewrite_rules' function. 
  602. * 
  603. * @since 1.7.0 
  604. * 
  605. * @param WP_Rewrite $wp_rewrite WP_Rewrite object. Passed by reference. 
  606. */ 
  607. do_action_ref_array( 'bp_generate_rewrite_rules', array( &$wp_rewrite ) ); 
  608.  
  609. /** 
  610. * Fire the 'bp_allowed_themes' filter. 
  611. * 
  612. * Filter the allowed themes list for BuddyPress-specific themes. 
  613. * 
  614. * @since 1.7.0 
  615. * 
  616. * @param array $themes The path of the template to include. 
  617. * @return array 
  618. */ 
  619. function bp_allowed_themes( $themes ) { 
  620.  
  621. /** 
  622. * Filters the allowed themes list for BuddyPress-specific themes. 
  623. * 
  624. * @since 1.7.0 
  625. * 
  626. * @param string $template The path of the template to include. 
  627. */ 
  628. return apply_filters( 'bp_allowed_themes', $themes ); 
  629.  
  630. /** Requests ******************************************************************/ 
  631.  
  632. /** 
  633. * The main action used for handling theme-side POST requests. 
  634. * 
  635. * @since 1.9.0 
  636. */ 
  637. function bp_post_request() { 
  638.  
  639. // Bail if not a POST action. 
  640. if ( ! bp_is_post_request() ) { 
  641. return; 
  642.  
  643. // Bail if no action. 
  644. if ( empty( $_POST['action'] ) ) { 
  645. return; 
  646.  
  647. // Sanitize the POST action. 
  648. $action = sanitize_key( $_POST['action'] ); 
  649.  
  650. /** 
  651. * Fires at the end of the bp_post_request function. 
  652. * 
  653. * This dynamic action is probably the one you want to use. It narrows down 
  654. * the scope of the 'action' without needing to check it in your function. 
  655. * 
  656. * @since 1.9.0 
  657. */ 
  658. do_action( 'bp_post_request_' . $action ); 
  659.  
  660. /** 
  661. * Fires at the end of the bp_post_request function. 
  662. * 
  663. * Use this static action if you don't mind checking the 'action' yourself. 
  664. * 
  665. * @since 1.9.0 
  666. * 
  667. * @param string $action The action being run. 
  668. */ 
  669. do_action( 'bp_post_request', $action ); 
  670.  
  671. /** 
  672. * The main action used for handling theme-side GET requests. 
  673. * 
  674. * @since 1.9.0 
  675. */ 
  676. function bp_get_request() { 
  677.  
  678. // Bail if not a POST action. 
  679. if ( ! bp_is_get_request() ) { 
  680. return; 
  681.  
  682. // Bail if no action. 
  683. if ( empty( $_GET['action'] ) ) { 
  684. return; 
  685.  
  686. // Sanitize the GET action. 
  687. $action = sanitize_key( $_GET['action'] ); 
  688.  
  689. /** 
  690. * Fires at the end of the bp_get_request function. 
  691. * 
  692. * This dynamic action is probably the one you want to use. It narrows down 
  693. * the scope of the 'action' without needing to check it in your function. 
  694. * 
  695. * @since 1.9.0 
  696. */ 
  697. do_action( 'bp_get_request_' . $action ); 
  698.  
  699. /** 
  700. * Fires at the end of the bp_get_request function. 
  701. * 
  702. * Use this static action if you don't mind checking the 'action' yourself. 
  703. * 
  704. * @since 1.9.0 
  705. * 
  706. * @param string $action The action being run. 
  707. */ 
  708. do_action( 'bp_get_request', $action ); 
.