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