Skip to:
Content

BuddyPress.org

Changeset 6953


Ignore:
Timestamp:
04/26/2013 08:46:42 PM (11 years ago)
Author:
johnjamesjacoby
Message:

BP_Component improvements:

  • Improve accuracy of phpdoc
  • Correct default parameter values
  • PHP5'ize (no scope changes)
  • No functional changes, but motivated by changes that will be part of #4954
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-component.php

    r6648 r6953  
    11<?php
     2
    23// Exit if accessed directly
    34if ( !defined( 'ABSPATH' ) ) exit;
     
    1920class BP_Component {
    2021
     22    /** Variables *************************************************************/
     23
    2124    /**
    2225     * @var string Unique name (for internal identification)
    2326     * @internal
    2427     */
    25     var $name;
     28    public $name = '';
    2629
    2730    /**
    2831     * @var Unique ID (normally for custom post type)
    2932     */
    30     var $id;
     33    public $id = '';
    3134
    3235    /**
    3336     * @var string Unique slug (used in query string and permalinks)
    3437     */
    35     var $slug;
     38    public $slug = '';
    3639
    3740    /**
    3841     * @var bool Does this component need a top-level directory?
    3942     */
    40     var $has_directory;
     43    public $has_directory = false;
    4144
    4245    /**
    4346     * @var string The path to the component's files
    4447     */
    45     var $path;
     48    public $path = '';
    4649
    4750    /**
    4851     * @var WP_Query The loop for this component
    4952     */
    50     var $query;
     53    public $query = false;
    5154
    5255    /**
    5356     * @var string The current ID of the queried object
    5457     */
    55     var $current_id;
     58    public $current_id = '';
    5659
    5760    /**
    5861     * @var string Function to call for notifications
    5962     */
    60     var $notification_callback;
     63    public $notification_callback = '';
    6164
    6265    /**
    6366     * @var array WordPress Toolbar links
    6467     */
    65     var $admin_menu;
     68    public $admin_menu = '';
    6669
    6770    /**
     
    7174     * @var string
    7275     */
    73     public $search_string;
     76    public $search_string = '';
    7477
    7578    /**
     
    7982     * @var string
    8083     */
    81     public $root_slug;
     84    public $root_slug = '';
     85
     86    /** Methods ***************************************************************/
    8287
    8388    /**
     
    8691     * @since BuddyPress (1.5)
    8792     *
    88      * @param mixed $args Required. Supports these args:
    89      *  - id: Unique ID (for internal identification). Letters, numbers, and underscores only
    90      *  - 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     *
    9297     * @uses bp_Component::setup_actions() Setup the hooks and actions
    9398     */
    94     function start( $id, $name, $path ) {
     99    public function start( $id = '', $name = '', $path = '' ) {
     100
    95101        // Internal identifier of component
    96102        $this->id   = $id;
     
    116122     * @param arr $args Used to
    117123     */
    118     function setup_globals( $args = '' ) {
    119         global $bp;
     124    public function setup_globals( $args = array() ) {
    120125
    121126        /** Slugs *************************************************************/
    122127
    123         $defaults = array(
     128        $r = wp_parse_args( $args, array(
    124129            'slug'                  => $this->id,
    125130            'root_slug'             => '',
     
    128133            'search_string'         => '',
    129134            'global_tables'         => ''
    130         );
    131         $r = wp_parse_args( $args, $defaults );
     135        ) );
    132136
    133137        // 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']                  );
    135139
    136140        // 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']             );
    138142
    139143        // 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']        );
    141145
    142146        // 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']        );
    144148
    145149        // Notifications callback
     
    148152        // Set up global table names
    149153        if ( !empty( $r['global_tables'] ) ) {
     154
    150155            // This filter allows for component-specific filtering of table names
    151156            // To filter *all* tables, use the 'bp_core_get_table_prefix' filter instead
     
    155160                $this->$global_name = $table_name;
    156161            }
    157                 }
     162        }
    158163
    159164        /** BuddyPress ********************************************************/
    160165
    161166        // Register this component in the loaded components array
    162         $bp->loaded_components[$this->slug] = $this->id;
     167        buddypress()->loaded_components[$this->slug] = $this->id;
    163168
    164169        // Call action
     
    190195     * @uses do_action() Calls 'bp_{@link bp_Component::name}includes'
    191196     */
    192     function includes( $includes = '' ) {
     197    public function includes( $includes = array() ) {
     198
     199        // Bail if no files to include
    193200        if ( empty( $includes ) )
    194201            return;
     
    197204
    198205        // Loop through files to be included
    199         foreach ( $includes as $file ) {
     206        foreach ( (array) $includes as $file ) {
    200207
    201208            $paths = array(
     
    232239     * @uses do_action() Calls 'bp_{@link BP_Component::name}setup_actions'
    233240     */
    234     function setup_actions() {
     241    public function setup_actions() {
    235242
    236243        // Setup globals
    237         add_action( 'bp_setup_globals',          array ( $this, 'setup_globals'          ), 10 );
     244        add_action( 'bp_setup_globals',          array( $this, 'setup_globals'          ), 10 );
    238245
    239246        // Include required files. Called early to ensure that BP core
     
    242249        // compatibility; henceforth, plugins should register themselves by
    243250        // extending this base class.
    244         add_action( 'bp_include',                array ( $this, 'includes'               ), 8 );
     251        add_action( 'bp_include',                array( $this, 'includes'               ), 8 );
    245252
    246253        // Setup navigation
    247         add_action( 'bp_setup_nav',              array ( $this, 'setup_nav'              ), 10 );
     254        add_action( 'bp_setup_nav',              array( $this, 'setup_nav'              ), 10 );
    248255
    249256        // Setup WP Toolbar menus
    250         add_action( 'bp_setup_admin_bar',        array ( $this, 'setup_admin_bar'        ), 10 );
     257        add_action( 'bp_setup_admin_bar',        array( $this, 'setup_admin_bar'        ), 10 );
    251258
    252259        // Setup component title
    253         add_action( 'bp_setup_title',            array ( $this, 'setup_title'            ), 10 );
     260        add_action( 'bp_setup_title',            array( $this, 'setup_title'            ), 10 );
    254261
    255262        // Register post types
    256         add_action( 'bp_register_post_types',    array ( $this, 'register_post_types'    ), 10 );
     263        add_action( 'bp_register_post_types',    array( $this, 'register_post_types'    ), 10 );
    257264
    258265        // Register taxonomies
    259         add_action( 'bp_register_taxonomies',    array ( $this, 'register_taxonomies'    ), 10 );
     266        add_action( 'bp_register_taxonomies',    array( $this, 'register_taxonomies'    ), 10 );
    260267
    261268        // Add the rewrite tags
    262         add_action( 'bp_add_rewrite_tags',       array ( $this, 'add_rewrite_tags'       ), 10 );
     269        add_action( 'bp_add_rewrite_tags',       array( $this, 'add_rewrite_tags'       ), 10 );
    263270
    264271        // Generate rewrite rules
    265         add_action( 'bp_generate_rewrite_rules', array ( $this, 'generate_rewrite_rules' ), 10 );
     272        add_action( 'bp_generate_rewrite_rules', array( $this, 'generate_rewrite_rules' ), 10 );
    266273
    267274        // Additional actions can be attached here
     
    272279     * Setup the navigation
    273280     *
    274      * @param arr $main_nav Optional
    275      * @param arr $sub_nav Optional
    276      */
    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() ) {
    278285
    279286        // No sub nav items without a main nav item
     
    283290            // Sub nav items are not required
    284291            if ( !empty( $sub_nav ) ) {
    285                 foreach( $sub_nav as $nav ) {
     292                foreach( (array) $sub_nav as $nav ) {
    286293                    bp_core_new_subnav_item( $nav );
    287294                }
     
    299306     * @param array $wp_admin_menus
    300307     */
    301     function setup_admin_bar( $wp_admin_nav = '' ) {
     308    public function setup_admin_bar( $wp_admin_nav = array() ) {
    302309
    303310        // Bail if this is an ajax request
     
    319326
    320327            // Add each admin menu
    321             foreach( $this->admin_menu as $admin_menu )
     328            foreach( $this->admin_menu as $admin_menu ) {
    322329                $wp_admin_bar->add_menu( $admin_menu );
     330            }
    323331        }
    324332
     
    334342     * @uses do_action() Calls 'bp_{@link bp_Component::name}setup_title'
    335343     */
    336     function setup_title( ) {
     344    public function setup_title() {
    337345        do_action(  'bp_' . $this->id . '_setup_title' );
    338346    }
     
    345353     * @uses do_action() Calls 'bp_{@link bp_Component::name}_register_post_types'
    346354     */
    347     function register_post_types() {
     355    public function register_post_types() {
    348356        do_action( 'bp_' . $this->id . '_register_post_types' );
    349357    }
     
    356364     * @uses do_action() Calls 'bp_{@link bp_Component::name}_register_taxonomies'
    357365     */
    358     function register_taxonomies() {
     366    public function register_taxonomies() {
    359367        do_action( 'bp_' . $this->id . '_register_taxonomies' );
    360368    }
     
    367375     * @uses do_action() Calls 'bp_{@link bp_Component::name}_add_rewrite_tags'
    368376     */
    369     function add_rewrite_tags() {
     377    public function add_rewrite_tags() {
    370378        do_action( 'bp_' . $this->id . '_add_rewrite_tags' );
    371379    }
     
    378386     * @uses do_action() Calls 'bp_{@link bp_Component::name}_generate_rewrite_rules'
    379387     */
    380     function generate_rewrite_rules ( $wp_rewrite ) {
     388    public function generate_rewrite_rules() {
    381389        do_action( 'bp_' . $this->id . '_generate_rewrite_rules' );
    382390    }
Note: See TracChangeset for help on using the changeset viewer.