Skip to:
Content

bbPress.org


Ignore:
Timestamp:
06/12/2012 07:04:49 AM (12 years ago)
Author:
johnjamesjacoby
Message:

Code Improvement:

  • Move preset bbPress class variables into bbPress::setup_globals() action.
  • Introduce magic get/set methods to handle main bbPress class variables.
  • Keeps by-reference bbPress->current_user outside of bbPress->data.
  • Reduces code duplication in bbPress class.
  • Fixes #1847.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbpress.php

    r3948 r3951  
    3434final class bbPress {
    3535
    36     /**
    37      * Note to Plugin and Theme authors:
    38      *
    39      * Do not directly reference the variables below in your code. Their names
    40      * and locations in the bbPress class are subject to change at any time.
    41      *
    42      * Most of them have reference functions located in bbp-includes. The ones
    43      * that don't can be accessed via their respective WordPress API's.
    44      */
    45 
    46     /** Version ***************************************************************/
    47 
    48     /**
    49      * @var string bbPress version
    50      */
    51     public $version = '2.1-r3947';
    52 
    53     /**
    54      * @var string bbPress DB version
    55      */
    56     public $db_version = '201';
    57 
    58     /** Post types ************************************************************/
    59 
    60     /**
    61      * @var string Forum post type id
    62      */
    63     public $forum_post_type = '';
    64 
    65     /**
    66      * @var string Topic post type id
    67      */
    68     public $topic_post_type = '';
    69 
    70     /**
    71      * @var string Reply post type id
    72      */
    73     public $reply_post_type = '';
    74 
    75     /** Taxonomies ************************************************************/
    76 
    77     /**
    78      * @var string Topic tag id
    79      */
    80     public $topic_tag_tax_id = '';
    81 
    82     /** Permastructs **********************************************************/
    83 
    84     /**
    85      * @var string User struct
    86      */
    87     public $user_id = '';
    88 
    89     /**
    90      * @var string View struct
    91      */
    92     public $view_id = '';
    93 
    94     /**
    95      * @var string Edit struct
    96      */
    97     public $edit_id = '';
    98 
    99     /** Post statuses *********************************************************/
    100 
    101     /**
    102      * @var string Public post status id. Used by forums, topics, and replies.
    103      */
    104     public $public_status_id = '';
    105 
    106     /**
    107      * @var string Pending post status id. Used by topics and replies
    108      */
    109     public $pending_status_id = '';
    110 
    111     /**
    112      * @var string Private post status id. Used by forums and topics.
    113      */
    114     public $private_status_id = '';
    115 
    116     /**
    117      * @var string Closed post status id. Used by topics.
    118      */
    119     public $closed_status_id = '';
    120 
    121     /**
    122      * @var string Spam post status id. Used by topics and replies.
    123      */
    124     public $spam_status_id = '';
    125 
    126     /**
    127      * @var string Trash post status id. Used by topics and replies.
    128      */
    129     public $trash_status_id = '';
    130 
    131     /**
    132      * @var string Orphan post status id. Used by topics and replies.
    133      */
    134     public $orphan_status_id = '';
    135 
    136     /**
    137      * @var string Hidden post status id. Used by forums.
    138      */
    139     public $hidden_status_id = '';
    140 
    141     /** Paths *****************************************************************/
    142 
    143     /**
    144      * @var string Basename of the bbPress plugin directory
    145      */
    146     public $basename = '';
    147 
    148     /**
    149      * @var string Absolute path to the bbPress plugin directory
    150      */
    151     public $plugin_dir = '';
    152 
    153     /**
    154      * @var string Absolute path to the bbPress themes directory
    155      */
    156     public $themes_dir = '';
    157 
    158     /**
    159      * @var string Absolute path to the bbPress language directory
    160      */
    161     public $lang_dir = '';
    162 
    163     /** URLs ******************************************************************/
    164 
    165     /**
    166      * @var string URL to the bbPress plugin directory
    167      */
    168     public $plugin_url = '';
    169 
    170     /**
    171      * @var string URL to the bbPress themes directory
    172      */
    173     public $themes_url = '';
    174 
    175     /** Current ID's **********************************************************/
    176 
    177     /**
    178      * @var string Current forum id
    179      */
    180     public $current_forum_id = 0;
    181 
    182     /**
    183      * @var string Current topic id
    184      */
    185     public $current_topic_id = 0;
    186 
    187     /**
    188      * @var string Current reply id
    189      */
    190     public $current_reply_id = 0;
    191 
    192     /**
    193      * @var string Current topic tag id
    194      */
    195     public $current_topic_tag_id = 0;
    196 
    197     /** Users *****************************************************************/
    198 
    199     /**
    200      * @var object Current user
    201      */
    202     public $current_user = array();
    203 
    204     /**
    205      * @var object Displayed user
    206      */
    207     public $displayed_user = array();
    208 
    209     /** Queries ***************************************************************/
    210 
    211     /**
    212      * @var WP_Query For forums
    213      */
    214     public $forum_query;
    215 
    216     /**
    217      * @var WP_Query For topics
    218      */
    219     public $topic_query;
    220 
    221     /**
    222      * @var WP_Query For replies
    223      */
    224     public $reply_query;
    225 
    226     /** Errors ****************************************************************/
    227 
    228     /**
    229      * @var WP_Error Used to log and display errors
    230      */
    231     public $errors = array();
    232 
    233     /** Views *****************************************************************/
    234 
    235     /**
    236      * @var array An array of registered bbPress views
    237      */
    238     public $views = array();
    239 
    240     /** Forms *****************************************************************/
    241 
    242     /**
    243      * @var int The current tab index for form building
    244      */
    245     public $tab_index = 0;
    246 
    247     /** Theme Compat **********************************************************/
    248 
    249     /**
    250      * @var string Theme to use for theme compatibility
    251      */
    252     public $theme_compat;
    253 
    254     /** Extensions ************************************************************/
    255 
    256     /**
    257      * @var mixed bbPress add-ons should append globals to this
    258      */
    259     public $extend = false;
    260 
    261     /** Option Overload *******************************************************/
    262 
    263     /**
    264      * Overloads default options retrieved from get_option()
    265      *
    266      * @var array Optional array( $key => $value );
    267      */
    268     public $options = array();
    269 
    270     /**
    271      * Overloads default user options retrieved from get_user_option()
    272      *
    273      * @var array Optional array( $user_id => array( $key => $value ) );
    274      */
    275     public $user_options = array();
     36    /** Byref *****************************************************************/
     37
     38    /**
     39     * @var mixed False when not logged in; WP_User object when logged in
     40     */
     41    public $current_user   = false;
    27642
    27743    /** Singleton *************************************************************/
     44
     45    /**
     46     * @var array Magic data store to get and set various runtime information.
     47     */
     48    private $data;
    27849
    27950    /**
     
    335106    public function __wakeup() { wp_die( __( 'Cheatin’ huh?', 'bbpress' ) ); }
    336107
     108    /**
     109     * Magic method for checking the existence of a certain custom field
     110     *
     111     * @since bbPress (rxxxx)
     112     */
     113    public function __isset( $key ) { return isset( $this->data[$key] ); }
     114
     115    /**
     116     * Magic method for getting bbPress varibles
     117     *
     118     * @since bbPress (rxxxx)
     119     */
     120    public function __get( $key ) { return isset( $this->data[$key] ) ? $this->data[$key] : null; }
     121
     122    /**
     123     * Magic method for setting bbPress varibles
     124     *
     125     * @since bbPress (rxxxx)
     126     */
     127    public function __set( $key, $value ) { $this->data[$key] = &$value; }
     128
    337129    /** Private Methods *******************************************************/
    338130
     
    348140     */
    349141    private function setup_globals() {
     142
     143        /** Versions **********************************************************/
     144
     145        $this->version    = '2.1-r3947'; // bbPress version
     146        $this->db_version = '201';       // bbPress DB version
    350147
    351148        /** Paths *************************************************************/
     
    389186        /** Queries ***********************************************************/
    390187
    391         $this->forum_query       = new stdClass;
    392         $this->topic_query       = new stdClass;
    393         $this->reply_query       = new stdClass;
     188        $this->current_forum_id     = 0; // Current forum id
     189        $this->current_topic_id     = 0; // Current topic id
     190        $this->current_reply_id     = 0; // Current reply id
     191        $this->current_topic_tag_id = 0; // Current topic tag id
     192
     193        $this->forum_query    = new stdClass; // Main forum query
     194        $this->topic_query    = new stdClass; // Main topic query
     195        $this->reply_query    = new stdClass; // Main reply query
     196
     197        /** Theme Compat ******************************************************/
     198
     199        $this->theme_compat   = new stdClass(); // Base theme compatibility class
     200        $this->filters        = new stdClass(); // Used when adding/removing filters
     201
     202        /** Users *************************************************************/
     203
     204        $this->current_user   = new stdClass(); // Currently logged in user
     205        $this->displayed_user = new stdClass(); // Currently displayed user
     206
     207        /** Plugins ***********************************************************/
     208
     209        $this->extend         = false;   // Add-ons should append globals to this
     210
     211        /** Overrides *********************************************************/
     212
     213        $this->options        = array(); // Overloads get_option()
     214        $this->user_options   = array(); // Overloads get_user_meta()
    394215
    395216        /** Misc **************************************************************/
    396217
    397         $this->errors            = new WP_Error();
    398         $this->views             = array();
    399         $this->tab_index         = apply_filters( 'bbp_default_tab_index', 100 );
    400 
    401         /** Theme Compat ******************************************************/
    402 
    403         // Base theme compatibility class
    404         $this->theme_compat      = new stdClass();
     218        $this->errors         = new WP_Error(); // Feedback
     219        $this->views          = array();        // Topic Views
     220        $this->tab_index      = apply_filters( 'bbp_default_tab_index', 100 );
    405221
    406222        /** Cache *************************************************************/
Note: See TracChangeset for help on using the changeset viewer.