<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][6953] trunk/bp-core/bp-core-component.php: BP_Component improvements:</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/6953">6953</a></dd>
<dt>Author</dt> <dd>johnjamesjacoby</dd>
<dt>Date</dt> <dd>2013-04-26 20:46:42 +0000 (Fri, 26 Apr 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>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 <a href="http://buddypress.trac.wordpress.org/ticket/4954">#4954</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpcorebpcorecomponentphp">trunk/bp-core/bp-core-component.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpcorebpcorecomponentphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-component.php (6952 => 6953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-component.php      2013-04-26 19:35:15 UTC (rev 6952)
+++ trunk/bp-core/bp-core-component.php 2013-04-26 20:46:42 UTC (rev 6953)
</span><span class="lines">@@ -1,4 +1,5 @@
</span><span class="cx"> <?php
</span><ins>+
</ins><span class="cx"> // Exit if accessed directly
</span><span class="cx"> if ( !defined( 'ABSPATH' ) ) exit;
</span><span class="cx"> 
</span><span class="lines">@@ -18,51 +19,53 @@
</span><span class="cx">  */
</span><span class="cx"> class BP_Component {
</span><span class="cx"> 
</span><ins>+       /** Variables *************************************************************/
+
</ins><span class="cx">   /**
</span><span class="cx">   * @var string Unique name (for internal identification)
</span><span class="cx">   * @internal
</span><span class="cx">   */
</span><del>-       var $name;
</del><ins>+        public $name = '';
</ins><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * @var Unique ID (normally for custom post type)
</span><span class="cx">   */
</span><del>-       var $id;
</del><ins>+        public $id = '';
</ins><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * @var string Unique slug (used in query string and permalinks)
</span><span class="cx">   */
</span><del>-       var $slug;
</del><ins>+        public $slug = '';
</ins><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * @var bool Does this component need a top-level directory?
</span><span class="cx">   */
</span><del>-       var $has_directory;
</del><ins>+        public $has_directory = false;
</ins><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * @var string The path to the component's files
</span><span class="cx">   */
</span><del>-       var $path;
</del><ins>+        public $path = '';
</ins><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * @var WP_Query The loop for this component
</span><span class="cx">   */
</span><del>-       var $query;
</del><ins>+        public $query = false;
</ins><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * @var string The current ID of the queried object
</span><span class="cx">   */
</span><del>-       var $current_id;
</del><ins>+        public $current_id = '';
</ins><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * @var string Function to call for notifications
</span><span class="cx">   */
</span><del>-       var $notification_callback;
</del><ins>+        public $notification_callback = '';
</ins><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * @var array WordPress Toolbar links
</span><span class="cx">   */
</span><del>-       var $admin_menu;
</del><ins>+        public $admin_menu = '';
</ins><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * Search input box placeholder string for the component
</span><span class="lines">@@ -70,7 +73,7 @@
</span><span class="cx">   * @since BuddyPress (1.5)
</span><span class="cx">   * @var string
</span><span class="cx">   */
</span><del>-       public $search_string;
</del><ins>+        public $search_string = '';
</ins><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * Component's root slug
</span><span class="lines">@@ -78,20 +81,23 @@
</span><span class="cx">   * @since BuddyPress (1.5)
</span><span class="cx">   * @var string
</span><span class="cx">   */
</span><del>-       public $root_slug;
</del><ins>+        public $root_slug = '';
</ins><span class="cx"> 
</span><ins>+       /** Methods ***************************************************************/
+
</ins><span class="cx">   /**
</span><span class="cx">   * Component loader
</span><span class="cx">   *
</span><span class="cx">   * @since BuddyPress (1.5)
</span><span class="cx">   *
</span><del>-        * @param mixed $args Required. Supports these args:
-        *  - id: Unique ID (for internal identification). Letters, numbers, and underscores only
-        *  - name: Unique name. This should be a translatable name, eg __( 'Groups', 'buddypress' )
-        *  - path: The file path for the component's files. Used by BP_Component::includes()
</del><ins>+         * @param string $id Unique ID (for internal identification). Letters, numbers, and underscores only
+        * @param string $name Unique name. This should be a translatable name, eg __( 'Groups', 'buddypress' )
+        * @param string $path The file path for the component's files. Used by BP_Component::includes()
+        *
</ins><span class="cx">    * @uses bp_Component::setup_actions() Setup the hooks and actions
</span><span class="cx">   */
</span><del>-       function start( $id, $name, $path ) {
</del><ins>+        public function start( $id = '', $name = '', $path = '' ) {
+
</ins><span class="cx">           // Internal identifier of component
</span><span class="cx">          $this->id   = $id;
</span><span class="cx"> 
</span><span class="lines">@@ -115,38 +121,37 @@
</span><span class="cx">   *
</span><span class="cx">   * @param arr $args Used to
</span><span class="cx">   */
</span><del>-       function setup_globals( $args = '' ) {
-               global $bp;
</del><ins>+        public function setup_globals( $args = array() ) {
</ins><span class="cx"> 
</span><span class="cx">          /** Slugs *************************************************************/
</span><span class="cx"> 
</span><del>-               $defaults = array(
</del><ins>+                $r = wp_parse_args( $args, array(
</ins><span class="cx">                   'slug'                  => $this->id,
</span><span class="cx">                  'root_slug'             => '',
</span><span class="cx">                  'has_directory'         => false,
</span><span class="cx">                  'notification_callback' => '',
</span><span class="cx">                  'search_string'         => '',
</span><span class="cx">                  'global_tables'         => ''
</span><del>-               );
-               $r = wp_parse_args( $args, $defaults );
</del><ins>+                ) );
</ins><span class="cx"> 
</span><span class="cx">          // Slug used for permalink URI chunk after root
</span><del>-               $this->slug          = apply_filters( 'bp_' . $this->id . '_slug',          $r['slug']          );
</del><ins>+                $this->slug                  = apply_filters( 'bp_' . $this->id . '_slug',                  $r['slug']                  );
</ins><span class="cx"> 
</span><span class="cx">          // Slug used for root directory
</span><del>-               $this->root_slug     = apply_filters( 'bp_' . $this->id . '_root_slug',     $r['root_slug']     );
</del><ins>+                $this->root_slug             = apply_filters( 'bp_' . $this->id . '_root_slug',             $r['root_slug']             );
</ins><span class="cx"> 
</span><span class="cx">          // Does this component have a top-level directory?
</span><del>-               $this->has_directory = apply_filters( 'bp_' . $this->id . '_has_directory', $r['has_directory'] );
</del><ins>+                $this->has_directory         = apply_filters( 'bp_' . $this->id . '_has_directory',         $r['has_directory']         );
</ins><span class="cx"> 
</span><span class="cx">          // Search string
</span><del>-               $this->search_string = apply_filters( 'bp_' . $this->id . '_search_string', $r['search_string'] );
</del><ins>+                $this->search_string         = apply_filters( 'bp_' . $this->id . '_search_string',         $r['search_string']         );
</ins><span class="cx"> 
</span><span class="cx">          // Notifications callback
</span><span class="cx">          $this->notification_callback = apply_filters( 'bp_' . $this->id . '_notification_callback', $r['notification_callback'] );
</span><span class="cx"> 
</span><span class="cx">          // Set up global table names
</span><span class="cx">          if ( !empty( $r['global_tables'] ) ) {
</span><ins>+
</ins><span class="cx">                   // This filter allows for component-specific filtering of table names
</span><span class="cx">                  // To filter *all* tables, use the 'bp_core_get_table_prefix' filter instead
</span><span class="cx">                  $r['global_tables'] = apply_filters( 'bp_' . $this->id . '_global_tables', $r['global_tables'] );
</span><span class="lines">@@ -154,12 +159,12 @@
</span><span class="cx">                  foreach ( $r['global_tables'] as $global_name => $table_name ) {
</span><span class="cx">                          $this->$global_name = $table_name;
</span><span class="cx">                  }
</span><del>-                }
</del><ins>+                }
</ins><span class="cx"> 
</span><span class="cx">          /** BuddyPress ********************************************************/
</span><span class="cx"> 
</span><span class="cx">          // Register this component in the loaded components array
</span><del>-               $bp->loaded_components[$this->slug] = $this->id;
</del><ins>+                buddypress()->loaded_components[$this->slug] = $this->id;
</ins><span class="cx"> 
</span><span class="cx">          // Call action
</span><span class="cx">          do_action( 'bp_' . $this->id . '_setup_globals' );
</span><span class="lines">@@ -189,14 +194,16 @@
</span><span class="cx">   *
</span><span class="cx">   * @uses do_action() Calls 'bp_{@link bp_Component::name}includes'
</span><span class="cx">   */
</span><del>-       function includes( $includes = '' ) {
</del><ins>+        public function includes( $includes = array() ) {
+
+               // Bail if no files to include
</ins><span class="cx">           if ( empty( $includes ) )
</span><span class="cx">                  return;
</span><span class="cx"> 
</span><span class="cx">          $slashed_path = trailingslashit( $this->path );
</span><span class="cx"> 
</span><span class="cx">          // Loop through files to be included
</span><del>-               foreach ( $includes as $file ) {
</del><ins>+                foreach ( (array) $includes as $file ) {
</ins><span class="cx"> 
</span><span class="cx">                  $paths = array(
</span><span class="cx"> 
</span><span class="lines">@@ -231,38 +238,38 @@
</span><span class="cx">   * @uses add_action() To add various actions
</span><span class="cx">   * @uses do_action() Calls 'bp_{@link BP_Component::name}setup_actions'
</span><span class="cx">   */
</span><del>-       function setup_actions() {
</del><ins>+        public function setup_actions() {
</ins><span class="cx"> 
</span><span class="cx">          // Setup globals
</span><del>-               add_action( 'bp_setup_globals',          array ( $this, 'setup_globals'          ), 10 );
</del><ins>+                add_action( 'bp_setup_globals',          array( $this, 'setup_globals'          ), 10 );
</ins><span class="cx"> 
</span><span class="cx">          // Include required files. Called early to ensure that BP core
</span><span class="cx">          // components are loaded before plugins that hook their loader functions
</span><span class="cx">          // to bp_include with the default priority of 10. This is for backwards
</span><span class="cx">          // compatibility; henceforth, plugins should register themselves by
</span><span class="cx">          // extending this base class.
</span><del>-               add_action( 'bp_include',                array ( $this, 'includes'               ), 8 );
</del><ins>+                add_action( 'bp_include',                array( $this, 'includes'               ), 8 );
</ins><span class="cx"> 
</span><span class="cx">          // Setup navigation
</span><del>-               add_action( 'bp_setup_nav',              array ( $this, 'setup_nav'              ), 10 );
</del><ins>+                add_action( 'bp_setup_nav',              array( $this, 'setup_nav'              ), 10 );
</ins><span class="cx"> 
</span><span class="cx">          // Setup WP Toolbar menus
</span><del>-               add_action( 'bp_setup_admin_bar',        array ( $this, 'setup_admin_bar'        ), 10 );
</del><ins>+                add_action( 'bp_setup_admin_bar',        array( $this, 'setup_admin_bar'        ), 10 );
</ins><span class="cx"> 
</span><span class="cx">          // Setup component title
</span><del>-               add_action( 'bp_setup_title',            array ( $this, 'setup_title'            ), 10 );
</del><ins>+                add_action( 'bp_setup_title',            array( $this, 'setup_title'            ), 10 );
</ins><span class="cx"> 
</span><span class="cx">          // Register post types
</span><del>-               add_action( 'bp_register_post_types',    array ( $this, 'register_post_types'    ), 10 );
</del><ins>+                add_action( 'bp_register_post_types',    array( $this, 'register_post_types'    ), 10 );
</ins><span class="cx"> 
</span><span class="cx">          // Register taxonomies
</span><del>-               add_action( 'bp_register_taxonomies',    array ( $this, 'register_taxonomies'    ), 10 );
</del><ins>+                add_action( 'bp_register_taxonomies',    array( $this, 'register_taxonomies'    ), 10 );
</ins><span class="cx"> 
</span><span class="cx">          // Add the rewrite tags
</span><del>-               add_action( 'bp_add_rewrite_tags',       array ( $this, 'add_rewrite_tags'       ), 10 );
</del><ins>+                add_action( 'bp_add_rewrite_tags',       array( $this, 'add_rewrite_tags'       ), 10 );
</ins><span class="cx"> 
</span><span class="cx">          // Generate rewrite rules
</span><del>-               add_action( 'bp_generate_rewrite_rules', array ( $this, 'generate_rewrite_rules' ), 10 );
</del><ins>+                add_action( 'bp_generate_rewrite_rules', array( $this, 'generate_rewrite_rules' ), 10 );
</ins><span class="cx"> 
</span><span class="cx">          // Additional actions can be attached here
</span><span class="cx">          do_action( 'bp_' . $this->id . '_setup_actions' );
</span><span class="lines">@@ -271,10 +278,10 @@
</span><span class="cx">  /**
</span><span class="cx">   * Setup the navigation
</span><span class="cx">   *
</span><del>-        * @param arr $main_nav Optional
-        * @param arr $sub_nav Optional
</del><ins>+         * @param array $main_nav Optional
+        * @param array $sub_nav Optional
</ins><span class="cx">    */
</span><del>-       function setup_nav( $main_nav = '', $sub_nav = '' ) {
</del><ins>+        public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
</ins><span class="cx"> 
</span><span class="cx">          // No sub nav items without a main nav item
</span><span class="cx">          if ( !empty( $main_nav ) ) {
</span><span class="lines">@@ -282,7 +289,7 @@
</span><span class="cx"> 
</span><span class="cx">                  // Sub nav items are not required
</span><span class="cx">                  if ( !empty( $sub_nav ) ) {
</span><del>-                               foreach( $sub_nav as $nav ) {
</del><ins>+                                foreach( (array) $sub_nav as $nav ) {
</ins><span class="cx">                                   bp_core_new_subnav_item( $nav );
</span><span class="cx">                          }
</span><span class="cx">                  }
</span><span class="lines">@@ -298,7 +305,7 @@
</span><span class="cx">   * @global obj $wp_admin_bar
</span><span class="cx">   * @param array $wp_admin_menus
</span><span class="cx">   */
</span><del>-       function setup_admin_bar( $wp_admin_nav = '' ) {
</del><ins>+        public function setup_admin_bar( $wp_admin_nav = array() ) {
</ins><span class="cx"> 
</span><span class="cx">          // Bail if this is an ajax request
</span><span class="cx">          if ( defined( 'DOING_AJAX' ) )
</span><span class="lines">@@ -318,8 +325,9 @@
</span><span class="cx">                  global $wp_admin_bar;
</span><span class="cx"> 
</span><span class="cx">                  // Add each admin menu
</span><del>-                       foreach( $this->admin_menu as $admin_menu )
</del><ins>+                        foreach( $this->admin_menu as $admin_menu ) {
</ins><span class="cx">                           $wp_admin_bar->add_menu( $admin_menu );
</span><ins>+                       }
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          // Call action
</span><span class="lines">@@ -333,7 +341,7 @@
</span><span class="cx">   *
</span><span class="cx">   * @uses do_action() Calls 'bp_{@link bp_Component::name}setup_title'
</span><span class="cx">   */
</span><del>-       function setup_title( ) {
</del><ins>+        public function setup_title() {
</ins><span class="cx">           do_action(  'bp_' . $this->id . '_setup_title' );
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="lines">@@ -344,7 +352,7 @@
</span><span class="cx">   *
</span><span class="cx">   * @uses do_action() Calls 'bp_{@link bp_Component::name}_register_post_types'
</span><span class="cx">   */
</span><del>-       function register_post_types() {
</del><ins>+        public function register_post_types() {
</ins><span class="cx">           do_action( 'bp_' . $this->id . '_register_post_types' );
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="lines">@@ -355,7 +363,7 @@
</span><span class="cx">   *
</span><span class="cx">   * @uses do_action() Calls 'bp_{@link bp_Component::name}_register_taxonomies'
</span><span class="cx">   */
</span><del>-       function register_taxonomies() {
</del><ins>+        public function register_taxonomies() {
</ins><span class="cx">           do_action( 'bp_' . $this->id . '_register_taxonomies' );
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="lines">@@ -366,7 +374,7 @@
</span><span class="cx">   *
</span><span class="cx">   * @uses do_action() Calls 'bp_{@link bp_Component::name}_add_rewrite_tags'
</span><span class="cx">   */
</span><del>-       function add_rewrite_tags() {
</del><ins>+        public function add_rewrite_tags() {
</ins><span class="cx">           do_action( 'bp_' . $this->id . '_add_rewrite_tags' );
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="lines">@@ -377,7 +385,7 @@
</span><span class="cx">   *
</span><span class="cx">   * @uses do_action() Calls 'bp_{@link bp_Component::name}_generate_rewrite_rules'
</span><span class="cx">   */
</span><del>-       function generate_rewrite_rules ( $wp_rewrite ) {
</del><ins>+        public function generate_rewrite_rules() {
</ins><span class="cx">           do_action( 'bp_' . $this->id . '_generate_rewrite_rules' );
</span><span class="cx">  }
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>