[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-core/ -> bp-core-dependency.php (source)

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


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1