[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Component classes. 4 * 5 * @package BuddyPress 6 * @subpackage Core 7 * @since 1.5.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 if ( !class_exists( 'BP_Component' ) ) : 14 15 /** 16 * BuddyPress Component Class. 17 * 18 * The BuddyPress component class is responsible for simplifying the creation 19 * of components that share similar behaviors and routines. It is used 20 * internally by BuddyPress to create the bundled components, but can be 21 * extended to create other really neat things. 22 * 23 * @since 1.5.0 24 */ 25 class BP_Component { 26 27 /** Variables *************************************************************/ 28 29 /** 30 * Translatable name for the component. 31 * 32 * @internal 33 * @var string $name 34 */ 35 public $name = ''; 36 37 /** 38 * Unique ID for the component. 39 * 40 * @since 1.5.0 41 * @var string $id 42 */ 43 public $id = ''; 44 45 /** 46 * Unique slug for the component, for use in query strings and URLs. 47 * 48 * @since 1.5.0 49 * @var string $slug 50 */ 51 public $slug = ''; 52 53 /** 54 * Does the component need a top-level directory? 55 * 56 * @since 1.5.0 57 * @var bool $has_directory 58 */ 59 public $has_directory = false; 60 61 /** 62 * The path to the component's files. 63 * 64 * @since 1.5.0 65 * @var string $path 66 */ 67 public $path = ''; 68 69 /** 70 * The WP_Query loop for this component. 71 * 72 * @since 1.5.0 73 * @var WP_Query $query 74 */ 75 public $query = false; 76 77 /** 78 * The current ID of the queried object. 79 * 80 * @since 1.5.0 81 * @var string $current_id 82 */ 83 public $current_id = ''; 84 85 /** 86 * Callback for formatting notifications. 87 * 88 * @since 1.5.0 89 * @var callable $notification_callback 90 */ 91 public $notification_callback = ''; 92 93 /** 94 * WordPress Toolbar links. 95 * 96 * @since 1.5.0 97 * @var array $admin_menu 98 */ 99 public $admin_menu = ''; 100 101 /** 102 * Placeholder text for component directory search box. 103 * 104 * @since 1.6.0 105 * @var string $search_string 106 */ 107 public $search_string = ''; 108 109 /** 110 * Root slug for the component. 111 * 112 * @since 1.6.0 113 * @var string $root_slug 114 */ 115 public $root_slug = ''; 116 117 /** 118 * Metadata tables for the component (if applicable). 119 * 120 * @since 2.0.0 121 * 122 * @var array 123 */ 124 public $meta_tables = array(); 125 126 /** 127 * Global tables for the component (if applicable). 128 * 129 * @since 2.0.0 130 * 131 * @var array 132 */ 133 public $global_tables = array(); 134 135 /** 136 * Query argument for component search URLs. 137 * 138 * @since 2.4.0 139 * @var string 140 */ 141 public $search_query_arg = 's'; 142 143 /** Methods ***************************************************************/ 144 145 /** 146 * Component loader. 147 * 148 * @since 1.5.0 149 * @since 1.9.0 Added $params as a parameter. 150 * @since 2.3.0 Added $params['features'] as a configurable value. 151 * @since 2.4.0 Added $params['search_query_arg'] as a configurable value. 152 * 153 * @param string $id Unique ID. Letters, numbers, and underscores only. 154 * @param string $name Unique name. This should be a translatable name, eg. 155 * __( 'Groups', 'buddypress' ). 156 * @param string $path The file path for the component's files. Used by {@link BP_Component::includes()}. 157 * @param array $params { 158 * Additional parameters used by the component. 159 * @type int $adminbar_myaccount_order Set the position for our menu under the WP Toolbar's "My Account menu". 160 * @type array $features An array of feature names. This is used to load additional files from your 161 * component directory and for feature active checks. eg. array( 'awesome' ) 162 * would look for a file called "bp-{$this->id}-awesome.php" and you could use 163 * bp_is_active( $this->id, 'awesome' ) to determine if the feature is active. 164 * @type string $search_query_arg String to be used as the query argument in component search URLs. 165 * } 166 */ 167 public function start( $id = '', $name = '', $path = '', $params = array() ) { 168 169 // Internal identifier of component. 170 $this->id = $id; 171 172 // Internal component name. 173 $this->name = $name; 174 175 // Path for includes. 176 $this->path = $path; 177 178 // Miscellaneous component parameters that need to be set early on. 179 if ( ! empty( $params ) ) { 180 // Sets the position for our menu under the WP Toolbar's "My Account" menu. 181 if ( ! empty( $params['adminbar_myaccount_order'] ) ) { 182 $this->adminbar_myaccount_order = (int) $params['adminbar_myaccount_order']; 183 } 184 185 // Register features. 186 if ( ! empty( $params['features'] ) ) { 187 $this->features = array_map( 'sanitize_title', (array) $params['features'] ); 188 } 189 190 if ( ! empty( $params['search_query_arg'] ) ) { 191 $this->search_query_arg = sanitize_title( $params['search_query_arg'] ); 192 } 193 194 // Set defaults if not passed. 195 } else { 196 // New component menus are added before the settings menu if not set. 197 $this->adminbar_myaccount_order = 90; 198 } 199 200 // Move on to the next step. 201 $this->setup_actions(); 202 } 203 204 /** 205 * Set up component global variables. 206 * 207 * @since 1.5.0 208 * 209 * 210 * @param array $args { 211 * All values are optional. 212 * @type string $slug The component slug. Used to construct certain URLs, such as 'friends' in 213 * http://example.com/members/joe/friends/. Default: the value of $this->id. 214 * @type string $root_slug The component root slug. Note that this value is generally unused if the 215 * component has a root directory (the slug will be overridden by the 216 * post_name of the directory page). Default: the slug of the directory page 217 * if one is found, otherwise an empty string. 218 * @type bool $has_directory Set to true if the component requires an associated WordPress page. 219 * @type callable $notification_callback Optional. The callable function that formats the component's notifications. 220 * @type string $search_term Optional. The placeholder text in the component directory search box. Eg, 221 * 'Search Groups...'. 222 * @type array $global_tables Optional. An array of database table names. 223 * @type array $meta_tables Optional. An array of metadata table names. 224 * } 225 */ 226 public function setup_globals( $args = array() ) { 227 228 /** Slugs ************************************************************ 229 */ 230 231 // If a WP directory page exists for the component, it should 232 // be the default value of 'root_slug'. 233 $default_root_slug = isset( buddypress()->pages->{$this->id}->slug ) ? buddypress()->pages->{$this->id}->slug : ''; 234 235 $r = wp_parse_args( $args, array( 236 'slug' => $this->id, 237 'root_slug' => $default_root_slug, 238 'has_directory' => false, 239 'directory_title' => '', 240 'notification_callback' => '', 241 'search_string' => '', 242 'global_tables' => '', 243 'meta_tables' => '', 244 ) ); 245 246 /** 247 * Filters the slug to be used for the permalink URI chunk after root. 248 * 249 * @since 1.5.0 250 * 251 * @param string $value Slug to use in permalink URI chunk. 252 */ 253 $this->slug = apply_filters( 'bp_' . $this->id . '_slug', $r['slug'] ); 254 255 /** 256 * Filters the slug used for root directory. 257 * 258 * @since 1.5.0 259 * 260 * @param string $value Root directory slug. 261 */ 262 $this->root_slug = apply_filters( 'bp_' . $this->id . '_root_slug', $r['root_slug'] ); 263 264 /** 265 * Filters the component's top-level directory if available. 266 * 267 * @since 1.5.0 268 * 269 * @param bool $value Whether or not there is a top-level directory. 270 */ 271 $this->has_directory = apply_filters( 'bp_' . $this->id . '_has_directory', $r['has_directory'] ); 272 273 /** 274 * Filters the component's directory title. 275 * 276 * @since 2.0.0 277 * 278 * @param string $value Title to use for the directory. 279 */ 280 $this->directory_title = apply_filters( 'bp_' . $this->id . '_directory_title', $r['directory_title'] ); 281 282 /** 283 * Filters the placeholder text for search inputs for component. 284 * 285 * @since 1.5.0 286 * 287 * @param string $value Name to use in search input placeholders. 288 */ 289 $this->search_string = apply_filters( 'bp_' . $this->id . '_search_string', $r['search_string'] ); 290 291 /** 292 * Filters the callable function that formats the component's notifications. 293 * 294 * @since 1.5.0 295 * 296 * @param string $value Function callback. 297 */ 298 $this->notification_callback = apply_filters( 'bp_' . $this->id . '_notification_callback', $r['notification_callback'] ); 299 300 // Set the global table names, if applicable. 301 if ( ! empty( $r['global_tables'] ) ) { 302 $this->register_global_tables( $r['global_tables'] ); 303 } 304 305 // Set the metadata table, if applicable. 306 if ( ! empty( $r['meta_tables'] ) ) { 307 $this->register_meta_tables( $r['meta_tables'] ); 308 } 309 310 /** BuddyPress ******************************************************* 311 */ 312 313 // Register this component in the loaded components array. 314 buddypress()->loaded_components[$this->slug] = $this->id; 315 316 /** 317 * Fires at the end of the setup_globals method inside BP_Component. 318 * 319 * This is a dynamic hook that is based on the component string ID. 320 * 321 * @since 1.5.0 322 */ 323 do_action( 'bp_' . $this->id . '_setup_globals' ); 324 } 325 326 /** 327 * Include required files. 328 * 329 * Please note that, by default, this method is fired on the bp_include 330 * hook, with priority 8. This is necessary so that core components are 331 * loaded in time to be available to third-party plugins. However, this 332 * load order means that third-party plugins whose main files are 333 * loaded at bp_include with priority 10 (as recommended), will not be 334 * loaded in time for their includes() method to fire automatically. 335 * 336 * For this reason, it is recommended that your plugin has its own 337 * method or function for requiring necessary files. If you must use 338 * this method, you will have to call it manually in your constructor 339 * class, ie 340 * $this->includes(); 341 * 342 * Note that when you pass an array value like 'actions' to includes, 343 * it looks for the following three files (assuming your component is 344 * called 'my_component'): 345 * - ./actions 346 * - ./bp-my_component/actions 347 * - ./bp-my_component/bp-my_component-actions.php 348 * 349 * @since 1.5.0 350 * 351 * 352 * @param array $includes An array of file names, or file name chunks, 353 * to be parsed and then included. 354 */ 355 public function includes( $includes = array() ) { 356 357 // Bail if no files to include. 358 if ( ! empty( $includes ) ) { 359 $slashed_path = trailingslashit( $this->path ); 360 361 // Loop through files to be included. 362 foreach ( (array) $includes as $file ) { 363 364 $paths = array( 365 366 // Passed with no extension. 367 'bp-' . $this->id . '/bp-' . $this->id . '-' . $file . '.php', 368 'bp-' . $this->id . '-' . $file . '.php', 369 'bp-' . $this->id . '/' . $file . '.php', 370 371 // Passed with extension. 372 $file, 373 'bp-' . $this->id . '-' . $file, 374 'bp-' . $this->id . '/' . $file, 375 ); 376 377 foreach ( $paths as $path ) { 378 if ( @is_file( $slashed_path . $path ) ) { 379 require( $slashed_path . $path ); 380 break; 381 } 382 } 383 } 384 } 385 386 /** 387 * Fires at the end of the includes method inside BP_Component. 388 * 389 * This is a dynamic hook that is based on the component string ID. 390 * 391 * @since 1.5.0 392 */ 393 do_action( 'bp_' . $this->id . '_includes' ); 394 } 395 396 /** 397 * Late includes method. 398 * 399 * Components should include files here only on specific pages using 400 * conditionals such as {@link bp_is_current_component()}. Intentionally left 401 * empty. 402 * 403 * @since 3.0.0 404 */ 405 public function late_includes() {} 406 407 /** 408 * Set up the actions. 409 * 410 * @since 1.5.0 411 * 412 */ 413 public function setup_actions() { 414 415 // Setup globals. 416 add_action( 'bp_setup_globals', array( $this, 'setup_globals' ), 10 ); 417 418 // Set up canonical stack. 419 add_action( 'bp_setup_canonical_stack', array( $this, 'setup_canonical_stack' ), 10 ); 420 421 // Include required files. Called early to ensure that BP core 422 // components are loaded before plugins that hook their loader functions 423 // to bp_include with the default priority of 10. This is for backwards 424 // compatibility; henceforth, plugins should register themselves by 425 // extending this base class. 426 add_action( 'bp_include', array( $this, 'includes' ), 8 ); 427 428 // Load files conditionally, based on certain pages. 429 add_action( 'bp_late_include', array( $this, 'late_includes' ) ); 430 431 // Setup navigation. 432 add_action( 'bp_setup_nav', array( $this, 'setup_nav' ), 10 ); 433 434 // Setup WP Toolbar menus. 435 add_action( 'bp_setup_admin_bar', array( $this, 'setup_admin_bar' ), $this->adminbar_myaccount_order ); 436 437 // Setup component title. 438 add_action( 'bp_setup_title', array( $this, 'setup_title' ), 10 ); 439 440 // Setup cache groups. 441 add_action( 'bp_setup_cache_groups', array( $this, 'setup_cache_groups' ), 10 ); 442 443 // Register post types. 444 add_action( 'bp_register_post_types', array( $this, 'register_post_types' ), 10 ); 445 446 // Register taxonomies. 447 add_action( 'bp_register_taxonomies', array( $this, 'register_taxonomies' ), 10 ); 448 449 // Add the rewrite tags. 450 add_action( 'bp_add_rewrite_tags', array( $this, 'add_rewrite_tags' ), 10 ); 451 452 // Add the rewrite rules. 453 add_action( 'bp_add_rewrite_rules', array( $this, 'add_rewrite_rules' ), 10 ); 454 455 // Add the permalink structure. 456 add_action( 'bp_add_permastructs', array( $this, 'add_permastructs' ), 10 ); 457 458 // Allow components to parse the main query. 459 add_action( 'bp_parse_query', array( $this, 'parse_query' ), 10 ); 460 461 // Generate rewrite rules. 462 add_action( 'bp_generate_rewrite_rules', array( $this, 'generate_rewrite_rules' ), 10 ); 463 464 // Register BP REST Endpoints. 465 if ( bp_rest_in_buddypress() && bp_rest_api_is_available() ) { 466 add_action( 'bp_rest_api_init', array( $this, 'rest_api_init' ), 10 ); 467 } 468 469 // Register BP Blocks. 470 if ( bp_support_blocks() ) { 471 add_action( 'bp_blocks_init', array( $this, 'blocks_init' ), 10 ); 472 } 473 474 /** 475 * Fires at the end of the setup_actions method inside BP_Component. 476 * 477 * This is a dynamic hook that is based on the component string ID. 478 * 479 * @since 1.5.0 480 */ 481 do_action( 'bp_' . $this->id . '_setup_actions' ); 482 } 483 484 /** 485 * Set up the canonical URL stack for this component. 486 * 487 * @since 2.1.0 488 */ 489 public function setup_canonical_stack() {} 490 491 /** 492 * Set up component navigation. 493 * 494 * @since 1.5.0 495 * 496 * @see bp_core_new_nav_item() For a description of the $main_nav 497 * parameter formatting. 498 * @see bp_core_new_subnav_item() For a description of how each item 499 * in the $sub_nav parameter array should be formatted. 500 * 501 * @param array $main_nav Optional. Passed directly to bp_core_new_nav_item(). 502 * See that function for a description. 503 * @param array $sub_nav Optional. Multidimensional array, each item in 504 * which is passed to bp_core_new_subnav_item(). See that 505 * function for a description. 506 */ 507 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 508 509 // No sub nav items without a main nav item. 510 if ( !empty( $main_nav ) ) { 511 // Always set the component ID. 512 $main_nav['component_id'] = $this->id; 513 514 bp_core_new_nav_item( $main_nav, 'members' ); 515 516 // Sub nav items are not required. 517 if ( !empty( $sub_nav ) ) { 518 foreach( (array) $sub_nav as $nav ) { 519 bp_core_new_subnav_item( $nav, 'members' ); 520 } 521 } 522 } 523 524 /** 525 * Fires at the end of the setup_nav method inside BP_Component. 526 * 527 * This is a dynamic hook that is based on the component string ID. 528 * 529 * @since 1.5.0 530 */ 531 do_action( 'bp_' . $this->id . '_setup_nav' ); 532 } 533 534 /** 535 * Set up the component entries in the WordPress Admin Bar. 536 * 537 * @since 1.5.0 538 * 539 * @see WP_Admin_Bar::add_menu() for a description of the syntax 540 * required by each item in the $wp_admin_nav parameter array. 541 * @global object $wp_admin_bar 542 * 543 * @param array $wp_admin_nav An array of nav item arguments. Each item in this parameter 544 * array is passed to {@link WP_Admin_Bar::add_menu()}. 545 * See that method for a description of the required syntax for 546 * each item. 547 */ 548 public function setup_admin_bar( $wp_admin_nav = array() ) { 549 550 // Bail if this is an ajax request. 551 if ( defined( 'DOING_AJAX' ) ) { 552 return; 553 } 554 555 // Do not proceed if BP_USE_WP_ADMIN_BAR constant is not set or is false. 556 if ( ! bp_use_wp_admin_bar() ) { 557 return; 558 } 559 560 /** 561 * Filters the admin navigation passed into setup_admin_bar. 562 * 563 * This is a dynamic hook that is based on the component string ID. 564 * 565 * @since 1.9.0 566 * 567 * @param array $wp_admin_nav Array of navigation items to add. 568 */ 569 $wp_admin_nav = apply_filters( 'bp_' . $this->id . '_admin_nav', $wp_admin_nav ); 570 571 // Do we have Toolbar menus to add? 572 if ( !empty( $wp_admin_nav ) ) { 573 // Fill in position if one wasn't passed for backpat. 574 $pos = 0; 575 $not_set_pos = 1; 576 foreach( $wp_admin_nav as $key => $nav ) { 577 if ( ! isset( $nav['position'] ) ) { 578 $wp_admin_nav[$key]['position'] = $pos + $not_set_pos; 579 580 if ( 9 !== $not_set_pos ) { 581 ++$not_set_pos; 582 } 583 } else { 584 $pos = $nav['position']; 585 586 // Reset not set pos to 1. 587 if ( $pos % 10 === 0 ) { 588 $not_set_pos = 1; 589 } 590 } 591 } 592 593 // Sort admin nav by position. 594 $wp_admin_nav = bp_sort_by_key( $wp_admin_nav, 'position', 'num' ); 595 596 // Set this objects menus. 597 $this->admin_menu = $wp_admin_nav; 598 599 // Define the WordPress global. 600 global $wp_admin_bar; 601 602 // Add each admin menu. 603 foreach( $this->admin_menu as $admin_menu ) { 604 $wp_admin_bar->add_node( $admin_menu ); 605 } 606 } 607 608 /** 609 * Fires at the end of the setup_admin_bar method inside BP_Component. 610 * 611 * This is a dynamic hook that is based on the component string ID. 612 * 613 * @since 1.5.0 614 */ 615 do_action( 'bp_' . $this->id . '_setup_admin_bar' ); 616 } 617 618 /** 619 * Set up the component title. 620 * 621 * @since 1.5.0 622 * 623 */ 624 public function setup_title() { 625 626 /** 627 * Fires in the setup_title method inside BP_Component. 628 * 629 * This is a dynamic hook that is based on the component string ID. 630 * 631 * @since 1.5.0 632 */ 633 do_action( 'bp_' . $this->id . '_setup_title' ); 634 } 635 636 /** 637 * Setup component-specific cache groups. 638 * 639 * @since 2.2.0 640 * 641 */ 642 public function setup_cache_groups() { 643 644 /** 645 * Fires in the setup_cache_groups method inside BP_Component. 646 * 647 * This is a dynamic hook that is based on the component string ID. 648 * 649 * @since 2.2.0 650 */ 651 do_action( 'bp_' . $this->id . '_setup_cache_groups' ); 652 } 653 654 /** 655 * Register global tables for the component, so that it may use WordPress's database API. 656 * 657 * @since 2.0.0 658 * 659 * @param array $tables Table names to register. 660 */ 661 public function register_global_tables( $tables = array() ) { 662 663 /** 664 * Filters the global tables for the component, so that it may use WordPress' database API. 665 * 666 * This is a dynamic hook that is based on the component string ID. 667 * It allows for component-specific filtering of table names. To filter 668 * *all* tables, use the 'bp_core_get_table_prefix' filter instead. 669 * 670 * @since 1.6.0 671 */ 672 $tables = apply_filters( 'bp_' . $this->id . '_global_tables', $tables ); 673 674 // Add to the BuddyPress global object. 675 if ( !empty( $tables ) && is_array( $tables ) ) { 676 foreach ( $tables as $global_name => $table_name ) { 677 $this->{$global_name} = $table_name; 678 } 679 680 // Keep a record of the metadata tables in the component. 681 $this->global_tables = $tables; 682 } 683 684 /** 685 * Fires at the end of the register_global_tables method inside BP_Component. 686 * 687 * This is a dynamic hook that is based on the component string ID. 688 * 689 * @since 2.0.0 690 */ 691 do_action( 'bp_' . $this->id . '_register_global_tables' ); 692 } 693 694 /** 695 * Register component metadata tables. 696 * 697 * Metadata tables are registered in the $wpdb global, for 698 * compatibility with the WordPress metadata API. 699 * 700 * @since 2.0.0 701 * 702 * @param array $tables Table names to register. 703 */ 704 public function register_meta_tables( $tables = array() ) { 705 global $wpdb; 706 707 /** 708 * Filters the global meta_tables for the component. 709 * 710 * This is a dynamic hook that is based on the component string ID. 711 * It allows for component-specific filtering of table names. To filter 712 * *all* tables, use the 'bp_core_get_table_prefix' filter instead. 713 * 714 * @since 2.0.0 715 */ 716 $tables = apply_filters( 'bp_' . $this->id . '_meta_tables', $tables ); 717 718 /** 719 * Add the name of each metadata table to WPDB to allow BuddyPress 720 * components to play nicely with the WordPress metadata API. 721 */ 722 if ( !empty( $tables ) && is_array( $tables ) ) { 723 foreach( $tables as $meta_prefix => $table_name ) { 724 $wpdb->{$meta_prefix . 'meta'} = $table_name; 725 } 726 727 // Keep a record of the metadata tables in the component. 728 $this->meta_tables = $tables; 729 } 730 731 /** 732 * Fires at the end of the register_meta_tables method inside BP_Component. 733 * 734 * This is a dynamic hook that is based on the component string ID. 735 * 736 * @since 2.0.0 737 */ 738 do_action( 'bp_' . $this->id . '_register_meta_tables' ); 739 } 740 741 /** 742 * Set up the component post types. 743 * 744 * @since 1.5.0 745 * 746 */ 747 public function register_post_types() { 748 749 /** 750 * Fires in the register_post_types method inside BP_Component. 751 * 752 * This is a dynamic hook that is based on the component string ID. 753 * 754 * @since 1.5.0 755 */ 756 do_action( 'bp_' . $this->id . '_register_post_types' ); 757 } 758 759 /** 760 * Register component-specific taxonomies. 761 * 762 * @since 1.5.0 763 * 764 */ 765 public function register_taxonomies() { 766 767 /** 768 * Fires in the register_taxonomies method inside BP_Component. 769 * 770 * This is a dynamic hook that is based on the component string ID. 771 * 772 * @since 1.5.0 773 */ 774 do_action( 'bp_' . $this->id . '_register_taxonomies' ); 775 } 776 777 /** 778 * Add any additional rewrite tags. 779 * 780 * @since 1.5.0 781 * 782 */ 783 public function add_rewrite_tags() { 784 785 /** 786 * Fires in the add_rewrite_tags method inside BP_Component. 787 * 788 * This is a dynamic hook that is based on the component string ID. 789 * 790 * @since 1.5.0 791 */ 792 do_action( 'bp_' . $this->id . '_add_rewrite_tags' ); 793 } 794 795 /** 796 * Add any additional rewrite rules. 797 * 798 * @since 1.9.0 799 * 800 */ 801 public function add_rewrite_rules() { 802 803 /** 804 * Fires in the add_rewrite_rules method inside BP_Component. 805 * 806 * This is a dynamic hook that is based on the component string ID. 807 * 808 * @since 1.9.0 809 */ 810 do_action( 'bp_' . $this->id . '_add_rewrite_rules' ); 811 } 812 813 /** 814 * Add any permalink structures. 815 * 816 * @since 1.9.0 817 * 818 */ 819 public function add_permastructs() { 820 821 /** 822 * Fires in the add_permastructs method inside BP_Component. 823 * 824 * This is a dynamic hook that is based on the component string ID. 825 * 826 * @since 1.9.0 827 */ 828 do_action( 'bp_' . $this->id . '_add_permastructs' ); 829 } 830 831 /** 832 * Allow components to parse the main query. 833 * 834 * @since 1.9.0 835 * 836 * 837 * @param object $query The main WP_Query. 838 */ 839 public function parse_query( $query ) { 840 841 /** 842 * Fires in the parse_query method inside BP_Component. 843 * 844 * This is a dynamic hook that is based on the component string ID. 845 * 846 * @since 1.9.0 847 * 848 * @param object $query Main WP_Query object. Passed by reference. 849 */ 850 do_action_ref_array( 'bp_' . $this->id . '_parse_query', array( &$query ) ); 851 } 852 853 /** 854 * Generate any additional rewrite rules. 855 * 856 * @since 1.5.0 857 * 858 */ 859 public function generate_rewrite_rules() { 860 861 /** 862 * Fires in the generate_rewrite_rules method inside BP_Component. 863 * 864 * This is a dynamic hook that is based on the component string ID. 865 * 866 * @since 1.5.0 867 */ 868 do_action( 'bp_' . $this->id . '_generate_rewrite_rules' ); 869 } 870 871 /** 872 * Init the BP REST API. 873 * 874 * @since 5.0.0 875 * 876 * @param array $controllers The list of BP REST controllers to load. 877 */ 878 public function rest_api_init( $controllers = array() ) { 879 if ( is_array( $controllers ) && $controllers ) { 880 // Built-in controllers. 881 $_controllers = $controllers; 882 883 /** 884 * Use this filter to disable all or some REST API controllers 885 * for the component. 886 * 887 * This is a dynamic hook that is based on the component string ID. 888 * 889 * @since 5.0.0 890 * 891 * @param array $controllers The list of BP REST API controllers to load. 892 */ 893 $controllers = (array) apply_filters( 'bp_' . $this->id . '_rest_api_controllers', $controllers ); 894 895 foreach( $controllers as $controller ) { 896 if ( ! in_array( $controller, $_controllers, true ) ) { 897 continue; 898 } 899 900 $component_controller = new $controller; 901 $component_controller->register_routes(); 902 } 903 } 904 905 /** 906 * Fires in the rest_api_init method inside BP_Component. 907 * 908 * This is a dynamic hook that is based on the component string ID. 909 * 910 * @since 5.0.0 911 */ 912 do_action( 'bp_' . $this->id . '_rest_api_init' ); 913 } 914 915 /** 916 * Register the BP Blocks. 917 * 918 * @since 6.0.0 919 * 920 * @param array $blocks The list of BP Blocks to register. 921 */ 922 public function blocks_init( $blocks = array() ) { 923 if ( is_array( $blocks ) && $blocks ) { 924 /** 925 * Filter here to disable all or some BP Blocks for a component. 926 * 927 * This is a dynamic hook that is based on the component string ID. 928 * 929 * @since 6.0.0 930 * 931 * @param array $blocks The list of BP Blocks for the component. 932 */ 933 $blocks = (array) apply_filters( 'bp_' . $this->id . '_register_blocks', $blocks ); 934 935 foreach ( $blocks as $block ) { 936 bp_register_block( $block ); 937 } 938 } 939 940 /** 941 * Fires in the blocks_init method inside BP_Component. 942 * 943 * This is a dynamic hook that is based on the component string ID. 944 * 945 * @since 6.0.0 946 */ 947 do_action( 'bp_' . $this->id . '_blocks_init' ); 948 } 949 } 950 endif; // BP_Component.
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Apr 19 01:01:38 2021 | Cross-referenced by PHPXref 0.7.1 |