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


Generated: Tue Jul 14 01:01:30 2020 Cross-referenced by PHPXref 0.7.1