Skip to:
Content

bbPress.org


Ignore:
Timestamp:
07/14/2015 12:31:42 AM (11 years ago)
Author:
johnjamesjacoby
Message:

Abstraction: Use bbp_db(), bbp_rewrite() & friends, introduced in r5823 & r5826.

This commit improves the stability of bbPress in the WordPress environment by reducing global variable exposure. It also comes with minimal opcode improvements in some circumstances where $GLOBALS is preferred over defining via global statements.

Some additional surrounding cleanup directly related to functions & methods being altered is also being performed here.

Fixes #2786.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/forums/functions.php

    r5775 r5827  
    822822    // Only run queries if visibility is changing
    823823    if ( bbp_get_public_status_id() !== $current_visibility ) {
    824 
    825         // Update forums visibility setting
    826         global $wpdb;
    827         $wpdb->update( $wpdb->posts, array( 'post_status' => bbp_get_public_status_id() ), array( 'ID' => $forum_id ) );
     824        $bbp_db = bbp_db();
     825        $bbp_db->update( $bbp_db->posts, array( 'post_status' => bbp_get_public_status_id() ), array( 'ID' => $forum_id ) );
    828826        wp_transition_post_status( bbp_get_public_status_id(), $current_visibility, get_post( $forum_id ) );
    829827        bbp_clean_post_cache( $forum_id );
     
    874872
    875873        // Update forums visibility setting
    876         global $wpdb;
    877         $wpdb->update( $wpdb->posts, array( 'post_status' => bbp_get_private_status_id() ), array( 'ID' => $forum_id ) );
     874        $bbp_db = bbp_db();
     875        $bbp_db->update( $bbp_db->posts, array( 'post_status' => bbp_get_private_status_id() ), array( 'ID' => $forum_id ) );
    878876        wp_transition_post_status( bbp_get_private_status_id(), $current_visibility, get_post( $forum_id ) );
    879877        bbp_clean_post_cache( $forum_id );
     
    924922
    925923        // Update forums visibility setting
    926         global $wpdb;
    927         $wpdb->update( $wpdb->posts, array( 'post_status' => bbp_get_hidden_status_id() ), array( 'ID' => $forum_id ) );
     924        $bbp_db = bbp_db();
     925        $bbp_db->update( $bbp_db->posts, array( 'post_status' => bbp_get_hidden_status_id() ), array( 'ID' => $forum_id ) );
    928926        wp_transition_post_status( bbp_get_hidden_status_id(), $current_visibility, get_post( $forum_id ) );
    929927        bbp_clean_post_cache( $forum_id );
     
    15111509 */
    15121510function bbp_update_forum_topic_count_hidden( $forum_id = 0, $topic_count = 0 ) {
    1513     global $wpdb;
    15141511
    15151512    // If topic_id was passed as $forum_id, then get its forum
     
    15281525        // Get topics of forum
    15291526        if ( empty( $topic_count ) ) {
     1527            $bbp_db      = bbp_db();
    15301528            $post_status = "'" . implode( "','", array( bbp_get_trash_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id() ) ) . "'";
    1531             $topic_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $forum_id, bbp_get_topic_post_type() ) );
     1529            $topic_count = $bbp_db->get_var( $bbp_db->prepare( "SELECT COUNT(ID) FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $forum_id, bbp_get_topic_post_type() ) );
    15321530        }
    15331531
     
    15631561 */
    15641562function bbp_update_forum_reply_count( $forum_id = 0 ) {
    1565     global $wpdb;
    15661563
    15671564    $forum_id = bbp_get_forum_id( $forum_id );
     
    15801577    $topic_ids   = bbp_forum_query_topic_ids( $forum_id );
    15811578    if ( ! empty( $topic_ids ) ) {
     1579        $bbp_db      = bbp_db();
    15821580        $topic_ids   = implode( ',', wp_parse_id_list( $topic_ids ) );
    1583         $reply_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s';", bbp_get_public_status_id(), bbp_get_reply_post_type() ) );
     1581        $reply_count = (int) $bbp_db->get_var( $bbp_db->prepare( "SELECT COUNT(ID) FROM {$bbp_db->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s';", bbp_get_public_status_id(), bbp_get_reply_post_type() ) );
    15841582    }
    15851583
     
    20042002 */
    20052003function bbp_forum_query_last_reply_id( $forum_id, $topic_ids = 0 ) {
    2006     global $wpdb;
    20072004
    20082005    $cache_id = 'bbp_get_forum_' . $forum_id . '_reply_id';
     
    20162013
    20172014        if ( !empty( $topic_ids ) ) {
     2015            $bbp_db    = bbp_db();
    20182016            $topic_ids = implode( ',', wp_parse_id_list( $topic_ids ) );
    2019             $reply_id  = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", bbp_get_public_status_id(), bbp_get_reply_post_type() ) );
     2017            $reply_id  = (int) $bbp_db->get_var( $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", bbp_get_public_status_id(), bbp_get_reply_post_type() ) );
    20202018        } else {
    20212019            $reply_id = 0;
Note: See TracChangeset for help on using the changeset viewer.