Changeset 7839
- Timestamp:
- 02/11/2014 02:58:47 AM (12 years ago)
- File:
-
- 1 edited
-
trunk/bp-core/bp-core-component.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-component.php
r7465 r7839 107 107 */ 108 108 public $root_slug = ''; 109 110 /** 111 * Metadata tables for the component (if applicable) 112 * 113 * @since BuddyPress (2.0.0) 114 * 115 * @var array 116 */ 117 public $meta_tables = array(); 118 119 /** 120 * Global tables for the component (if applicable) 121 * 122 * @since BuddyPress (2.0.0) 123 * 124 * @var array 125 */ 126 public $global_tables = array(); 109 127 110 128 /** Methods ***************************************************************/ … … 182 200 * @type array $global_tables Optional. An array of database table 183 201 * names. 202 * @type array $meta_tables Optional. An array of metadata table 203 * names. 184 204 * } 185 205 */ … … 198 218 'notification_callback' => '', 199 219 'search_string' => '', 200 'global_tables' => '' 220 'global_tables' => '', 221 'meta_tables' => '', 201 222 ) ); 202 223 … … 216 237 $this->notification_callback = apply_filters( 'bp_' . $this->id . '_notification_callback', $r['notification_callback'] ); 217 238 218 // Set up global table names 219 if ( !empty( $r['global_tables'] ) ) { 220 221 // This filter allows for component-specific filtering of table names 222 // To filter *all* tables, use the 'bp_core_get_table_prefix' filter instead 223 $r['global_tables'] = apply_filters( 'bp_' . $this->id . '_global_tables', $r['global_tables'] ); 224 225 foreach ( $r['global_tables'] as $global_name => $table_name ) { 226 $this->$global_name = $table_name; 227 } 239 // Set the global table names, if applicable 240 if ( ! empty( $r['global_tables'] ) ) { 241 $this->register_global_tables( $r['global_tables'] ); 242 } 243 244 // Set the metadata table, if applicable 245 if ( ! empty( $r['meta_tables'] ) ) { 246 $this->register_meta_tables( $r['meta_tables'] ); 228 247 } 229 248 … … 445 464 446 465 /** 466 * Register global tables for the component, so that it may use WordPress's database API. 467 * 468 * @since BuddyPress (2.0.0) 469 * 470 * @param array $tables 471 */ 472 public function register_global_tables( $tables = array() ) { 473 474 // This filter allows for component-specific filtering of table names 475 // To filter *all* tables, use the 'bp_core_get_table_prefix' filter instead 476 $tables = apply_filters( 'bp_' . $this->id . '_global_tables', $tables ); 477 478 // Add to the BuddyPress global object 479 if ( !empty( $tables ) && is_array( $tables ) ) { 480 foreach ( $tables as $global_name => $table_name ) { 481 $this->$global_name = $table_name; 482 } 483 484 // Keep a record of the metadata tables in the component 485 $this->global_tables = $tables; 486 } 487 488 do_action( 'bp_' . $this->id . '_register_global_tables' ); 489 } 490 491 /** 492 * Register component metadata tables. 493 * 494 * Metadata tables are registered in the $wpdb global, for 495 * compatibility with the WordPress metadata API. 496 * 497 * @since BuddyPress (2.0.0) 498 * 499 * @param array $tables 500 */ 501 public function register_meta_tables( $tables = array() ) { 502 global $wpdb; 503 504 // This filter allows for component-specific filtering of table names 505 // To filter *all* tables, use the 'bp_core_get_table_prefix' filter instead 506 $tables = apply_filters( 'bp_' . $this->id . '_meta_tables', $tables ); 507 508 /** 509 * Add the name of each metadata table to WPDB to allow BuddyPress 510 * components to play nicely with the WordPress metadata API. 511 */ 512 if ( !empty( $tables ) && is_array( $tables ) ) { 513 foreach( $tables as $meta_prefix => $table_name ) { 514 $wpdb->{$meta_prefix . 'meta'} = $table_name; 515 } 516 517 // Keep a record of the metadata tables in the component 518 $this->meta_tables = $tables; 519 } 520 521 do_action( 'bp_' . $this->id . '_register_meta_tables' ); 522 } 523 524 /** 447 525 * Set up the component post types. 448 526 *
Note: See TracChangeset
for help on using the changeset viewer.