Skip to:
Content

bbPress.org

Changeset 3760


Ignore:
Timestamp:
02/26/2012 07:51:14 PM (13 years ago)
Author:
johnjamesjacoby
Message:

Remove slug variables from bbPress class and rely on options and object cache going forward.

  • Net performance and memory usage win
  • Removes class variables that are already in object cache
  • Reduces code duplication
  • Fixes #1760
Location:
branches/plugin
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-common-template.php

    r3758 r3760  
    16671667        $pre_include_root = $pre_include_home = $pre_include_current = true;
    16681668
    1669         // Get bbPress
    1670         $bbp = bbpress();
    1671 
    16721669        /** Home Text *********************************************************/
    16731670
     
    16901687        // No custom root text
    16911688        if ( empty( $args['root_text'] ) ) {
    1692             $page = bbp_get_page_by_path( $bbp->root_slug );
     1689            $page = bbp_get_page_by_path( bbp_get_root_slug() );
    16931690            if ( !empty( $page ) ) {
    16941691                $root_id = $page->ID;
     
    18001797
    18011798            // Page exists at root slug path, so use its permalink
    1802             $page = bbp_get_page_by_path( $bbp->root_slug );
     1799            $page = bbp_get_page_by_path( bbp_get_root_slug() );
    18031800            if ( !empty( $page ) ) {
    18041801                $root_url = get_permalink( $page->ID );
  • branches/plugin/bbp-includes/bbp-core-options.php

    r3758 r3760  
    426426}
    427427
     428/** Slugs *********************************************************************/
     429
     430/**
     431 * Return the root slug
     432 *
     433 * @since bbPress (r3759)
     434 * @return string
     435 */
     436function bbp_get_root_slug( $default = 'forums' ) {
     437    return apply_filters( 'bbp_get_root_slug', get_option( '_bbp_root_slug', $default ) );
     438}
     439
     440/**
     441 * Are we including the root slug in front of forum pages?
     442 *
     443 * @since bbPress (r3759)
     444 * @return string
     445 */
     446function bbp_include_root_slug( $default = true ) {
     447    return (bool) apply_filters( 'bbp_include_root_slug', (bool) get_option( '_bbp_include_root', $default ) );
     448}
     449
     450/**
     451 * Maybe return the root slug, based on whether or not it's included in the url
     452 *
     453 * @since bbPress (r3759)
     454 * @return string
     455 */
     456function bbp_maybe_get_root_slug() {
     457    $retval = '';
     458
     459    if ( bbp_get_root_slug() && bbp_include_root_slug() )
     460        $retval = trailingslashit( bbp_get_root_slug() );
     461
     462    return apply_filters( 'bbp_maybe_get_root_slug', $retval );
     463}
     464
     465/**
     466 * Return the single forum slug
     467 *
     468 * @since bbPress (r3759)
     469 * @return string
     470 */
     471function bbp_get_forum_slug( $default = 'forum' ) {;
     472    return apply_filters( 'bbp_get_root_slug', bbp_maybe_get_root_slug() . get_option( '_bbp_forum_slug', $default ) );
     473}
     474
     475/**
     476 * Return the topic archive slug
     477 *
     478 * @since bbPress (r3759)
     479 * @return string
     480 */
     481function bbp_get_topic_archive_slug( $default = 'topics' ) {
     482    return apply_filters( 'bbp_get_topic_archive_slug', get_option( '_bbp_topic_archive_slug', $default ) );
     483}
     484
     485/**
     486 * Return the single topic slug
     487 *
     488 * @since bbPress (r3759)
     489 * @return string
     490 */
     491function bbp_get_topic_slug( $default = 'topic' ) {
     492    return apply_filters( 'bbp_get_topic_slug', bbp_maybe_get_root_slug() . get_option( '_bbp_topic_slug', $default ) );
     493}
     494
     495/**
     496 * Return the topic-tag taxonomy slug
     497 *
     498 * @since bbPress (r3759)
     499 * @return string
     500 */
     501function bbp_get_topic_tag_taxonomy_slug( $default = 'topic-tag' ) {
     502    return apply_filters( 'bbp_get_topic_tag_taxonomy_slug', bbp_maybe_get_root_slug() . get_option( '_bbp_topic_tag_slug', $default ) );
     503}
     504
     505/**
     506 * Return the single reply slug (used mostly for editing)
     507 *
     508 * @since bbPress (r3759)
     509 * @return string
     510 */
     511function bbp_get_reply_slug( $default = 'reply' ) {
     512    return apply_filters( 'bbp_get_reply_slug', bbp_maybe_get_root_slug() . get_option( '_bbp_reply_slug', $default ) );
     513}
     514
     515/**
     516 * Return the single user slug
     517 *
     518 * @since bbPress (r3759)
     519 * @return string
     520 */
     521function bbp_get_user_slug( $default = 'user' ) {
     522    return apply_filters( 'bbp_get_user_slug', bbp_maybe_get_root_slug() . get_option( '_bbp_user_slug', $default ) );
     523}
     524
     525/**
     526 * Return the topic view slug
     527 *
     528 * @since bbPress (r3759)
     529 * @return string
     530 */
     531function bbp_get_view_slug( $default = 'view' ) {
     532    return apply_filters( 'bbp_get_view_slug', bbp_maybe_get_root_slug() . get_option( '_bbp_view_slug', $default ) );
     533}
     534
    428535?>
  • branches/plugin/bbp-includes/bbp-extend-buddypress.php

    r3758 r3760  
    937937
    938938        // Name and slug
    939         $this->name          = __( 'Forums', 'bbpress' );
    940         $this->nav_item_name = __( 'Forums', 'bbpress' );
    941         $this->slug          = bp_get_option( '_bbp_forum_slug', 'forum' );
    942         $this->topic_slug    = bp_get_option( '_bbp_topic_slug', 'topic' );
    943         $this->reply_slug    = bp_get_option( '_bbp_reply_slug', 'reply' );
     939        $this->name          = bbp_get_forum_archive_title();
     940        $this->nav_item_name = bbp_get_forum_archive_title();
     941        $this->slug          = bbp_get_forum_slug();
     942        $this->topic_slug    = bbp_get_topic_slug();
     943        $this->reply_slug    = bbp_get_reply_slug();
    944944
    945945        // Forum component is visible @todo configure?
  • branches/plugin/bbp-includes/bbp-forum-template.php

    r3758 r3760  
    344344
    345345            // Set root text to page title
    346             $page = bbp_get_page_by_path( bbpress()->root_slug );
     346            $page = bbp_get_page_by_path( bbp_get_root_slug() );
    347347            if ( !empty( $page ) ) {
    348348                $title = get_the_title( $page->ID );
  • branches/plugin/bbp-includes/bbp-theme-compatibility.php

    r3758 r3760  
    563563
    564564        // Page exists where this archive should be
    565         $page = bbp_get_page_by_path( $bbp->root_slug );
     565        $page = bbp_get_page_by_path( bbp_get_root_slug() );
    566566        if ( !empty( $page ) ) {
    567567
     
    589589
    590590        // Page exists where this archive should be
    591         $page = bbp_get_page_by_path( $bbp->topic_archive_slug );
     591        $page = bbp_get_page_by_path( bbp_get_topic_archive_slug() );
    592592        if ( !empty( $page ) ) {
    593593
  • branches/plugin/bbp-includes/bbp-topic-template.php

    r3758 r3760  
    259259            // Topic archive
    260260            elseif ( bbp_is_topic_archive() )
    261                 $base = home_url( $bbp->topic_archive_slug );
     261                $base = home_url( bbp_get_topic_archive_slug() );
    262262
    263263            // Default
     
    538538
    539539            // Set root text to page title
    540             $page = bbp_get_page_by_path( bbpress()->topic_archive_slug );
     540            $page = bbp_get_page_by_path( bbp_get_topic_archive_slug() );
    541541            if ( !empty( $page ) ) {
    542542                $title = get_the_title( $page->ID );
  • branches/plugin/bbp-includes/bbp-user-template.php

    r3758 r3760  
    285285        // Pretty permalinks
    286286        if ( $wp_rewrite->using_permalinks() ) {
    287             $url = $wp_rewrite->root . $bbp->user_slug . '/%' . $bbp->user_id . '%';
     287            $url = $wp_rewrite->root . bbp_get_user_slug() . '/%' . $bbp->user_id . '%';
    288288
    289289            // Get username if not passed
     
    382382        // Pretty permalinks
    383383        if ( $wp_rewrite->using_permalinks() ) {
    384             $url = $wp_rewrite->root . $bbp->user_slug . '/%' . $bbp->user_id . '%/' . $bbp->edit_id;
     384            $url = $wp_rewrite->root . bbp_get_user_slug() . '/%' . $bbp->user_id . '%/' . $bbp->edit_id;
    385385
    386386            // Get username if not passed
  • branches/plugin/bbpress.php

    r3758 r3760  
    139139    public $hidden_status_id = '';
    140140
    141     /** Slugs *****************************************************************/
    142 
    143     /**
    144      * @var string Root slug
    145      */
    146     public $root_slug = '';
    147 
    148     /**
    149      * @var string Forum slug
    150      */
    151     public $forum_slug = '';
    152 
    153     /**
    154      * @var string Topic slug
    155      */
    156     public $topic_slug = '';
    157 
    158     /**
    159      * @var string Topic archive slug
    160      */
    161     public $topic_archive_slug = '';
    162 
    163     /**
    164      * @var string Reply slug
    165      */
    166     public $reply_slug = '';
    167 
    168     /**
    169      * @var string Topic tag slug
    170      */
    171     public $topic_tag_slug = '';
    172 
    173     /**
    174      * @var string User slug
    175      */
    176     public $user_slug = '';
    177 
    178     /**
    179      * @var string View slug
    180      */
    181     public $view_slug = '';
    182 
    183141    /** Paths *****************************************************************/
    184142
     
    399357        /** Paths *************************************************************/
    400358
    401         // bbPress root directory
     359        // Setup some base path and URL information
    402360        $this->file       = __FILE__;
    403361        $this->basename   = plugin_basename( $this->file );
     
    415373
    416374        // Post type identifiers
    417         $this->forum_post_type    = apply_filters( 'bbp_forum_post_type',  'forum'     );
    418         $this->topic_post_type    = apply_filters( 'bbp_topic_post_type',  'topic'     );
    419         $this->reply_post_type    = apply_filters( 'bbp_reply_post_type',  'reply'     );
    420         $this->topic_tag_tax_id   = apply_filters( 'bbp_topic_tag_tax_id', 'topic-tag' );
     375        $this->forum_post_type   = apply_filters( 'bbp_forum_post_type',  'forum'     );
     376        $this->topic_post_type   = apply_filters( 'bbp_topic_post_type',  'topic'     );
     377        $this->reply_post_type   = apply_filters( 'bbp_reply_post_type',  'reply'     );
     378        $this->topic_tag_tax_id  = apply_filters( 'bbp_topic_tag_tax_id', 'topic-tag' );
    421379
    422380        // Status identifiers
    423         $this->spam_status_id     = apply_filters( 'bbp_spam_post_status',    'spam'    );
    424         $this->closed_status_id   = apply_filters( 'bbp_closed_post_status',  'closed'  );
    425         $this->orphan_status_id   = apply_filters( 'bbp_orphan_post_status',  'orphan'  );
    426         $this->public_status_id   = apply_filters( 'bbp_public_post_status',  'publish' );
    427         $this->pending_status_id  = apply_filters( 'bbp_pending_post_status', 'pending' );
    428         $this->private_status_id  = apply_filters( 'bbp_private_post_status', 'private' );
    429         $this->hidden_status_id   = apply_filters( 'bbp_hidden_post_status',  'hidden'  );
    430         $this->trash_status_id    = apply_filters( 'bbp_trash_post_status',   'trash'   );
     381        $this->spam_status_id    = apply_filters( 'bbp_spam_post_status',    'spam'    );
     382        $this->closed_status_id  = apply_filters( 'bbp_closed_post_status',  'closed'  );
     383        $this->orphan_status_id  = apply_filters( 'bbp_orphan_post_status',  'orphan'  );
     384        $this->public_status_id  = apply_filters( 'bbp_public_post_status',  'publish' );
     385        $this->pending_status_id = apply_filters( 'bbp_pending_post_status', 'pending' );
     386        $this->private_status_id = apply_filters( 'bbp_private_post_status', 'private' );
     387        $this->hidden_status_id  = apply_filters( 'bbp_hidden_post_status',  'hidden'  );
     388        $this->trash_status_id   = apply_filters( 'bbp_trash_post_status',   'trash'   );
    431389
    432390        // Other identifiers
    433         $this->user_id            = apply_filters( 'bbp_user_id', 'bbp_user' );
    434         $this->view_id            = apply_filters( 'bbp_view_id', 'bbp_view' );
    435         $this->edit_id            = apply_filters( 'bbp_edit_id', 'edit'     );
    436 
    437         /** Slugs *************************************************************/
    438 
    439         // Root forum slug
    440         $this->root_slug          = apply_filters( 'bbp_root_slug',          get_option( '_bbp_root_slug',          'forums' ) );
    441         $this->topic_archive_slug = apply_filters( 'bbp_topic_archive_slug', get_option( '_bbp_topic_archive_slug', 'topics' ) );
    442 
    443         // Should we include the root slug in front of component slugs
    444         $prefix                   = !empty( $this->root_slug ) && get_option( '_bbp_include_root', true ) ? trailingslashit( $this->root_slug ) : '';
    445 
    446         // Component slugs
    447         $this->forum_slug         = apply_filters( 'bbp_forum_slug', $prefix . get_option( '_bbp_forum_slug', 'forum' ) );
    448         $this->topic_slug         = apply_filters( 'bbp_topic_slug', $prefix . get_option( '_bbp_topic_slug', 'topic' ) );
    449         $this->reply_slug         = apply_filters( 'bbp_reply_slug', $prefix . get_option( '_bbp_reply_slug', 'reply' ) );
    450 
    451         // Taxonomy slugs
    452         $this->topic_tag_slug     = apply_filters( 'bbp_topic_tag_slug', $prefix . get_option( '_bbp_topic_tag_slug', 'topic-tag'   ) );
    453 
    454         /** Other Slugs *******************************************************/
    455 
    456         $this->user_slug          = apply_filters( 'bbp_user_slug', $prefix . get_option( '_bbp_user_slug', 'user' ) );
    457         $this->view_slug          = apply_filters( 'bbp_view_slug', $prefix . get_option( '_bbp_view_slug', 'view' ) );
     391        $this->user_id           = apply_filters( 'bbp_user_id', 'bbp_user' );
     392        $this->view_id           = apply_filters( 'bbp_view_id', 'bbp_view' );
     393        $this->edit_id           = apply_filters( 'bbp_edit_id', 'edit'     );
    458394
    459395        /** Queries ***********************************************************/
    460        
    461         $this->forum_query        = new stdClass;
    462         $this->topic_query        = new stdClass;
    463         $this->reply_query        = new stdClass;
     396
     397        $this->forum_query       = new stdClass;
     398        $this->topic_query       = new stdClass;
     399        $this->reply_query       = new stdClass;
    464400
    465401        /** Misc **************************************************************/
    466402
    467403        // Errors
    468         $this->errors             = new WP_Error();
     404        $this->errors            = new WP_Error();
    469405
    470406        // Views
    471         $this->views              = array();
     407        $this->views             = array();
    472408
    473409        // Tab Index
    474         $this->tab_index          = apply_filters( 'bbp_default_tab_index', 100 );
     410        $this->tab_index         = apply_filters( 'bbp_default_tab_index', 100 );
    475411
    476412        /** Cache *************************************************************/
     
    492428        /** Core **************************************************************/
    493429
     430        require( $this->plugin_dir . 'bbp-includes/bbp-core-options.php'    ); // Configuration Options
    494431        require( $this->plugin_dir . 'bbp-includes/bbp-core-actions.php'    ); // All actions
    495432        require( $this->plugin_dir . 'bbp-includes/bbp-core-filters.php'    ); // All filters
    496         require( $this->plugin_dir . 'bbp-includes/bbp-core-options.php'    ); // Configuration Options
    497433        require( $this->plugin_dir . 'bbp-includes/bbp-core-caps.php'       ); // Roles and capabilities
    498434        require( $this->plugin_dir . 'bbp-includes/bbp-core-classes.php'    ); // Common classes
     
    500436        require( $this->plugin_dir . 'bbp-includes/bbp-core-shortcodes.php' ); // Shortcodes for use with pages and posts
    501437        require( $this->plugin_dir . 'bbp-includes/bbp-core-update.php'     ); // Database updater
    502        
     438
    503439        /** Templates *********************************************************/
    504        
     440
    505441        require( $this->plugin_dir . 'bbp-includes/bbp-template-functions.php'  ); // Template functions
    506442        require( $this->plugin_dir . 'bbp-includes/bbp-template-loader.php'     ); // Template loader
    507443        require( $this->plugin_dir . 'bbp-includes/bbp-theme-compatibility.php' ); // Theme compatibility for existing themes
    508        
     444
    509445        /** Extensions ********************************************************/
    510        
     446
    511447        require( $this->plugin_dir . 'bbp-includes/bbp-extend-akismet.php' ); // Spam prevention for topics and replies
    512448
     
    679615        // Forum rewrite
    680616        $forum['rewrite'] = array(
    681             'slug'       => $this->forum_slug,
     617            'slug'       => bbp_get_forum_slug(),
    682618            'with_front' => false
    683619        );
     
    699635            'capability_type'     => array( 'forum', 'forums' ),
    700636            'menu_position'       => 56,
    701             'has_archive'         => $this->root_slug,
     637            'has_archive'         => bbp_get_root_slug(),
    702638            'exclude_from_search' => true,
    703639            'show_in_nav_menus'   => true,
     
    736672        // Topic rewrite
    737673        $topic['rewrite'] = array(
    738             'slug'       => $this->topic_slug,
     674            'slug'       => bbp_get_topic_slug(),
    739675            'with_front' => false
    740676        );
     
    756692            'capability_type'     => array( 'topic', 'topics' ),
    757693            'menu_position'       => 57,
    758             'has_archive'         => $this->topic_archive_slug,
     694            'has_archive'         => bbp_get_topic_archive_slug(),
    759695            'exclude_from_search' => true,
    760696            'show_in_nav_menus'   => false,
     
    793729        // Reply rewrite
    794730        $reply['rewrite'] = array(
    795             'slug'       => $this->reply_slug,
     731            'slug'       => bbp_get_reply_slug(),
    796732            'with_front' => false
    797733        );
     
    933869        // Topic tag rewrite
    934870        $topic_tag['rewrite'] = array(
    935             'slug'       => $this->topic_tag_slug,
     871            'slug'       => bbp_get_topic_tag_taxonomy_slug(),
    936872            'with_front' => false
    937873        );
     
    1032968    public function generate_rewrite_rules( $wp_rewrite ) {
    1033969
     970        $user_slug = bbp_get_user_slug();
     971        $view_slug = bbp_get_view_slug();
     972
     973        $root_rule = '/([^/]+)/?$';
     974        $edit_rule = '/([^/]+)/edit/?$';
     975        $feed_rule = '/([^/]+)/feed/?$';
     976        $page_rule = '/([^/]+)/page/?([0-9]{1,})/?$';
     977
    1034978        // New rules to merge with existing
    1035979        $bbp_rules = array(
    1036980
    1037981            // Edit Forum/Topic/Reply
    1038             $this->forum_slug     . '/([^/]+)/edit/?$' => 'index.php?' . $this->forum_post_type  . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
    1039             $this->topic_slug     . '/([^/]+)/edit/?$' => 'index.php?' . $this->topic_post_type  . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
    1040             $this->reply_slug     . '/([^/]+)/edit/?$' => 'index.php?' . $this->reply_post_type  . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
     982            bbp_get_forum_slug() . $edit_rule => 'index.php?' . $this->forum_post_type  . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
     983            bbp_get_topic_slug() . $edit_rule => 'index.php?' . $this->topic_post_type  . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
     984            bbp_get_reply_slug() . $edit_rule => 'index.php?' . $this->reply_post_type  . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
    1041985
    1042986            // Edit Topic Tag
    1043             $this->topic_tag_slug . '/([^/]+)/edit/?$' => 'index.php?' . $this->topic_tag_tax_id . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
     987            bbp_get_topic_tag_taxonomy_slug() . $edit_rule => 'index.php?' . $this->topic_tag_tax_id . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
    1044988
    1045989            // Profile Page
    1046             $this->user_slug      . '/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?' . $this->user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
    1047             $this->user_slug      . '/([^/]+)/?$'                   => 'index.php?' . $this->user_id  . '=' . $wp_rewrite->preg_index( 1 ),
    1048             $this->user_slug      . '/([^/]+)/edit/?$'              => 'index.php?' . $this->user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
     990            $user_slug . $page_rule => 'index.php?' . $this->user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
     991            $user_slug . $edit_rule => 'index.php?' . $this->user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&edit=1',
     992            $user_slug . $root_rule => 'index.php?' . $this->user_id  . '=' . $wp_rewrite->preg_index( 1 ),
    1049993
    1050994            // View Page
    1051             $this->view_slug      . '/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?' . $this->view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
    1052             $this->view_slug      . '/([^/]+)/feed/?$'              => 'index.php?' . $this->view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&feed='  . $wp_rewrite->preg_index( 2 ),
    1053             $this->view_slug      . '/([^/]+)/?$'                   => 'index.php?' . $this->view_id . '=' . $wp_rewrite->preg_index( 1 )
     995            $view_slug . $page_rule => 'index.php?' . $this->view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
     996            $view_slug . $feed_rule => 'index.php?' . $this->view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&feed='  . $wp_rewrite->preg_index( 2 ),
     997            $view_slug . $root_rule => 'index.php?' . $this->view_id . '=' . $wp_rewrite->preg_index( 1 ),
    1054998        );
    1055999
Note: See TracChangeset for help on using the changeset viewer.