Skip to:
Content

bbPress.org


Ignore:
Timestamp:
03/26/2012 07:36:47 AM (12 years ago)
Author:
johnjamesjacoby
Message:

Add 'bump' functions for forum, topic, reply, and voice counts.

  • Functions not used yet
  • See #1799
File:
1 edited

Legend:

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

    r3799 r3826  
    951951}
    952952
     953/** Count Bumpers *************************************************************/
     954
     955/**
     956 * Bump the total topic count of a forum
     957 *
     958 * @since bbPress (r3825)
     959 *
     960 * @param int $forum_id Optional. Forum id.
     961 * @param int $difference Optional. Default 1
     962 * @param bool $update_ancestors Optional. Default true
     963 * @uses bbp_get_forum_id() To get the forum id
     964 * @uses update_post_meta() To update the forum's topic count meta
     965 * @uses apply_filters() Calls 'bbp_bump_forum_topic_count' with the topic
     966 *                        count, forum id, and difference
     967 * @return int Forum topic count
     968 */
     969function bbp_bump_forum_topic_count( $forum_id = 0, $difference = 1, $update_ancestors = true ) {
     970
     971    // Get some counts
     972    $forum_id          = bbp_get_forum_id( $forum_id );
     973    $topic_count       = bbp_get_forum_topic_count( $forum_id, false );
     974    $total_topic_count = bbp_get_forum_topic_count( $forum_id, true  );
     975
     976    // Update this forum id
     977    update_post_meta( $forum_id, '_bbp_topic_count',       (int) $topic_count       + (int) $difference );
     978    update_post_meta( $forum_id, '_bbp_total_topic_count', (int) $total_topic_count + (int) $difference );
     979
     980    // Check for ancestors
     981    if ( true === $update_ancestors ) {
     982
     983        // Get post ancestors
     984        $forum     = get_post( $forum_id );
     985        $ancestors = get_post_ancestors( $forum );
     986
     987        // If has ancestors, loop through them...
     988        if ( !empty( $ancestors ) ) {
     989            foreach ( (array) $ancestors as $parent_forum_id ) {
     990
     991                // Get forum counts
     992                $parent_topic_count       = bbp_get_forum_topic_count( $parent_forum_id, false );
     993                $parent_total_topic_count = bbp_get_forum_topic_count( $parent_forum_id, true  );
     994
     995                // Update counts
     996                update_post_meta( $parent_forum_id, '_bbp_topic_count',       (int) $parent_topic_count       + (int) $difference );
     997                update_post_meta( $parent_forum_id, '_bbp_total_topic_count', (int) $parent_total_topic_count + (int) $difference );
     998            }
     999        }
     1000    }
     1001
     1002    return (int) apply_filters( 'bbp_bump_forum_topic_count', (int) $total_topic_count + (int) $difference, $forum_id, (int) $difference, (bool) $update_ancestors );
     1003}
     1004
     1005/**
     1006 * Bump the total hidden topic count of a forum
     1007 *
     1008 * @since bbPress (r3825)
     1009 *
     1010 * @param int $forum_id Optional. Forum id.
     1011 * @param int $difference Optional. Default 1
     1012 * @uses bbp_get_forum_id() To get the forum id
     1013 * @uses update_post_meta() To update the forum's topic count meta
     1014 * @uses apply_filters() Calls 'bbp_bump_forum_topic_count_hidden' with the
     1015 *                        topic count, forum id, and difference
     1016 * @return int Forum hidden topic count
     1017 */
     1018function bbp_bump_forum_topic_count_hidden( $forum_id = 0, $difference = 1 ) {
     1019
     1020    // Get some counts
     1021    $forum_id    = bbp_get_forum_id( $forum_id );
     1022    $topic_count = bbp_get_forum_topic_count_hidden( $forum_id, false );
     1023    $new_count   = (int) $topic_count + (int) $difference;
     1024
     1025    // Update this forum id
     1026    update_post_meta( $forum_id, '_bbp_topic_count_hidden', (int) $new_count );
     1027
     1028    return (int) apply_filters( 'bbp_bump_forum_topic_count_hidden', (int) $new_count, $forum_id, (int) $difference );
     1029}
     1030
     1031/**
     1032 * Bump the total topic count of a forum
     1033 *
     1034 * @since bbPress (r3825)
     1035 *
     1036 * @param int $forum_id Optional. Forum id.
     1037 * @param int $difference Optional. Default 1
     1038 * @param bool $update_ancestors Optional. Default true
     1039 * @uses bbp_get_forum_id() To get the forum id
     1040 * @uses update_post_meta() To update the forum's topic count meta
     1041 * @uses apply_filters() Calls 'bbp_bump_forum_reply_count' with the topic
     1042 *                        count, forum id, and difference
     1043 * @return int Forum topic count
     1044 */
     1045function bbp_bump_forum_reply_count( $forum_id = 0, $difference = 1, $update_ancestors = true ) {
     1046
     1047    // Get some counts
     1048    $forum_id          = bbp_get_forum_id( $forum_id );
     1049    $topic_count       = bbp_get_forum_reply_count( $forum_id, false );
     1050    $total_reply_count = bbp_get_forum_reply_count( $forum_id, true  );
     1051
     1052    // Update this forum id
     1053    update_post_meta( $forum_id, '_bbp_reply_count',       (int) $topic_count       + (int) $difference );
     1054    update_post_meta( $forum_id, '_bbp_total_reply_count', (int) $total_reply_count + (int) $difference );
     1055
     1056    // Check for ancestors
     1057    if ( true === $update_ancestors ) {
     1058
     1059        // Get post ancestors
     1060        $forum     = get_post( $forum_id );
     1061        $ancestors = get_post_ancestors( $forum );
     1062
     1063        // If has ancestors, loop through them...
     1064        if ( !empty( $ancestors ) ) {
     1065            foreach ( (array) $ancestors as $parent_forum_id ) {
     1066
     1067                // Get forum counts
     1068                $parent_topic_count       = bbp_get_forum_reply_count( $parent_forum_id, false );
     1069                $parent_total_reply_count = bbp_get_forum_reply_count( $parent_forum_id, true  );
     1070
     1071                // Update counts
     1072                update_post_meta( $parent_forum_id, '_bbp_reply_count',       (int) $parent_topic_count       + (int) $difference );
     1073                update_post_meta( $parent_forum_id, '_bbp_total_reply_count', (int) $parent_total_reply_count + (int) $difference );
     1074            }
     1075        }
     1076    }
     1077
     1078    return (int) apply_filters( 'bbp_bump_forum_reply_count', (int) $total_reply_count + (int) $difference, $forum_id, (int) $difference, (bool) $update_ancestors );
     1079}
     1080
    9531081/** Forum Updaters ************************************************************/
    9541082
Note: See TracChangeset for help on using the changeset viewer.