Skip to:
Content

bbPress.org

Changeset 3349


Ignore:
Timestamp:
06/27/2011 10:18:38 AM (10 years ago)
Author:
johnjamesjacoby
Message:

Add _insert_ functions for forums, topics, and replies. Audit (forum/topic/hidden) meta key and updater function names and and normalize them where needed.

(Existing installs will need to run recounts, or let them adjust themselves naturally as new topics and replies come in.)

Location:
branches/plugin
Files:
10 edited

Legend:

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

    r3337 r3349  
    271271    $result    = __( 'Failed!', 'bbpress' );
    272272
    273     $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` = '_bbp_hidden_reply_count';";
     273    $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` = '_bbp_reply_count_hidden';";
    274274    if ( is_wp_error( $wpdb->query( $sql_delete ) ) )
    275275        return array( 1, sprintf( $statement, $result ) );
    276276
    277     $sql = "INSERT INTO `{$wpdb->postmeta}` (`post_id`, `meta_key`, `meta_value`) (SELECT `post_parent`, '_bbp_hidden_reply_count', COUNT(`post_status`) as `meta_value` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_reply_post_type() . "' AND `post_status` IN ( '" . join( "','", array( 'trash', $bbp->spam_status_id ) ) . "') GROUP BY `post_parent`);";
     277    $sql = "INSERT INTO `{$wpdb->postmeta}` (`post_id`, `meta_key`, `meta_value`) (SELECT `post_parent`, '_bbp_reply_count_hidden', COUNT(`post_status`) as `meta_value` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_reply_post_type() . "' AND `post_status` IN ( '" . join( "','", array( 'trash', $bbp->spam_status_id ) ) . "') GROUP BY `post_parent`);";
    278278    if ( is_wp_error( $wpdb->query( $sql ) ) )
    279279        return array( 2, sprintf( $statement, $result ) );
     
    301301    $result    = __( 'Failed!', 'bbpress' );
    302302
    303     $sql_delete = "DELETE FROM {$wpdb->postmeta} WHERE meta_key IN ( '_bbp_forum_topic_count', '_bbp_total_topic_count' );";
     303    $sql_delete = "DELETE FROM {$wpdb->postmeta} WHERE meta_key IN ( '_bbp_topic_count', '_bbp_total_topic_count' );";
    304304    if ( is_wp_error( $wpdb->query( $sql_delete ) ) )
    305305        return array( 1, sprintf( $statement, $result ) );
  • branches/plugin/bbp-admin/bbp-metaboxes.php

    r3348 r3349  
    144144            </tr>
    145145
    146             <?php if ( isset( $hidden_topic_count ) ) : ?>
     146            <?php if ( isset( $topic_count_hidden ) ) : ?>
    147147
    148148                <tr>
    149149
    150150                    <?php
    151                         $num  = $hidden_topic_count;
    152                         $text = _n( 'Hidden Topic', 'Hidden Topics', $hidden_topic_count, 'bbpress' );
     151                        $num  = $topic_count_hidden;
     152                        $text = _n( 'Hidden Topic', 'Hidden Topics', $topic_count_hidden, 'bbpress' );
    153153                        $link = add_query_arg( array( 'post_type' => bbp_get_topic_post_type() ), get_admin_url( null, 'edit.php' ) );
    154154                        $num  = '<a href="' . $link . '" title="' . esc_attr( $hidden_topic_title ) . '">' . $num  . '</a>';
     
    163163            <?php endif; ?>
    164164
    165             <?php if ( isset( $hidden_reply_count ) ) : ?>
     165            <?php if ( isset( $reply_count_hidden ) ) : ?>
    166166
    167167                <tr>
    168168
    169169                    <?php
    170                         $num  = $hidden_reply_count;
    171                         $text = _n( 'Hidden Reply', 'Hidden Replies', $hidden_reply_count, 'bbpress' );
     170                        $num  = $reply_count_hidden;
     171                        $text = _n( 'Hidden Reply', 'Hidden Replies', $reply_count_hidden, 'bbpress' );
    172172                        $link = add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), get_admin_url( null, 'edit.php' ) );
    173173                        $num  = '<a href="' . $link . '" title="' . esc_attr( $hidden_reply_title ) . '">' . $num  . '</a>';
  • branches/plugin/bbp-admin/importers/bbpress.php

    r3267 r3349  
    10721072                            update_post_meta( $inserted_topic, '_bbp_last_active_time',   $last_active_time );
    10731073                            update_post_meta( $inserted_topic, '_bbp_reply_count',        $replies          );
    1074                             update_post_meta( $inserted_topic, '_bbp_hidden_reply_count', $hidden_replies   );
     1074                            update_post_meta( $inserted_topic, '_bbp_reply_count_hidden', $hidden_replies   );
    10751075
    10761076                            // Voices will be done by recount
  • branches/plugin/bbp-includes/bbp-common-functions.php

    r3348 r3349  
    431431
    432432            // Total hidden (private + spam + trash)
    433             $hidden_topic_count = $topics['private'] + $topics['spammed'] + $topics['trashed'];
     433            $topic_count_hidden = $topics['private'] + $topics['spammed'] + $topics['trashed'];
    434434
    435435            // Generate the hidden topic count's title attribute
     
    463463
    464464            // Total hidden (private + spam + trash)
    465             $hidden_reply_count = $replies['private'] + $replies['spammed'] + $replies['trashed'];
     465            $reply_count_hidden = $replies['private'] + $replies['spammed'] + $replies['trashed'];
    466466
    467467            // Generate the hidden topic count's title attribute
     
    489489
    490490    // Tally the tallies
    491     $statistics = compact( 'user_count', 'forum_count', 'topic_count', 'hidden_topic_count', 'reply_count', 'hidden_reply_count', 'topic_tag_count', 'empty_topic_tag_count' );
     491    $statistics = compact( 'user_count', 'forum_count', 'topic_count', 'topic_count_hidden', 'reply_count', 'reply_count_hidden', 'topic_tag_count', 'empty_topic_tag_count' );
    492492    $statistics = array_map( 'absint',             $statistics );
    493493    $statistics = array_map( 'number_format_i18n', $statistics );
  • branches/plugin/bbp-includes/bbp-forum-functions.php

    r3310 r3349  
    1010// Exit if accessed directly
    1111if ( !defined( 'ABSPATH' ) ) exit;
     12
     13/** Insert ********************************************************************/
     14
     15/**
     16 * A wrapper for wp_insert_post() that also includes the necessary meta values
     17 * for the forum to function properly.
     18 *
     19 * @since bbPress (r3349)
     20 *
     21 * @uses wp_parse_args()
     22 * @uses bbp_get_forum_post_type()
     23 * @uses wp_insert_post()
     24 * @uses update_post_meta()
     25 *
     26 * @param array $forum_data Forum post data
     27 * @param arrap $forum_meta Forum meta data
     28 */
     29function bbp_insert_forum( $forum_data = array(), $forum_meta = array() ) {
     30
     31    // Forum
     32    $default_forum = array(
     33        'post_parent'   => 0, // forum ID
     34        'post_status'   => 'publish',
     35        'post_type'     => bbp_get_forum_post_type(),
     36        'post_author'   => 0,
     37        'post_password' => '',
     38        'post_content'  => '',
     39        'post_title'    => '',
     40        'menu_order'    => 0,
     41    );
     42
     43    // Parse args
     44    $forum_data = wp_parse_args( $forum_data, $default_forum );
     45
     46    // Insert forum
     47    $forum_id   = wp_insert_post( $forum_data );
     48
     49    // Bail if no forum was added
     50    if ( empty( $forum_id ) )
     51        return false;
     52
     53    // Forum meta
     54    $default_meta = array(
     55        'reply_count'          => 0,
     56        'topic_count'          => 0,
     57        'topic_count_hidden'   => 0,
     58        'total_reply_count'    => 0,
     59        'total_topic_count'    => 0,
     60        'last_topic_id'        => 0,
     61        'last_reply_id'        => 0,
     62        'last_active_id'       => 0,
     63        'last_active_time'     => 0,
     64        'forum_subforum_count' => 0,
     65    );
     66
     67    // Parse args
     68    $forum_meta = wp_parse_args( $forum_meta, $default_meta );
     69
     70    // Insert forum meta
     71    foreach ( $forum_meta as $meta_key => $meta_value )
     72        update_post_meta( $forum_id, '_bbp_' . $meta_key, $meta_value );
     73
     74    // Return new forum ID
     75    return $forum_id;
     76}
    1277
    1378/** Walk **********************************************************************/
     
    535600
    536601    // Update the count
    537     update_post_meta( $forum_id, '_bbp_forum_topic_count', (int) $topics       );
     602    update_post_meta( $forum_id, '_bbp_topic_count',      (int) $topics       );
    538603    update_post_meta( $forum_id, '_bbp_total_topic_count', (int) $total_topics );
    539604
     
    555620 * @uses wpdb::get_col() To execute our query and get the column back
    556621 * @uses update_post_meta() To update the forum hidden topic count meta
    557  * @uses apply_filters() Calls 'bbp_update_forum_hidden_topic_count' with the
     622 * @uses apply_filters() Calls 'bbp_update_forum_topic_count_hidden' with the
    558623 *                        hidden topic count and forum id
    559624 * @return int Topic hidden topic count
    560625 */
    561 function bbp_update_forum_hidden_topic_count( $forum_id = 0, $topic_count = 0 ) {
     626function bbp_update_forum_topic_count_hidden( $forum_id = 0, $topic_count = 0 ) {
    562627    global $wpdb, $bbp;
    563628
     
    583648    }
    584649
    585     return apply_filters( 'bbp_update_forum_hidden_topic_count', (int) $topic_count, $forum_id );
     650    return apply_filters( 'bbp_update_forum_topic_count_hidden', (int) $topic_count, $forum_id );
    586651}
    587652
     
    657722 * @uses bbp_update_forum_topic_count() To update the forum topic count
    658723 * @uses bbp_update_forum_reply_count() To update the forum reply count
    659  * @uses bbp_update_forum_hidden_topic_count() To update the hidden topic count
     724 * @uses bbp_update_forum_topic_count_hidden() To update the hidden topic count
    660725 */
    661726function bbp_update_forum( $args = '' ) {
     
    689754    bbp_update_forum_reply_count       ( $forum_id );
    690755    bbp_update_forum_topic_count       ( $forum_id );
    691     bbp_update_forum_hidden_topic_count( $forum_id );
     756    bbp_update_forum_topic_count_hidden( $forum_id );
    692757
    693758    // Update the parent forum if one was passed
  • branches/plugin/bbp-includes/bbp-forum-template.php

    r3344 r3349  
    10631063     * @uses bbp_get_forum_permalink() To get the forum permalink
    10641064     * @uses remove_query_arg() To remove args from the url
    1065      * @uses bbp_get_forum_hidden_topic_count() To get the forum hidden
     1065     * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden
    10661066     *                                           topic count
    10671067     * @uses current_user_can() To check if the current user can edit others
     
    10871087
    10881088        // This forum has hidden topics
    1089         if ( current_user_can( 'edit_others_topics' ) && ( $deleted = bbp_get_forum_hidden_topic_count( $forum_id ) ) ) {
     1089        if ( current_user_can( 'edit_others_topics' ) && ( $deleted = bbp_get_forum_topic_count_hidden( $forum_id ) ) ) {
    10901090
    10911091            // Extra text
     
    11621162    function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true ) {
    11631163        $forum_id = bbp_get_forum_id( $forum_id );
    1164         $topics   = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_forum_topic_count' : '_bbp_total_topic_count', true );
     1164        $topics   = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count', true );
    11651165
    11661166        return apply_filters( 'bbp_get_forum_topic_count', (int) $topics, $forum_id );
     
    12411241 *
    12421242 * @param int $forum_id Optional. Topic id
    1243  * @uses bbp_get_forum_hidden_topic_count() To get the forum hidden topic count
    1244  */
    1245 function bbp_forum_hidden_topic_count( $forum_id = 0 ) {
    1246     echo bbp_get_forum_hidden_topic_count( $forum_id );
     1243 * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden topic count
     1244 */
     1245function bbp_forum_topic_count_hidden( $forum_id = 0 ) {
     1246    echo bbp_get_forum_topic_count_hidden( $forum_id );
    12471247}
    12481248    /**
     
    12551255     * @uses bbp_get_forum_id() To get the forum id
    12561256     * @uses get_post_meta() To get the hidden topic count
    1257      * @uses apply_filters() Calls 'bbp_get_forum_hidden_topic_count' with
     1257     * @uses apply_filters() Calls 'bbp_get_forum_topic_count_hidden' with
    12581258     *                        the hidden topic count and forum id
    12591259     * @return int Topic hidden topic count
    12601260     */
    1261     function bbp_get_forum_hidden_topic_count( $forum_id = 0 ) {
     1261    function bbp_get_forum_topic_count_hidden( $forum_id = 0 ) {
    12621262        $forum_id = bbp_get_forum_id( $forum_id );
    12631263        $topics   = get_post_meta( $forum_id, '_bbp_topic_count_hidden', true );
    12641264
    1265         return apply_filters( 'bbp_get_forum_hidden_topic_count', (int) $topics, $forum_id );
     1265        return apply_filters( 'bbp_get_forum_topic_count_hidden', (int) $topics, $forum_id );
    12661266    }
    12671267
  • branches/plugin/bbp-includes/bbp-reply-functions.php

    r3348 r3349  
    1111if ( !defined( 'ABSPATH' ) ) exit;
    1212
    13 /**
    14  * Update the reply with its forum id it is in
    15  *
    16  * @since bbPress (r2855)
    17  *
    18  * @param int $reply_id Optional. Reply id to update
    19  * @param int $forum_id Optional. Forum id
    20  * @uses bbp_get_reply_id() To get the reply id
    21  * @uses bbp_get_forum_id() To get the forum id
    22  * @uses get_post_ancestors() To get the reply's forum
    23  * @uses get_post_field() To get the post type of the post
    24  * @uses update_post_meta() To update the reply forum id meta
    25  * @uses apply_filters() Calls 'bbp_update_reply_forum_id' with the forum id
    26  *                        and reply id
    27  * @return bool Reply's forum id
    28  */
    29 function bbp_update_reply_forum_id( $reply_id = 0, $forum_id = 0 ) {
    30 
    31     // Validation
    32     $reply_id = bbp_get_reply_id( $reply_id );
    33     $forum_id = bbp_get_forum_id( $forum_id );
    34 
    35     // If no forum_id was passed, walk up ancestors and look for forum type
    36     if ( empty( $forum_id ) ) {
    37 
    38         // Get ancestors
    39         $ancestors = get_post_ancestors( $reply_id );
    40 
    41         // Loop through ancestors
    42         foreach ( $ancestors as $ancestor ) {
    43 
    44             // Get first parent that is a forum
    45             if ( get_post_field( 'post_type', $ancestor ) == bbp_get_forum_post_type() ) {
    46                 $forum_id = $ancestor;
    47 
    48                 // Found a forum, so exit the loop and continue
    49                 continue;
    50             }
    51         }
    52     }
    53 
    54     // Update the forum ID
    55     bbp_update_forum_id( $reply_id, $forum_id );
    56 
    57     return apply_filters( 'bbp_update_reply_forum_id', (int) $forum_id, $reply_id );
    58 }
    59 
    60 /**
    61  * Update the reply with its topic id it is in
    62  *
    63  * @since bbPress (r2855)
    64  *
    65  * @param int $reply_id Optional. Reply id to update
    66  * @param int $topic_id Optional. Topic id
    67  * @uses bbp_get_reply_id() To get the reply id
    68  * @uses bbp_get_topic_id() To get the topic id
    69  * @uses get_post_ancestors() To get the reply's topic
    70  * @uses get_post_field() To get the post type of the post
    71  * @uses update_post_meta() To update the reply topic id meta
    72  * @uses apply_filters() Calls 'bbp_update_reply_topic_id' with the topic id
    73  *                        and reply id
    74  * @return bool Reply's topic id
    75  */
    76 function bbp_update_reply_topic_id( $reply_id = 0, $topic_id = 0 ) {
    77 
    78     // Validation
    79     $reply_id = bbp_get_reply_id( $reply_id );
    80     $topic_id = bbp_get_topic_id( $topic_id );
    81 
    82     // If no topic_id was passed, walk up ancestors and look for topic type
    83     if ( empty( $topic_id ) ) {
    84 
    85         // Get ancestors
    86         $ancestors = get_post_ancestors( $reply_id );
    87 
    88         // Loop through ancestors
    89         foreach ( $ancestors as $ancestor ) {
    90 
    91             // Get first parent that is a forum
    92             if ( get_post_field( 'post_type', $ancestor ) == bbp_get_topic_post_type() ) {
    93                 $topic_id = $ancestor;
    94 
    95                 // Found a forum, so exit the loop and continue
    96                 continue;
    97             }
    98         }
    99     }
    100 
    101     // Update the topic ID
    102     bbp_update_topic_id( $reply_id, $topic_id );
    103 
    104     return apply_filters( 'bbp_update_reply_topic_id', (int) $topic_id, $reply_id );
     13/** Insert ********************************************************************/
     14
     15/**
     16 * A wrapper for wp_insert_post() that also includes the necessary meta values
     17 * for the reply to function properly.
     18 *
     19 * @since bbPress (r3349)
     20 *
     21 * @uses wp_parse_args()
     22 * @uses bbp_get_reply_post_type()
     23 * @uses wp_insert_post()
     24 * @uses update_post_meta()
     25 *
     26 * @param array $reply_data Forum post data
     27 * @param arrap $reply_meta Forum meta data
     28 */
     29function bbp_insert_reply( $reply_data = array(), $reply_meta = array() ) {
     30
     31    // Forum
     32    $default_reply = array(
     33        'post_parent'   => 0, // topic ID
     34        'post_status'   => 'publish',
     35        'post_type'     => bbp_get_reply_post_type(),
     36        'post_author'   => 0,
     37        'post_password' => '',
     38        'post_content'  => '',
     39        'post_title'    => '',
     40        'menu_order'    => 0,
     41    );
     42
     43    // Parse args
     44    $reply_data = wp_parse_args( $reply_data, $default_reply );
     45
     46    // Insert reply
     47    $reply_id   = wp_insert_post( $reply_data );
     48
     49    // Bail if no reply was added
     50    if ( empty( $reply_id ) )
     51        return false;
     52
     53    // Forum meta
     54    $default_meta = array(
     55        'author_ip' => bbp_current_author_ip(),
     56        'forum_id'  => 0,
     57        'topic_id'  => 0,
     58    );
     59
     60    // Parse args
     61    $reply_meta = wp_parse_args( $reply_meta, $default_meta );
     62
     63    // Insert reply meta
     64    foreach ( $reply_meta as $meta_key => $meta_value )
     65        update_post_meta( $reply_id, '_bbp_' . $meta_key, $meta_value );
     66
     67    // Update the topic
     68    if ( $topic_id = bbp_get_reply_topic_id( $reply_id ) )
     69        bbp_update_topic( $topic_id );
     70
     71    // Return new reply ID
     72    return $reply_id;
    10573}
    10674
     
    688656 * @uses bbp_update_topic_voice_count() To update the topic voice count
    689657 * @uses bbp_update_topic_reply_count() To update the topic reply count
    690  * @uses bbp_update_topic_hidden_reply_count() To update the topic hidden reply
     658 * @uses bbp_update_topic_reply_count_hidden() To update the topic hidden reply
    691659 *                                              count
    692660 * @uses bbp_is_forum() To check if the ancestor is a forum
     
    748716            bbp_update_topic_voice_count       ( $ancestor );
    749717            bbp_update_topic_reply_count       ( $ancestor );
    750             bbp_update_topic_hidden_reply_count( $ancestor );
     718            bbp_update_topic_reply_count_hidden( $ancestor );
    751719
    752720        // Forum meta relating to most recent topic
     
    771739        }
    772740    }
     741}
     742
     743/** Reply Updaters ************************************************************/
     744
     745/**
     746 * Update the reply with its forum id it is in
     747 *
     748 * @since bbPress (r2855)
     749 *
     750 * @param int $reply_id Optional. Reply id to update
     751 * @param int $forum_id Optional. Forum id
     752 * @uses bbp_get_reply_id() To get the reply id
     753 * @uses bbp_get_forum_id() To get the forum id
     754 * @uses get_post_ancestors() To get the reply's forum
     755 * @uses get_post_field() To get the post type of the post
     756 * @uses update_post_meta() To update the reply forum id meta
     757 * @uses apply_filters() Calls 'bbp_update_reply_forum_id' with the forum id
     758 *                        and reply id
     759 * @return bool Reply's forum id
     760 */
     761function bbp_update_reply_forum_id( $reply_id = 0, $forum_id = 0 ) {
     762
     763    // Validation
     764    $reply_id = bbp_get_reply_id( $reply_id );
     765    $forum_id = bbp_get_forum_id( $forum_id );
     766
     767    // If no forum_id was passed, walk up ancestors and look for forum type
     768    if ( empty( $forum_id ) ) {
     769
     770        // Get ancestors
     771        $ancestors = get_post_ancestors( $reply_id );
     772
     773        // Loop through ancestors
     774        foreach ( $ancestors as $ancestor ) {
     775
     776            // Get first parent that is a forum
     777            if ( get_post_field( 'post_type', $ancestor ) == bbp_get_forum_post_type() ) {
     778                $forum_id = $ancestor;
     779
     780                // Found a forum, so exit the loop and continue
     781                continue;
     782            }
     783        }
     784    }
     785
     786    // Update the forum ID
     787    bbp_update_forum_id( $reply_id, $forum_id );
     788
     789    return apply_filters( 'bbp_update_reply_forum_id', (int) $forum_id, $reply_id );
     790}
     791
     792/**
     793 * Update the reply with its topic id it is in
     794 *
     795 * @since bbPress (r2855)
     796 *
     797 * @param int $reply_id Optional. Reply id to update
     798 * @param int $topic_id Optional. Topic id
     799 * @uses bbp_get_reply_id() To get the reply id
     800 * @uses bbp_get_topic_id() To get the topic id
     801 * @uses get_post_ancestors() To get the reply's topic
     802 * @uses get_post_field() To get the post type of the post
     803 * @uses update_post_meta() To update the reply topic id meta
     804 * @uses apply_filters() Calls 'bbp_update_reply_topic_id' with the topic id
     805 *                        and reply id
     806 * @return bool Reply's topic id
     807 */
     808function bbp_update_reply_topic_id( $reply_id = 0, $topic_id = 0 ) {
     809
     810    // Validation
     811    $reply_id = bbp_get_reply_id( $reply_id );
     812    $topic_id = bbp_get_topic_id( $topic_id );
     813
     814    // If no topic_id was passed, walk up ancestors and look for topic type
     815    if ( empty( $topic_id ) ) {
     816
     817        // Get ancestors
     818        $ancestors = get_post_ancestors( $reply_id );
     819
     820        // Loop through ancestors
     821        foreach ( $ancestors as $ancestor ) {
     822
     823            // Get first parent that is a forum
     824            if ( get_post_field( 'post_type', $ancestor ) == bbp_get_topic_post_type() ) {
     825                $topic_id = $ancestor;
     826
     827                // Found a forum, so exit the loop and continue
     828                continue;
     829            }
     830        }
     831    }
     832
     833    // Update the topic ID
     834    bbp_update_topic_id( $reply_id, $topic_id );
     835
     836    return apply_filters( 'bbp_update_reply_topic_id', (int) $topic_id, $reply_id );
    773837}
    774838
  • branches/plugin/bbp-includes/bbp-topic-functions.php

    r3348 r3349  
    1010// Exit if accessed directly
    1111if ( !defined( 'ABSPATH' ) ) exit;
     12
     13/** Insert ********************************************************************/
     14
     15/**
     16 * A wrapper for wp_insert_post() that also includes the necessary meta values
     17 * for the topic to function properly.
     18 *
     19 * @since bbPress (r3349)
     20 *
     21 * @uses wp_parse_args()
     22 * @uses bbp_get_topic_post_type()
     23 * @uses wp_insert_post()
     24 * @uses update_post_meta()
     25 *
     26 * @param array $topic_data Forum post data
     27 * @param arrap $topic_meta Forum meta data
     28 */
     29function bbp_insert_topic( $topic_data = array(), $topic_meta = array() ) {
     30
     31    // Forum
     32    $default_topic = array(
     33        'post_parent'   => 0, // forum ID
     34        'post_status'   => 'publish',
     35        'post_type'     => bbp_get_topic_post_type(),
     36        'post_author'   => 0,
     37        'post_password' => '',
     38        'post_content'  => '',
     39        'post_title'    => '',
     40        'menu_order'    => 0,
     41    );
     42
     43    // Parse args
     44    $topic_data = wp_parse_args( $topic_data, $default_topic );
     45
     46    // Insert topic
     47    $topic_id   = wp_insert_post( $topic_data );
     48
     49    // Bail if no topic was added
     50    if ( empty( $topic_id ) )
     51        return false;
     52
     53    // Forum meta
     54    $default_meta = array(
     55        'author_ip'          => bbp_current_author_ip(),
     56        'forum_id'           => 0,
     57        'topic_id'           => $topic_id,
     58        'voice_count'        => 1,
     59        'reply_count'        => 0,
     60        'reply_count_hidden' => 0,
     61        'last_reply_id'      => 0,
     62        'last_active_id'     => $topic_id,
     63        'last_active_time'   => get_post_field( 'post_date', $topic_id, 'db' ),
     64    );
     65
     66    // Parse args
     67    $topic_meta = wp_parse_args( $topic_meta, $default_meta );
     68
     69    // Insert topic meta
     70    foreach ( $topic_meta as $meta_key => $meta_value )
     71        update_post_meta( $topic_id, '_bbp_' . $meta_key, $meta_value );
     72
     73    // Update the forum
     74    if ( $forum_id = bbp_get_topic_forum_id( $topic_id ) )
     75        bbp_update_forum( $forum_id );
     76
     77    // Return new topic ID
     78    return $topic_id;
     79}
    1280
    1381/** Post Form Handlers ********************************************************/
     
    589657 * @uses bbp_update_topic_last_active_time() To update the last active topic meta
    590658 * @uses bbp_update_topic_reply_count() To update the topic reply count
    591  * @uses bbp_update_topic_hidden_reply_count() To udpate the topic hidden reply count
     659 * @uses bbp_update_topic_reply_count_hidden() To udpate the topic hidden reply count
    592660 * @uses bbp_update_topic_voice_count() To update the topic voice count
    593661 * @uses bbp_update_topic_walker() To udpate the topic's ancestors
     
    660728        bbp_update_topic_last_active_time   ( $topic_id, $last_active );
    661729        bbp_update_topic_reply_count        ( $topic_id, 0            );
    662         bbp_update_topic_hidden_reply_count ( $topic_id, 0            );
     730        bbp_update_topic_reply_count_hidden ( $topic_id, 0            );
    663731        bbp_update_topic_voice_count        ( $topic_id               );
    664732
     
    10301098 * @uses bbp_update_topic_reply_count() To update the topic reply counts
    10311099 * @uses bbp_update_topic_voice_count() To update the topic voice counts
    1032  * @uses bbp_update_topic_hidden_reply_count() To update the topic hidden reply
     1100 * @uses bbp_update_topic_reply_count_hidden() To update the topic hidden reply
    10331101 *                                              count
    10341102 * @uses do_action() Calls 'bbp_merge_topic_count' with the destination topic
     
    10511119
    10521120    // Topic Hidden Reply Counts
    1053     bbp_update_topic_hidden_reply_count( $destination_topic_id );
     1121    bbp_update_topic_reply_count_hidden( $destination_topic_id );
    10541122
    10551123    // Topic Voice Counts
     
    13391407 * @uses bbp_update_topic_reply_count() To update the topic reply counts
    13401408 * @uses bbp_update_topic_voice_count() To update the topic voice counts
    1341  * @uses bbp_update_topic_hidden_reply_count() To update the topic hidden reply
     1409 * @uses bbp_update_topic_reply_count_hidden() To update the topic hidden reply
    13421410 *                                              count
    13431411 * @uses do_action() Calls 'bbp_split_topic_count' with the from reply id,
     
    13571425
    13581426    // Topic Hidden Reply Counts
    1359     bbp_update_topic_hidden_reply_count( $source_topic_id      );
    1360     bbp_update_topic_hidden_reply_count( $destination_topic_id );
     1427    bbp_update_topic_reply_count_hidden( $source_topic_id      );
     1428    bbp_update_topic_reply_count_hidden( $destination_topic_id );
    13611429
    13621430    // Topic Voice Counts
     
    18961964 * @uses wpdb::get_var() To execute our query and get the var back
    18971965 * @uses update_post_meta() To update the topic hidden reply count meta
    1898  * @uses apply_filters() Calls 'bbp_update_topic_hidden_reply_count' with the
     1966 * @uses apply_filters() Calls 'bbp_update_topic_reply_count_hidden' with the
    18991967 *                        hidden reply count and topic id
    19001968 * @return int Topic hidden reply count
    19011969 */
    1902 function bbp_update_topic_hidden_reply_count( $topic_id = 0, $reply_count = 0 ) {
     1970function bbp_update_topic_reply_count_hidden( $topic_id = 0, $reply_count = 0 ) {
    19031971    global $wpdb, $bbp;
    19041972
     
    19131981        $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() ) );
    19141982
    1915     update_post_meta( $topic_id, '_bbp_hidden_reply_count', (int) $reply_count );
    1916 
    1917     return apply_filters( 'bbp_update_topic_hidden_reply_count', (int) $reply_count, $topic_id );
     1983    update_post_meta( $topic_id, '_bbp_reply_count_hidden', (int) $reply_count );
     1984
     1985    return apply_filters( 'bbp_update_topic_reply_count_hidden', (int) $reply_count, $topic_id );
    19181986}
    19191987
  • branches/plugin/bbp-includes/bbp-topic-template.php

    r3348 r3349  
    16061606     * @uses bbp_get_topic_permalink() To get the topic permalink
    16071607     * @uses remove_query_arg() To remove args from the url
    1608      * @uses bbp_get_topic_hidden_reply_count() To get the topic hidden
     1608     * @uses bbp_get_topic_reply_count_hidden() To get the topic hidden
    16091609     *                                           reply count
    16101610     * @uses current_user_can() To check if the current user can edit others
     
    16301630
    16311631        // This forum has hidden topics
    1632         if ( current_user_can( 'edit_others_replies' ) && ( $deleted = bbp_get_topic_hidden_reply_count( $topic_id ) ) ) {
     1632        if ( current_user_can( 'edit_others_replies' ) && ( $deleted = bbp_get_topic_reply_count_hidden( $topic_id ) ) ) {
    16331633
    16341634            // Extra text
     
    17141714 *
    17151715 * @param int $topic_id Optional. Topic id
    1716  * @uses bbp_get_topic_hidden_reply_count() To get the topic hidden reply count
    1717  */
    1718 function bbp_topic_hidden_reply_count( $topic_id = 0 ) {
    1719     echo bbp_get_topic_hidden_reply_count( $topic_id );
     1716 * @uses bbp_get_topic_reply_count_hidden() To get the topic hidden reply count
     1717 */
     1718function bbp_topic_reply_count_hidden( $topic_id = 0 ) {
     1719    echo bbp_get_topic_reply_count_hidden( $topic_id );
    17201720}
    17211721    /**
     
    17281728     * @uses bbp_get_topic_id() To get the topic id
    17291729     * @uses get_post_meta() To get the hidden reply count
    1730      * @uses apply_filters() Calls 'bbp_get_topic_hidden_reply_count' with
     1730     * @uses apply_filters() Calls 'bbp_get_topic_reply_count_hidden' with
    17311731     *                        the hidden reply count and topic id
    17321732     * @return int Topic hidden reply count
    17331733     */
    1734     function bbp_get_topic_hidden_reply_count( $topic_id = 0 ) {
     1734    function bbp_get_topic_reply_count_hidden( $topic_id = 0 ) {
    17351735        $topic_id = bbp_get_topic_id( $topic_id );
    1736         $replies  = get_post_meta( $topic_id, '_bbp_hidden_reply_count', true );
    1737 
    1738         return apply_filters( 'bbp_get_topic_hidden_reply_count', (int) $replies, $topic_id );
     1736        $replies  = get_post_meta( $topic_id, '_bbp_reply_count_hidden', true );
     1737
     1738        return apply_filters( 'bbp_get_topic_reply_count_hidden', (int) $replies, $topic_id );
    17391739    }
    17401740
  • branches/plugin/bbp-themes/bbp-twentyten/page-forum-statistics.php

    r3130 r3349  
    6767                                <?php endif; ?>
    6868
    69                                 <?php if ( !empty( $hidden_topic_count ) ) : ?>
     69                                <?php if ( !empty( $topic_count_hidden ) ) : ?>
    7070
    7171                                    <dt><?php _e( 'Hidden Topics', 'bbpress' ); ?></dt>
    7272                                    <dd>
    7373                                        <strong>
    74                                             <abbr title="<?php echo esc_attr( $hidden_topic_title ); ?>"><?php echo $hidden_topic_count; ?></abbr>
     74                                            <abbr title="<?php echo esc_attr( $hidden_topic_title ); ?>"><?php echo $topic_count_hidden; ?></abbr>
    7575                                        </strong>
    7676                                    </dd>
     
    7878                                <?php endif; ?>
    7979
    80                                 <?php if ( !empty( $hidden_reply_count ) ) : ?>
     80                                <?php if ( !empty( $reply_count_hidden ) ) : ?>
    8181
    8282                                    <dt><?php _e( 'Hidden Replies', 'bbpress' ); ?></dt>
    8383                                    <dd>
    8484                                        <strong>
    85                                             <abbr title="<?php echo esc_attr( $hidden_reply_title ); ?>"><?php echo $hidden_reply_count; ?></abbr>
     85                                            <abbr title="<?php echo esc_attr( $hidden_reply_title ); ?>"><?php echo $reply_count_hidden; ?></abbr>
    8686                                        </strong>
    8787                                    </dd>
Note: See TracChangeset for help on using the changeset viewer.