Skip to:
Content

bbPress.org

Ticket #1799: 1799.15.diff

File 1799.15.diff, 88.5 KB (added by thebrandonallen, 5 years ago)
  • src/bbpress.php

    diff --git src/bbpress.php src/bbpress.php
    index d56c58d..305eb1d 100644
    final class bbPress { 
    293293
    294294                /** Misc **************************************************************/
    295295
    296                 $this->domain         = 'bbpress';      // Unique identifier for retrieving translated strings
    297                 $this->extend         = new stdClass(); // Plugins add data here
    298                 $this->errors         = new WP_Error(); // Feedback
     296                $this->domain             = 'bbpress';      // Unique identifier for retrieving translated strings
     297                $this->extend             = new stdClass(); // Plugins add data here
     298                $this->errors             = new WP_Error(); // Feedback
     299                $this->transitioned_posts = array();        // Transitioned post ids.
    299300
    300301                /** Deprecated ********************************************************/
    301302
  • src/includes/admin/forums.php

    diff --git src/includes/admin/forums.php src/includes/admin/forums.php
    index 3c3f2c0..2229000 100644
    class BBP_Forums_Admin { 
    7575                add_action( 'add_meta_boxes', array( $this, 'comments_metabox'      ) );
    7676                add_action( 'save_post',      array( $this, 'save_meta_boxes'       ) );
    7777
     78                // Transitioned forum actions.
     79                add_action( 'save_post', 'bbp_transitioned_forum_status_new_public',    20 );
     80                add_action( 'save_post', 'bbp_transitioned_forum_status_new_moderated', 20 );
     81                add_action( 'save_post', 'bbp_transitioned_forum_status_public',        20 );
     82                add_action( 'save_post', 'bbp_transitioned_forum_status_moderated',     20 );
     83
    7884                // Check if there are any bbp_toggle_forum_* requests on admin_init, also have a message displayed
    7985                add_action( 'load-edit.php',  array( $this, 'toggle_forum'        ) );
    8086                add_action( 'admin_notices',  array( $this, 'toggle_forum_notice' ) );
  • src/includes/admin/replies.php

    diff --git src/includes/admin/replies.php src/includes/admin/replies.php
    index cce5647..aa35785 100644
    class BBP_Replies_Admin { 
    8282                add_action( 'add_meta_boxes', array( $this, 'comments_metabox'   ) );
    8383                add_action( 'save_post',      array( $this, 'save_meta_boxes'    ) );
    8484
     85                // Transitioned reply actions.
     86                add_action( 'save_post', 'bbp_transitioned_reply_status_new_public',    20 );
     87                add_action( 'save_post', 'bbp_transitioned_reply_status_new_moderated', 20 );
     88                add_action( 'save_post', 'bbp_transitioned_reply_status_public',        20 );
     89                add_action( 'save_post', 'bbp_transitioned_reply_status_moderated',     20 );
     90
    8591                // Check if there are any bbp_toggle_reply_* requests on admin_init, also have a message displayed
    8692                add_action( 'load-edit.php',  array( $this, 'toggle_reply'        ) );
    8793                add_action( 'admin_notices',  array( $this, 'toggle_reply_notice' ) );
  • src/includes/admin/topics.php

    diff --git src/includes/admin/topics.php src/includes/admin/topics.php
    index e9d2a83..b9bbfc4 100644
    class BBP_Topics_Admin { 
    8686                add_action( 'add_meta_boxes', array( $this, 'comments_metabox'      ) );
    8787                add_action( 'save_post',      array( $this, 'save_meta_boxes'       ) );
    8888
     89                // Transitioned topic actions.
     90                add_action( 'save_post', 'bbp_transitioned_topic_status_new_public',    20 );
     91                add_action( 'save_post', 'bbp_transitioned_topic_status_new_moderated', 20 );
     92                add_action( 'save_post', 'bbp_transitioned_topic_status_public',        20 );
     93                add_action( 'save_post', 'bbp_transitioned_topic_status_moderated',     20 );
     94
    8995                // Check if there are any bbp_toggle_topic_* requests on admin_init, also have a message displayed
    9096                add_action( 'load-edit.php',  array( $this, 'toggle_topic'        ) );
    9197                add_action( 'admin_notices',  array( $this, 'toggle_topic_notice' ) );
  • src/includes/common/functions.php

    diff --git src/includes/common/functions.php src/includes/common/functions.php
    index ccaa650..87fd19c 100644
    function bbp_set_404() { 
    19531953
    19541954        $wp_query->set_404();
    19551955}
     1956
     1957/** Statuses ******************************************************************/
     1958
     1959/**
     1960 * Store the transitioned forum/topic/reply id along with it's transitioned
     1961 * status (new/public/moderated).
     1962 *
     1963 * @since x.x.x bbPress (rXXXX)
     1964 *
     1965 * @param int    $post_id The forum/topic/reply id.
     1966 * @param string $status  The transition status. Expects new/public/moderated.
     1967 *
     1968 * @return void
     1969 */
     1970function bbp_store_transitioned_post_id( $post_id = 0, $status = '' ) {
     1971
     1972        // Bail if we don't have all the necessary data.
     1973        if ( empty( $post_id ) || empty( $status ) ) {
     1974                return;
     1975        }
     1976
     1977        // Grab the globals.
     1978        $bbp                = bbpress();
     1979        $transitioned_posts = (array) $bbp->transitioned_posts;
     1980
     1981        // Store the transitioned post.
     1982        $transitioned_posts[ $post_id ] = $status;
     1983
     1984        // Add the new array back to the bbPress::transitioned_posts.
     1985        $bbp->transitioned_posts = $transitioned_posts;
     1986}
     1987
     1988/**
     1989 * Returns the transitioned post status.
     1990 *
     1991 * @since x.x.x bbPress (rXXXX)
     1992 *
     1993 * @param int $post_id The forum/topic/reply id.
     1994 *
     1995 * @return string new/public/moderated. Empty on failure.
     1996 */
     1997function bbp_get_post_transitioned_status( $post_id = 0 ) {
     1998
     1999        // The bbPress global.
     2000        $bbp = bbpress();
     2001
     2002        // Get the transitioned post status.
     2003        $status = empty( $bbp->transitioned_posts[ $post_id ] )
     2004                          ? ''
     2005                          : $bbp->transitioned_posts[ $post_id ];
     2006
     2007        /**
     2008         * Filters the return of `bbp_get_post_transitioned_status()`.
     2009         *
     2010         * @since x.x.x bbPress (rXXXX)
     2011         *
     2012         * @param string $status  new/public/moderated. Empty on failure.
     2013         * @param int    $post_id The forum/topic/reply id.
     2014         */
     2015        return apply_filters( 'bbp_get_post_transitioned_status', $status, $post_id );
     2016}
     2017
     2018/**
     2019 * Checks if a given post id was transitioned to new public.
     2020 *
     2021 * @since x.x.x bbPress (rXXXX)
     2022 *
     2023 * @param int $post_id The forum/topic/reply id.
     2024 *
     2025 * @return bool True if the post id was transitioned to new public.
     2026 */
     2027function bbp_is_post_transitioned_new_public( $post_id = 0 ) {
     2028
     2029        // Default to false.
     2030        $retval = false;
     2031
     2032        if ( 'new_public' === bbp_get_post_transitioned_status( $post_id ) ) {
     2033                $retval = true;
     2034        }
     2035
     2036        /**
     2037         * Filters the return of `bbp_is_post_transitioned_new_public()`.
     2038         *
     2039         * @since x.x.x bbPress (rXXXX)
     2040         *
     2041         * @param bool $retval  True if the post was transitioned to new public.
     2042         * @param int  $post_id The forum/topic/reply id.
     2043         */
     2044        return apply_filters( 'bbp_is_post_transitioned_new_public', $retval, $post_id );
     2045}
     2046
     2047/**
     2048 * Checks if a given post id was transitioned to new moderated.
     2049 *
     2050 * @since x.x.x bbPress (rXXXX)
     2051 *
     2052 * @param int $post_id The forum/topic/reply id.
     2053 *
     2054 * @return bool True if the post id was transitioned to new moderated.
     2055 */
     2056function bbp_is_post_transitioned_new_moderated( $post_id = 0 ) {
     2057
     2058        // Default to false.
     2059        $retval = false;
     2060
     2061        if ( 'new_moderated' === bbp_get_post_transitioned_status( $post_id ) ) {
     2062                $retval = true;
     2063        }
     2064
     2065        /**
     2066         * Filters the return of `bbp_is_post_transitioned_new_moderated()`.
     2067         *
     2068         * @since x.x.x bbPress (rXXXX)
     2069         *
     2070         * @param bool $retval  True if the post was transitioned to new moderated.
     2071         * @param int  $post_id The forum/topic/reply id.
     2072         */
     2073        return apply_filters( 'bbp_is_post_transitioned_new_moderated', $retval, $post_id );
     2074}
     2075
     2076/**
     2077 * Checks if a given post id was transitioned public.
     2078 *
     2079 * @since x.x.x bbPress (rXXXX)
     2080 *
     2081 * @param int $post_id The forum/topic/reply id.
     2082 *
     2083 * @return bool True if the post id was transitioned public.
     2084 */
     2085function bbp_is_post_transitioned_public( $post_id = 0 ) {
     2086
     2087        // Default to false.
     2088        $retval = false;
     2089
     2090        if ( 'public' === bbp_get_post_transitioned_status( $post_id ) ) {
     2091                $retval = true;
     2092        }
     2093
     2094        /**
     2095         * Filters the return of `bbp_is_post_transitioned_public()`.
     2096         *
     2097         * @since x.x.x bbPress (rXXXX)
     2098         *
     2099         * @param bool $retval  True if the post was transitioned public.
     2100         * @param int  $post_id The forum/topic/reply id.
     2101         */
     2102        return apply_filters( 'bbp_is_post_transitioned_public', $retval, $post_id );
     2103}
     2104
     2105/**
     2106 * Checks if a given post id was transitioned moderated.
     2107 *
     2108 * @since x.x.x bbPress (rXXXX)
     2109 *
     2110 * @param int $post_id The forum/topic/reply id.
     2111 *
     2112 * @return bool True if the post id was transitioned moderated.
     2113 */
     2114function bbp_is_post_transitioned_moderated( $post_id = 0 ) {
     2115
     2116        // Default to false.
     2117        $retval = false;
     2118
     2119        if ( 'moderated' === bbp_get_post_transitioned_status( $post_id ) ) {
     2120                $retval = true;
     2121        }
     2122
     2123        /**
     2124         * Filters the return of `bbp_is_post_transitioned_moderated()`.
     2125         *
     2126         * @since x.x.x bbPress (rXXXX)
     2127         *
     2128         * @param bool $retval  True if the post was transitioned moderated.
     2129         * @param int  $post_id The forum/topic/reply id.
     2130         */
     2131        return apply_filters( 'bbp_is_post_transitioned_moderated', $retval, $post_id );
     2132}
  • src/includes/core/actions.php

    diff --git src/includes/core/actions.php src/includes/core/actions.php
    index 1dbf139..07d216d 100644
    add_action( 'trashed_post', 'bbp_trashed_forum' ); 
    164164add_action( 'untrashed_post', 'bbp_untrashed_forum' );
    165165add_action( 'deleted_post',   'bbp_deleted_forum'   );
    166166
     167// Transition forum status.
     168add_action( 'transition_post_status',      'bbp_transition_forum_status',               10, 3 );
     169add_action( 'bbp_transition_forum_status', 'bbp_transition_forum_status_new_public',    10, 3 );
     170add_action( 'bbp_transition_forum_status', 'bbp_transition_forum_status_new_moderated', 10, 3 );
     171add_action( 'bbp_transition_forum_status', 'bbp_transition_forum_status_public',        10, 3 );
     172add_action( 'bbp_transition_forum_status', 'bbp_transition_forum_status_moderated',     10, 3 );
     173
     174// Transitioned forum status.
     175add_action( 'bbp_new_forum',       'bbp_transitioned_forum_status_new_public',    20 );
     176add_action( 'bbp_new_forum',       'bbp_transitioned_forum_status_new_moderated', 20 );
     177add_action( 'bbp_insert_forum',    'bbp_transitioned_forum_status_new_public',    20 );
     178add_action( 'bbp_insert_forum',    'bbp_transitioned_forum_status_new_moderated', 20 );
     179add_action( 'bbp_trashed_forum',   'bbp_transitioned_forum_status_moderated',     20 );
     180add_action( 'bbp_untrashed_forum', 'bbp_transitioned_forum_status_public',        20 );
     181
    167182// Auto trash/untrash/delete a forums topics
    168183add_action( 'bbp_delete_forum',  'bbp_delete_forum_topics',  10 );
    169184add_action( 'bbp_trash_forum',   'bbp_trash_forum_topics',   10 );
    add_action( 'trashed_post', 'bbp_trashed_reply' ); 
    193208add_action( 'untrashed_post', 'bbp_untrashed_reply' );
    194209add_action( 'deleted_post',   'bbp_deleted_reply'   );
    195210
     211// Transition reply status.
     212add_action( 'transition_post_status',      'bbp_transition_reply_status',               10, 3 );
     213add_action( 'bbp_transition_reply_status', 'bbp_transition_reply_status_new_public',    10, 3 );
     214add_action( 'bbp_transition_reply_status', 'bbp_transition_reply_status_new_moderated', 10, 3 );
     215add_action( 'bbp_transition_reply_status', 'bbp_transition_reply_status_public',        10, 3 );
     216add_action( 'bbp_transition_reply_status', 'bbp_transition_reply_status_moderated',     10, 3 );
     217
     218// Transitioned reply status.
     219add_action( 'bbp_new_reply',        'bbp_transitioned_reply_status_new_public',    20 );
     220add_action( 'bbp_new_reply',        'bbp_transitioned_reply_status_new_moderated', 20 );
     221add_action( 'bbp_insert_reply',     'bbp_transitioned_reply_status_new_public',    20 );
     222add_action( 'bbp_insert_reply',     'bbp_transitioned_reply_status_new_moderated', 20 );
     223add_action( 'bbp_trashed_reply',    'bbp_transitioned_reply_status_moderated',     20 );
     224add_action( 'bbp_untrashed_reply',  'bbp_transitioned_reply_status_public',        20 );
     225add_action( 'bbp_spammed_reply',    'bbp_transitioned_reply_status_moderated',     20 );
     226add_action( 'bbp_unspammed_reply',  'bbp_transitioned_reply_status_public',        20 );
     227add_action( 'bbp_approved_reply',   'bbp_transitioned_reply_status_public',        20 );
     228add_action( 'bbp_unapproved_reply', 'bbp_transitioned_reply_status_moderated',     20 );
     229
    196230// New/Edit Topic
    197231add_action( 'bbp_new_topic',  'bbp_update_topic', 10, 5 );
    198232add_action( 'bbp_edit_topic', 'bbp_update_topic', 10, 5 );
    add_action( 'trashed_post', 'bbp_trashed_topic' ); 
    215249add_action( 'untrashed_post', 'bbp_untrashed_topic' );
    216250add_action( 'deleted_post',   'bbp_deleted_topic'   );
    217251
     252// Transition topic status.
     253add_action( 'transition_post_status',      'bbp_transition_topic_status',               10, 3 );
     254add_action( 'bbp_transition_topic_status', 'bbp_transition_topic_status_new_public',    10, 3 );
     255add_action( 'bbp_transition_topic_status', 'bbp_transition_topic_status_new_moderated', 10, 3 );
     256add_action( 'bbp_transition_topic_status', 'bbp_transition_topic_status_public',        10, 3 );
     257add_action( 'bbp_transition_topic_status', 'bbp_transition_topic_status_moderated',     10, 3 );
     258
     259// Transitioned topic status.
     260add_action( 'bbp_new_topic',        'bbp_transitioned_topic_status_new_public',    20 );
     261add_action( 'bbp_new_topic',        'bbp_transitioned_topic_status_new_moderated', 20 );
     262add_action( 'bbp_insert_topic',     'bbp_transitioned_topic_status_new_public',    20 );
     263add_action( 'bbp_insert_topic',     'bbp_transitioned_topic_status_new_moderated', 20 );
     264add_action( 'bbp_trashed_topic',    'bbp_transitioned_topic_status_moderated',     20 );
     265add_action( 'bbp_untrashed_topic',  'bbp_transitioned_topic_status_public',        20 );
     266add_action( 'bbp_spammed_topic',    'bbp_transitioned_topic_status_moderated',     20 );
     267add_action( 'bbp_unspammed_topic',  'bbp_transitioned_topic_status_public',        20 );
     268add_action( 'bbp_approved_topic',   'bbp_transitioned_topic_status_public',        20 );
     269add_action( 'bbp_unapproved_topic', 'bbp_transitioned_topic_status_moderated',     20 );
     270
    218271// Favorites
    219272add_action( 'bbp_spam_topic',   'bbp_remove_topic_from_all_favorites' );
    220273add_action( 'bbp_trash_topic',  'bbp_remove_topic_from_all_favorites' );
    add_action( 'bbp_approved_reply', 'bbp_update_reply_walker' ); 
    253306add_action( 'bbp_unapproved_reply', 'bbp_update_reply_walker' );
    254307
    255308// Update forum topic/reply counts.
    256 add_action( 'bbp_new_reply',        'bbp_increase_forum_reply_count'        );
    257 add_action( 'bbp_new_topic',        'bbp_increase_forum_topic_count'        );
    258 add_action( 'bbp_trashed_reply',    'bbp_decrease_forum_reply_count'        );
    259 add_action( 'bbp_trashed_topic',    'bbp_decrease_forum_topic_count'        );
    260 add_action( 'bbp_trashed_topic',    'bbp_increase_forum_topic_count_hidden' );
    261 add_action( 'bbp_untrashed_reply',  'bbp_increase_forum_reply_count'        );
    262 add_action( 'bbp_untrashed_topic',  'bbp_increase_forum_topic_count'        );
    263 add_action( 'bbp_untrashed_topic',  'bbp_decrease_forum_topic_count_hidden' );
    264 add_action( 'bbp_spammed_reply',    'bbp_decrease_forum_reply_count'        );
    265 add_action( 'bbp_spammed_topic',    'bbp_decrease_forum_topic_count'        );
    266 add_action( 'bbp_spammed_topic',    'bbp_increase_forum_topic_count_hidden' );
    267 add_action( 'bbp_unspammed_reply',  'bbp_increase_forum_reply_count'        );
    268 add_action( 'bbp_unspammed_topic',  'bbp_increase_forum_topic_count'        );
    269 add_action( 'bbp_unspammed_topic',  'bbp_decrease_forum_topic_count_hidden' );
    270 add_action( 'bbp_approved_reply',   'bbp_increase_forum_reply_count'        );
    271 add_action( 'bbp_approved_topic',   'bbp_increase_forum_topic_count'        );
    272 add_action( 'bbp_approved_topic',   'bbp_decrease_forum_topic_count_hidden' );
    273 add_action( 'bbp_unapproved_reply', 'bbp_decrease_forum_reply_count'        );
    274 add_action( 'bbp_unapproved_topic', 'bbp_decrease_forum_topic_count'        );
    275 add_action( 'bbp_unapproved_topic', 'bbp_increase_forum_topic_count_hidden' );
     309add_action( 'bbp_transitioned_reply_status_new_public',    'bbp_increase_forum_reply_count'        );
     310add_action( 'bbp_transitioned_reply_status_public',        'bbp_increase_forum_reply_count'        );
     311add_action( 'bbp_transitioned_reply_status_moderated',     'bbp_decrease_forum_reply_count'        );
     312add_action( 'bbp_transitioned_topic_status_new_public',    'bbp_increase_forum_topic_count'        );
     313add_action( 'bbp_transitioned_topic_status_new_moderated', 'bbp_increase_forum_topic_count_hidden' );
     314add_action( 'bbp_transitioned_topic_status_public',        'bbp_increase_forum_topic_count'        );
     315add_action( 'bbp_transitioned_topic_status_public',        'bbp_decrease_forum_topic_count_hidden' );
     316add_action( 'bbp_transitioned_topic_status_moderated',     'bbp_decrease_forum_topic_count'        );
     317add_action( 'bbp_transitioned_topic_status_moderated',     'bbp_increase_forum_topic_count_hidden' );
    276318
    277319// Update forum reply counts for approved/unapproved topics.
    278320add_action( 'bbp_approved_topic',   'bbp_approved_unapproved_topic_update_forum_reply_count' );
    279321add_action( 'bbp_unapproved_topic', 'bbp_approved_unapproved_topic_update_forum_reply_count' );
    280322
    281323// Update topic reply counts.
    282 add_action( 'bbp_new_reply',        'bbp_increase_topic_reply_count'        );
    283 add_action( 'bbp_trashed_reply',    'bbp_decrease_topic_reply_count'        );
    284 add_action( 'bbp_trashed_reply',    'bbp_increase_topic_reply_count_hidden' );
    285 add_action( 'bbp_untrashed_reply',  'bbp_increase_topic_reply_count'        );
    286 add_action( 'bbp_untrashed_reply',  'bbp_decrease_topic_reply_count_hidden' );
    287 add_action( 'bbp_spammed_reply',    'bbp_decrease_topic_reply_count'        );
    288 add_action( 'bbp_spammed_reply',    'bbp_increase_topic_reply_count_hidden' );
    289 add_action( 'bbp_unspammed_reply',  'bbp_increase_topic_reply_count'        );
    290 add_action( 'bbp_unspammed_reply',  'bbp_decrease_topic_reply_count_hidden' );
    291 add_action( 'bbp_approved_reply',   'bbp_increase_topic_reply_count'        );
    292 add_action( 'bbp_approved_reply',   'bbp_decrease_topic_reply_count_hidden' );
    293 add_action( 'bbp_unapproved_reply', 'bbp_decrease_topic_reply_count'        );
    294 add_action( 'bbp_unapproved_reply', 'bbp_increase_topic_reply_count_hidden' );
     324add_action( 'bbp_transitioned_reply_status_new_public',    'bbp_increase_topic_reply_count'        );
     325add_action( 'bbp_transitioned_reply_status_new_moderated', 'bbp_increase_topic_reply_count_hidden' );
     326add_action( 'bbp_transitioned_reply_status_public',        'bbp_increase_topic_reply_count'        );
     327add_action( 'bbp_transitioned_reply_status_public',        'bbp_decrease_topic_reply_count_hidden' );
     328add_action( 'bbp_transitioned_reply_status_moderated',     'bbp_decrease_topic_reply_count'        );
     329add_action( 'bbp_transitioned_reply_status_moderated',     'bbp_increase_topic_reply_count_hidden' );
    295330
    296331// Users topic & reply counts.
    297 add_action( 'bbp_new_topic',     'bbp_increase_user_topic_count' );
    298 add_action( 'bbp_new_reply',     'bbp_increase_user_reply_count' );
    299 add_action( 'bbp_untrash_topic', 'bbp_increase_user_topic_count' );
    300 add_action( 'bbp_untrash_reply', 'bbp_increase_user_reply_count' );
    301 add_action( 'bbp_unspam_topic',  'bbp_increase_user_topic_count' );
    302 add_action( 'bbp_unspam_reply',  'bbp_increase_user_reply_count' );
    303 add_action( 'bbp_trash_topic',   'bbp_decrease_user_topic_count' );
    304 add_action( 'bbp_trash_reply',   'bbp_decrease_user_reply_count' );
    305 add_action( 'bbp_spam_topic',    'bbp_decrease_user_topic_count' );
    306 add_action( 'bbp_spam_reply',    'bbp_decrease_user_reply_count' );
    307 
    308 // Insert topic/reply counts.
    309 add_action( 'bbp_insert_topic', 'bbp_insert_topic_update_counts', 10, 2 );
    310 add_action( 'bbp_insert_reply', 'bbp_insert_reply_update_counts', 10, 3 );
     332add_action( 'bbp_transitioned_reply_status_new_public', 'bbp_increase_user_reply_count' );
     333add_action( 'bbp_transitioned_reply_status_public',     'bbp_increase_user_reply_count' );
     334add_action( 'bbp_transitioned_reply_status_moderated',  'bbp_decrease_user_reply_count' );
     335add_action( 'bbp_transitioned_topic_status_new_public', 'bbp_increase_user_topic_count' );
     336add_action( 'bbp_transitioned_topic_status_public',     'bbp_increase_user_topic_count' );
     337add_action( 'bbp_transitioned_topic_status_moderated',  'bbp_decrease_user_topic_count' );
    311338
    312339// Update topic voice counts.
    313340add_action( 'bbp_new_reply',        'bbp_update_topic_voice_count' );
  • src/includes/forums/functions.php

    diff --git src/includes/forums/functions.php src/includes/forums/functions.php
    index a4f3746..ed31b48 100644
    function bbp_update_forum( $args = array() ) { 
    19721972        bbp_update_forum_subforum_count( $r['forum_id'] );
    19731973
    19741974        // Only update topic count if we're deleting a topic, or in the dashboard.
    1975         if ( in_array( current_filter(), array( 'bbp_deleted_topic', 'save_post' ), true ) ) {
     1975        if ( 'bbp_deleted_topic' === current_action() ) {
    19761976                bbp_update_forum_reply_count(        $r['forum_id'] );
    19771977                bbp_update_forum_topic_count(        $r['forum_id'] );
    19781978                bbp_update_forum_topic_count_hidden( $r['forum_id'] );
    function bbp_untrashed_forum( $forum_id = 0 ) { 
    27792779
    27802780        do_action( 'bbp_untrashed_forum', $forum_id );
    27812781}
     2782/** Transition Forum Statuses *************************************************/
     2783
     2784/**
     2785 * Called when transitioning a forum's post status.
     2786 *
     2787 * @since x.x.x bbPress (rXXXX)
     2788 *
     2789 * @param string  $new_status The new post status.
     2790 * @param string  $old_status The old post status.
     2791 * @param WP_Post $post       The post object.
     2792 *
     2793 * @return bool
     2794 */
     2795function bbp_transition_forum_status( $new_status, $old_status, $post ) {
     2796
     2797        // Validate the forum.
     2798        $forum = bbp_get_forum( $post );
     2799
     2800        // Bail if the post object isn't a forum.
     2801        if ( empty( $forum ) ) {
     2802                return false;
     2803        }
     2804
     2805        /**
     2806         * Fires when a forum's post status is transitioned.
     2807         *
     2808         * @since x.x.x bbPress (rXXXX)
     2809         *
     2810         * @param string  $new_status The new post status.
     2811         * @param string  $old_status The old post status.
     2812         * @param WP_Post $forum      The forum post object.
     2813         */
     2814        do_action( 'bbp_transition_forum_status', $new_status, $old_status, $forum );
     2815
     2816        return true;
     2817}
     2818
     2819/**
     2820 * Called when transitioning a forum's post status to a public status from a
     2821 * draft/new status.
     2822 *
     2823 * @since x.x.x bbPress (rXXXX)
     2824 *
     2825 * @param string  $new_status The new post status.
     2826 * @param string  $old_status The old post status.
     2827 * @param WP_Post $forum      The forum post object.
     2828 *
     2829 * @return bool
     2830 */
     2831function bbp_transition_forum_status_new_public( $new_status, $old_status, $forum ) {
     2832
     2833        // Validate the forum.
     2834        $forum = bbp_get_forum( $forum );
     2835
     2836        // Bail if the post object isn't a forum.
     2837        if ( empty( $forum ) ) {
     2838                return false;
     2839        }
     2840
     2841        // Is the new status public?
     2842        if ( ! in_array( $new_status, bbp_get_public_forum_statuses(), true ) ) {
     2843                return false;
     2844        }
     2845
     2846        // Is the old status draft or new?
     2847        if ( ! in_array( $old_status, bbp_get_draft_new_forum_statuses(), true ) ) {
     2848                return false;
     2849        }
     2850
     2851        $forum_id = bbp_get_forum_id( $forum->ID );
     2852
     2853        // Store the transitioned forum id.
     2854        bbp_store_transitioned_post_id( $forum_id, 'new_public' );
     2855
     2856        /**
     2857         * Fires when a forum's post status is transitioned to a public status from
     2858         * a draft/new status.
     2859         *
     2860         * @since x.x.x bbPress (rXXXX)
     2861         *
     2862         * @param int $forum_id The forum id.
     2863         */
     2864        do_action( 'bbp_transition_forum_status_new_public', $forum_id );
     2865
     2866        return true;
     2867}
     2868
     2869/**
     2870 * Called when transitioning a forum's post status to a moderated status from a
     2871 * draft/new status.
     2872 *
     2873 * @since x.x.x bbPress (rXXXX)
     2874 *
     2875 * @param string  $new_status The new post status.
     2876 * @param string  $old_status The old post status.
     2877 * @param WP_Post $forum      The forum post object.
     2878 *
     2879 * @return bool
     2880 */
     2881function bbp_transition_forum_status_new_moderated( $new_status, $old_status, $forum ) {
     2882
     2883        // Validate the reply.
     2884        $forum = bbp_get_forum( $forum );
     2885
     2886        // Bail if the post object isn't a forum.
     2887        if ( empty( $forum ) ) {
     2888                return false;
     2889        }
     2890
     2891        // Is the new status moderated?
     2892        if ( ! in_array( $new_status, bbp_get_moderated_forum_statuses(), true ) ) {
     2893                return false;
     2894        }
     2895
     2896        // Is the old status draft or new?
     2897        if ( ! in_array( $old_status, bbp_get_draft_new_forum_statuses(), true ) ) {
     2898                return false;
     2899        }
     2900
     2901        $forum_id = bbp_get_forum_id( $forum->ID );
     2902
     2903        // Store the transitioned forum id.
     2904        bbp_store_transitioned_post_id( $forum_id, 'new_moderated' );
     2905
     2906        /**
     2907         * Fires when a forum's post status is transitioned to a public status from
     2908         * a draft/new status.
     2909         *
     2910         * @since x.x.x bbPress (rXXXX)
     2911         *
     2912         * @param int $forum_id The forum id.
     2913         */
     2914        do_action( 'bbp_transition_forum_status_new_moderated', $forum_id );
     2915
     2916        return true;
     2917}
     2918
     2919/**
     2920 * Called when transitioning a forum's post status to a public status from a
     2921 * moderated status.
     2922 *
     2923 * @since x.x.x bbPress (rXXXX)
     2924 *
     2925 * @param string  $new_status The new post status.
     2926 * @param string  $old_status The old post status.
     2927 * @param WP_Post $forum      The forum post object.
     2928 *
     2929 * @return bool
     2930 */
     2931function bbp_transition_forum_status_public( $new_status, $old_status, $forum ) {
     2932
     2933        // Validate the forum.
     2934        $forum = bbp_get_forum( $forum );
     2935
     2936        // Bail if the post object isn't a forum.
     2937        if ( empty( $forum ) ) {
     2938                return false;
     2939        }
     2940
     2941        // Is the new status public?
     2942        if ( ! in_array( $new_status, bbp_get_public_forum_statuses(), true ) ) {
     2943                return false;
     2944        }
     2945
     2946        // Is the old status moderated?
     2947        if ( ! in_array( $old_status, bbp_get_moderated_forum_statuses(), true ) ) {
     2948                return false;
     2949        }
     2950
     2951        $forum_id = bbp_get_forum_id( $forum->ID );
     2952
     2953        // Store the transitioned forum id.
     2954        bbp_store_transitioned_post_id( $forum_id, 'public' );
     2955
     2956        /**
     2957         * Fires when a forum's post status is transitioned to a public status from
     2958         * a moderated status.
     2959         *
     2960         * @since x.x.x bbPress (rXXXX)
     2961         *
     2962         * @param int $forum_id The forum id.
     2963         */
     2964        do_action( 'bbp_transition_forum_status_public', $forum_id );
     2965
     2966        return true;
     2967}
     2968
     2969/**
     2970 * Called when transitioning a forum's post status to a moderated status from a
     2971 * public status.
     2972 *
     2973 * @since x.x.x bbPress (rXXXX)
     2974 *
     2975 * @param string  $new_status The new post status.
     2976 * @param string  $old_status The old post status.
     2977 * @param WP_Post $forum      The forum post object.
     2978 *
     2979 * @return bool
     2980 */
     2981function bbp_transition_forum_status_moderated( $new_status, $old_status, $forum ) {
     2982
     2983        // Validate the forum.
     2984        $forum = bbp_get_forum( $forum );
     2985
     2986        // Bail if the post object isn't a forum.
     2987        if ( empty( $forum ) ) {
     2988                return false;
     2989        }
     2990
     2991        // Is the new status moderated?
     2992        if ( ! in_array( $new_status, bbp_get_moderated_forum_statuses(), true ) ) {
     2993                return false;
     2994        }
     2995
     2996        // Is the old status public?
     2997        if ( ! in_array( $old_status, bbp_get_public_forum_statuses(), true ) ) {
     2998                return false;
     2999        }
     3000
     3001        $forum_id = bbp_get_forum_id( $forum->ID );
     3002
     3003        // Store the transitioned forum id.
     3004        bbp_store_transitioned_post_id( $forum_id, 'moderated' );
     3005
     3006        /**
     3007         * Fires when a forum's post status is transitioned to a moderated status
     3008         * from a public status.
     3009         *
     3010         * @since x.x.x bbPress (rXXXX)
     3011         *
     3012         * @param int $forum_id The forum id.
     3013         */
     3014        do_action( 'bbp_transition_forum_status_moderated', $forum_id );
     3015
     3016        return true;
     3017}
     3018
     3019/**
     3020 * Called after transitioning a forum's post status to a public status from a
     3021 * draft/new status and it's post meta has been updated.
     3022 *
     3023 * @since x.x.x bbPress (rXXXX)
     3024 *
     3025 * @param int $forum_id The forum id.
     3026 *
     3027 * @return bool
     3028 */
     3029function bbp_transitioned_forum_status_new_public( $forum_id = 0 ) {
     3030        $forum_id = bbp_get_forum_id( $forum_id );
     3031
     3032        if ( empty( $forum_id ) || ! bbp_is_forum( $forum_id ) ) {
     3033                return false;
     3034        }
     3035
     3036        // Bail if the forum wasn't transitioned to a new public status.
     3037        if ( ! bbp_is_post_transitioned_new_public( $forum_id ) ) {
     3038                return false;
     3039        }
     3040
     3041        /**
     3042         * Fires when a forum's post status is transitioned to a public status from
     3043         * a draft/new status and it's post meta has been updated.
     3044         *
     3045         * @since x.x.x bbPress (rXXXX)
     3046         *
     3047         * @param int $forum_id The forum id.
     3048         */
     3049        do_action( 'bbp_transitioned_forum_status_new_public', $forum_id );
     3050
     3051        return true;
     3052}
     3053
     3054/**
     3055 * Called after transitioning a forum's post status to a moderated status from a
     3056 * draft/new status and it's post meta has been updated.
     3057 *
     3058 * @since x.x.x bbPress (rXXXX)
     3059 *
     3060 * @param int $forum_id The forum id.
     3061 *
     3062 * @return bool
     3063 */
     3064function bbp_transitioned_forum_status_new_moderated( $forum_id = 0 ) {
     3065        $forum_id = bbp_get_forum_id( $forum_id );
     3066
     3067        if ( empty( $forum_id ) || ! bbp_is_forum( $forum_id ) ) {
     3068                return false;
     3069        }
     3070
     3071        // Bail if the forum wasn't transitioned to a new moderated status.
     3072        if ( ! bbp_is_post_transitioned_new_moderated( $forum_id ) ) {
     3073                return false;
     3074        }
     3075
     3076        /**
     3077         * Fires when a forum's post status is transitioned to a moderated status
     3078         * from a draft/new status and it's post meta has been updated.
     3079         *
     3080         * @since x.x.x bbPress (rXXXX)
     3081         *
     3082         * @param int $forum_id The forum id.
     3083         */
     3084        do_action( 'bbp_transitioned_forum_status_new_moderated', $forum_id );
     3085
     3086        return true;
     3087}
     3088
     3089/**
     3090 * Called after transitioning a forum's post status to a public status from a
     3091 * moderated status and it's post meta has been updated.
     3092 *
     3093 * @since x.x.x bbPress (rXXXX)
     3094 *
     3095 * @param int $forum_id The forum id.
     3096 *
     3097 * @return bool
     3098 */
     3099function bbp_transitioned_forum_status_public( $forum_id = 0 ) {
     3100        $forum_id = bbp_get_forum_id( $forum_id );
     3101
     3102        if ( empty( $forum_id ) || ! bbp_is_forum( $forum_id ) ) {
     3103                return false;
     3104        }
     3105
     3106        // Bail if the forum wasn't transitioned to a public status.
     3107        if ( ! bbp_is_post_transitioned_public( $forum_id ) ) {
     3108                return false;
     3109        }
     3110
     3111        /**
     3112         * Fires when a forum's post status is transitioned to a public status from
     3113         * a public status and it's post meta has been updated.
     3114         *
     3115         * @since x.x.x bbPress (rXXXX)
     3116         *
     3117         * @param int $forum_id The forum id.
     3118         */
     3119        do_action( 'bbp_transitioned_forum_status_public', $forum_id );
     3120
     3121        return true;
     3122}
     3123
     3124/**
     3125 * Called after transitioning a forum's post status to a moderated status from a
     3126 * public status and it's post meta has been updated.
     3127 *
     3128 * @since x.x.x bbPress (rXXXX)
     3129 *
     3130 * @param int $forum_id The forum id.
     3131 *
     3132 * @return bool
     3133 */
     3134function bbp_transitioned_forum_status_moderated( $forum_id = 0 ) {
     3135        $forum_id = bbp_get_forum_id( $forum_id );
     3136
     3137        if ( empty( $forum_id ) || ! bbp_is_forum( $forum_id ) ) {
     3138                return false;
     3139        }
     3140
     3141        // Bail if the forum wasn't transitioned to a moderated status.
     3142        if ( ! bbp_is_post_transitioned_moderated( $forum_id ) ) {
     3143                return false;
     3144        }
     3145
     3146        /**
     3147         * Fires when a forum's post status is transitioned to a moderated status
     3148         * from a public status and it's post meta has been updated.
     3149         *
     3150         * @since x.x.x bbPress (rXXXX)
     3151         *
     3152         * @param int $forum_id The forum id.
     3153         */
     3154        do_action( 'bbp_transitioned_forum_status_moderated', $forum_id );
     3155
     3156        return true;
     3157}
  • src/includes/forums/template.php

    diff --git src/includes/forums/template.php src/includes/forums/template.php
    index 4cce868..08cf9cc 100644
    function bbp_forum_status( $forum_id = 0 ) { 
    15381538        }
    15391539
    15401540/**
     1541 * Return array of draft/new forum statuses.
     1542 *
     1543 * The `new` status is applied by `wp_insert_post` when a post object has no
     1544 * previous status.
     1545 *
     1546 * @since x.x.x bbPress (rXXXX)
     1547 *
     1548 * @return array
     1549 */
     1550function bbp_get_draft_new_forum_statuses() {
     1551        $statuses = array( 'auto-draft', 'draft', 'new' );
     1552
     1553        /**
     1554         * Filters the return of `bbp_get_draft_new_forum_statuses()`.
     1555         *
     1556         * @since x.x.x bbPress (rXXXX)
     1557         *
     1558         * @param array $statuses The draft/new forum statuses.
     1559         */
     1560        return (array) apply_filters( 'bbp_get_draft_new_forum_statuses', $statuses );
     1561}
     1562
     1563/**
     1564 * Return array of public forum statuses.
     1565 *
     1566 * @since x.x.x bbPress (rXXXX)
     1567 *
     1568 * @return array
     1569 */
     1570function bbp_get_public_forum_statuses() {
     1571        $statuses = array(
     1572                bbp_get_public_status_id(),
     1573                bbp_get_closed_status_id(),
     1574                bbp_get_private_status_id(),
     1575                bbp_get_hidden_status_id(),
     1576        );
     1577
     1578        /**
     1579         * Filters the return of `bbp_get_public_forum_statuses()`.
     1580         *
     1581         * @since x.x.x bbPress (rXXXX)
     1582         *
     1583         * @param array $statuses The public forum statuses.
     1584         */
     1585        return (array) apply_filters( 'bbp_get_public_forum_statuses', $statuses );
     1586}
     1587
     1588/**
     1589 * Return array of moderated forum statuses.
     1590 *
     1591 * @since x.x.x bbPress (rXXXX)
     1592 *
     1593 * @return array
     1594 */
     1595function bbp_get_moderated_forum_statuses() {
     1596        $statuses = array( bbp_get_trash_status_id() );
     1597
     1598        /**
     1599         * Filters the return of `bbp_get_moderated_forum_statuses()`.
     1600         *
     1601         * @since x.x.x bbPress (rXXXX)
     1602         *
     1603         * @param array $statuses The moderated forum statuses.
     1604         */
     1605        return (array) apply_filters( 'bbp_get_moderated_forum_statuses', $statuses );
     1606}
     1607
     1608/**
    15411609 * Output the visibility of the forum
    15421610 *
    15431611 * @since 2.0.0 bbPress (r2997)
  • src/includes/replies/functions.php

    diff --git src/includes/replies/functions.php src/includes/replies/functions.php
    index 210260a..c0b1064 100644
    function bbp_insert_reply( $reply_data = array(), $reply_meta = array() ) { 
    8484 * Update counts after a reply is inserted via `bbp_insert_reply`.
    8585 *
    8686 * @since 2.6.0 bbPress (r6036)
     87 * @deprecated x.x.x bbPress (rXXXX)
     88 * @todo Do we completely remove, or add a deprecation notice?
    8789 *
    8890 * @param int $reply_id The reply id.
    8991 * @param int $topic_id The topic id.
    function bbp_update_reply_walker( $reply_id, $last_active_time = '', $forum_id = 
    10151017                                bbp_update_topic_last_active_time( $ancestor, $topic_last_active_time );
    10161018
    10171019                                // Only update reply count if we're deleting a reply, or in the dashboard.
    1018                                 if ( in_array( current_filter(), array( 'bbp_deleted_reply', 'save_post' ), true ) ) {
     1020                                if ( 'bbp_deleted_reply' === current_action() ) {
    10191021                                        bbp_update_topic_reply_count(        $ancestor );
    10201022                                        bbp_update_topic_reply_count_hidden( $ancestor );
    10211023                                        bbp_update_topic_voice_count(        $ancestor );
    function bbp_update_reply_walker( $reply_id, $last_active_time = '', $forum_id = 
    10441046
    10451047                                // Counts
    10461048                                // Only update reply count if we're deleting a reply, or in the dashboard.
    1047                                 if ( in_array( current_filter(), array( 'bbp_deleted_reply', 'save_post' ), true ) ) {
     1049                                if ( 'bbp_deleted_reply' === current_action() ) {
    10481050                                        bbp_update_forum_reply_count( $ancestor );
    10491051                                }
    10501052                        }
    function bbp_untrashed_reply( $reply_id = 0 ) { 
    21042106        do_action( 'bbp_untrashed_reply', $reply_id );
    21052107}
    21062108
     2109/** Transition Reply Statuses *************************************************/
     2110
     2111/**
     2112 * Called when transitioning a reply's post status.
     2113 *
     2114 * @since x.x.x bbPress (rXXXX)
     2115 *
     2116 * @param string  $new_status The new post status.
     2117 * @param string  $old_status The old post status.
     2118 * @param WP_Post $post       The post object.
     2119 *
     2120 * @return bool
     2121 */
     2122function bbp_transition_reply_status( $new_status, $old_status, $post ) {
     2123
     2124        // Validate the reply.
     2125        $reply = bbp_get_reply( $post );
     2126
     2127        // Bail if the post object isn't a forum.
     2128        if ( empty( $reply ) ) {
     2129                return false;
     2130        }
     2131
     2132        /**
     2133         * Fires when a reply's post status is transitioned.
     2134         *
     2135         * @since x.x.x bbPress (rXXXX)
     2136         *
     2137         * @param string  $new_status The new post status.
     2138         * @param string  $old_status The old post status.
     2139         * @param WP_Post $reply      The reply post object.
     2140         */
     2141        do_action( 'bbp_transition_reply_status', $new_status, $old_status, $reply );
     2142
     2143        return true;
     2144}
     2145
     2146/**
     2147 * Called when transitioning a reply's post status to a public status from a
     2148 * draft/new status.
     2149 *
     2150 * @since x.x.x bbPress (rXXXX)
     2151 *
     2152 * @param string  $new_status The new post status.
     2153 * @param string  $old_status The old post status.
     2154 * @param WP_Post $reply      The reply post object.
     2155 *
     2156 * @return bool
     2157 */
     2158function bbp_transition_reply_status_new_public( $new_status, $old_status, $reply ) {
     2159
     2160        // Validate the reply.
     2161        $reply = bbp_get_reply( $reply );
     2162
     2163        // Bail if the post object isn't a reply.
     2164        if ( empty( $reply ) ) {
     2165                return false;
     2166        }
     2167
     2168        // Is the new status public?
     2169        if ( ! in_array( $new_status, bbp_get_public_reply_statuses(), true ) ) {
     2170                return false;
     2171        }
     2172
     2173        // Is the old status draft or new?
     2174        if ( ! in_array( $old_status, bbp_get_draft_new_reply_statuses(), true ) ) {
     2175                return false;
     2176        }
     2177
     2178        $reply_id = bbp_get_reply_id( $reply->ID );
     2179
     2180        // Store the transitioned reply id.
     2181        bbp_store_transitioned_post_id( $reply_id, 'new_public' );
     2182
     2183        /**
     2184         * Fires when a reply's post status is transitioned to a public status from
     2185         * a draft/new status.
     2186         *
     2187         * @since x.x.x bbPress (rXXXX)
     2188         *
     2189         * @param int $reply_id The reply id.
     2190         */
     2191        do_action( 'bbp_transition_reply_status_new_public', $reply_id );
     2192
     2193        return true;
     2194}
     2195
     2196/**
     2197 * Called when transitioning a reply's post status to a moderated status from a
     2198 * draft/new status.
     2199 *
     2200 * @since x.x.x bbPress (rXXXX)
     2201 *
     2202 * @param string  $new_status The new post status.
     2203 * @param string  $old_status The old post status.
     2204 * @param WP_Post $reply      The reply post object.
     2205 *
     2206 * @return bool
     2207 */
     2208function bbp_transition_reply_status_new_moderated( $new_status, $old_status, $reply ) {
     2209
     2210        // Validate the reply.
     2211        $reply = bbp_get_reply( $reply );
     2212
     2213        // Bail if the post object isn't a reply.
     2214        if ( empty( $reply ) ) {
     2215                return false;
     2216        }
     2217
     2218        // Is the new status moderated?
     2219        if ( ! in_array( $new_status, bbp_get_moderated_reply_statuses(), true ) ) {
     2220                return false;
     2221        }
     2222
     2223        // Is the old status draft or new?
     2224        if ( ! in_array( $old_status, bbp_get_draft_new_reply_statuses(), true ) ) {
     2225                return false;
     2226        }
     2227
     2228        $reply_id = bbp_get_reply_id( $reply->ID );
     2229
     2230        // Store the transitioned reply id.
     2231        bbp_store_transitioned_post_id( $reply_id, 'new_moderated' );
     2232
     2233        /**
     2234         * Fires when a reply's post status is transitioned to a public status from
     2235         * a draft/new status.
     2236         *
     2237         * @since x.x.x bbPress (rXXXX)
     2238         *
     2239         * @param int $reply_id The reply id.
     2240         */
     2241        do_action( 'bbp_transition_reply_status_new_moderated', $reply_id );
     2242
     2243        return true;
     2244}
     2245
     2246/**
     2247 * Called when transitioning a reply's post status to a public status from a
     2248 * moderated status.
     2249 *
     2250 * @since x.x.x bbPress (rXXXX)
     2251 *
     2252 * @param string  $new_status The new post status.
     2253 * @param string  $old_status The old post status.
     2254 * @param WP_Post $reply      The reply post object.
     2255 *
     2256 * @return bool
     2257 */
     2258function bbp_transition_reply_status_public( $new_status, $old_status, $reply ) {
     2259
     2260        // Validate the reply.
     2261        $reply = bbp_get_reply( $reply );
     2262
     2263        // Bail if the post object isn't a reply.
     2264        if ( empty( $reply ) ) {
     2265                return false;
     2266        }
     2267
     2268        // Is the new status public?
     2269        if ( ! in_array( $new_status, bbp_get_public_reply_statuses(), true ) ) {
     2270                return false;
     2271        }
     2272
     2273        // Is the old status moderated?
     2274        if ( ! in_array( $old_status, bbp_get_moderated_reply_statuses(), true ) ) {
     2275                return false;
     2276        }
     2277
     2278        $reply_id = bbp_get_reply_id( $reply->ID );
     2279
     2280        // Store the transitioned reply id.
     2281        bbp_store_transitioned_post_id( $reply_id, 'public' );
     2282
     2283        /**
     2284         * Fires when a reply's post status is transitioned to a public status from
     2285         * a moderated status.
     2286         *
     2287         * @since x.x.x bbPress (rXXXX)
     2288         *
     2289         * @param int $reply_id The reply id.
     2290         */
     2291        do_action( 'bbp_transition_reply_status_public', $reply_id );
     2292
     2293        return true;
     2294}
     2295
     2296/**
     2297 * Called when transitioning a reply's post status to a moderated status from a
     2298 * public status.
     2299 *
     2300 * @since x.x.x bbPress (rXXXX)
     2301 *
     2302 * @param string  $new_status The new post status.
     2303 * @param string  $old_status The old post status.
     2304 * @param WP_Post $reply      The reply post object.
     2305 *
     2306 * @return bool
     2307 */
     2308function bbp_transition_reply_status_moderated( $new_status, $old_status, $reply ) {
     2309
     2310        // Validate the reply.
     2311        $reply = bbp_get_reply( $reply );
     2312
     2313        // Bail if the post object isn't a reply.
     2314        if ( empty( $reply ) ) {
     2315                return false;
     2316        }
     2317
     2318        // Is the new status moderated?
     2319        if ( ! in_array( $new_status, bbp_get_moderated_reply_statuses(), true ) ) {
     2320                return false;
     2321        }
     2322
     2323        // Is the old status public?
     2324        if ( ! in_array( $old_status, bbp_get_public_reply_statuses(), true ) ) {
     2325                return false;
     2326        }
     2327
     2328        $reply_id = bbp_get_reply_id( $reply->ID );
     2329
     2330        // Store the transitioned reply id.
     2331        bbp_store_transitioned_post_id( $reply_id, 'moderated' );
     2332
     2333        /**
     2334         * Fires when a reply's post status is transitioned to a moderated status
     2335         * from a public status.
     2336         *
     2337         * @since x.x.x bbPress (rXXXX)
     2338         *
     2339         * @param int $reply_id The reply id.
     2340         */
     2341        do_action( 'bbp_transition_reply_status_moderated', $reply_id );
     2342
     2343        return true;
     2344}
     2345
     2346/**
     2347 * Called after transitioning a reply's post status to a public status from a
     2348 * draft/new status and it's post meta has been updated.
     2349 *
     2350 * @since x.x.x bbPress (rXXXX)
     2351 *
     2352 * @param int $reply_id The reply id.
     2353 *
     2354 * @return bool
     2355 */
     2356function bbp_transitioned_reply_status_new_public( $reply_id = 0 ) {
     2357        $reply_id = bbp_get_reply_id( $reply_id );
     2358
     2359        if ( empty( $reply_id ) || ! bbp_is_reply( $reply_id ) ) {
     2360                return false;
     2361        }
     2362
     2363        // Bail if the reply wasn't transitioned to a new public status.
     2364        if ( ! bbp_is_post_transitioned_new_public( $reply_id ) ) {
     2365                return false;
     2366        }
     2367
     2368        /**
     2369         * Fires when a reply's post status is transitioned to a public status from
     2370         * a draft/new status and it's post meta has been updated.
     2371         *
     2372         * @since x.x.x bbPress (rXXXX)
     2373         *
     2374         * @param int $reply_id The reply id.
     2375         */
     2376        do_action( 'bbp_transitioned_reply_status_new_public', $reply_id );
     2377
     2378        return true;
     2379}
     2380
     2381/**
     2382 * Called after transitioning a reply's post status to a moderated status from a
     2383 * draft/new status and it's post meta has been updated.
     2384 *
     2385 * @since x.x.x bbPress (rXXXX)
     2386 *
     2387 * @param int $reply_id The reply id.
     2388 *
     2389 * @return bool
     2390 */
     2391function bbp_transitioned_reply_status_new_moderated( $reply_id = 0 ) {
     2392        $reply_id = bbp_get_reply_id( $reply_id );
     2393
     2394        if ( empty( $reply_id ) || ! bbp_is_reply( $reply_id ) ) {
     2395                return false;
     2396        }
     2397
     2398        // Bail if the reply wasn't transitioned to a new moderated status.
     2399        if ( ! bbp_is_post_transitioned_new_moderated( $reply_id ) ) {
     2400                return false;
     2401        }
     2402
     2403        /**
     2404         * Fires when a reply's post status is transitioned to a moderated status
     2405         * from a draft/new status and it's post meta has been updated.
     2406         *
     2407         * @since x.x.x bbPress (rXXXX)
     2408         *
     2409         * @param int $reply_id The reply id.
     2410         */
     2411        do_action( 'bbp_transitioned_reply_status_new_moderated', $reply_id );
     2412
     2413        return true;
     2414}
     2415
     2416/**
     2417 * Called after transitioning a reply's post status to a public status from a
     2418 * moderated status and it's post meta has been updated.
     2419 *
     2420 * @since x.x.x bbPress (rXXXX)
     2421 *
     2422 * @param int $reply_id The reply id.
     2423 *
     2424 * @return bool
     2425 */
     2426function bbp_transitioned_reply_status_public( $reply_id = 0 ) {
     2427        $reply_id = bbp_get_reply_id( $reply_id );
     2428
     2429        if ( empty( $reply_id ) || ! bbp_is_reply( $reply_id ) ) {
     2430                return false;
     2431        }
     2432
     2433        // Bail if the reply wasn't transitioned to a public status.
     2434        if ( ! bbp_is_post_transitioned_public( $reply_id ) ) {
     2435                return false;
     2436        }
     2437
     2438        /**
     2439         * Fires when a reply's post status is transitioned to a public status from
     2440         * a public status and it's post meta has been updated.
     2441         *
     2442         * @since x.x.x bbPress (rXXXX)
     2443         *
     2444         * @param int $reply_id The reply id.
     2445         */
     2446        do_action( 'bbp_transitioned_reply_status_public', $reply_id );
     2447
     2448        return true;
     2449}
     2450
     2451/**
     2452 * Called after transitioning a reply's post status to a moderated status from a
     2453 * public status and it's post meta has been updated.
     2454 *
     2455 * @since x.x.x bbPress (rXXXX)
     2456 *
     2457 * @param int $reply_id The reply id.
     2458 *
     2459 * @return bool
     2460 */
     2461function bbp_transitioned_reply_status_moderated( $reply_id = 0 ) {
     2462        $reply_id = bbp_get_reply_id( $reply_id );
     2463
     2464        if ( empty( $reply_id ) || ! bbp_is_reply( $reply_id ) ) {
     2465                return false;
     2466        }
     2467
     2468        // Bail if the reply wasn't transitioned to a moderated status.
     2469        if ( ! bbp_is_post_transitioned_moderated( $reply_id ) ) {
     2470                return false;
     2471        }
     2472
     2473        /**
     2474         * Fires when a reply's post status is transitioned to a moderated status
     2475         * from a public status and it's post meta has been updated.
     2476         *
     2477         * @since x.x.x bbPress (rXXXX)
     2478         *
     2479         * @param int $reply_id The reply id.
     2480         */
     2481        do_action( 'bbp_transitioned_reply_status_moderated', $reply_id );
     2482
     2483        return true;
     2484}
     2485
    21072486/** Settings ******************************************************************/
    21082487
    21092488/**
  • src/includes/replies/template.php

    diff --git src/includes/replies/template.php src/includes/replies/template.php
    index 92ff8bf..bac3894 100644
    function bbp_reply_status( $reply_id = 0 ) { 
    917917        }
    918918
    919919/**
     920 * Return array of draft/new reply statuses.
     921 *
     922 * The `new` status is applied by `wp_insert_post` when a post object has no
     923 * previous status.
     924 *
     925 * @since x.x.x bbPress (rXXXX)
     926 *
     927 * @return array
     928 */
     929function bbp_get_draft_new_reply_statuses() {
     930        $statuses = array( 'auto-draft', 'draft', 'new' );
     931
     932        /**
     933         * Filters the return of `bbp_get_draft_new_reply_statuses()`.
     934         *
     935         * @since x.x.x bbPress (rXXXX)
     936         *
     937         * @param array $statuses The draft/new reply statuses.
     938         */
     939        return (array) apply_filters( 'bbp_get_draft_new_reply_statuses', $statuses );
     940}
     941
     942/**
     943 * Return array of public reply statuses.
     944 *
     945 * @since x.x.x bbPress (rXXXX)
     946 *
     947 * @return array
     948 */
     949function bbp_get_public_reply_statuses() {
     950        $statuses = array( bbp_get_public_status_id() );
     951
     952        /**
     953         * Filters the return of `bbp_get_public_reply_statuses()`.
     954         *
     955         * @since x.x.x bbPress (rXXXX)
     956         *
     957         * @param array $statuses The public reply statuses.
     958         */
     959        return (array) apply_filters( 'bbp_get_public_reply_statuses', $statuses );
     960}
     961
     962/**
     963 * Return array of moderated reply statuses.
     964 *
     965 * @since x.x.x bbPress (rXXXX)
     966 *
     967 * @return array
     968 */
     969function bbp_get_moderated_reply_statuses() {
     970        $statuses = array(
     971                bbp_get_pending_status_id(),
     972                bbp_get_spam_status_id(),
     973                bbp_get_trash_status_id(),
     974        );
     975
     976        /**
     977         * Filters the return of `bbp_get_moderated_reply_statuses()`.
     978         *
     979         * @since x.x.x bbPress (rXXXX)
     980         *
     981         * @param array $statuses The moderated reply statuses.
     982         */
     983        return (array) apply_filters( 'bbp_get_moderated_reply_statuses', $statuses );
     984}
     985
     986/**
    920987 * Is the reply not spam or deleted?
    921988 *
    922989 * @since 2.0.0 bbPress (r3496)
  • src/includes/topics/functions.php

    diff --git src/includes/topics/functions.php src/includes/topics/functions.php
    index 328581d..52527bb 100644
    function bbp_decrease_topic_reply_count_hidden( $topic_id = 0 ) { 
    26312631 * Update counts after a topic is inserted via `bbp_insert_topic`.
    26322632 *
    26332633 * @since 2.6.0 bbPress (r6036)
     2634 * @deprecated x.x.x bbPress (rXXXX)
     2635 * @todo Do we completely remove, or add a deprecation notice?
    26342636 *
    26352637 * @param int $topic_id The topic id.
    26362638 * @param int $forum_id The forum id.
    function bbp_untrashed_topic( $topic_id = 0 ) { 
    39163918        do_action( 'bbp_untrashed_topic', $topic_id );
    39173919}
    39183920
     3921/** Transition Topic Statuses *************************************************/
     3922
     3923/**
     3924 * Called when transitioning a topic's post status.
     3925 *
     3926 * @since x.x.x bbPress (rXXXX)
     3927 *
     3928 * @param string  $new_status The new post status.
     3929 * @param string  $old_status The old post status.
     3930 * @param WP_Post $post       The post object.
     3931 *
     3932 * @return bool
     3933 */
     3934function bbp_transition_topic_status( $new_status, $old_status, $post ) {
     3935
     3936        // Validate the topic.
     3937        $topic = bbp_get_topic( $post );
     3938
     3939        // Bail if the post object isn't a topic.
     3940        if ( empty( $topic ) ) {
     3941                return false;
     3942        }
     3943
     3944        /**
     3945         * Fires when a topic's post status is transitioned.
     3946         *
     3947         * @since x.x.x bbPress (rXXXX)
     3948         *
     3949         * @param string  $new_status The new post status.
     3950         * @param string  $old_status The old post status.
     3951         * @param WP_Post $topic      The topic post object.
     3952         */
     3953        do_action( 'bbp_transition_topic_status', $new_status, $old_status, $topic );
     3954
     3955        return true;
     3956}
     3957
     3958/**
     3959 * Called when transitioning a topic's post status to a public status from a
     3960 * draft/new status.
     3961 *
     3962 * @since x.x.x bbPress (rXXXX)
     3963 *
     3964 * @param string  $new_status The new post status.
     3965 * @param string  $old_status The old post status.
     3966 * @param WP_Post $topic      The topic post object.
     3967 *
     3968 * @return bool
     3969 */
     3970function bbp_transition_topic_status_new_public( $new_status, $old_status, $topic ) {
     3971
     3972        // Validate the topic.
     3973        $topic = bbp_get_topic( $topic );
     3974
     3975        // Bail if the post object isn't a topic.
     3976        if ( empty( $topic ) ) {
     3977                return false;
     3978        }
     3979
     3980        // Is the new status public?
     3981        if ( ! in_array( $new_status, bbp_get_public_topic_statuses(), true ) ) {
     3982                return false;
     3983        }
     3984
     3985        // Is the old status draft or new?
     3986        if ( ! in_array( $old_status, bbp_get_draft_new_topic_statuses(), true ) ) {
     3987                return false;
     3988        }
     3989
     3990        $topic_id = bbp_get_topic_id( $topic->ID );
     3991
     3992        // Store the transitioned topic id.
     3993        bbp_store_transitioned_post_id( $topic_id, 'new_public' );
     3994
     3995        /**
     3996         * Fires when a topic's post status is transitioned to a public status from
     3997         * a draft/new status.
     3998         *
     3999         * @since x.x.x bbPress (rXXXX)
     4000         *
     4001         * @param int $topic_id The topic id.
     4002         */
     4003        do_action( 'bbp_transition_topic_status_new_public', $topic_id );
     4004
     4005        return true;
     4006}
     4007
     4008/**
     4009 * Called when transitioning a topic's post status to a moderated status
     4010 * from a draft/new status.
     4011 *
     4012 * @since x.x.x bbPress (rXXXX)
     4013 *
     4014 * @param string  $new_status The new post status.
     4015 * @param string  $old_status The old post status.
     4016 * @param WP_Post $topic      The topic post object.
     4017 *
     4018 * @return bool
     4019 */
     4020function bbp_transition_topic_status_new_moderated( $new_status, $old_status, $topic ) {
     4021
     4022        // Validate the topic.
     4023        $topic = bbp_get_topic( $topic );
     4024
     4025        // Bail if the post object isn't a topic.
     4026        if ( empty( $topic ) ) {
     4027                return false;
     4028        }
     4029
     4030        // Is the new status moderated?
     4031        if ( ! in_array( $new_status, bbp_get_moderated_reply_statuses(), true ) ) {
     4032                return false;
     4033        }
     4034
     4035        // Is the old status draft or new?
     4036        if ( ! in_array( $old_status, bbp_get_draft_new_reply_statuses(), true ) ) {
     4037                return false;
     4038        }
     4039
     4040        $topic_id = bbp_get_topic_id( $topic->ID );
     4041
     4042        // Store the transitioned topic id.
     4043        bbp_store_transitioned_post_id( $topic_id, 'new_moderated' );
     4044
     4045        /**
     4046         * Fires when a topic's post status is transitioned to a moderated status
     4047         * from a draft/new status.
     4048         *
     4049         * @since x.x.x bbPress (rXXXX)
     4050         *
     4051         * @param int $topic_id The topic id.
     4052         */
     4053        do_action( 'bbp_transition_topic_status_new_moderated', $topic_id );
     4054
     4055        return true;
     4056}
     4057
     4058/**
     4059 * Called when transitioning a topic's post status to a public status from a
     4060 * moderated status.
     4061 *
     4062 * @since x.x.x bbPress (rXXXX)
     4063 *
     4064 * @param string  $new_status The new post status.
     4065 * @param string  $old_status The old post status.
     4066 * @param WP_Post $topic      The topic post object.
     4067 *
     4068 * @return bool
     4069 */
     4070function bbp_transition_topic_status_public( $new_status, $old_status, $topic ) {
     4071
     4072        // Validate the topic.
     4073        $topic = bbp_get_topic( $topic );
     4074
     4075        // Bail if the post object isn't a topic.
     4076        if ( empty( $topic ) ) {
     4077                return false;
     4078        }
     4079
     4080        // Is the new status public?
     4081        if ( ! in_array( $new_status, bbp_get_public_reply_statuses(), true ) ) {
     4082                return false;
     4083        }
     4084
     4085        // Is the old status moderated?
     4086        if ( ! in_array( $old_status, bbp_get_moderated_reply_statuses(), true ) ) {
     4087                return false;
     4088        }
     4089
     4090        $topic_id = bbp_get_topic_id( $topic->ID );
     4091
     4092        // Store the transitioned topic id.
     4093        bbp_store_transitioned_post_id( $topic_id, 'public' );
     4094
     4095        /**
     4096         * Fires when a topic's post status is transitioned to a public status from
     4097         * a moderated status.
     4098         *
     4099         * @since x.x.x bbPress (rXXXX)
     4100         *
     4101         * @param int $topic_id The topic id.
     4102         */
     4103        do_action( 'bbp_transition_topic_status_public', $topic_id );
     4104
     4105        return true;
     4106}
     4107
     4108/**
     4109 * Called when transitioning a topic's post status to a moderated status from a
     4110 * public status.
     4111 *
     4112 * @since x.x.x bbPress (rXXXX)
     4113 *
     4114 * @param string  $new_status The new post status.
     4115 * @param string  $old_status The old post status.
     4116 * @param WP_Post $topic      The topic post object.
     4117 *
     4118 * @return bool
     4119 */
     4120function bbp_transition_topic_status_moderated( $new_status, $old_status, $topic ) {
     4121
     4122        // Validate the topic.
     4123        $topic = bbp_get_topic( $topic );
     4124
     4125        // Bail if the post object isn't a topic.
     4126        if ( empty( $topic ) ) {
     4127                return false;
     4128        }
     4129
     4130        // Is the new status moderated?
     4131        if ( ! in_array( $new_status, bbp_get_moderated_reply_statuses(), true ) ) {
     4132                return false;
     4133        }
     4134
     4135        // Is the old status public?
     4136        if ( ! in_array( $old_status, bbp_get_public_reply_statuses(), true ) ) {
     4137                return false;
     4138        }
     4139
     4140        $topic_id = bbp_get_topic_id( $topic->ID );
     4141
     4142        // Store the transitioned topic id.
     4143        bbp_store_transitioned_post_id( $topic_id, 'moderated' );
     4144
     4145        /**
     4146         * Fires when a topic's post status is transitioned to a moderated status
     4147         * from a public status.
     4148         *
     4149         * @since x.x.x bbPress (rXXXX)
     4150         *
     4151         * @param int $topic_id The topic id.
     4152         */
     4153        do_action( 'bbp_transition_topic_status_moderated', $topic_id );
     4154
     4155        return true;
     4156}
     4157
     4158/**
     4159 * Called after transitioning a topic's post status to a public status from a
     4160 * draft/new status and it's post meta has been updated.
     4161 *
     4162 * @since x.x.x bbPress (rXXXX)
     4163 *
     4164 * @param int $topic_id The topic id.
     4165 *
     4166 * @return bool
     4167 */
     4168function bbp_transitioned_topic_status_new_public( $topic_id = 0 ) {
     4169        $topic_id = bbp_get_topic_id( $topic_id );
     4170
     4171        if ( empty( $topic_id ) || ! bbp_is_topic( $topic_id ) ) {
     4172                return false;
     4173        }
     4174
     4175        // Bail if the topic wasn't transitioned to a new public status.
     4176        if ( ! bbp_is_post_transitioned_new_public( $topic_id ) ) {
     4177                return false;
     4178        }
     4179
     4180        /**
     4181         * Fires when a topic's post status is transitioned to a public status from
     4182         * a draft/new status and it's post meta has been updated.
     4183         *
     4184         * @since x.x.x bbPress (rXXXX)
     4185         *
     4186         * @param int $topic_id The topic id.
     4187         */
     4188        do_action( 'bbp_transitioned_topic_status_new_public', $topic_id );
     4189
     4190        return true;
     4191}
     4192
     4193/**
     4194 * Called after transitioning a topic's post status to a moderated status from a
     4195 * draft/new status and it's post meta has been updated.
     4196 *
     4197 * @since x.x.x bbPress (rXXXX)
     4198 *
     4199 * @param int $topic_id The topic id.
     4200 *
     4201 * @return bool
     4202 */
     4203function bbp_transitioned_topic_status_new_moderated( $topic_id = 0 ) {
     4204        $topic_id = bbp_get_topic_id( $topic_id );
     4205
     4206        if ( empty( $topic_id ) || ! bbp_is_topic( $topic_id ) ) {
     4207                return false;
     4208        }
     4209
     4210        // Bail if the topic wasn't transitioned to a new moderated status.
     4211        if ( ! bbp_is_post_transitioned_new_moderated( $topic_id ) ) {
     4212                return false;
     4213        }
     4214
     4215        /**
     4216         * Fires when a topic's post status is transitioned to a moderated status
     4217         * from a draft/new status and it's post meta has been updated.
     4218         *
     4219         * @since x.x.x bbPress (rXXXX)
     4220         *
     4221         * @param int $topic_id The topic id.
     4222         */
     4223        do_action( 'bbp_transitioned_topic_status_new_moderated', $topic_id );
     4224
     4225        return true;
     4226}
     4227
     4228/**
     4229 * Called after transitioning a topic's post status to a public status from a
     4230 * moderated status and it's post meta has been updated.
     4231 *
     4232 * @since x.x.x bbPress (rXXXX)
     4233 *
     4234 * @param int $topic_id The topic id.
     4235 *
     4236 * @return bool
     4237 */
     4238function bbp_transitioned_topic_status_public( $topic_id = 0 ) {
     4239        $topic_id = bbp_get_topic_id( $topic_id );
     4240
     4241        if ( empty( $topic_id ) || ! bbp_is_topic( $topic_id ) ) {
     4242                return false;
     4243        }
     4244
     4245        // Bail if the topic wasn't transitioned to a public status.
     4246        if ( ! bbp_is_post_transitioned_public( $topic_id ) ) {
     4247                return false;
     4248        }
     4249
     4250        /**
     4251         * Fires when a topic's post status is transitioned to a public status from
     4252         * a public status and it's post meta has been updated.
     4253         *
     4254         * @since x.x.x bbPress (rXXXX)
     4255         *
     4256         * @param int $topic_id The topic id.
     4257         */
     4258        do_action( 'bbp_transitioned_topic_status_public', $topic_id );
     4259
     4260        return true;
     4261}
     4262
     4263/**
     4264 * Called after transitioning a topic's post status to a moderated status from a
     4265 * public status and it's post meta has been updated.
     4266 *
     4267 * @since x.x.x bbPress (rXXXX)
     4268 *
     4269 * @param int $topic_id The topic id.
     4270 *
     4271 * @return bool
     4272 */
     4273function bbp_transitioned_topic_status_moderated( $topic_id = 0 ) {
     4274        $topic_id = bbp_get_topic_id( $topic_id );
     4275
     4276        if ( empty( $topic_id ) || ! bbp_is_topic( $topic_id ) ) {
     4277                return false;
     4278        }
     4279
     4280        // Bail if the topic wasn't transitioned to a moderated status.
     4281        if ( ! bbp_is_post_transitioned_moderated( $topic_id ) ) {
     4282                return false;
     4283        }
     4284
     4285        /**
     4286         * Fires when a topic's post status is transitioned to a moderated status
     4287         * from a public status and it's post meta has been updated.
     4288         *
     4289         * @since x.x.x bbPress (rXXXX)
     4290         *
     4291         * @param int $topic_id The topic id.
     4292         */
     4293        do_action( 'bbp_transitioned_topic_status_moderated', $topic_id );
     4294
     4295        return true;
     4296}
     4297
    39194298/** Settings ******************************************************************/
    39204299
    39214300/**
  • src/includes/topics/template.php

    diff --git src/includes/topics/template.php src/includes/topics/template.php
    index 57b122c..ca7bbaf 100644
    function bbp_topic_status( $topic_id = 0 ) { 
    11671167        }
    11681168
    11691169/**
     1170 * Return array of draft/new topic statuses.
     1171 *
     1172 * The `new` status is applied by `wp_insert_post` when a post object has no
     1173 * previous status.
     1174 *
     1175 * @since x.x.x bbPress (rXXXX)
     1176 *
     1177 * @return array
     1178 */
     1179function bbp_get_draft_new_topic_statuses() {
     1180        $statuses = array( 'auto-draft', 'draft', 'new' );
     1181
     1182        /**
     1183         * Filters the return of `bbp_get_draft_new_topic_statuses()`.
     1184         *
     1185         * @since x.x.x bbPress (rXXXX)
     1186         *
     1187         * @param array $statuses The draft/new topic statuses.
     1188         */
     1189        return (array) apply_filters( 'bbp_get_draft_new_topic_statuses', $statuses );
     1190}
     1191
     1192/**
    11701193 * Return array of public topic statuses.
    11711194 *
    11721195 * @since 2.6.0 bbPress (r6383)
    function bbp_topic_status( $topic_id = 0 ) { 
    11791202function bbp_get_public_topic_statuses() {
    11801203        $statuses = array( bbp_get_public_status_id(), bbp_get_closed_status_id() );
    11811204
     1205        /**
     1206         * Filters the return of `bbp_get_public_topic_statuses()`.
     1207         *
     1208         * @since 2.6.0 bbPress (r6383)
     1209         *
     1210         * @param array $statuses The public topic statuses.
     1211         */
    11821212        return (array) apply_filters( 'bbp_get_public_topic_statuses', $statuses );
    11831213}
    11841214
    11851215/**
     1216 * Return array of moderated topic statuses.
     1217 *
     1218 * @since x.x.x bbPress (rXXXX)
     1219 *
     1220 * @return array
     1221 */
     1222function bbp_get_moderated_topic_statuses() {
     1223        $statuses = array(
     1224                bbp_get_pending_status_id(),
     1225                bbp_get_spam_status_id(),
     1226                bbp_get_trash_status_id(),
     1227        );
     1228
     1229        /**
     1230         * Filters the return of `bbp_get_moderated_topic_statuses()`.
     1231         *
     1232         * @since x.x.x bbPress (rXXXX)
     1233         *
     1234         * @param array $statuses The moderated topic statuses.
     1235         */
     1236        return (array) apply_filters( 'bbp_get_moderated_topic_statuses', $statuses );
     1237}
     1238
     1239/**
    11861240 * Is the topic closed to new replies?
    11871241 *
    11881242 * @since 2.0.0 bbPress (r2746)
  • tests/phpunit/testcases/common/functions.php

    diff --git tests/phpunit/testcases/common/functions.php tests/phpunit/testcases/common/functions.php
    index 02d6ddd..17d5549 100644
    class BBP_Tests_Common_Functions extends BBP_UnitTestCase { 
    12211221                        'This test has not been implemented yet.'
    12221222                );
    12231223        }
     1224
     1225        /**
     1226         * @covers ::bbp_store_transitioned_post_id
     1227         */
     1228        public function test_bbp_store_transitioned_post_id() {
     1229                $bbp = bbpress();
     1230
     1231                // Reset transitioned posts.
     1232                $bbp->transitioned_posts = array();
     1233
     1234                bbp_store_transitioned_post_id( 1, 'new' );
     1235                $this->assertArrayHasKey( 1, $bbp->transitioned_posts );
     1236
     1237                bbp_store_transitioned_post_id( 2, 'moderated' );
     1238                $this->assertArrayHasKey( 1, $bbp->transitioned_posts );
     1239                $this->assertArrayHasKey( 2, $bbp->transitioned_posts );
     1240        }
     1241
     1242        /**
     1243         * @covers ::bbp_get_post_transitioned_status
     1244         */
     1245        public function test_bbp_get_post_transitioned_status() {
     1246
     1247                // Reset transitioned posts.
     1248                bbpress()->transitioned_posts = array();
     1249
     1250                bbp_store_transitioned_post_id( 1, 'new_public' );
     1251
     1252                $status = bbp_get_post_transitioned_status( 1 );
     1253                $this->assertEquals( 'new_public', $status );
     1254        }
     1255
     1256        /**
     1257         * @covers ::bbp_is_post_transitioned_new_public
     1258         */
     1259        public function test_bbp_is_post_transitioned_new_public() {
     1260
     1261                // Reset transitioned posts.
     1262                bbpress()->transitioned_posts = array();
     1263
     1264                bbp_store_transitioned_post_id( 1, 'new_public' );
     1265                $this->assertTrue( bbp_is_post_transitioned_new_public( 1 ) );
     1266
     1267                bbp_store_transitioned_post_id( 2, 'moderated' );
     1268                $this->assertFalse( bbp_is_post_transitioned_new_public( 2 ) );
     1269        }
     1270
     1271        /**
     1272         * @covers ::bbp_is_post_transitioned_new_moderated
     1273         */
     1274        public function test_bbp_is_post_transitioned_new_moderated() {
     1275
     1276                // Reset transitioned posts.
     1277                bbpress()->transitioned_posts = array();
     1278
     1279                bbp_store_transitioned_post_id( 1, 'new_moderated' );
     1280                $this->assertTrue( bbp_is_post_transitioned_new_moderated( 1 ) );
     1281
     1282                bbp_store_transitioned_post_id( 2, 'moderated' );
     1283                $this->assertFalse( bbp_is_post_transitioned_new_moderated( 2 ) );
     1284        }
     1285
     1286        /**
     1287         * @covers ::bbp_is_post_transitioned_public
     1288         */
     1289        public function test_bbp_is_post_transitioned_public() {
     1290
     1291                // Reset transitioned posts.
     1292                bbpress()->transitioned_posts = array();
     1293
     1294                bbp_store_transitioned_post_id( 1, 'public' );
     1295                $this->assertTrue( bbp_is_post_transitioned_public( 1 ) );
     1296
     1297                bbp_store_transitioned_post_id( 2, 'moderated' );
     1298                $this->assertFalse( bbp_is_post_transitioned_public( 2 ) );
     1299        }
     1300
     1301        /**
     1302         * @covers ::bbp_is_post_transitioned_moderated
     1303         */
     1304        public function test_bbp_is_post_transitioned_moderated() {
     1305
     1306                // Reset transitioned posts.
     1307                bbpress()->transitioned_posts = array();
     1308
     1309                bbp_store_transitioned_post_id( 1, 'moderated' );
     1310                $this->assertTrue( bbp_is_post_transitioned_moderated( 1 ) );
     1311
     1312                bbp_store_transitioned_post_id( 2, 'new' );
     1313                $this->assertFalse( bbp_is_post_transitioned_moderated( 2 ) );
     1314        }
    12241315}
  • tests/phpunit/testcases/forums/functions/counts.php

    diff --git tests/phpunit/testcases/forums/functions/counts.php tests/phpunit/testcases/forums/functions/counts.php
    index eaf91d2..8cb73c0 100644
    class BBP_Tests_Forums_Functions_Counts extends BBP_UnitTestCase { 
    1313         * Generic function to test the forum counts with a new topic
    1414         */
    1515        public function test_bbp_forum_new_topic_counts() {
    16                 remove_action( 'bbp_insert_topic', 'bbp_insert_topic_update_counts', 10 );
     16
     17                // Remove the transitioned new action so we can simulate a new topic.
     18                remove_action( 'bbp_insert_topic', 'bbp_transitioned_topic_status_new' );
    1719
    1820                $f = $this->factory->forum->create();
    1921                $t1 = $this->factory->topic->create( array(
    class BBP_Tests_Forums_Functions_Counts extends BBP_UnitTestCase { 
    2527                ) );
    2628                $u = $this->factory->user->create();
    2729
    28                 // Don't attempt to send an email. This is for speed and PHP errors.
    29                 remove_action( 'bbp_new_topic', 'bbp_notify_forum_subscribers', 11, 4 );
    30 
    31                 // Simulate the 'bbp_new_topic' action.
    32                 do_action( 'bbp_new_topic', $t1, $f, false, bbp_get_current_user_id(), $t1 );
     30                // Simulate the 'bbp_transitioned_topic_status_new' action.
     31                do_action( 'bbp_transitioned_topic_status_new', $t1 );
    3332
    3433                $count = bbp_get_forum_topic_count( $f, true, true );
    3534                $this->assertSame( 1, $count );
    class BBP_Tests_Forums_Functions_Counts extends BBP_UnitTestCase { 
    4544                        ),
    4645                ) );
    4746
    48                 // Simulate the 'bbp_new_topic' action.
    49                 do_action( 'bbp_new_topic', $t2, $f, false, $u , $t2 );
     47                // Simulate the 'bbp_transitioned_topic_status_new' action.
     48                do_action( 'bbp_transitioned_topic_status_new', $t2 );
    5049
    5150                $count = bbp_get_forum_topic_count( $f, true, true );
    5251                $this->assertSame( 2, $count );
    class BBP_Tests_Forums_Functions_Counts extends BBP_UnitTestCase { 
    5453                $count = bbp_get_forum_topic_count_hidden( $f, true, true );
    5554                $this->assertSame( 0, $count );
    5655
    57                 // Re-add removed actions.
    58                 add_action( 'bbp_insert_topic', 'bbp_insert_topic_update_counts', 10, 2 );
    59                 add_action( 'bbp_new_topic',    'bbp_notify_forum_subscribers',   11, 4 );
     56                // Re-add the transitioned new action.
     57                add_action( 'bbp_insert_topic', 'bbp_transitioned_topic_status_new' );
    6058        }
    6159
    6260        /**
  • tests/phpunit/testcases/forums/functions/status.php

    diff --git tests/phpunit/testcases/forums/functions/status.php tests/phpunit/testcases/forums/functions/status.php
    index c9ffe1b..4987a3a 100644
    class BBP_Tests_Forums_Functions_Status extends BBP_UnitTestCase { 
    107107                        'This test has not been implemented yet.'
    108108                );
    109109        }
     110
     111        /**
     112         * @covers ::bbp_transition_forum_status
     113         */
     114        public function test_bbp_transition_forum_status() {
     115                $f = $this->factory->forum->create();
     116
     117                $result = bbp_transition_forum_status(
     118                        bbp_get_public_status_id(),
     119                        'new',
     120                        bbp_get_forum( $f )
     121                );
     122
     123                // A true result means the action was added, as failures return false.
     124                $this->assertTrue( $result );
     125        }
     126
     127        /**
     128         * @covers ::bbp_transition_forum_status_new_public
     129         */
     130        public function test_bbp_transition_forum_status_new_public() {
     131                $f = $this->factory->forum->create();
     132
     133                $result = bbp_transition_forum_status_new_public(
     134                        bbp_get_public_status_id(),
     135                        'new',
     136                        bbp_get_forum( $f )
     137                );
     138
     139                // A true result means the action was added, as failures return false.
     140                $this->assertTrue( $result );
     141
     142                $this->assertEquals( 'new_public', bbp_get_post_transitioned_status( $f ) );
     143        }
     144
     145        /**
     146         * @covers ::bbp_transition_forum_status_new_moderated
     147         */
     148        public function test_bbp_transition_forum_status_new_moderated() {
     149                $f = $this->factory->forum->create();
     150
     151                $result = bbp_transition_forum_status_new_moderated(
     152                        bbp_get_trash_status_id(),
     153                        'new',
     154                        bbp_get_forum( $f )
     155                );
     156
     157                // A true result means the action was added, as failures return false.
     158                $this->assertTrue( $result );
     159
     160                $this->assertEquals( 'new_moderated', bbp_get_post_transitioned_status( $f ) );
     161        }
     162
     163        /**
     164         * @covers ::bbp_transition_forum_status_public
     165         */
     166        public function test_bbp_transition_forum_status_public() {
     167                $f = $this->factory->forum->create();
     168
     169                $result = bbp_transition_forum_status_public(
     170                        bbp_get_public_status_id(),
     171                        bbp_get_trash_status_id(),
     172                        bbp_get_forum( $f )
     173                );
     174
     175                // A true result means the action was added, as failures return false.
     176                $this->assertTrue( $result );
     177
     178                $this->assertEquals( 'public', bbp_get_post_transitioned_status( $f ) );
     179        }
     180
     181        /**
     182         * @covers ::bbp_transition_forum_status_moderated
     183         */
     184        public function test_bbp_transition_forum_status_moderated() {
     185                $f = $this->factory->forum->create();
     186
     187                $result = bbp_transition_forum_status_moderated(
     188                        bbp_get_trash_status_id(),
     189                        bbp_get_public_status_id(),
     190                        bbp_get_forum( $f )
     191                );
     192
     193                // A true result means the action was added, as failures return false.
     194                $this->assertTrue( $result );
     195
     196                $this->assertEquals( 'moderated', bbp_get_post_transitioned_status( $f ) );
     197        }
     198
     199        /**
     200         * @covers ::bbp_transitioned_forum_status_new_public
     201         */
     202        public function test_bbp_transitioned_forum_status_new_public() {
     203                $f = $this->factory->forum->create();
     204
     205                $result = bbp_transitioned_forum_status_new_public( $f );
     206
     207                // A true result means the action was added, as failures return false.
     208                $this->assertTrue( $result );
     209        }
     210
     211        /**
     212         * @covers ::bbp_transitioned_forum_status_new_moderated
     213         */
     214        public function test_bbp_transitioned_forum_status_new_moderated() {
     215                $f = $this->factory->forum->create( array(
     216                        'post_status' => bbp_get_trash_status_id(),
     217                ) );
     218
     219                $result = bbp_transitioned_forum_status_new_moderated( $f );
     220
     221                // A true result means the action was added, as failures return false.
     222                $this->assertTrue( $result );
     223        }
     224
     225        /**
     226         * @covers ::bbp_transitioned_forum_status_public
     227         */
     228        public function test_bbp_transitioned_forum_status_public() {
     229                $f = $this->factory->forum->create();
     230
     231                wp_trash_post( $f );
     232                wp_untrash_post( $f );
     233
     234                $result = bbp_transitioned_forum_status_public( $f );
     235
     236                // A true result means the action was added, as failures return false.
     237                $this->assertTrue( $result );
     238        }
     239
     240        /**
     241         * @covers ::bbp_transitioned_forum_status_moderated
     242         */
     243        public function test_bbp_transitioned_forum_status_moderated() {
     244                $f = $this->factory->forum->create();
     245
     246                wp_trash_post( $f );
     247
     248                $result = bbp_transitioned_forum_status_moderated( $f );
     249
     250                // A true result means the action was added, as failures return false.
     251                $this->assertTrue( $result );
     252        }
    110253}
  • tests/phpunit/testcases/forums/template/status.php

    diff --git tests/phpunit/testcases/forums/template/status.php tests/phpunit/testcases/forums/template/status.php
    index 26a9347..3e92623 100644
    class BBP_Tests_Forums_Template_Status extends BBP_UnitTestCase { 
    2424        }
    2525
    2626        /**
     27         * @covers ::bbp_get_draft_new_forum_statuses
     28         */
     29        public function test_bbp_get_draft_new_forum_statuses() {
     30
     31                $expected = array( 'auto-draft', 'draft', 'new' );
     32
     33                $this->assertEquals( $expected, bbp_get_draft_new_forum_statuses() );
     34        }
     35
     36        /**
     37         * @covers ::bbp_get_public_forum_statuses
     38         */
     39        public function test_bbp_get_public_forum_statuses() {
     40
     41                $expected = array(
     42                        bbp_get_public_status_id(),
     43                        bbp_get_closed_status_id(),
     44                        bbp_get_private_status_id(),
     45                        bbp_get_hidden_status_id(),
     46                );
     47
     48                $this->assertEquals( $expected, bbp_get_public_forum_statuses() );
     49        }
     50
     51        /**
     52         * @covers ::bbp_get_moderated_forum_statuses
     53         */
     54        public function test_bbp_get_moderated_forum_statuses() {
     55
     56                $expected = array( bbp_get_trash_status_id() );
     57
     58                $this->assertEquals( $expected, bbp_get_moderated_forum_statuses() );
     59        }
     60
     61        /**
    2762         * @covers ::bbp_forum_type
    2863         * @covers ::bbp_get_forum_type
    2964         */
  • tests/phpunit/testcases/replies/functions/status.php

    diff --git tests/phpunit/testcases/replies/functions/status.php tests/phpunit/testcases/replies/functions/status.php
    index 7b13b90..d2e42eb 100644
    class BBP_Tests_Replies_Functions_Status extends BBP_UnitTestCase { 
    213213                $topic_reply_count = bbp_get_topic_reply_count( $t );
    214214                $this->assertSame( '1', $topic_reply_count );
    215215        }
     216
     217        /**
     218         * @covers ::bbp_transition_reply_status
     219         */
     220        public function test_bbp_transition_reply_status() {
     221                $f = $this->factory->forum->create();
     222                $t = $this->factory->topic->create( array(
     223                        'post_parent' => $f,
     224                        'topic_meta'  => array(
     225                                'forum_id' => $f,
     226                        ),
     227                ) );
     228                $r = $this->factory->reply->create( array(
     229                        'post_parent' => $t,
     230                        'reply_meta'  => array(
     231                                'forum_id' => $f,
     232                                'topic_id' => $t,
     233                        ),
     234                ) );
     235
     236                $result = bbp_transition_reply_status(
     237                        bbp_get_public_status_id(),
     238                        'new',
     239                        bbp_get_reply( $r )
     240                );
     241
     242                // A true result means the action was added, as failures return false.
     243                $this->assertTrue( $result );
     244        }
     245
     246        /**
     247         * @covers ::bbp_transition_reply_status_new_public
     248         */
     249        public function test_bbp_transition_reply_status_new_public() {
     250                $f = $this->factory->forum->create();
     251                $t = $this->factory->topic->create( array(
     252                        'post_parent' => $f,
     253                        'topic_meta'  => array(
     254                                'forum_id' => $f,
     255                        ),
     256                ) );
     257                $r = $this->factory->reply->create( array(
     258                        'post_parent' => $t,
     259                        'reply_meta'  => array(
     260                                'forum_id' => $f,
     261                                'topic_id' => $t,
     262                        ),
     263                ) );
     264
     265                $result = bbp_transition_reply_status_new_public(
     266                        bbp_get_public_status_id(),
     267                        'new',
     268                        bbp_get_reply( $r )
     269                );
     270
     271                // A true result means the action was added, as failures return false.
     272                $this->assertTrue( $result );
     273
     274                $this->assertEquals( 'new_public', bbp_get_post_transitioned_status( $r ) );
     275        }
     276
     277        /**
     278         * @covers ::bbp_transition_reply_status_new_moderated
     279         */
     280        public function test_bbp_transition_reply_status_new_moderated() {
     281                $f = $this->factory->forum->create();
     282                $t = $this->factory->topic->create( array(
     283                        'post_parent' => $f,
     284                        'topic_meta'  => array(
     285                                'forum_id' => $f,
     286                        ),
     287                ) );
     288                $r = $this->factory->reply->create( array(
     289                        'post_parent' => $t,
     290                        'reply_meta'  => array(
     291                                'forum_id' => $f,
     292                                'topic_id' => $t,
     293                        ),
     294                ) );
     295
     296                $result = bbp_transition_reply_status_new_moderated(
     297                        bbp_get_pending_status_id(),
     298                        'new',
     299                        bbp_get_reply( $r )
     300                );
     301
     302                // A true result means the action was added, as failures return false.
     303                $this->assertTrue( $result );
     304
     305                $this->assertEquals( 'new_moderated', bbp_get_post_transitioned_status( $r ) );
     306        }
     307
     308        /**
     309         * @covers ::bbp_transition_reply_status_public
     310         */
     311        public function test_bbp_transition_reply_status_public() {
     312                $f = $this->factory->forum->create();
     313                $t = $this->factory->topic->create( array(
     314                        'post_parent' => $f,
     315                        'topic_meta'  => array(
     316                                'forum_id' => $f,
     317                        ),
     318                ) );
     319                $r = $this->factory->reply->create( array(
     320                        'post_parent' => $t,
     321                        'reply_meta'  => array(
     322                                'forum_id' => $f,
     323                                'topic_id' => $t,
     324                        ),
     325                ) );
     326
     327                $result = bbp_transition_reply_status_public(
     328                        bbp_get_public_status_id(),
     329                        bbp_get_pending_status_id(),
     330                        bbp_get_reply( $r )
     331                );
     332
     333                // A true result means the action was added, as failures return false.
     334                $this->assertTrue( $result );
     335
     336                $this->assertEquals( 'public', bbp_get_post_transitioned_status( $r ) );
     337        }
     338
     339        /**
     340         * @covers ::bbp_transition_reply_status_moderated
     341         */
     342        public function test_bbp_transition_reply_status_moderated() {
     343                $f = $this->factory->forum->create();
     344                $t = $this->factory->topic->create( array(
     345                        'post_parent' => $f,
     346                        'topic_meta'  => array(
     347                                'forum_id' => $f,
     348                        ),
     349                ) );
     350                $r = $this->factory->reply->create( array(
     351                        'post_parent' => $t,
     352                        'reply_meta'  => array(
     353                                'forum_id' => $f,
     354                                'topic_id' => $t,
     355                        ),
     356                ) );
     357
     358                $result = bbp_transition_reply_status_moderated(
     359                        bbp_get_pending_status_id(),
     360                        bbp_get_public_status_id(),
     361                        bbp_get_reply( $r )
     362                );
     363
     364                // A true result means the action was added, as failures return false.
     365                $this->assertTrue( $result );
     366
     367                $this->assertEquals( 'moderated', bbp_get_post_transitioned_status( $r ) );
     368        }
     369
     370        /**
     371         * @covers ::bbp_transitioned_reply_status_new_public
     372         */
     373        public function test_bbp_transitioned_reply_status_new_public() {
     374                $f = $this->factory->forum->create();
     375                $t = $this->factory->topic->create( array(
     376                        'post_parent' => $f,
     377                        'topic_meta'  => array(
     378                                'forum_id' => $f,
     379                        ),
     380                ) );
     381                $r = $this->factory->reply->create( array(
     382                        'post_parent' => $t,
     383                        'reply_meta'  => array(
     384                                'forum_id' => $f,
     385                                'topic_id' => $t,
     386                        ),
     387                ) );
     388
     389                $result = bbp_transitioned_reply_status_new_public( $r );
     390
     391                // A true result means the action was added, as failures return false.
     392                $this->assertTrue( $result );
     393        }
     394
     395        /**
     396         * @covers ::bbp_transitioned_reply_status_new_moderated
     397         */
     398        public function test_bbp_transitioned_reply_status_new_moderated() {
     399                $f = $this->factory->forum->create();
     400                $t = $this->factory->topic->create( array(
     401                        'post_parent' => $f,
     402                        'topic_meta'  => array(
     403                                'forum_id' => $f,
     404                        ),
     405                ) );
     406                $r = $this->factory->reply->create( array(
     407                        'post_parent' => $t,
     408                        'post_status' => bbp_get_pending_status_id(),
     409                        'reply_meta'  => array(
     410                                'forum_id' => $f,
     411                                'topic_id' => $t,
     412                        ),
     413                ) );
     414
     415                $result = bbp_transitioned_reply_status_new_moderated( $r );
     416
     417                // A true result means the action was added, as failures return false.
     418                $this->assertTrue( $result );
     419        }
     420
     421        /**
     422         * @covers ::bbp_transitioned_reply_status_public
     423         */
     424        public function test_bbp_transitioned_reply_status_public() {
     425                $f = $this->factory->forum->create();
     426                $t = $this->factory->topic->create( array(
     427                        'post_parent' => $f,
     428                        'topic_meta'  => array(
     429                                'forum_id' => $f,
     430                        ),
     431                ) );
     432                $r = $this->factory->reply->create( array(
     433                        'post_parent' => $t,
     434                        'post_status' => bbp_get_pending_status_id(),
     435                        'reply_meta'  => array(
     436                                'forum_id' => $f,
     437                                'topic_id' => $t,
     438                        ),
     439                ) );
     440
     441                bbp_approve_reply( $r );
     442
     443                $result = bbp_transitioned_reply_status_public( $r );
     444
     445                // A true result means the action was added, as failures return false.
     446                $this->assertTrue( $result );
     447        }
     448
     449        /**
     450         * @covers ::bbp_transitioned_reply_status_moderated
     451         */
     452        public function test_bbp_transitioned_reply_status_moderated() {
     453                $f = $this->factory->forum->create();
     454                $t = $this->factory->topic->create( array(
     455                        'post_parent' => $f,
     456                        'topic_meta'  => array(
     457                                'forum_id' => $f,
     458                        ),
     459                ) );
     460                $r = $this->factory->reply->create( array(
     461                        'post_parent' => $t,
     462                        'reply_meta'  => array(
     463                                'forum_id' => $f,
     464                                'topic_id' => $t,
     465                        ),
     466                ) );
     467
     468                bbp_unapprove_reply( $r );
     469
     470                $result = bbp_transitioned_reply_status_moderated( $r );
     471
     472                // A true result means the action was added, as failures return false.
     473                $this->assertTrue( $result );
     474        }
    216475}
  • tests/phpunit/testcases/replies/template/status.php

    diff --git tests/phpunit/testcases/replies/template/status.php tests/phpunit/testcases/replies/template/status.php
    index 588e59d..203042e 100644
    class BBP_Tests_Repliess_Template_Status extends BBP_UnitTestCase { 
    3737        }
    3838
    3939        /**
     40         * @covers ::bbp_get_draft_new_reply_statuses
     41         */
     42        public function test_bbp_get_draft_new_reply_statuses() {
     43
     44                $expected = array( 'auto-draft', 'draft', 'new' );
     45
     46                $this->assertEquals( $expected, bbp_get_draft_new_reply_statuses() );
     47        }
     48
     49        /**
     50         * @covers ::bbp_get_public_reply_statuses
     51         */
     52        public function test_bbp_get_public_reply_statuses() {
     53
     54                $expected = array( bbp_get_public_status_id() );
     55
     56                $this->assertEquals( $expected, bbp_get_public_reply_statuses() );
     57        }
     58
     59        /**
     60         * @covers ::bbp_get_moderated_reply_statuses
     61         */
     62        public function test_bbp_get_moderated_reply_statuses() {
     63
     64                $expected = array(
     65                        bbp_get_pending_status_id(),
     66                        bbp_get_spam_status_id(),
     67                        bbp_get_trash_status_id(),
     68                );
     69
     70                $this->assertEquals( $expected, bbp_get_moderated_reply_statuses() );
     71        }
     72
     73        /**
    4074         * @covers ::bbp_is_reply_published
    4175         */
    4276        public function test_bbp_is_reply_published() {
  • tests/phpunit/testcases/topics/functions/counts.php

    diff --git tests/phpunit/testcases/topics/functions/counts.php tests/phpunit/testcases/topics/functions/counts.php
    index f2296af..21befaf 100644
    class BBP_Tests_Topics_Functions_Counts extends BBP_UnitTestCase { 
    1313         * Generic function to test the topics counts with a new reply
    1414         */
    1515        public function test_bbp_topic_new_reply_counts() {
    16                 remove_action( 'bbp_insert_reply', 'bbp_insert_reply_update_counts', 10 );
     16
     17                // Remove the transitioned new action so we can simulate a new reply.
     18                remove_action( 'bbp_insert_reply', 'bbp_transitioned_reply_status_new' );
    1719
    1820                $u  = $this->factory->user->create();
    1921                $u2 = $this->factory->user->create();
    class BBP_Tests_Topics_Functions_Counts extends BBP_UnitTestCase { 
    3436                        ),
    3537                ) );
    3638
    37                 // Don't attempt to send an email. This is for speed and PHP errors.
    38                 remove_action( 'bbp_new_reply', 'bbp_notify_topic_subscribers', 11, 5 );
    39 
    40                 // Simulate the 'bbp_new_reply' action.
    41                 do_action( 'bbp_new_reply', $r1, $t, $f, false, bbp_get_current_user_id() );
     39                // Simulate the 'bbp_transitioned_reply_status_new' action.
     40                do_action( 'bbp_transitioned_reply_status_new', $r1 );
    4241
    4342                $count = bbp_get_topic_reply_count( $t, true );
    4443                $this->assertSame( 1, $count );
    class BBP_Tests_Topics_Functions_Counts extends BBP_UnitTestCase { 
    5857                        ),
    5958                ) );
    6059
    61                 // Simulate the 'bbp_new_topic' action.
    62                 do_action( 'bbp_new_reply', $r2, $t, $f, false, $u2 );
     60                // Simulate the 'bbp_transitioned_reply_status_new' action.
     61                do_action( 'bbp_transitioned_reply_status_new', $r2 );
    6362
    6463                $count = bbp_get_topic_reply_count( $t, true );
    6564                $this->assertSame( 2, $count );
    class BBP_Tests_Topics_Functions_Counts extends BBP_UnitTestCase { 
    7069                $count = bbp_get_topic_voice_count( $t, true );
    7170                $this->assertSame( 2, $count );
    7271
    73                 // Re-add removed actions.
    74                 add_action( 'bbp_insert_reply', 'bbp_insert_reply_update_counts', 10, 2 );
    75                 add_action( 'bbp_new_reply',    'bbp_notify_topic_subscribers',   11, 5 );
     72                // Re-add the transitioned new action.
     73                add_action( 'bbp_insert_reply', 'bbp_transitioned_reply_status_new' );
    7674        }
    7775
    7876        /**
  • tests/phpunit/testcases/topics/functions/status.php

    diff --git tests/phpunit/testcases/topics/functions/status.php tests/phpunit/testcases/topics/functions/status.php
    index 2f56fde..c80991e 100644
    class BBP_Tests_Topics_Functions_Status extends BBP_UnitTestCase { 
    419419                        'This test has not been implemented yet.'
    420420                );
    421421        }
     422
     423        /**
     424         * @covers ::bbp_transition_topic_status
     425         */
     426        public function test_bbp_transition_topic_status() {
     427                $f = $this->factory->forum->create();
     428                $t = $this->factory->topic->create( array(
     429                        'post_parent' => $f,
     430                        'topic_meta'  => array(
     431                                'forum_id' => $f,
     432                        ),
     433                ) );
     434
     435                $result = bbp_transition_topic_status(
     436                        bbp_get_public_status_id(),
     437                        'new',
     438                        bbp_get_topic( $t )
     439                );
     440
     441                // A true result means the action was added, as failures return false.
     442                $this->assertTrue( $result );
     443        }
     444
     445        /**
     446         * @covers ::bbp_transition_topic_status_new_public
     447         */
     448        public function test_bbp_transition_topic_status_new_public() {
     449                $f = $this->factory->forum->create();
     450                $t = $this->factory->topic->create( array(
     451                        'post_parent' => $f,
     452                        'topic_meta'  => array(
     453                                'forum_id' => $f,
     454                        ),
     455                ) );
     456
     457                $result = bbp_transition_topic_status_new_public(
     458                        bbp_get_public_status_id(),
     459                        'new',
     460                        bbp_get_topic( $t )
     461                );
     462
     463                // A true result means the action was added, as failures return false.
     464                $this->assertTrue( $result );
     465
     466                $this->assertEquals( 'new_public', bbp_get_post_transitioned_status( $t ) );
     467        }
     468
     469        /**
     470         * @covers ::bbp_transition_topic_status_new_moderated
     471         */
     472        public function test_bbp_transition_topic_status_new_moderated() {
     473                $f = $this->factory->forum->create();
     474                $t = $this->factory->topic->create( array(
     475                        'post_parent' => $f,
     476                        'topic_meta'  => array(
     477                                'forum_id' => $f,
     478                        ),
     479                ) );
     480
     481                $result = bbp_transition_topic_status_new_moderated(
     482                        bbp_get_pending_status_id(),
     483                        'new',
     484                        bbp_get_topic( $t )
     485                );
     486
     487                // A true result means the action was added, as failures return false.
     488                $this->assertTrue( $result );
     489
     490                $this->assertEquals( 'new_moderated', bbp_get_post_transitioned_status( $t ) );
     491        }
     492
     493        /**
     494         * @covers ::bbp_transition_topic_status_public
     495         */
     496        public function test_bbp_transition_topic_status_public() {
     497                $f = $this->factory->forum->create();
     498                $t = $this->factory->topic->create( array(
     499                        'post_parent' => $f,
     500                        'topic_meta'  => array(
     501                                'forum_id' => $f,
     502                        ),
     503                ) );
     504
     505                $result = bbp_transition_topic_status_public(
     506                        bbp_get_public_status_id(),
     507                        bbp_get_pending_status_id(),
     508                        bbp_get_topic( $t )
     509                );
     510
     511                // A true result means the action was added, as failures return false.
     512                $this->assertTrue( $result );
     513
     514                $this->assertEquals( 'public', bbp_get_post_transitioned_status( $t ) );
     515        }
     516
     517        /**
     518         * @covers ::bbp_transition_topic_status_moderated
     519         */
     520        public function test_bbp_transition_topic_status_moderated() {
     521                $f = $this->factory->forum->create();
     522                $t = $this->factory->topic->create( array(
     523                        'post_parent' => $f,
     524                        'topic_meta'  => array(
     525                                'forum_id' => $f,
     526                        ),
     527                ) );
     528
     529                $result = bbp_transition_topic_status_moderated(
     530                        bbp_get_pending_status_id(),
     531                        bbp_get_public_status_id(),
     532                        bbp_get_topic( $t )
     533                );
     534
     535                // A true result means the action was added, as failures return false.
     536                $this->assertTrue( $result );
     537
     538                $this->assertEquals( 'moderated', bbp_get_post_transitioned_status( $t ) );
     539        }
     540
     541        /**
     542         * @covers ::bbp_transitioned_topic_status_new_public
     543         */
     544        public function test_bbp_transitioned_topic_status_new_public() {
     545                $f = $this->factory->forum->create();
     546                $t = $this->factory->topic->create( array(
     547                        'post_parent' => $f,
     548                        'topic_meta'  => array(
     549                                'forum_id' => $f,
     550                        ),
     551                ) );
     552
     553                $result = bbp_transitioned_topic_status_new_public( $t );
     554
     555                // A true result means the action was added, as failures return false.
     556                $this->assertTrue( $result );
     557        }
     558
     559        /**
     560         * @covers ::bbp_transitioned_topic_status_new_moderated
     561         */
     562        public function test_bbp_transitioned_topic_status_new_moderated() {
     563                $f = $this->factory->forum->create();
     564                $t = $this->factory->topic->create( array(
     565                        'post_parent' => $f,
     566                        'post_status' => bbp_get_pending_status_id(),
     567                        'topic_meta'  => array(
     568                                'forum_id' => $f,
     569                        ),
     570                ) );
     571
     572                $result = bbp_transitioned_topic_status_new_moderated( $t );
     573
     574                // A true result means the action was added, as failures return false.
     575                $this->assertTrue( $result );
     576        }
     577
     578        /**
     579         * @covers ::bbp_transitioned_topic_status_public
     580         */
     581        public function test_bbp_transitioned_topic_status_public() {
     582                $f = $this->factory->forum->create();
     583                $t = $this->factory->topic->create( array(
     584                        'post_parent' => $f,
     585                        'post_status' => bbp_get_pending_status_id(),
     586                        'topic_meta'  => array(
     587                                'forum_id' => $f,
     588                        ),
     589                ) );
     590
     591                bbp_approve_topic( $t );
     592
     593                $result = bbp_transitioned_topic_status_public( $t );
     594
     595                // A true result means the action was added, as failures return false.
     596                $this->assertTrue( $result );
     597        }
     598
     599        /**
     600         * @covers ::bbp_transitioned_topic_status_moderated
     601         */
     602        public function test_bbp_transitioned_topic_status_moderated() {
     603                $f = $this->factory->forum->create();
     604                $t = $this->factory->topic->create( array(
     605                        'post_parent' => $f,
     606                        'topic_meta'  => array(
     607                                'forum_id' => $f,
     608                        ),
     609                ) );
     610
     611                bbp_unapprove_topic( $t );
     612
     613                $result = bbp_transitioned_topic_status_moderated( $t );
     614
     615                // A true result means the action was added, as failures return false.
     616                $this->assertTrue( $result );
     617        }
    422618}
  • tests/phpunit/testcases/topics/template/status.php

    diff --git tests/phpunit/testcases/topics/template/status.php tests/phpunit/testcases/topics/template/status.php
    index 3dc3ece..da2779f 100644
    class BBP_Tests_Topics_Template_Status extends BBP_UnitTestCase { 
    5454        }
    5555
    5656        /**
     57         * @covers ::bbp_get_draft_new_topic_statuses
     58         */
     59        public function test_bbp_get_draft_new_topic_statuses() {
     60
     61                $expected = array( 'auto-draft', 'draft', 'new' );
     62
     63                $this->assertEquals( $expected, bbp_get_draft_new_topic_statuses() );
     64        }
     65
     66        /**
     67         * @covers ::bbp_get_public_topic_statuses
     68         */
     69        public function test_bbp_get_public_topic_statuses() {
     70
     71                $expected = array( bbp_get_public_status_id(), bbp_get_closed_status_id() );
     72
     73                $this->assertEquals( $expected, bbp_get_public_topic_statuses() );
     74        }
     75
     76        /**
     77         * @covers ::bbp_get_moderated_topic_statuses
     78         */
     79        public function test_bbp_get_moderated_topic_statuses() {
     80
     81                $expected = array(
     82                        bbp_get_pending_status_id(),
     83                        bbp_get_spam_status_id(),
     84                        bbp_get_trash_status_id(),
     85                );
     86
     87                $this->assertEquals( $expected, bbp_get_moderated_topic_statuses() );
     88        }
     89
     90        /**
    5791         * @covers ::bbp_is_topic_closed
    5892         * @todo   Implement test_bbp_is_topic_closed().
    5993         */
  • tests/phpunit/testcases/users/functions/counts.php

    diff --git tests/phpunit/testcases/users/functions/counts.php tests/phpunit/testcases/users/functions/counts.php
    index 190a9cd..30fd2ec 100644
    class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 
    266266         * @covers ::bbp_increase_user_topic_count
    267267         */
    268268        public function test_bbp_increase_user_topic_count() {
     269
     270                // Remove the transitioned new action so we manually manipulate counts.
     271                remove_action( 'bbp_insert_topic', 'bbp_transitioned_topic_status_new_public', 20 );
     272
    269273                $u = $this->factory->user->create();
    270274                $int_value = 3;
    271275                $integer = true;
    class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 
    283287
    284288                $count = bbp_get_user_topic_count( $u, $integer );
    285289                $this->assertSame( $int_value + 1, $count );
     290
     291                // Re-add the transitioned new action.
     292                add_action( 'bbp_insert_topic', 'bbp_transitioned_topic_status_new_public', 20 );
    286293        }
    287294
    288295        /**
    289296         * @covers ::bbp_increase_user_reply_count
    290297         */
    291298        public function test_bbp_increase_user_reply_count() {
     299
     300                // Remove the transitioned new action so we manually manipulate counts.
     301                remove_action( 'bbp_insert_reply', 'bbp_transitioned_reply_status_new_public', 20 );
     302
    292303                $u = $this->factory->user->create();
    293304                $int_value = 3;
    294305                $integer = true;
    class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 
    312323
    313324                $count = bbp_get_user_reply_count( $u, $integer );
    314325                $this->assertSame( $int_value, $count );
     326
     327                // Re-add the transitioned new action.
     328                add_action( 'bbp_insert_reply', 'bbp_transitioned_reply_status_new_public', 20 );
    315329        }
    316330
    317331        /**
    318332         * @covers ::bbp_decrease_user_topic_count
    319333         */
    320334        public function test_bbp_decrease_user_topic_count() {
     335
     336                // Remove the transitioned new action so we manually manipulate counts.
     337                remove_action( 'bbp_insert_topic', 'bbp_transitioned_topic_status_new_public', 20 );
     338
    321339                $u = $this->factory->user->create();
    322340                $int_value = 3;
    323341                $integer = true;
    class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 
    342360
    343361                $count = bbp_get_user_topic_count( $u, $integer );
    344362                $this->assertSame( $int_value - 2, $count );
     363
     364                // Re-add the transitioned new action.
     365                add_action( 'bbp_insert_topic', 'bbp_transitioned_topic_status_new_public', 20 );
    345366        }
    346367
    347368        /**
    348369         * @covers ::bbp_decrease_user_reply_count
    349370         */
    350371        public function test_bbp_decrease_user_reply_count() {
     372
     373                // Remove the transitioned new action so we manually manipulate counts.
     374                remove_action( 'bbp_insert_reply', 'bbp_transitioned_reply_status_new_public', 20 );
     375
    351376                $u = $this->factory->user->create();
    352377                $int_value = 3;
    353378                $integer = true;
    class BBP_Tests_Users_Functions_Counts extends BBP_UnitTestCase { 
    378403
    379404                $count = bbp_get_user_reply_count( $u, $integer );
    380405                $this->assertSame( $int_value - 2, $count );
     406
     407                // Re-add the transitioned new action.
     408                add_action( 'bbp_insert_reply', 'bbp_transitioned_reply_status_new_public', 20 );
    381409        }
    382410}