Changeset 6953
- Timestamp:
- 04/26/2013 08:46:42 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-component.php
r6648 r6953 1 1 <?php 2 2 3 // Exit if accessed directly 3 4 if ( !defined( 'ABSPATH' ) ) exit; … … 19 20 class BP_Component { 20 21 22 /** Variables *************************************************************/ 23 21 24 /** 22 25 * @var string Unique name (for internal identification) 23 26 * @internal 24 27 */ 25 var $name;28 public $name = ''; 26 29 27 30 /** 28 31 * @var Unique ID (normally for custom post type) 29 32 */ 30 var $id;33 public $id = ''; 31 34 32 35 /** 33 36 * @var string Unique slug (used in query string and permalinks) 34 37 */ 35 var $slug;38 public $slug = ''; 36 39 37 40 /** 38 41 * @var bool Does this component need a top-level directory? 39 42 */ 40 var $has_directory;43 public $has_directory = false; 41 44 42 45 /** 43 46 * @var string The path to the component's files 44 47 */ 45 var $path;48 public $path = ''; 46 49 47 50 /** 48 51 * @var WP_Query The loop for this component 49 52 */ 50 var $query;53 public $query = false; 51 54 52 55 /** 53 56 * @var string The current ID of the queried object 54 57 */ 55 var $current_id;58 public $current_id = ''; 56 59 57 60 /** 58 61 * @var string Function to call for notifications 59 62 */ 60 var $notification_callback;63 public $notification_callback = ''; 61 64 62 65 /** 63 66 * @var array WordPress Toolbar links 64 67 */ 65 var $admin_menu;68 public $admin_menu = ''; 66 69 67 70 /** … … 71 74 * @var string 72 75 */ 73 public $search_string ;76 public $search_string = ''; 74 77 75 78 /** … … 79 82 * @var string 80 83 */ 81 public $root_slug; 84 public $root_slug = ''; 85 86 /** Methods ***************************************************************/ 82 87 83 88 /** … … 86 91 * @since BuddyPress (1.5) 87 92 * 88 * @param mixed $args Required. Supports these args:89 * - id: Unique ID (for internal identification). Letters, numbers, and underscores only90 * - name: Unique name. This should be a translatable name, eg __( 'Groups', 'buddypress')91 * - path: The file path for the component's files. Used by BP_Component::includes()93 * @param string $id Unique ID (for internal identification). Letters, numbers, and underscores only 94 * @param string $name Unique name. This should be a translatable name, eg __( 'Groups', 'buddypress' ) 95 * @param string $path The file path for the component's files. Used by BP_Component::includes() 96 * 92 97 * @uses bp_Component::setup_actions() Setup the hooks and actions 93 98 */ 94 function start( $id, $name, $path ) { 99 public function start( $id = '', $name = '', $path = '' ) { 100 95 101 // Internal identifier of component 96 102 $this->id = $id; … … 116 122 * @param arr $args Used to 117 123 */ 118 function setup_globals( $args = '' ) { 119 global $bp; 124 public function setup_globals( $args = array() ) { 120 125 121 126 /** Slugs *************************************************************/ 122 127 123 $ defaults =array(128 $r = wp_parse_args( $args, array( 124 129 'slug' => $this->id, 125 130 'root_slug' => '', … … 128 133 'search_string' => '', 129 134 'global_tables' => '' 130 ); 131 $r = wp_parse_args( $args, $defaults ); 135 ) ); 132 136 133 137 // Slug used for permalink URI chunk after root 134 $this->slug = apply_filters( 'bp_' . $this->id . '_slug', $r['slug']);138 $this->slug = apply_filters( 'bp_' . $this->id . '_slug', $r['slug'] ); 135 139 136 140 // Slug used for root directory 137 $this->root_slug = apply_filters( 'bp_' . $this->id . '_root_slug', $r['root_slug']);141 $this->root_slug = apply_filters( 'bp_' . $this->id . '_root_slug', $r['root_slug'] ); 138 142 139 143 // Does this component have a top-level directory? 140 $this->has_directory = apply_filters( 'bp_' . $this->id . '_has_directory', $r['has_directory']);144 $this->has_directory = apply_filters( 'bp_' . $this->id . '_has_directory', $r['has_directory'] ); 141 145 142 146 // Search string 143 $this->search_string = apply_filters( 'bp_' . $this->id . '_search_string', $r['search_string']);147 $this->search_string = apply_filters( 'bp_' . $this->id . '_search_string', $r['search_string'] ); 144 148 145 149 // Notifications callback … … 148 152 // Set up global table names 149 153 if ( !empty( $r['global_tables'] ) ) { 154 150 155 // This filter allows for component-specific filtering of table names 151 156 // To filter *all* tables, use the 'bp_core_get_table_prefix' filter instead … … 155 160 $this->$global_name = $table_name; 156 161 } 157 162 } 158 163 159 164 /** BuddyPress ********************************************************/ 160 165 161 166 // Register this component in the loaded components array 162 $bp->loaded_components[$this->slug] = $this->id;167 buddypress()->loaded_components[$this->slug] = $this->id; 163 168 164 169 // Call action … … 190 195 * @uses do_action() Calls 'bp_{@link bp_Component::name}includes' 191 196 */ 192 function includes( $includes = '' ) { 197 public function includes( $includes = array() ) { 198 199 // Bail if no files to include 193 200 if ( empty( $includes ) ) 194 201 return; … … 197 204 198 205 // Loop through files to be included 199 foreach ( $includes as $file ) {206 foreach ( (array) $includes as $file ) { 200 207 201 208 $paths = array( … … 232 239 * @uses do_action() Calls 'bp_{@link BP_Component::name}setup_actions' 233 240 */ 234 function setup_actions() {241 public function setup_actions() { 235 242 236 243 // Setup globals 237 add_action( 'bp_setup_globals', array 244 add_action( 'bp_setup_globals', array( $this, 'setup_globals' ), 10 ); 238 245 239 246 // Include required files. Called early to ensure that BP core … … 242 249 // compatibility; henceforth, plugins should register themselves by 243 250 // extending this base class. 244 add_action( 'bp_include', array 251 add_action( 'bp_include', array( $this, 'includes' ), 8 ); 245 252 246 253 // Setup navigation 247 add_action( 'bp_setup_nav', array 254 add_action( 'bp_setup_nav', array( $this, 'setup_nav' ), 10 ); 248 255 249 256 // Setup WP Toolbar menus 250 add_action( 'bp_setup_admin_bar', array 257 add_action( 'bp_setup_admin_bar', array( $this, 'setup_admin_bar' ), 10 ); 251 258 252 259 // Setup component title 253 add_action( 'bp_setup_title', array 260 add_action( 'bp_setup_title', array( $this, 'setup_title' ), 10 ); 254 261 255 262 // Register post types 256 add_action( 'bp_register_post_types', array 263 add_action( 'bp_register_post_types', array( $this, 'register_post_types' ), 10 ); 257 264 258 265 // Register taxonomies 259 add_action( 'bp_register_taxonomies', array 266 add_action( 'bp_register_taxonomies', array( $this, 'register_taxonomies' ), 10 ); 260 267 261 268 // Add the rewrite tags 262 add_action( 'bp_add_rewrite_tags', array 269 add_action( 'bp_add_rewrite_tags', array( $this, 'add_rewrite_tags' ), 10 ); 263 270 264 271 // Generate rewrite rules 265 add_action( 'bp_generate_rewrite_rules', array 272 add_action( 'bp_generate_rewrite_rules', array( $this, 'generate_rewrite_rules' ), 10 ); 266 273 267 274 // Additional actions can be attached here … … 272 279 * Setup the navigation 273 280 * 274 * @param arr $main_nav Optional275 * @param arr $sub_nav Optional276 */ 277 function setup_nav( $main_nav = '', $sub_nav = '') {281 * @param array $main_nav Optional 282 * @param array $sub_nav Optional 283 */ 284 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 278 285 279 286 // No sub nav items without a main nav item … … 283 290 // Sub nav items are not required 284 291 if ( !empty( $sub_nav ) ) { 285 foreach( $sub_nav as $nav ) {292 foreach( (array) $sub_nav as $nav ) { 286 293 bp_core_new_subnav_item( $nav ); 287 294 } … … 299 306 * @param array $wp_admin_menus 300 307 */ 301 function setup_admin_bar( $wp_admin_nav = '') {308 public function setup_admin_bar( $wp_admin_nav = array() ) { 302 309 303 310 // Bail if this is an ajax request … … 319 326 320 327 // Add each admin menu 321 foreach( $this->admin_menu as $admin_menu ) 328 foreach( $this->admin_menu as $admin_menu ) { 322 329 $wp_admin_bar->add_menu( $admin_menu ); 330 } 323 331 } 324 332 … … 334 342 * @uses do_action() Calls 'bp_{@link bp_Component::name}setup_title' 335 343 */ 336 function setup_title() {344 public function setup_title() { 337 345 do_action( 'bp_' . $this->id . '_setup_title' ); 338 346 } … … 345 353 * @uses do_action() Calls 'bp_{@link bp_Component::name}_register_post_types' 346 354 */ 347 function register_post_types() {355 public function register_post_types() { 348 356 do_action( 'bp_' . $this->id . '_register_post_types' ); 349 357 } … … 356 364 * @uses do_action() Calls 'bp_{@link bp_Component::name}_register_taxonomies' 357 365 */ 358 function register_taxonomies() {366 public function register_taxonomies() { 359 367 do_action( 'bp_' . $this->id . '_register_taxonomies' ); 360 368 } … … 367 375 * @uses do_action() Calls 'bp_{@link bp_Component::name}_add_rewrite_tags' 368 376 */ 369 function add_rewrite_tags() {377 public function add_rewrite_tags() { 370 378 do_action( 'bp_' . $this->id . '_add_rewrite_tags' ); 371 379 } … … 378 386 * @uses do_action() Calls 'bp_{@link bp_Component::name}_generate_rewrite_rules' 379 387 */ 380 function generate_rewrite_rules ( $wp_rewrite) {388 public function generate_rewrite_rules() { 381 389 do_action( 'bp_' . $this->id . '_generate_rewrite_rules' ); 382 390 }
Note: See TracChangeset
for help on using the changeset viewer.