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

    r3499 r3505  
    440440 */
    441441function bbp_get_statistics( $args = '' ) {
    442     global $bbp;
    443442
    444443    $defaults = array (
     
    470469    }
    471470
     471    // Post statuses
     472    $private = bbp_get_private_status_id();
     473    $spam    = bbp_get_spam_status_id();
     474    $trash   = bbp_get_trash_status_id();
     475    $closed  = bbp_get_closed_status_id();
     476
    472477    // Topics
    473478    if ( !empty( $count_topics ) ) {
     
    476481
    477482        // Published (publish + closed)
    478         $topic_count = $all_topics->publish + $all_topics->{$bbp->closed_status_id};
     483        $topic_count = $all_topics->publish + $all_topics->{$closed};
    479484
    480485        if ( current_user_can( 'read_private_topics' ) || current_user_can( 'edit_others_topics' ) || current_user_can( 'view_trash' ) ) {
    481486
    482487            // Private
    483             $topics['private'] = ( !empty( $count_private_topics ) && current_user_can( 'read_private_topics' ) ) ? (int) $all_topics->private                : 0;
     488            $topics['private'] = ( !empty( $count_private_topics ) && current_user_can( 'read_private_topics' ) ) ? (int) $all_topics->{$private} : 0;
    484489
    485490            // Spam
    486             $topics['spammed'] = ( !empty( $count_spammed_topics ) && current_user_can( 'edit_others_topics'  ) ) ? (int) $all_topics->{$bbp->spam_status_id}  : 0;
     491            $topics['spammed'] = ( !empty( $count_spammed_topics ) && current_user_can( 'edit_others_topics'  ) ) ? (int) $all_topics->{$spam}    : 0;
    487492
    488493            // Trash
    489             $topics['trashed'] = ( !empty( $count_trashed_topics ) && current_user_can( 'view_trash'          ) ) ? (int) $all_topics->{$bbp->trash_status_id} : 0;
     494            $topics['trashed'] = ( !empty( $count_trashed_topics ) && current_user_can( 'view_trash'          ) ) ? (int) $all_topics->{$trash}  : 0;
    490495
    491496            // Total hidden (private + spam + trash)
     
    513518
    514519            // Private
    515             $replies['private'] = ( !empty( $count_private_replies ) && current_user_can( 'read_private_replies' ) ) ? (int) $all_replies->private                : 0;
     520            $replies['private'] = ( !empty( $count_private_replies ) && current_user_can( 'read_private_replies' ) ) ? (int) $all_replies->{$private} : 0;
    516521
    517522            // Spam
    518             $replies['spammed'] = ( !empty( $count_spammed_replies ) && current_user_can( 'edit_others_replies'  ) ) ? (int) $all_replies->{$bbp->spam_status_id}  : 0;
     523            $replies['spammed'] = ( !empty( $count_spammed_replies ) && current_user_can( 'edit_others_replies'  ) ) ? (int) $all_replies->{$spam}    : 0;
    519524
    520525            // Trash
    521             $replies['trashed'] = ( !empty( $count_trashed_replies ) && current_user_can( 'view_trash'           ) ) ? (int) $all_replies->{$bbp->trash_status_id} : 0;
     526            $replies['trashed'] = ( !empty( $count_trashed_replies ) && current_user_can( 'view_trash'           ) ) ? (int) $all_replies->{$trash}  : 0;
    522527
    523528            // Total hidden (private + spam + trash)
     
    714719 */
    715720function bbp_filter_anonymous_post_data( $args = '', $is_edit = false ) {
    716     global $bbp;
    717721
    718722    // Assign variables
     
    769773        return true;
    770774
    771     global $bbp, $wpdb;
     775    global $wpdb;
    772776
    773777    extract( $post_data, EXTR_SKIP );
     
    792796    // Simple duplicate check
    793797    // Expected slashed ($post_type, $post_parent, $post_author, $post_content, $anonymous_data)
    794     $dupe  = "SELECT ID FROM {$wpdb->posts} {$join} WHERE post_type = '{$post_type}' AND post_status != '{$bbp->trash_status_id}' AND post_author = {$post_author} AND post_content = '{$post_content}' {$where}";
    795     $dupe .= !empty( $post_parent ) ? " AND post_parent = '{$post_parent}'" : '';
    796     $dupe .= " LIMIT 1";
    797     $dupe  = apply_filters( 'bbp_check_for_duplicate_query', $dupe, $post_data );
     798    $status = bbp_get_trash_status_id();
     799    $dupe   = "SELECT ID FROM {$wpdb->posts} {$join} WHERE post_type = '{$post_type}' AND post_status != '{$status}' AND post_author = {$post_author} AND post_content = '{$post_content}' {$where}";
     800    $dupe  .= !empty( $post_parent ) ? " AND post_parent = '{$post_parent}'" : '';
     801    $dupe  .= " LIMIT 1";
     802    $dupe   = apply_filters( 'bbp_check_for_duplicate_query', $dupe, $post_data );
    798803
    799804    if ( $wpdb->get_var( $dupe ) ) {
     
    855860 * @since bbPress (r3446)
    856861 *
    857  * @global bbPress $bbp
    858862 * @param array $anonymous_data Anonymous user data
    859863 * @param int $author_id Topic or reply author ID
     
    980984 */
    981985function bbp_notify_subscribers( $reply_id = 0 ) {
    982     global $bbp, $wpdb;
     986    global $wpdb;
    983987
    984988    // Bail if subscriptions are turned off
     
    11581162    // The ID of the cached query
    11591163    $cache_id    = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_last_id';
    1160     $post_status = array( 'publish' );
     1164    $post_status = array( bbp_get_public_status_id() );
    11611165
    11621166    // Add closed status if topic post type
    11631167    if ( $post_type == bbp_get_topic_post_type() )
    1164         $post_status[] = $bbp->closed_status_id;
     1168        $post_status[] = bbp_get_closed_status_id();
    11651169
    11661170    // Join post statuses together
     
    11921196 */
    11931197function bbp_get_public_child_count( $parent_id = 0, $post_type = 'post' ) {
    1194     global $wpdb, $bbp;
     1198    global $wpdb;
    11951199
    11961200    // Bail if nothing passed
     
    12001204    // The ID of the cached query
    12011205    $cache_id    = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_count';
    1202     $post_status = array( 'publish' );
     1206    $post_status = array( bbp_get_public_status_id() );
    12031207
    12041208    // Add closed status if topic post type
    12051209    if ( $post_type == bbp_get_topic_post_type() )
    1206         $post_status[] = $bbp->closed_status_id;
     1210        $post_status[] = bbp_get_closed_status_id();
    12071211
    12081212    // Join post statuses together
     
    12341238 */
    12351239function bbp_get_public_child_ids( $parent_id = 0, $post_type = 'post' ) {
    1236     global $wpdb, $bbp;
     1240    global $wpdb;
    12371241
    12381242    // Bail if nothing passed
     
    12421246    // The ID of the cached query
    12431247    $cache_id    = 'bbp_parent_public_' . $parent_id . '_type_' . $post_type . '_child_ids';
    1244     $post_status = array( 'publish' );
     1248    $post_status = array( bbp_get_public_status_id() );
    12451249
    12461250    // Add closed status if topic post type
    12471251    if ( $post_type == bbp_get_topic_post_type() )
    1248         $post_status[] = $bbp->closed_status_id;
     1252        $post_status[] = bbp_get_closed_status_id();
    12491253
    12501254    // Join post statuses together
     
    12751279 */
    12761280function bbp_get_all_child_ids( $parent_id = 0, $post_type = 'post' ) {
    1277     global $wpdb, $bbp;
     1281    global $wpdb;
    12781282
    12791283    // Bail if nothing passed
     
    12831287    // The ID of the cached query
    12841288    $cache_id    = 'bbp_parent_all_' . $parent_id . '_type_' . $post_type . '_child_ids';
    1285     $post_status = array( 'publish' );
     1289    $post_status = array( bbp_get_public_status_id() );
    12861290
    12871291    // Extra post statuses based on post type
     
    12901294        // Forum
    12911295        case bbp_get_forum_post_type() :
    1292             $post_status[] = 'private';
    1293             $post_status[] = $bbp->hidden_status_id;
     1296            $post_status[] = bbp_get_private_status_id();
     1297            $post_status[] = bbp_get_hidden_status_id();
    12941298            break;
    12951299
    12961300        // Topic
    12971301        case bbp_get_topic_post_type() :
    1298             $post_status[] = $bbp->closed_status_id;
    1299             $post_status[] = $bbp->trash_status_id;
    1300             $post_status[] = $bbp->spam_status_id;
     1302            $post_status[] = bbp_get_closed_status_id();
     1303            $post_status[] = bbp_get_trash_status_id();
     1304            $post_status[] = bbp_get_spam_status_id();
    13011305            break;
    13021306
    13031307        // Reply
    13041308        case bbp_get_reply_post_type() :
    1305             $post_status[] = $bbp->trash_status_id;
    1306             $post_status[] = $bbp->spam_status_id;
     1309            $post_status[] = bbp_get_trash_status_id();
     1310            $post_status[] = bbp_get_spam_status_id();
    13071311            break;
    13081312    }
     
    13311335 *
    13321336 * @global WP_Query $wp_query
    1333  * @global bbPress $bbp
    13341337 * @param array $query_vars
    13351338 * @return array
    13361339 */
    13371340function bbp_request_feed_trap( $query_vars ) {
    1338     global $wp_query, $bbp;
     1341    global $wp_query;
    13391342
    13401343    // Looking at a feed
     
    13491352                // Forum
    13501353                case bbp_get_forum_post_type() :
     1354
     1355                    // Declare local variable(s)
     1356                    $meta_query = array();
    13511357
    13521358                    // Single forum
     
    13681374                            'value'   => $forum_id,
    13691375                            'compare' => '='
    1370                         ) );
    1371                        
    1372                     // No restrictions on forum ID
    1373                     } else {
    1374                         $meta_query = array();
     1376                        ) );                       
    13751377                    }
    13761378
     
    13831385                            'post_type'      => bbp_get_reply_post_type(),
    13841386                            'post_parent'    => 'any',
    1385                             'post_status'    => join( ',', array( 'publish', $bbp->closed_status_id ) ),
     1387                            'post_status'    => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ),
    13861388                            'posts_per_page' => get_option( '_bbp_replies_per_rss_page', 25 ),
    13871389                            'order'          => 'DESC',
     
    14001402                            'post_type'      => bbp_get_topic_post_type(),
    14011403                            'post_parent'    => 'any',
    1402                             'post_status'    => join( ',', array( 'publish', $bbp->closed_status_id ) ),
     1404                            'post_status'    => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ),
    14031405                            'posts_per_page' => get_option( '_bbp_topics_per_rss_page', 25 ),
    14041406                            'order'          => 'DESC',
     
    14171419                            'post_type'      => array( bbp_get_reply_post_type(), bbp_get_topic_post_type() ),
    14181420                            'post_parent'    => 'any',
    1419                             'post_status'    => join( ',', array( 'publish', $bbp->closed_status_id ) ),
     1421                            'post_status'    => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ),
    14201422                            'posts_per_page' => get_option( '_bbp_replies_per_rss_page', 25 ),
    14211423                            'order'          => 'DESC',
     
    15341536}
    15351537
     1538/** Post Statuses *************************************************************/
     1539
     1540/**
     1541 * Return the public post status ID
     1542 *
     1543 * @since bbPress (r3504)
     1544 *
     1545 * @global bbPress $bbp
     1546 * @return string
     1547 */
     1548function bbp_get_public_status_id() {
     1549    global $bbp;
     1550    return $bbp->public_status_id;
     1551}
     1552
     1553/**
     1554 * Return the private post status ID
     1555 *
     1556 * @since bbPress (r3504)
     1557 *
     1558 * @global bbPress $bbp
     1559 * @return string
     1560 */
     1561function bbp_get_private_status_id() {
     1562    global $bbp;
     1563    return $bbp->private_status_id;
     1564}
     1565
     1566/**
     1567 * Return the hidden post status ID
     1568 *
     1569 * @since bbPress (r3504)
     1570 *
     1571 * @global bbPress $bbp
     1572 * @return string
     1573 */
     1574function bbp_get_hidden_status_id() {
     1575    global $bbp;
     1576    return $bbp->hidden_status_id;
     1577}
     1578
     1579/**
     1580 * Return the closed post status ID
     1581 *
     1582 * @since bbPress (r3504)
     1583 *
     1584 * @global bbPress $bbp
     1585 * @return string
     1586 */
     1587function bbp_get_closed_status_id() {
     1588    global $bbp;
     1589    return $bbp->closed_status_id;
     1590}
     1591
     1592/**
     1593 * Return the spam post status ID
     1594 *
     1595 * @since bbPress (r3504)
     1596 *
     1597 * @global bbPress $bbp
     1598 * @return string
     1599 */
     1600function bbp_get_spam_status_id() {
     1601    global $bbp;
     1602    return $bbp->spam_status_id;
     1603}
     1604
     1605/**
     1606 * Return the trash post status ID
     1607 *
     1608 * @since bbPress (r3504)
     1609 *
     1610 * @global bbPress $bbp
     1611 * @return string
     1612 */
     1613function bbp_get_trash_status_id() {
     1614    global $bbp;
     1615    return $bbp->trash_status_id;
     1616}
     1617
     1618/**
     1619 * Return the orphan post status ID
     1620 *
     1621 * @since bbPress (r3504)
     1622 *
     1623 * @global bbPress $bbp
     1624 * @return string
     1625 */
     1626function bbp_get_orphan_status_id() {
     1627    global $bbp;
     1628    return $bbp->orphan_status_id;
     1629}
     1630
    15361631?>
Note: See TracChangeset for help on using the changeset viewer.