Skip to:
Content

bbPress.org


Ignore:
Timestamp:
09/10/2011 10:27:19 PM (13 years ago)
Author:
johnjamesjacoby
Message:

API adjustments:

  • Refactor _status_ vars into callable functions.
  • Audit usage of $bbp global.
  • Perform get_class() checks on extensions to avoid errors if global $bbp is overloaded.
  • Bump DB version to 175.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-forum-functions.php

    r3501 r3505  
    3232    $default_forum = array(
    3333        'post_parent'   => 0, // forum ID
    34         'post_status'   => 'publish',
     34        'post_status'   => bbp_get_public_status_id(),
    3535        'post_type'     => bbp_get_forum_post_type(),
    3636        'post_author'   => 0,
     
    208208
    209209    // Only run queries if visibility is changing
    210     if ( 'publish' != $current_visibility ) {
     210    if ( bbp_get_public_status_id() != $current_visibility ) {
    211211
    212212        // Remove from _bbp_private_forums site option
    213         if ( 'private' == $current_visibility ) {
     213        if ( bbp_get_private_status_id() == $current_visibility ) {
    214214
    215215            // Get private forums
     
    230230
    231231        // Remove from _bbp_hidden_forums site option
    232         if ( 'hidden' == $current_visibility ) {
     232        if ( bbp_get_hidden_status_id() == $current_visibility ) {
    233233
    234234            // Get hidden forums
     
    250250        // Update forum post_status
    251251        global $wpdb;
    252         $wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $forum_id ) );
    253         wp_transition_post_status( 'publish', $current_visibility, get_post( $forum_id ) );
     252        $wpdb->update( $wpdb->posts, array( 'post_status' => bbp_get_public_status_id() ), array( 'ID' => $forum_id ) );
     253        wp_transition_post_status( bbp_get_public_status_id(), $current_visibility, get_post( $forum_id ) );
    254254    }
    255255
     
    275275
    276276    // Only run queries if visibility is changing
    277     if ( 'private' != $current_visibility ) {
     277    if ( bbp_get_private_status_id() != $current_visibility ) {
    278278
    279279        // Remove from _bbp_hidden_forums site option
    280         if ( 'hidden' == $current_visibility ) {
     280        if ( bbp_get_hidden_status_id() == $current_visibility ) {
    281281
    282282            // Get hidden forums
     
    303303        // Update forums visibility setting
    304304        global $wpdb;
    305         $wpdb->update( $wpdb->posts, array( 'post_status' => 'private' ), array( 'ID' => $forum_id ) );
    306         wp_transition_post_status( 'private', $current_visibility, get_post( $forum_id ) );
     305        $wpdb->update( $wpdb->posts, array( 'post_status' => bbp_get_private_status_id() ), array( 'ID' => $forum_id ) );
     306        wp_transition_post_status( bbp_get_private_status_id(), $current_visibility, get_post( $forum_id ) );
    307307    }
    308308
     
    328328
    329329    // Only run queries if visibility is changing
    330     if ( 'hidden' != $current_visibility ) {
     330    if ( bbp_get_hidden_status_id() != $current_visibility ) {
    331331
    332332        // Remove from _bbp_private_forums site option
    333         if ( 'private' == $current_visibility ) {
     333        if ( bbp_get_private_status_id() == $current_visibility ) {
    334334
    335335            // Get private forums
     
    355355
    356356        // Update forums visibility setting
    357         global $bbp, $wpdb;
    358         $wpdb->update( $wpdb->posts, array( 'post_status' => 'hidden' ), array( 'ID' => $forum_id ) );
    359         wp_transition_post_status( $bbp->hidden_status_id, $current_visibility, get_post( $forum_id ) );
     357        global $wpdb;
     358        $wpdb->update( $wpdb->posts, array( 'post_status' => bbp_get_hidden_status_id() ), array( 'ID' => $forum_id ) );
     359        wp_transition_post_status( bbp_get_hidden_status_id(), $current_visibility, get_post( $forum_id ) );
    360360    }
    361361
     
    511511 */
    512512function bbp_update_forum_last_active_id( $forum_id = 0, $active_id = 0 ) {
     513
    513514    $forum_id = bbp_get_forum_id( $forum_id );
    514515
     
    544545
    545546    // Update only if published
    546     if ( 'publish' == get_post_status( $active_id ) )
     547    if ( bbp_get_public_status_id() == get_post_status( $active_id ) )
    547548        update_post_meta( $forum_id, '_bbp_last_active_id', (int) $active_id );
    548549
     
    661662 */
    662663function bbp_update_forum_topic_count_hidden( $forum_id = 0, $topic_count = 0 ) {
    663     global $wpdb, $bbp;
     664    global $wpdb;
    664665
    665666    // If topic_id was passed as $forum_id, then get its forum
     
    678679        // Get topics of forum
    679680        if ( empty( $topic_count ) )
    680             $topic_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( '" . join( '\',\'', array( $bbp->trash_status_id, $bbp->spam_status_id ) ) . "') AND post_type = '%s';", $forum_id, bbp_get_topic_post_type() ) );
     681            $topic_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( '" . join( '\',\'', array( bbp_get_trash_status_id(), bbp_get_spam_status_id() ) ) . "') AND post_type = '%s';", $forum_id, bbp_get_topic_post_type() ) );
    681682
    682683        // Update the count
     
    709710 */
    710711function bbp_update_forum_reply_count( $forum_id = 0 ) {
    711     global $wpdb, $bbp;
     712    global $wpdb;
    712713
    713714    $forum_id = bbp_get_forum_id( $forum_id );
     
    721722    // Don't count replies if the forum is a category
    722723    if ( $topic_ids = bbp_forum_query_topic_ids( $forum_id ) )
    723         $reply_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent IN ( " . join( ',', $topic_ids ) . " ) AND post_status = 'publish' AND post_type = '%s';", bbp_get_reply_post_type() ) );
     724        $reply_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent IN ( " . join( ',', $topic_ids ) . " ) AND post_status = '%s' AND post_type = '%s';", bbp_get_public_status_id(), bbp_get_reply_post_type() ) );
    724725    else
    725726        $reply_count = 0;
     
    768769        'last_active_id'     => 0,
    769770        'last_active_time'   => 0,
    770         'last_active_status' => 'publish'
     771        'last_active_status' => bbp_get_public_status_id()
    771772    );
    772773
     
    785786        $last_active_time = get_post_field( 'post_date', $last_active_id );
    786787
    787     if ( 'publish' == $last_active_status ) {
     788    if ( bbp_get_public_status_id() == $last_active_status ) {
    788789        bbp_update_forum_last_active_time( $forum_id, $last_active_time );
    789790    }
     
    980981 */
    981982function bbp_forum_query_topic_ids( $forum_id ) {
    982     global $bbp;
    983 
    984983    $topic_ids = bbp_get_public_child_ids( $forum_id, bbp_get_topic_post_type() );
    985984
     
    10011000 */
    10021001function bbp_forum_query_subforum_ids( $forum_id ) {
    1003     global $bbp, $wpdb;
    1004 
    10051002    $subforum_ids = bbp_get_public_child_ids( $forum_id, bbp_get_forum_post_type() );
    10061003
     
    10251022 */
    10261023function bbp_forum_query_last_reply_id( $forum_id, $topic_ids = 0 ) {
    1027     global $bbp, $wpdb;
     1024    global $wpdb;
    10281025
    10291026    $cache_id = 'bbp_get_forum_' . $forum_id . '_reply_id';
     
    10341031            $topic_ids = bbp_forum_query_topic_ids( $forum_id );
    10351032
    1036         if ( !empty( $topic_ids ) && ( $reply_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent IN ( " . join( ',', $topic_ids ) . " ) AND post_status = 'publish' AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", bbp_get_reply_post_type() ) ) ) )
     1033        if ( !empty( $topic_ids ) && ( $reply_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent IN ( " . join( ',', $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() ) ) ) )
    10371034            wp_cache_set( $cache_id, $reply_id, 'bbpress' );
    10381035        else
Note: See TracChangeset for help on using the changeset viewer.