[ 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 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  /**
  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   * Fire the 'bp_customize_register' action when the Customizer has loaded,
 272   * allowing scripts and styles to be initialized.
 273   *
 274   * @since 2.5.0
 275   *
 276   * @param WP_Customize_Manager $customizer Customizer instance.
 277   */
 278  function bp_customize_register( WP_Customize_Manager $customizer ) {
 279  
 280      /**
 281       * Fires once the Customizer has loaded, allow scripts and styles to be initialized.
 282       *
 283       * @since 2.5.0
 284       *
 285       * @param WP_Customize_Manager $customizer Customizer instance.
 286       */
 287      do_action( 'bp_customize_register', $customizer );
 288  }
 289  
 290  /**
 291   * Fire the 'bp_loaded' action, which fires after BP's core plugin files have been loaded.
 292   *
 293   * Attached to 'plugins_loaded'.
 294   *
 295   * @since 1.2.0
 296   */
 297  function bp_loaded() {
 298  
 299      /**
 300       * Fires inside the 'bp_loaded' function, which fires after BP's core plugin files have been loaded.
 301       *
 302       * @since 1.2.5
 303       */
 304      do_action( 'bp_loaded' );
 305  }
 306  
 307  /**
 308   * Fire the 'bp_ready' action, which runs after BP is set up and the page is about to render.
 309   *
 310   * Attached to 'wp'.
 311   *
 312   * @since 1.6.0
 313   */
 314  function bp_ready() {
 315  
 316      /**
 317       * Fires inside the 'bp_ready' function, which runs after BP is set up and the page is about to render.
 318       *
 319       * @since 1.6.0
 320       */
 321      do_action( 'bp_ready' );
 322  }
 323  
 324  /**
 325   * Fire the 'bp_actions' action, which runs just before rendering.
 326   *
 327   * Attach potential template actions, such as catching form requests or routing
 328   * custom URLs.
 329   *
 330   * @since 1.5.0
 331   */
 332  function bp_actions() {
 333  
 334      /**
 335       * Fires inside the 'bp_actions' function, which runs just before rendering.
 336       *
 337       * @since 1.5.0
 338       */
 339      do_action( 'bp_actions' );
 340  }
 341  
 342  /**
 343   * Fire the 'bp_screens' action, which runs just before rendering.
 344   *
 345   * Runs just after 'bp_actions'. Use this hook to attach your template
 346   * loaders.
 347   *
 348   * @since 1.5.0
 349   */
 350  function bp_screens() {
 351  
 352      /**
 353       * Fires inside the 'bp_screens' function, which runs just before rendering.
 354       *
 355       * Runs just after 'bp_actions'. Use this hook to attach your template loaders.
 356       *
 357       * @since 1.5.0
 358       */
 359      do_action( 'bp_screens' );
 360  }
 361  
 362  /**
 363   * Fire 'bp_widgets_init', which runs after widgets have been set up.
 364   *
 365   * Hooked to 'widgets_init'.
 366   *
 367   * @since 1.6.0
 368   */
 369  function bp_widgets_init() {
 370  
 371      /**
 372       * Fires inside the 'bp_widgets_init' function, which runs after widgets have been set up.
 373       *
 374       * Hooked to 'widgets_init'.
 375       *
 376       * @since 1.6.0
 377       */
 378      do_action( 'bp_widgets_init' );
 379  }
 380  
 381  /**
 382   * Fire 'bp_head', which is used to hook scripts and styles in the <head>.
 383   *
 384   * Hooked to 'wp_head'.
 385   *
 386   * @since 1.6.0
 387   */
 388  function bp_head() {
 389  
 390      /**
 391       * Fires inside the 'bp_head' function, which runs on 'wp_head'.
 392       *
 393       * @since 1.6.0
 394       */
 395      do_action( 'bp_head' );
 396  }
 397  
 398  /** Theme Permissions *********************************************************/
 399  
 400  /**
 401   * Fire the 'bp_template_redirect' action.
 402   *
 403   * Run at 'template_redirect', just before WordPress selects and loads a theme
 404   * template. The main purpose of this hook in BuddyPress is to redirect users
 405   * who do not have the proper permission to access certain content.
 406   *
 407   * @since 1.6.0
 408   */
 409  function bp_template_redirect() {
 410  
 411      /**
 412       * Fires inside the 'bp_template_redirect' function.
 413       *
 414       * @since 1.6.0
 415       */
 416      do_action( 'bp_template_redirect' );
 417  }
 418  
 419  /** Theme Helpers *************************************************************/
 420  
 421  /**
 422   * Fire the 'bp_register_theme_directory' action.
 423   *
 424   * The main action used registering theme directories.
 425   *
 426   * @since 1.5.0
 427   */
 428  function bp_register_theme_directory() {
 429  
 430      /**
 431       * Fires inside the 'bp_register_theme_directory' function.
 432       *
 433       * The main action used registering theme directories.
 434       *
 435       * @since 1.7.0
 436       */
 437      do_action( 'bp_register_theme_directory' );
 438  }
 439  
 440  /**
 441   * Fire the 'bp_register_theme_packages' action.
 442   *
 443   * The main action used registering theme packages.
 444   *
 445   * @since 1.7.0
 446   */
 447  function bp_register_theme_packages() {
 448  
 449      /**
 450       * Fires inside the 'bp_register_theme_packages' function.
 451       *
 452       * @since 1.7.0
 453       */
 454      do_action( 'bp_register_theme_packages' );
 455  }
 456  
 457  /**
 458   * Fire the 'bp_enqueue_scripts' action, where BP enqueues its CSS and JS.
 459   *
 460   * @since 1.6.0
 461   */
 462  function bp_enqueue_scripts() {
 463  
 464      /**
 465       * Fires inside the 'bp_enqueue_scripts' function, where BP enqueues its CSS and JS.
 466       *
 467       * @since 1.6.0
 468       */
 469      do_action( 'bp_enqueue_scripts' );
 470  }
 471  
 472  /**
 473   * Fires the 'bp_enqueue_embed_scripts' action in the <head> for BP oEmbeds.
 474   *
 475   * @since 2.6.0
 476   */
 477  function bp_enqueue_embed_scripts() {
 478      if ( ! is_buddypress() ) {
 479          return;
 480      }
 481  
 482      /**
 483       * Enqueue CSS and JS files for BuddyPress embeds.
 484       *
 485       * @since 2.6.0
 486       */
 487      do_action( 'bp_enqueue_embed_scripts' );
 488  }
 489  
 490  /**
 491   * Fire the 'bp_add_rewrite_tag' action, where BP adds its custom rewrite tags.
 492   *
 493   * @since 1.8.0
 494   */
 495  function bp_add_rewrite_tags() {
 496  
 497      /**
 498       * Fires inside the 'bp_add_rewrite_tags' function, where BP adds its custom rewrite tags.
 499       *
 500       * @since 1.8.0
 501       */
 502      do_action( 'bp_add_rewrite_tags' );
 503  }
 504  
 505  /**
 506   * Fire the 'bp_add_rewrite_rules' action, where BP adds its custom rewrite rules.
 507   *
 508   * @since 1.9.0
 509   */
 510  function bp_add_rewrite_rules() {
 511  
 512      /**
 513       * Fires inside the 'bp_add_rewrite_rules' function, where BP adds its custom rewrite rules.
 514       *
 515       * @since 1.9.0
 516       */
 517      do_action( 'bp_add_rewrite_rules' );
 518  }
 519  
 520  /**
 521   * Fire the 'bp_add_permastructs' action, where BP adds its BP-specific permalink structure.
 522   *
 523   * @since 1.9.0
 524   */
 525  function bp_add_permastructs() {
 526  
 527      /**
 528       * Fires inside the 'bp_add_permastructs' function, where BP adds its BP-specific permalink structure.
 529       *
 530       * @since 1.9.0
 531       */
 532      do_action( 'bp_add_permastructs' );
 533  }
 534  
 535  /**
 536   * Fire the 'bp_setup_theme' action.
 537   *
 538   * The main purpose of 'bp_setup_theme' is give themes a place to load their
 539   * BuddyPress-specific functionality.
 540   *
 541   * @since 1.6.0
 542   */
 543  function bp_setup_theme() {
 544  
 545      /**
 546       * Fires inside the 'bp_setup_theme' function.
 547       *
 548       * @since 1.6.0
 549       */
 550      do_action( 'bp_setup_theme' );
 551  }
 552  
 553  /**
 554   * Fire the 'bp_after_setup_theme' action.
 555   *
 556   * Piggy-back action for BuddyPress-specific theme actions once the theme has
 557   * been set up and the theme's functions.php has loaded.
 558   *
 559   * Hooked to 'after_setup_theme' with a priority of 100. This allows plenty of
 560   * time for other themes to load their features, such as BuddyPress support,
 561   * before our theme compatibility layer kicks in.
 562   *
 563   * @since 1.6.0
 564   */
 565  function bp_after_setup_theme() {
 566  
 567      /**
 568       * Fires inside the 'bp_after_setup_theme' function.
 569       *
 570       * @since 1.7.0
 571       */
 572      do_action( 'bp_after_setup_theme' );
 573  }
 574  
 575  /** Theme Compatibility Filter ************************************************/
 576  
 577  /**
 578   * Fire the 'bp_request' filter, a piggy-back of WP's 'request'.
 579   *
 580   * @since 1.7.0
 581   *
 582   * @see WP::parse_request() for a description of parameters.
 583   *
 584   * @param array $query_vars See {@link WP::parse_request()}.
 585   * @return array $query_vars See {@link WP::parse_request()}.
 586   */
 587  function bp_request( $query_vars = array() ) {
 588  
 589      /**
 590       * Filters the query_vars for the current request.
 591       *
 592       * @since 1.7.0
 593       *
 594       * @param array $query_vars Array of query variables.
 595       */
 596      return apply_filters( 'bp_request', $query_vars );
 597  }
 598  
 599  /**
 600   * Fire the 'bp_login_redirect' filter, a piggy-back of WP's 'login_redirect'.
 601   *
 602   * @since 1.7.0
 603   *
 604   * @param string $redirect_to     See 'login_redirect'.
 605   * @param string $redirect_to_raw See 'login_redirect'.
 606   * @param bool   $user            See 'login_redirect'.
 607   * @return string
 608   */
 609  function bp_login_redirect( $redirect_to = '', $redirect_to_raw = '', $user = false ) {
 610  
 611      /**
 612       * Filters the URL to redirect to after login.
 613       *
 614       * @since 1.7.0
 615       *
 616       * @param string           $redirect_to     The redirect destination URL.
 617       * @param string           $redirect_to_raw The requested redirect destination URL passed as a parameter.
 618       * @param WP_User|WP_Error $user            WP_User object if login was successful, WP_Error object otherwise.
 619       */
 620      return apply_filters( 'bp_login_redirect', $redirect_to, $redirect_to_raw, $user );
 621  }
 622  
 623  /**
 624   * Fire 'bp_template_include', main filter used for theme compatibility and displaying custom BP theme files.
 625   *
 626   * Hooked to 'template_include'.
 627   *
 628   * @since 1.6.0
 629   *
 630   * @param string $template See 'template_include'.
 631   * @return string Template file to use.
 632   */
 633  function bp_template_include( $template = '' ) {
 634  
 635      /**
 636       * Filters the template to use with template_include.
 637       *
 638       * @since 1.6.0
 639       *
 640       * @param string $template The path of the template to include.
 641       */
 642      return apply_filters( 'bp_template_include', $template );
 643  }
 644  
 645  /**
 646   * Fire the 'bp_generate_rewrite_rules' action, where BP generates its rewrite rules.
 647   *
 648   * @since 1.7.0
 649   *
 650   * @param WP_Rewrite $wp_rewrite See 'generate_rewrite_rules'.
 651   */
 652  function bp_generate_rewrite_rules( $wp_rewrite ) {
 653  
 654      /**
 655       * Fires inside the 'bp_generate_rewrite_rules' function.
 656       *
 657       * @since 1.7.0
 658       *
 659       * @param WP_Rewrite $wp_rewrite WP_Rewrite object. Passed by reference.
 660       */
 661      do_action_ref_array( 'bp_generate_rewrite_rules', array( &$wp_rewrite ) );
 662  }
 663  
 664  /**
 665   * Fire the 'bp_allowed_themes' filter.
 666   *
 667   * Filter the allowed themes list for BuddyPress-specific themes.
 668   *
 669   * @since 1.7.0
 670   *
 671   * @param array $themes The path of the template to include.
 672   * @return array
 673   */
 674  function bp_allowed_themes( $themes ) {
 675  
 676      /**
 677       * Filters the allowed themes list for BuddyPress-specific themes.
 678       *
 679       * @since 1.7.0
 680       *
 681       * @param string $template The path of the template to include.
 682       */
 683      return apply_filters( 'bp_allowed_themes', $themes );
 684  }
 685  
 686  /** Requests ******************************************************************/
 687  
 688  /**
 689   * The main action used for handling theme-side POST requests.
 690   *
 691   * @since 1.9.0
 692   */
 693  function bp_post_request() {
 694  
 695      // Bail if not a POST action.
 696      if ( ! bp_is_post_request() ) {
 697          return;
 698      }
 699  
 700      // Bail if no action.
 701      if ( empty( $_POST['action'] ) ) {
 702          return;
 703      }
 704  
 705      // Sanitize the POST action.
 706      $action = sanitize_key( $_POST['action'] );
 707  
 708      /**
 709       * Fires at the end of the bp_post_request function.
 710       *
 711       * This dynamic action is probably the one you want to use. It narrows down
 712       * the scope of the 'action' without needing to check it in your function.
 713       *
 714       * @since 1.9.0
 715       */
 716      do_action( 'bp_post_request_' . $action );
 717  
 718      /**
 719       * Fires at the end of the bp_post_request function.
 720       *
 721       * Use this static action if you don't mind checking the 'action' yourself.
 722       *
 723       * @since 1.9.0
 724       *
 725       * @param string $action The action being run.
 726       */
 727      do_action( 'bp_post_request',   $action );
 728  }
 729  
 730  /**
 731   * The main action used for handling theme-side GET requests.
 732   *
 733   * @since 1.9.0
 734   */
 735  function bp_get_request() {
 736  
 737      // Bail if not a POST action.
 738      if ( ! bp_is_get_request() ) {
 739          return;
 740      }
 741  
 742      // Bail if no action.
 743      if ( empty( $_GET['action'] ) ) {
 744          return;
 745      }
 746  
 747      // Sanitize the GET action.
 748      $action = sanitize_key( $_GET['action'] );
 749  
 750      /**
 751       * Fires at the end of the bp_get_request function.
 752       *
 753       * This dynamic action is probably the one you want to use. It narrows down
 754       * the scope of the 'action' without needing to check it in your function.
 755       *
 756       * @since 1.9.0
 757       */
 758      do_action( 'bp_get_request_' . $action );
 759  
 760      /**
 761       * Fires at the end of the bp_get_request function.
 762       *
 763       * Use this static action if you don't mind checking the 'action' yourself.
 764       *
 765       * @since 1.9.0
 766       *
 767       * @param string $action The action being run.
 768       */
 769      do_action( 'bp_get_request',   $action );
 770  }


Generated: Sun Nov 17 01:01:36 2019 Cross-referenced by PHPXref 0.7.1