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-topic-functions.php

    r3501 r3505  
    3232    $default_topic = array(
    3333        'post_parent'   => 0, // forum ID
    34         'post_status'   => 'publish',
     34        'post_status'   => bbp_get_public_status_id(),
    3535        'post_type'     => bbp_get_topic_post_type(),
    3636        'post_author'   => 0,
     
    124124        return;
    125125
    126     global $bbp;
    127 
    128126    // Nonce check
    129127    check_admin_referer( 'bbp-new-topic' );
     
    268266            'post_parent'  => $forum_id,
    269267            'tax_input'    => $terms,
    270             'post_status'  => 'publish',
     268            'post_status'  => bbp_get_public_status_id(),
    271269            'post_type'    => bbp_get_topic_post_type()
    272270        );
     
    310308            // If the forum is trash, or the topic_status is switched to
    311309            // trash, trash it properly
    312             if ( ( get_post_field( 'post_status', $forum_id ) == $bbp->trash_status_id ) || ( $topic_data['post_status'] == $bbp->trash_status_id ) ) {
     310            if ( ( get_post_field( 'post_status', $forum_id ) == bbp_get_trash_status_id() ) || ( $topic_data['post_status'] == bbp_get_trash_status_id() ) ) {
    313311
    314312                // Trash the reply
     
    322320
    323321            // If reply or topic are spam, officially spam this reply
    324             if ( $topic_data['post_status'] == $bbp->spam_status_id ) {
    325                 add_post_meta( $topic_id, '_bbp_spam_meta_status', 'publish' );
     322            if ( $topic_data['post_status'] == bbp_get_spam_status_id() ) {
     323                add_post_meta( $topic_id, '_bbp_spam_meta_status', bbp_get_public_status_id() );
    326324
    327325                // Force view=all
     
    817815    if ( true == $refresh ) {
    818816        $forum_id = $topic_id = $reply_id = $active_id = $last_active_time = 0;
    819         $topic_status = 'publish';
     817        $topic_status = bbp_get_public_status_id();
    820818    }
    821819
     
    12791277        return;
    12801278
    1281     global $wpdb, $bbp;
     1279    global $wpdb;
    12821280
    12831281    // Prevent debug notices
     
    21222120 */
    21232121function bbp_update_topic_reply_count_hidden( $topic_id = 0, $reply_count = 0 ) {
    2124     global $wpdb, $bbp;
     2122    global $wpdb;
    21252123
    21262124    // If it's a reply, then get the parent (topic id)
     
    21322130    // Get replies of topic
    21332131    if ( empty( $reply_count ) )
    2134         $reply_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';", $topic_id, bbp_get_reply_post_type() ) );
     2132        $reply_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';", $topic_id, bbp_get_reply_post_type() ) );
    21352133
    21362134    update_post_meta( $topic_id, '_bbp_reply_count_hidden', (int) $reply_count );
     
    21732171
    21742172    // Update only if published
    2175     if ( 'publish' == get_post_status( $active_id ) )
     2173    if ( bbp_get_public_status_id() == get_post_status( $active_id ) )
    21762174        update_post_meta( $topic_id, '_bbp_last_active_id', (int) $active_id );
    21772175
     
    22852283
    22862284    // Query the DB to get voices in this topic
    2287     $voices = $wpdb->get_col( $wpdb->prepare( "SELECT COUNT( DISTINCT post_author ) FROM {$wpdb->posts} WHERE ( post_parent = %d AND post_status = 'publish' AND post_type = '%s' ) OR ( ID = %d AND post_type = '%s' );", $topic_id, bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ) );
     2285    $voices = $wpdb->get_col( $wpdb->prepare( "SELECT COUNT( DISTINCT post_author ) FROM {$wpdb->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' ) OR ( ID = %d AND post_type = '%s' );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ) );
    22882286
    22892287    // If there's an error, make sure we at least have 1 voice
     
    23262324        return;
    23272325
    2328     $anonymous_replies = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( ID ) FROM {$wpdb->posts} WHERE ( post_parent = %d AND post_status = 'publish' AND post_type = '%s' AND post_author = 0 ) OR ( ID = %d AND post_type = '%s' AND post_author = 0 );", $topic_id, bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ) );
     2326    $anonymous_replies = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( ID ) FROM {$wpdb->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' AND post_author = 0 ) OR ( ID = %d AND post_type = '%s' AND post_author = 0 );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ) );
    23292327
    23302328    update_post_meta( $topic_id, '_bbp_anonymous_reply_count', (int) $anonymous_replies );
     
    23912389 */
    23922390function bbp_close_topic( $topic_id = 0 ) {
    2393     global $bbp;
    23942391
    23952392    // Get topic
     
    23982395
    23992396    // Bail if already closed
    2400     if ( $topic['post_status'] == $bbp->closed_status_id )
     2397    if ( bbp_get_closed_status_id == $topic['post_status'] )
    24012398        return false;
    24022399
     
    24082405
    24092406    // Set closed status
    2410     $topic['post_status'] = $bbp->closed_status_id;
     2407    $topic['post_status'] = bbp_get_closed_status_id();
    24112408
    24122409    // No revisions
     
    24382435 */
    24392436function bbp_open_topic( $topic_id = 0 ) {
    2440     global $bbp;
    24412437
    24422438    // Get topic
     
    24452441
    24462442    // Bail if already open
    2447     if ( $topic['post_status'] != $bbp->closed_status_id )
     2443    if ( bbp_get_closed_status_id() != $topic['post_status'])
    24482444        return false;
    24492445
     
    24872483 */
    24882484function bbp_spam_topic( $topic_id = 0 ) {
    2489     global $bbp;
    24902485
    24912486    // Get the topic
     
    24942489
    24952490    // Bail if topic is spam
    2496     if ( $topic['post_status'] == $bbp->spam_status_id )
     2491    if ( bbp_get_spam_status_id() == $topic['post_status'] )
    24972492        return false;
    24982493
     
    25262521   
    25272522    // Set post status to spam
    2528     $topic['post_status'] = $bbp->spam_status_id;
     2523    $topic['post_status'] = bbp_get_spam_status_id();
    25292524
    25302525    // No revisions
     
    25562551 */
    25572552function bbp_unspam_topic( $topic_id = 0 ) {
    2558     global $bbp;
    25592553
    25602554    // Get the topic
     
    25632557
    25642558    // Bail if already not spam
    2565     if ( $topic['post_status'] != $bbp->spam_status_id )
     2559    if ( bbp_get_spam_status_id() != $topic['post_status'] )
    25662560        return false;
    25672561
     
    27132707 */
    27142708function bbp_delete_topic( $topic_id = 0 ) {
    2715     global $bbp;
    27162709
    27172710    // Validate topic ID
     
    27242717
    27252718    // Valid topic/reply statuses
    2726     $post_stati = join( ',', array( 'publish', $bbp->spam_status_id, 'trash' ) );
     2719    $post_stati = join( ',', array( bbp_get_public_status_id(), bbp_get_spam_status_id(), 'trash' ) );
    27272720
    27282721    // Topic is being permanently deleted, so its replies gotta go too
     
    27742767    if ( bbp_has_replies( array(
    27752768        'post_type'      => bbp_get_reply_post_type(),
    2776         'post_status'    => 'publish',
     2769        'post_status'    => bbp_get_public_status_id(),
    27772770        'posts_per_page' => -1,
    27782771        'meta_query'     => array( array(
Note: See TracChangeset for help on using the changeset viewer.