Skip to:
Content

bbPress.org


Ignore:
Timestamp:
06/27/2011 10:18:38 AM (11 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.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.