Ticket #1799: 1799.16.diff
File 1799.16.diff, 96.6 KB (added by , 8 years ago) |
---|
-
src/bbpress.php
5 5 * 6 6 * bbPress is forum software with a twist from the creators of WordPress. 7 7 * 8 * $Id: bbpress.php 6341 2017-03- 25 18:46:32Z johnjamesjacoby $8 * $Id: bbpress.php 6341 2017-03-02 04:46:00Z johnjamesjacoby $ 9 9 * 10 10 * @package bbPress 11 11 * @subpackage Main … … 246 246 247 247 // Status identifiers 248 248 $this->spam_status_id = apply_filters( 'bbp_spam_post_status', 'spam' ); 249 $this->open_status_id = apply_filters( 'bbp_open_post_status', 'open' ); 249 250 $this->closed_status_id = apply_filters( 'bbp_closed_post_status', 'closed' ); 250 251 $this->orphan_status_id = apply_filters( 'bbp_orphan_post_status', 'orphan' ); 251 252 $this->public_status_id = apply_filters( 'bbp_public_post_status', 'publish' ); … … 293 294 294 295 /** Misc **************************************************************/ 295 296 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 297 $this->domain = 'bbpress'; // Unique identifier for retrieving translated strings 298 $this->extend = new stdClass(); // Plugins add data here 299 $this->errors = new WP_Error(); // Feedback 300 $this->transitioned_posts = array(); // Transitioned post ids. 299 301 300 302 /** Deprecated ********************************************************/ 301 303 … … 341 343 // Forums 342 344 require $this->includes_dir . 'forums/capabilities.php'; 343 345 require $this->includes_dir . 'forums/functions.php'; 346 require $this->includes_dir . 'forums/status.php'; 344 347 require $this->includes_dir . 'forums/template.php'; 345 348 346 349 // Topics 347 350 require $this->includes_dir . 'topics/capabilities.php'; 348 351 require $this->includes_dir . 'topics/functions.php'; 352 require $this->includes_dir . 'topics/status.php'; 349 353 require $this->includes_dir . 'topics/template.php'; 350 354 351 355 // Replies 352 356 require $this->includes_dir . 'replies/capabilities.php'; 353 357 require $this->includes_dir . 'replies/functions.php'; 358 require $this->includes_dir . 'replies/status.php'; 354 359 require $this->includes_dir . 'replies/template.php'; 355 360 356 361 // Search -
src/includes/admin/forums.php
75 75 add_action( 'add_meta_boxes', array( $this, 'comments_metabox' ) ); 76 76 add_action( 'save_post', array( $this, 'save_meta_boxes' ) ); 77 77 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 78 84 // Check if there are any bbp_toggle_forum_* requests on admin_init, also have a message displayed 79 85 add_action( 'load-edit.php', array( $this, 'toggle_forum' ) ); 80 86 add_action( 'admin_notices', array( $this, 'toggle_forum_notice' ) ); -
src/includes/admin/metaboxes.php
316 316 ?> 317 317 318 318 <p> 319 <strong class="label"><?php esc_html_e( ' Status:', 'bbpress' ); ?></strong>320 <label class="screen-reader-text" for="bbp_forum_status_select"><?php esc_html_e( ' Status:', 'bbpress' ) ?></label>321 <?php bbp_form_forum_ status_dropdown( array( 'forum_id' => $post->ID ) ); ?>319 <strong class="label"><?php esc_html_e( 'Lock:', 'bbpress' ); ?></strong> 320 <label class="screen-reader-text" for="bbp_forum_status_select"><?php esc_html_e( 'Lock:', 'bbpress' ) ?></label> 321 <?php bbp_form_forum_lock_dropdown( array( 'forum_id' => $post->ID ) ); ?> 322 322 </p> 323 323 324 324 <?php -
src/includes/admin/replies.php
82 82 add_action( 'add_meta_boxes', array( $this, 'comments_metabox' ) ); 83 83 add_action( 'save_post', array( $this, 'save_meta_boxes' ) ); 84 84 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 85 91 // Check if there are any bbp_toggle_reply_* requests on admin_init, also have a message displayed 86 92 add_action( 'load-edit.php', array( $this, 'toggle_reply' ) ); 87 93 add_action( 'admin_notices', array( $this, 'toggle_reply_notice' ) ); -
src/includes/admin/topics.php
86 86 add_action( 'add_meta_boxes', array( $this, 'comments_metabox' ) ); 87 87 add_action( 'save_post', array( $this, 'save_meta_boxes' ) ); 88 88 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 89 95 // Check if there are any bbp_toggle_topic_* requests on admin_init, also have a message displayed 90 96 add_action( 'load-edit.php', array( $this, 'toggle_topic' ) ); 91 97 add_action( 'admin_notices', array( $this, 'toggle_topic_notice' ) ); -
src/includes/common/functions.php
1775 1775 'feed' => true, 1776 1776 'post_type' => bbp_get_reply_post_type(), 1777 1777 'post_parent' => 'any', 1778 'post_status' => bbp_get_ public_topic_statuses(),1778 'post_status' => bbp_get_topic_statuses( null, 'public', true ), 1779 1779 'posts_per_page' => bbp_get_replies_per_rss_page(), 1780 1780 'order' => 'DESC', 1781 1781 'meta_query' => $meta_query … … 1793 1793 'feed' => true, 1794 1794 'post_type' => bbp_get_topic_post_type(), 1795 1795 'post_parent' => bbp_get_forum_id(), 1796 'post_status' => bbp_get_ public_topic_statuses(),1796 'post_status' => bbp_get_topic_statuses( null, 'public', true ), 1797 1797 'posts_per_page' => bbp_get_topics_per_rss_page(), 1798 1798 'order' => 'DESC' 1799 1799 ); … … 1815 1815 'feed' => true, 1816 1816 'post_type' => array( bbp_get_reply_post_type(), bbp_get_topic_post_type() ), 1817 1817 'post_parent' => 'any', 1818 'post_status' => bbp_get_ public_topic_statuses(),1818 'post_status' => bbp_get_topic_statuses( null, 'public', true ), 1819 1819 'posts_per_page' => bbp_get_replies_per_rss_page(), 1820 1820 'order' => 'DESC', 1821 1821 'meta_query' => $meta_query … … 1953 1953 1954 1954 $wp_query->set_404(); 1955 1955 } 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 2.6.0 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 */ 1970 function bbp_stash_transitioned_post_status( $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 // Copy to a variable, to update. 1978 $bbp = bbpress(); 1979 $transitioned_posts = $bbp->transitioned_posts; 1980 1981 // Update the global. 1982 $transitioned_posts[ $post_id ] = $status; 1983 $bbp->transitioned_posts = $transitioned_posts; 1984 } 1985 1986 /** 1987 * Returns the transitioned post status. 1988 * 1989 * @since 2.6.0 bbPress (rXXXX) 1990 * 1991 * @param int $post_id The forum/topic/reply id. 1992 * 1993 * @return string new/public/moderated. Empty on failure. 1994 */ 1995 function bbp_get_transitioned_post_status( $post_id = 0 ) { 1996 1997 // Get transitioned posts 1998 $transitioned_posts = bbpress()->transitioned_posts; 1999 2000 // Get the transitioned post status. 2001 $status = ! empty( $transitioned_posts[ $post_id ] ) 2002 ? $transitioned_posts[ $post_id ] 2003 : ''; 2004 2005 /** 2006 * Filters the return of `bbp_get_transitioned_post_status()`. 2007 * 2008 * @since 2.6.0 bbPress (rXXXX) 2009 * 2010 * @param string $status new/public/moderated. Empty on failure. 2011 * @param int $post_id The forum/topic/reply id. 2012 */ 2013 return apply_filters( 'bbp_get_transitioned_post_status', $status, $post_id ); 2014 } 2015 2016 /** 2017 * Checks if a given post id was transitioned to a given status. 2018 * 2019 * @since 2.6.0 bbPress (rXXXX) 2020 * 2021 * @param int $post_id The forum/topic/reply id. 2022 * @param string $status The status. 2023 * 2024 * @return bool True if the post id was transitioned to new public. 2025 */ 2026 function bbp_is_post_status_transitioned( $post_id = 0, $status = 'new_public' ) { 2027 2028 // Is status? 2029 $retval = ( bbp_get_transitioned_post_status( $post_id ) === $status ); 2030 2031 /** 2032 * Filters the return of `bbp_is_post_status_transitioned()`. 2033 * 2034 * @since 2.6.0 bbPress (rXXXX) 2035 * 2036 * @param bool $retval True if the post was transitioned to the status. 2037 * @param int $post_id The forum/topic/reply id. 2038 */ 2039 return (bool) apply_filters( 'bbp_is_post_status_transitioned', $retval, $post_id, $status ); 2040 } -
src/includes/common/widgets.php
745 745 'post_type' => bbp_get_topic_post_type(), 746 746 'post_parent' => $settings['parent_forum'], 747 747 'posts_per_page' => (int) $settings['max_shown'], 748 'post_status' => bbp_get_ public_topic_statuses(),748 'post_status' => bbp_get_topic_statuses( null, 'public', true ), 749 749 'ignore_sticky_posts' => true, 750 750 'no_found_rows' => true, 751 751 'meta_key' => '_bbp_last_active_time', … … 761 761 'post_type' => bbp_get_topic_post_type(), 762 762 'post_parent' => $settings['parent_forum'], 763 763 'posts_per_page' => (int) $settings['max_shown'], 764 'post_status' => bbp_get_ public_topic_statuses(),764 'post_status' => bbp_get_topic_statuses( null, 'public', true ), 765 765 'ignore_sticky_posts' => true, 766 766 'no_found_rows' => true, 767 767 'meta_key' => '_bbp_reply_count', … … 778 778 'post_type' => bbp_get_topic_post_type(), 779 779 'post_parent' => $settings['parent_forum'], 780 780 'posts_per_page' => (int) $settings['max_shown'], 781 'post_status' => bbp_get_ public_topic_statuses(),781 'post_status' => bbp_get_topic_statuses( null, 'public', true ), 782 782 'ignore_sticky_posts' => true, 783 783 'no_found_rows' => true, 784 784 'order' => 'DESC' … … 1130 1130 // bbp_pre_get_posts_normalize_forum_visibility action and function. 1131 1131 $widget_query = new WP_Query( array( 1132 1132 'post_type' => bbp_get_reply_post_type(), 1133 'post_status' => bbp_get_ public_topic_statuses(),1133 'post_status' => bbp_get_topic_statuses( null, 'public', true ), 1134 1134 'posts_per_page' => (int) $settings['max_shown'], 1135 1135 'ignore_sticky_posts' => true, 1136 1136 'no_found_rows' => true, -
src/includes/core/actions.php
53 53 add_action( 'login_form_login', 'bbp_login_form_login', 10 ); 54 54 add_action( 'profile_update', 'bbp_profile_update', 10, 2 ); // user_id and old_user_data 55 55 add_action( 'user_register', 'bbp_user_register', 10 ); 56 add_action( 'transition_post_status', 'bbp_transition_post_status', 10, 3 ); 56 57 57 58 /** 58 59 * bbp_loaded - Attached to 'plugins_loaded' above … … 164 165 add_action( 'untrashed_post', 'bbp_untrashed_forum' ); 165 166 add_action( 'deleted_post', 'bbp_deleted_forum' ); 166 167 168 // Transition forum status. 169 add_action( 'bbp_transition_forum_status', 'bbp_transition_forum_status_new_public', 10, 3 ); 170 add_action( 'bbp_transition_forum_status', 'bbp_transition_forum_status_new_moderated', 10, 3 ); 171 add_action( 'bbp_transition_forum_status', 'bbp_transition_forum_status_public', 10, 3 ); 172 add_action( 'bbp_transition_forum_status', 'bbp_transition_forum_status_moderated', 10, 3 ); 173 174 // Transitioned forum status. 175 add_action( 'bbp_new_forum', 'bbp_transitioned_forum_status_new_public', 20 ); 176 add_action( 'bbp_new_forum', 'bbp_transitioned_forum_status_new_moderated', 20 ); 177 add_action( 'bbp_insert_forum', 'bbp_transitioned_forum_status_new_public', 20 ); 178 add_action( 'bbp_insert_forum', 'bbp_transitioned_forum_status_new_moderated', 20 ); 179 add_action( 'bbp_trashed_forum', 'bbp_transitioned_forum_status_moderated', 20 ); 180 add_action( 'bbp_untrashed_forum', 'bbp_transitioned_forum_status_public', 20 ); 181 167 182 // Auto trash/untrash/delete a forums topics 168 183 add_action( 'bbp_delete_forum', 'bbp_delete_forum_topics', 10 ); 169 184 add_action( 'bbp_trash_forum', 'bbp_trash_forum_topics', 10 ); … … 193 208 add_action( 'untrashed_post', 'bbp_untrashed_reply' ); 194 209 add_action( 'deleted_post', 'bbp_deleted_reply' ); 195 210 211 // Transition reply status. 212 add_action( 'bbp_transition_reply_status', 'bbp_transition_reply_status_new_public', 10, 3 ); 213 add_action( 'bbp_transition_reply_status', 'bbp_transition_reply_status_new_moderated', 10, 3 ); 214 add_action( 'bbp_transition_reply_status', 'bbp_transition_reply_status_public', 10, 3 ); 215 add_action( 'bbp_transition_reply_status', 'bbp_transition_reply_status_moderated', 10, 3 ); 216 217 // Transitioned reply status. 218 add_action( 'bbp_new_reply', 'bbp_transitioned_reply_status_new_public', 20 ); 219 add_action( 'bbp_new_reply', 'bbp_transitioned_reply_status_new_moderated', 20 ); 220 add_action( 'bbp_insert_reply', 'bbp_transitioned_reply_status_new_public', 20 ); 221 add_action( 'bbp_insert_reply', 'bbp_transitioned_reply_status_new_moderated', 20 ); 222 add_action( 'bbp_trashed_reply', 'bbp_transitioned_reply_status_moderated', 20 ); 223 add_action( 'bbp_untrashed_reply', 'bbp_transitioned_reply_status_public', 20 ); 224 add_action( 'bbp_spammed_reply', 'bbp_transitioned_reply_status_moderated', 20 ); 225 add_action( 'bbp_unspammed_reply', 'bbp_transitioned_reply_status_public', 20 ); 226 add_action( 'bbp_approved_reply', 'bbp_transitioned_reply_status_public', 20 ); 227 add_action( 'bbp_unapproved_reply', 'bbp_transitioned_reply_status_moderated', 20 ); 228 196 229 // New/Edit Topic 197 230 add_action( 'bbp_new_topic', 'bbp_update_topic', 10, 5 ); 198 231 add_action( 'bbp_edit_topic', 'bbp_update_topic', 10, 5 ); … … 215 248 add_action( 'untrashed_post', 'bbp_untrashed_topic' ); 216 249 add_action( 'deleted_post', 'bbp_deleted_topic' ); 217 250 251 // Transition topic status. 252 add_action( 'bbp_transition_topic_status', 'bbp_transition_topic_status_new_public', 10, 3 ); 253 add_action( 'bbp_transition_topic_status', 'bbp_transition_topic_status_new_moderated', 10, 3 ); 254 add_action( 'bbp_transition_topic_status', 'bbp_transition_topic_status_public', 10, 3 ); 255 add_action( 'bbp_transition_topic_status', 'bbp_transition_topic_status_moderated', 10, 3 ); 256 257 // Transitioned topic status. 258 add_action( 'bbp_new_topic', 'bbp_transitioned_topic_status_new_public', 20 ); 259 add_action( 'bbp_new_topic', 'bbp_transitioned_topic_status_new_moderated', 20 ); 260 add_action( 'bbp_insert_topic', 'bbp_transitioned_topic_status_new_public', 20 ); 261 add_action( 'bbp_insert_topic', 'bbp_transitioned_topic_status_new_moderated', 20 ); 262 add_action( 'bbp_trashed_topic', 'bbp_transitioned_topic_status_moderated', 20 ); 263 add_action( 'bbp_untrashed_topic', 'bbp_transitioned_topic_status_public', 20 ); 264 add_action( 'bbp_spammed_topic', 'bbp_transitioned_topic_status_moderated', 20 ); 265 add_action( 'bbp_unspammed_topic', 'bbp_transitioned_topic_status_public', 20 ); 266 add_action( 'bbp_approved_topic', 'bbp_transitioned_topic_status_public', 20 ); 267 add_action( 'bbp_unapproved_topic', 'bbp_transitioned_topic_status_moderated', 20 ); 268 218 269 // Favorites 219 270 add_action( 'bbp_spam_topic', 'bbp_remove_topic_from_all_favorites' ); 220 271 add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_favorites' ); … … 253 304 add_action( 'bbp_unapproved_reply', 'bbp_update_reply_walker' ); 254 305 255 306 // 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' ); 307 add_action( 'bbp_transitioned_reply_status_new_public', 'bbp_increase_forum_reply_count' ); 308 add_action( 'bbp_transitioned_reply_status_public', 'bbp_increase_forum_reply_count' ); 309 add_action( 'bbp_transitioned_reply_status_moderated', 'bbp_decrease_forum_reply_count' ); 310 add_action( 'bbp_transitioned_topic_status_new_public', 'bbp_increase_forum_topic_count' ); 311 add_action( 'bbp_transitioned_topic_status_new_moderated', 'bbp_increase_forum_topic_count_hidden' ); 312 add_action( 'bbp_transitioned_topic_status_public', 'bbp_increase_forum_topic_count' ); 313 add_action( 'bbp_transitioned_topic_status_public', 'bbp_decrease_forum_topic_count_hidden' ); 314 add_action( 'bbp_transitioned_topic_status_moderated', 'bbp_decrease_forum_topic_count' ); 315 add_action( 'bbp_transitioned_topic_status_moderated', 'bbp_increase_forum_topic_count_hidden' ); 276 316 277 317 // Update forum reply counts for approved/unapproved topics. 278 318 add_action( 'bbp_approved_topic', 'bbp_approved_unapproved_topic_update_forum_reply_count' ); 279 319 add_action( 'bbp_unapproved_topic', 'bbp_approved_unapproved_topic_update_forum_reply_count' ); 280 320 281 321 // 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' ); 322 add_action( 'bbp_transitioned_reply_status_new_public', 'bbp_increase_topic_reply_count' ); 323 add_action( 'bbp_transitioned_reply_status_new_moderated', 'bbp_increase_topic_reply_count_hidden' ); 324 add_action( 'bbp_transitioned_reply_status_public', 'bbp_increase_topic_reply_count' ); 325 add_action( 'bbp_transitioned_reply_status_public', 'bbp_decrease_topic_reply_count_hidden' ); 326 add_action( 'bbp_transitioned_reply_status_moderated', 'bbp_decrease_topic_reply_count' ); 327 add_action( 'bbp_transitioned_reply_status_moderated', 'bbp_increase_topic_reply_count_hidden' ); 295 328 296 329 // 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' ); 330 add_action( 'bbp_transitioned_reply_status_new_public', 'bbp_increase_user_reply_count' ); 331 add_action( 'bbp_transitioned_reply_status_public', 'bbp_increase_user_reply_count' ); 332 add_action( 'bbp_transitioned_reply_status_moderated', 'bbp_decrease_user_reply_count' ); 333 add_action( 'bbp_transitioned_topic_status_new_public', 'bbp_increase_user_topic_count' ); 334 add_action( 'bbp_transitioned_topic_status_public', 'bbp_increase_user_topic_count' ); 335 add_action( 'bbp_transitioned_topic_status_moderated', 'bbp_decrease_user_topic_count' ); 307 336 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 );311 312 337 // Update topic voice counts. 313 338 add_action( 'bbp_new_reply', 'bbp_update_topic_voice_count' ); 314 339 add_action( 'bbp_trashed_reply', 'bbp_update_topic_voice_count' ); -
src/includes/core/functions.php
448 448 } 449 449 450 450 /** 451 * Return the open post status ID 452 * 453 * @since 2.6.0 bbPress (rXXXX) 454 * 455 * @return string 456 */ 457 function bbp_get_open_status_id() { 458 return bbpress()->open_status_id; 459 } 460 461 /** 451 462 * Return the closed post status ID 452 463 * 453 464 * @since 2.0.0 bbPress (r3504) -
src/includes/core/sub-actions.php
534 534 function bbp_map_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) { 535 535 return apply_filters( 'bbp_map_meta_caps', $caps, $cap, $user_id, $args ); 536 536 } 537 538 /** Statuses ******************************************************************/ 539 540 /** 541 * Maps forum/topic/reply status transition 542 * 543 * @since 2.6.0 bbPress (rXXXX) 544 * 545 * @param string $new_status The new post status 546 * @param string $old_status The old post status 547 * @param WP_Post $post The post being transitioned 548 */ 549 function bbp_transition_post_status( $new_status = '', $old_status = '', $post = 0 ) { 550 551 // Get type of post 552 $post_type = get_post_type( $post ); 553 554 // Bail if not a bbPress post type 555 if ( ! in_array( $post_type, array( 556 bbp_get_forum_post_type(), 557 bbp_get_topic_post_type(), 558 bbp_get_reply_post_type() 559 ), true ) ) { 560 return; 561 } 562 563 /** 564 * Transition a bbPress post-type status 565 * 566 * @since 2.6.0 bbPress (rXXXX) 567 */ 568 do_action( "bbp_transition_{$post_type}_status", $new_status, $old_status, $post ); 569 } -
src/includes/forums/functions.php
644 644 645 645 /** Forum Status **********************************************************/ 646 646 647 if ( ! empty( $_POST['bbp_forum_ status'] ) && in_array( $_POST['bbp_forum_status'], array( 'open', 'closed') ) ) {648 if ( 'closed' === $_POST['bbp_forum_status'] && ! bbp_is_forum_closed( $forum_id, false ) ) {647 if ( ! empty( $_POST['bbp_forum_lock'] ) && in_array( $_POST['bbp_forum_lock'], array_keys( bbp_get_forum_locks( $forum_id ) ) ) ) { 648 if ( bbp_get_closed_status_id() === $_POST['bbp_forum_lock'] && ! bbp_is_forum_closed( $forum_id, false ) ) { 649 649 bbp_close_forum( $forum_id ); 650 } elseif ( 'open' === $_POST['bbp_forum_status'] && bbp_is_forum_open( $forum_id, false ) ) {650 } elseif ( bbp_get_open_status_id() === $_POST['bbp_forum_lock'] && bbp_is_forum_open( $forum_id, false ) ) { 651 651 bbp_open_forum( $forum_id ); 652 } elseif ( 'open' === $_POST['bbp_forum_status'] && bbp_is_forum_closed( $forum_id, false ) ) {652 } elseif ( bbp_get_open_status_id() === $_POST['bbp_forum_lock'] && bbp_is_forum_closed( $forum_id, false ) ) { 653 653 bbp_open_forum( $forum_id ); 654 654 } 655 655 } … … 668 668 669 669 /** Forum Visibility ******************************************************/ 670 670 671 if ( ! empty( $_POST['bbp_forum_visibility'] ) && in_array( $_POST['bbp_forum_visibility'], array_keys( bbp_get_forum_visibilities( ) ) ) ) {671 if ( ! empty( $_POST['bbp_forum_visibility'] ) && in_array( $_POST['bbp_forum_visibility'], array_keys( bbp_get_forum_visibilities( $forum_id ) ) ) ) { 672 672 673 673 // Get forums current visibility 674 674 $old_visibility = bbp_get_forum_visibility( $forum_id ); … … 762 762 763 763 do_action( 'bbp_close_forum', $forum_id ); 764 764 765 update_post_meta( $forum_id, '_bbp_status', 'closed');765 update_post_meta( $forum_id, '_bbp_status', bbp_get_closed_status_id() ); 766 766 767 767 do_action( 'bbp_closed_forum', $forum_id ); 768 768 … … 787 787 788 788 do_action( 'bbp_open_forum', $forum_id ); 789 789 790 update_post_meta( $forum_id, '_bbp_status', 'open');790 update_post_meta( $forum_id, '_bbp_status', bbp_get_open_status_id() ); 791 791 792 792 do_action( 'bbp_opened_forum', $forum_id ); 793 793 … … 1972 1972 bbp_update_forum_subforum_count( $r['forum_id'] ); 1973 1973 1974 1974 // 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() ) { 1976 1976 bbp_update_forum_reply_count( $r['forum_id'] ); 1977 1977 bbp_update_forum_topic_count( $r['forum_id'] ); 1978 1978 bbp_update_forum_topic_count_hidden( $r['forum_id'] ); … … 1990 1990 /** Helpers *******************************************************************/ 1991 1991 1992 1992 /** 1993 * Return an associative array of available topic statuses1993 * Return an associative array of forum locks and labels 1994 1994 * 1995 * @since 2. 4.0 bbPress (r5059)1995 * @since 2.6.0 bbPress (rXXXX) 1996 1996 * 1997 * @param int $forum_id Optional. Forum id. 1998 * 1997 * @param int $forum_id The forum ID to get locks for 1999 1998 * @return array 2000 1999 */ 2001 function bbp_get_forum_ statuses( $forum_id = 0 ) {2002 return apply_filters( 'bbp_get_forum_statuses', array(2003 'open' => _x( 'Open','Open the forum', 'bbpress' ),2004 'closed' => _x( 'Closed','Close the forum', 'bbpress' )2000 function bbp_get_forum_locks( $forum_id = 0 ) { 2001 return (array) apply_filters( 'bbp_get_forum_statuses', array( 2002 bbp_get_open_status_id() => _x( 'Open', 'Open the forum', 'bbpress' ), 2003 bbp_get_closed_status_id() => _x( 'Closed', 'Close the forum', 'bbpress' ) 2005 2004 ), $forum_id ); 2006 2005 } 2007 2006 2008 2007 /** 2009 * Return an associative array of forum types 2008 * Return an associative array of forum types and labels 2010 2009 * 2011 2010 * @since 2.4.0 bbPress (r5059) 2012 2011 * … … 2022 2021 } 2023 2022 2024 2023 /** 2025 * Return an associative array of forum visibilit y2024 * Return an associative array of forum visibilities and labels 2026 2025 * 2027 2026 * @since 2.4.0 bbPress (r5059) 2028 2027 * … … 2038 2037 ), $forum_id ); 2039 2038 } 2040 2039 2040 /** 2041 * Return an associative array of available topic statuses 2042 * 2043 * @since 2.4.0 bbPress (r5059) 2044 * @since 2.6.0 bbPress (rXXXX) Switched to work for post_status vs locks 2045 * 2046 * @param int $forum_id Optional. Forum id. 2047 * @param string $type Optional. all|new|public|moderated 2048 * @param bool $keys_only Optional. Just return array keys 2049 * 2050 * @return array 2051 */ 2052 function bbp_get_forum_statuses( $forum_id = 0, $type = 'all', $keys_only = false ) { 2053 static $all_statuses = null; 2054 2055 // All statuses 2056 if ( null === $all_statuses ) { 2057 $all_statuses = array( 2058 bbp_get_public_status_id() => _x( 'Published', 'Open the forum', 'bbpress' ), 2059 bbp_get_closed_status_id() => _x( 'Closed', 'Close the forum', 'bbpress' ), 2060 bbp_get_spam_status_id() => _x( 'Spam', 'Spam the reply', 'bbpress' ), 2061 bbp_get_trash_status_id() => _x( 'Trash', 'Trash the reply', 'bbpress' ), 2062 bbp_get_pending_status_id() => _x( 'Pending', 'Mark reply as pending', 'bbpress' ) 2063 ); 2064 } 2065 2066 // What type of statuses do we want? 2067 switch ( $type ) { 2068 case 'new' : 2069 $statuses = array( 2070 'auto-draft' => '', 2071 'draft' => '', 2072 'new' => '' 2073 ); 2074 break; 2075 case 'all' : 2076 $statuses = $all_statuses; 2077 break; 2078 case 'public' : 2079 $keys = array( bbp_get_public_status_id(), bbp_get_closed_status_id() ); 2080 $statuses = array_intersect_key( $all_statuses, array_flip( $keys ) ); 2081 break; 2082 case 'moderated' : 2083 $keys = array( bbp_get_spam_status_id(), bbp_get_trash_status_id(), bbp_get_pending_status_id() ); 2084 $statuses = array_intersect_key( $all_statuses, array_flip( $keys ) ); 2085 break; 2086 } 2087 2088 // Only return status keys 2089 if ( true === $keys_only ) { 2090 $statuses = array_keys( $statuses ); 2091 } 2092 2093 /** 2094 * Filter the returned reply statuses 2095 * 2096 * @since 2.0.0 bbPress (r2740) 2097 * 2098 * @param array $statuses Array of statuses 2099 * @param int $reply_id Reply ID 2100 * @param string $type Type of statuses 2101 */ 2102 return (array) apply_filters( 'bbp_get_forum_statuses', $statuses, $forum_id, $type ); 2103 } 2104 2041 2105 /** Queries *******************************************************************/ 2042 2106 2043 2107 /** -
src/includes/forums/status.php
1 <?php 2 3 /** 4 * bbPress Forum Status Transitions 5 * 6 * @package bbPress 7 * @subpackage Statuses 8 */ 9 10 // Exit if accessed directly 11 defined( 'ABSPATH' ) || exit; 12 13 /** Transition Forum Statuses *************************************************/ 14 15 /** 16 * Called when transitioning a forum post status to a public status from a 17 * draft/new status. 18 * 19 * @since 2.6.0 bbPress (rXXXX) 20 * 21 * @param string $new_status The new post status. 22 * @param string $old_status The old post status. 23 * @param WP_Post $forum The forum post object. 24 * 25 * @return bool 26 */ 27 function bbp_transition_forum_status_new_public( $new_status, $old_status, $forum ) { 28 29 // Is the new status public? 30 if ( ! in_array( $new_status, bbp_get_forum_statuses( $forum->ID, 'public', true ), true ) ) { 31 return false; 32 } 33 34 // Is the old status draft or new? 35 if ( ! in_array( $old_status, bbp_get_forum_statuses( $forum->ID, 'new', true ), true ) ) { 36 return false; 37 } 38 39 // Store the transitioned forum id. 40 bbp_stash_transitioned_post_status( $forum->ID, 'new_public' ); 41 42 /** 43 * Fires when a forum post status is transitioned to a public status from 44 * a draft/new status. 45 * 46 * @since 2.6.0 bbPress (rXXXX) 47 * 48 * @param int $forum_id The forum id. 49 */ 50 do_action( 'bbp_transition_forum_status_new_public', $forum->ID ); 51 52 return true; 53 } 54 55 /** 56 * Called when transitioning a forum post status to a moderated status from a 57 * draft/new status. 58 * 59 * @since 2.6.0 bbPress (rXXXX) 60 * 61 * @param string $new_status The new post status. 62 * @param string $old_status The old post status. 63 * @param WP_Post $forum The forum post object. 64 * 65 * @return bool 66 */ 67 function bbp_transition_forum_status_new_moderated( $new_status, $old_status, $forum ) { 68 69 // Is the new status moderated? 70 if ( ! in_array( $new_status, bbp_get_forum_statuses( $forum->ID, 'moderated', true ), true ) ) { 71 return false; 72 } 73 74 // Is the old status draft or new? 75 if ( ! in_array( $old_status, bbp_get_forum_statuses( $forum->ID, 'new', true ), true ) ) { 76 return false; 77 } 78 79 // Store the transitioned forum id. 80 bbp_stash_transitioned_post_status( $forum->ID, 'new_moderated' ); 81 82 /** 83 * Fires when a forum post status is transitioned to a public status from 84 * a draft/new status. 85 * 86 * @since 2.6.0 bbPress (rXXXX) 87 * 88 * @param int $forum_id The forum id. 89 */ 90 do_action( 'bbp_transition_forum_status_new_moderated', $forum->ID ); 91 92 return true; 93 } 94 95 /** 96 * Called when transitioning a forum post status to a public status from a 97 * moderated status. 98 * 99 * @since 2.6.0 bbPress (rXXXX) 100 * 101 * @param string $new_status The new post status. 102 * @param string $old_status The old post status. 103 * @param WP_Post $forum The forum post object. 104 * 105 * @return bool 106 */ 107 function bbp_transition_forum_status_public( $new_status, $old_status, $forum ) { 108 109 // Is the new status public? 110 if ( ! in_array( $new_status, bbp_get_forum_statuses( $forum->ID, 'public', true ), true ) ) { 111 return false; 112 } 113 114 // Is the old status moderated? 115 if ( ! in_array( $old_status, bbp_get_forum_statuses( $forum->ID, 'moderated', true ), true ) ) { 116 return false; 117 } 118 119 // Store the transitioned forum id. 120 bbp_stash_transitioned_post_status( $forum->ID, 'public' ); 121 122 /** 123 * Fires when a forum post status is transitioned to a public status from 124 * a moderated status. 125 * 126 * @since 2.6.0 bbPress (rXXXX) 127 * 128 * @param int $forum_id The forum id. 129 */ 130 do_action( 'bbp_transition_forum_status_public', $forum->ID ); 131 132 return true; 133 } 134 135 /** 136 * Called when transitioning a forum post status to a moderated status from a 137 * public status. 138 * 139 * @since 2.6.0 bbPress (rXXXX) 140 * 141 * @param string $new_status The new post status. 142 * @param string $old_status The old post status. 143 * @param WP_Post $forum The forum post object. 144 * 145 * @return bool 146 */ 147 function bbp_transition_forum_status_moderated( $new_status, $old_status, $forum ) { 148 149 // Is the new status moderated? 150 if ( ! in_array( $new_status, bbp_get_forum_statuses( $forum->ID, 'moderated', true ), true ) ) { 151 return false; 152 } 153 154 // Is the old status public? 155 if ( ! in_array( $old_status, bbp_get_forum_statuses( $forum->ID, 'public', true ), true ) ) { 156 return false; 157 } 158 159 // Store the transitioned forum id. 160 bbp_stash_transitioned_post_status( $forum->ID, 'moderated' ); 161 162 /** 163 * Fires when a forum post status is transitioned to a moderated status 164 * from a public status. 165 * 166 * @since 2.6.0 bbPress (rXXXX) 167 * 168 * @param int $forum_id The forum id. 169 */ 170 do_action( 'bbp_transition_forum_status_moderated', $forum->ID ); 171 172 return true; 173 } 174 175 /** 176 * Called after transitioning a forum post status to a public status from a 177 * draft/new status and it's post meta has been updated. 178 * 179 * @since 2.6.0 bbPress (rXXXX) 180 * 181 * @param int $forum_id The forum id. 182 * 183 * @return bool 184 */ 185 function bbp_transitioned_forum_status_new_public( $forum_id = 0 ) { 186 187 // Bail if the forum wasn't transitioned to a new public status. 188 if ( ! bbp_is_post_status_transitioned( $forum_id, 'new_public' ) ) { 189 return false; 190 } 191 192 /** 193 * Fires when a forum post status is transitioned to a public status from 194 * a draft/new status and it's post meta has been updated. 195 * 196 * @since 2.6.0 bbPress (rXXXX) 197 * 198 * @param int $forum_id The forum id. 199 */ 200 do_action( 'bbp_transitioned_forum_status_new_public', $forum_id ); 201 202 return true; 203 } 204 205 /** 206 * Called after transitioning a forum post status to a moderated status from a 207 * draft/new status and it's post meta has been updated. 208 * 209 * @since 2.6.0 bbPress (rXXXX) 210 * 211 * @param int $forum_id The forum id. 212 * 213 * @return bool 214 */ 215 function bbp_transitioned_forum_status_new_moderated( $forum_id = 0 ) { 216 217 // Bail if the forum wasn't transitioned to a new moderated status. 218 if ( ! bbp_is_post_status_transitioned( $forum_id, 'new_moderated' ) ) { 219 return false; 220 } 221 222 /** 223 * Fires when a forum post status is transitioned to a moderated status 224 * from a draft/new status and it's post meta has been updated. 225 * 226 * @since 2.6.0 bbPress (rXXXX) 227 * 228 * @param int $forum_id The forum id. 229 */ 230 do_action( 'bbp_transitioned_forum_status_new_moderated', $forum_id ); 231 232 return true; 233 } 234 235 /** 236 * Called after transitioning a forum post status to a public status from a 237 * moderated status and it's post meta has been updated. 238 * 239 * @since 2.6.0 bbPress (rXXXX) 240 * 241 * @param int $forum_id The forum id. 242 * 243 * @return bool 244 */ 245 function bbp_transitioned_forum_status_public( $forum_id = 0 ) { 246 247 // Bail if the forum wasn't transitioned to a public status. 248 if ( ! bbp_is_post_status_transitioned( $forum_id, 'public' ) ) { 249 return false; 250 } 251 252 /** 253 * Fires when a forum post status is transitioned to a public status from 254 * a public status and it's post meta has been updated. 255 * 256 * @since 2.6.0 bbPress (rXXXX) 257 * 258 * @param int $forum_id The forum id. 259 */ 260 do_action( 'bbp_transitioned_forum_status_public', $forum_id ); 261 262 return true; 263 } 264 265 /** 266 * Called after transitioning a forum post status to a moderated status from a 267 * public status and it's post meta has been updated. 268 * 269 * @since 2.6.0 bbPress (rXXXX) 270 * 271 * @param int $forum_id The forum id. 272 * 273 * @return bool 274 */ 275 function bbp_transitioned_forum_status_moderated( $forum_id = 0 ) { 276 277 // Bail if the forum wasn't transitioned to a moderated status. 278 if ( ! bbp_is_post_status_transitioned( $forum_id, 'moderated' ) ) { 279 return false; 280 } 281 282 /** 283 * Fires when a forum post status is transitioned to a moderated status 284 * from a public status and it's post meta has been updated. 285 * 286 * @since 2.6.0 bbPress (rXXXX) 287 * 288 * @param int $forum_id The forum id. 289 */ 290 do_action( 'bbp_transitioned_forum_status_moderated', $forum_id ); 291 292 return true; 293 } -
src/includes/forums/template.php
1531 1531 $status = get_post_meta( $forum_id, '_bbp_status', true ); 1532 1532 1533 1533 if ( empty( $status ) ) { 1534 $status = 'open';1534 $status = bbp_get_open_status_id(); 1535 1535 } 1536 1536 1537 1537 return apply_filters( 'bbp_get_forum_status', $status, $forum_id ); … … 2617 2617 * 2618 2618 * @since 2.1.0 bbPress (r3563) 2619 2619 * 2620 * @param type $args 2621 * @return type 2622 */ 2623 function bbp_get_form_forum_status_dropdown( $args = array() ) { 2624 $retval = bbp_get_form_forum_lock_dropdown( $args ); 2625 2626 return apply_filters( 'bbp_get_form_forum_status_dropdown', $retval, $args ); 2627 } 2628 2629 /** 2630 * Output value forum lock dropdown 2631 * 2632 * @since 2.6.0 bbPress (rXXXX) 2633 * 2634 * @param $args This function supports these arguments: 2635 * - select_id: Select id. Defaults to bbp_forum_status 2636 * - tab: Deprecated. Tabindex 2637 * - forum_id: Forum id 2638 * - selected: Override the selected option 2639 * @uses bbp_get_form_forum_status() To get the topic's forum id 2640 */ 2641 function bbp_form_forum_lock_dropdown( $args = array() ) { 2642 echo bbp_get_form_forum_lock_dropdown( $args ); 2643 } 2644 /** 2645 * Return the forum lock dropdown 2646 * 2647 * @since 2.6.0 bbPress (rXXXX) 2648 * 2620 2649 * @param $args This function supports these arguments: 2621 2650 * - select_id: Select id. Defaults to bbp_forum_status 2622 2651 * - tab: Deprecated. Tabindex … … 2627 2656 * @uses apply_filters() 2628 2657 * @return string HTML select list for selecting forum status 2629 2658 */ 2630 function bbp_get_form_forum_ status_dropdown( $args = array() ) {2659 function bbp_get_form_forum_lock_dropdown( $args = array() ) { 2631 2660 2632 2661 // Backpat for handling passing of a forum ID 2633 2662 if ( is_int( $args ) ) { … … 2639 2668 2640 2669 // Parse arguments against default values 2641 2670 $r = bbp_parse_args( $args, array( 2642 'select_id' => 'bbp_forum_ status',2671 'select_id' => 'bbp_forum_lock', 2643 2672 'select_class' => 'bbp_dropdown', 2644 2673 'tab' => false, 2645 2674 'forum_id' => $forum_id, 2646 2675 'selected' => false 2647 ), 'forum_ status_select' );2676 ), 'forum_lock_select' ); 2648 2677 2649 2678 // No specific selected value passed 2650 2679 if ( empty( $r['selected'] ) ) { … … 2676 2705 2677 2706 <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php echo $tab; ?>> 2678 2707 2679 <?php foreach ( bbp_get_forum_ statuses( $r['forum_id'] ) as $key => $label ) : ?>2708 <?php foreach ( bbp_get_forum_locks( $r['forum_id'] ) as $key => $label ) : ?> 2680 2709 2681 2710 <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option> 2682 2711 … … 2687 2716 <?php 2688 2717 2689 2718 // Return the results 2690 return apply_filters( 'bbp_get_form_forum_ status_dropdown', ob_get_clean(), $r, $args );2719 return apply_filters( 'bbp_get_form_forum_lock_dropdown', ob_get_clean(), $r, $args ); 2691 2720 } 2692 2721 2693 2722 /** -
src/includes/replies/functions.php
84 84 * Update counts after a reply is inserted via `bbp_insert_reply`. 85 85 * 86 86 * @since 2.6.0 bbPress (r6036) 87 * @deprecated 2.6.0 bbPress (rXXXX) 88 * @todo Do we completely remove, or add a deprecation notice? 87 89 * 88 90 * @param int $reply_id The reply id. 89 91 * @param int $topic_id The topic id. … … 827 829 * @uses bbp_update_reply_forum_id() To update the reply forum id 828 830 * @uses bbp_update_reply_topic_id() To update the reply topic id 829 831 * @uses bbp_update_reply_to() To update the reply to id 830 * @uses bbp_update_reply_walker() To update the reply 'sancestors' counts832 * @uses bbp_update_reply_walker() To update the reply ancestors' counts 831 833 */ 832 834 function bbp_update_reply( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0 ) { 833 835 … … 1015 1017 bbp_update_topic_last_active_time( $ancestor, $topic_last_active_time ); 1016 1018 1017 1019 // 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() ) { 1019 1021 bbp_update_topic_reply_count( $ancestor ); 1020 1022 bbp_update_topic_reply_count_hidden( $ancestor ); 1021 1023 bbp_update_topic_voice_count( $ancestor ); … … 1044 1046 1045 1047 // Counts 1046 1048 // 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() ) { 1048 1050 bbp_update_forum_reply_count( $ancestor ); 1049 1051 } 1050 1052 } … … 1063 1065 * @param int $forum_id Optional. Forum id 1064 1066 * @uses bbp_get_reply_id() To get the reply id 1065 1067 * @uses bbp_get_forum_id() To get the forum id 1066 * @uses get_post_ancestors() To get the reply 'sforum1068 * @uses get_post_ancestors() To get the reply forum 1067 1069 * @uses get_post_field() To get the post type of the post 1068 1070 * @uses update_post_meta() To update the reply forum id meta 1069 1071 * @uses apply_filters() Calls 'bbp_update_reply_forum_id' with the forum id … … 1112 1114 * @param int $topic_id Optional. Topic id 1113 1115 * @uses bbp_get_reply_id() To get the reply id 1114 1116 * @uses bbp_get_topic_id() To get the topic id 1115 * @uses get_post_ancestors() To get the reply 'stopic1117 * @uses get_post_ancestors() To get the reply topic 1116 1118 * @uses get_post_field() To get the post type of the post 1117 1119 * @uses update_post_meta() To update the reply topic id meta 1118 1120 * @uses apply_filters() Calls 'bbp_update_reply_topic_id' with the topic id … … 1153 1155 } 1154 1156 1155 1157 /* 1156 * Update the reply 'smeta data with its reply to id1158 * Update the reply meta data with its reply to id 1157 1159 * 1158 1160 * @since 2.4.0 bbPress (r4944) 1159 1161 * … … 1338 1340 1339 1341 /** Topic to Move From ***************************************************/ 1340 1342 1341 // Get the reply 'scurrent topic1343 // Get the reply current topic 1342 1344 $source_topic = bbp_get_topic( $move_reply->post_parent ); 1343 1345 1344 1346 // No topic … … 1770 1772 * Return an associative array of available reply statuses 1771 1773 * 1772 1774 * @since 2.6.0 bbPress (r5399) 1775 * @since 2.6.0 bbPress (rXXXX) Added $type and $keys_only parameters 1773 1776 * 1774 * @param int $reply_id Optional. Reply id. 1777 * @param int $reply_id Optional. Reply id. 1778 * @param string $type Optional. all|new|public|moderated 1779 * @param bool $keys_only Optional. Just return array keys 1775 1780 * 1776 1781 * @return array 1777 1782 */ 1778 function bbp_get_reply_statuses( $reply_id = 0 ) { 1779 return apply_filters( 'bbp_get_reply_statuses', array( 1780 bbp_get_public_status_id() => _x( 'Publish', 'Publish the reply', 'bbpress' ), 1781 bbp_get_spam_status_id() => _x( 'Spam', 'Spam the reply', 'bbpress' ), 1782 bbp_get_trash_status_id() => _x( 'Trash', 'Trash the reply', 'bbpress' ), 1783 bbp_get_pending_status_id() => _x( 'Pending', 'Mark reply as pending', 'bbpress' ), 1784 ), $reply_id ); 1783 function bbp_get_reply_statuses( $reply_id = 0, $type = 'all', $keys_only = false ) { 1784 static $all_statuses = null; 1785 1786 // All statuses 1787 if ( null === $all_statuses ) { 1788 $all_statuses = array( 1789 bbp_get_public_status_id() => _x( 'Open', 'Publish the reply', 'bbpress' ), 1790 bbp_get_spam_status_id() => _x( 'Spam', 'Spam the reply', 'bbpress' ), 1791 bbp_get_trash_status_id() => _x( 'Trash', 'Trash the reply', 'bbpress' ), 1792 bbp_get_pending_status_id() => _x( 'Pending', 'Mark reply as pending', 'bbpress' ) 1793 ); 1794 } 1795 1796 // What type of statuses do we want? 1797 switch ( $type ) { 1798 case 'new' : 1799 $statuses = array( 1800 'auto-draft' => '', 1801 'draft' => '', 1802 'new' => '' 1803 ); 1804 break; 1805 case 'all' : 1806 $statuses = $all_statuses; 1807 break; 1808 case 'public' : 1809 $keys = array( bbp_get_public_status_id() ); 1810 $statuses = array_intersect_key( $all_statuses, array_flip( $keys ) ); 1811 break; 1812 case 'moderated' : 1813 $keys = array( bbp_get_spam_status_id(), bbp_get_trash_status_id(), bbp_get_pending_status_id() ); 1814 $statuses = array_intersect_key( $all_statuses, array_flip( $keys ) ); 1815 break; 1816 } 1817 1818 // Only return status keys 1819 if ( true === $keys_only ) { 1820 $statuses = array_keys( $statuses ); 1821 } 1822 1823 /** 1824 * Filter the returned reply statuses 1825 * 1826 * @since 2.0.0 bbPress (r2740) 1827 * 1828 * @param array $statuses Array of statuses 1829 * @param int $reply_id Reply ID 1830 * @param string $type Type of statuses 1831 */ 1832 return (array) apply_filters( 'bbp_get_reply_statuses', $statuses, $reply_id, $type ); 1785 1833 } 1786 1834 1787 1835 /** -
src/includes/replies/status.php
1 <?php 2 3 /** 4 * bbPress Reply Status Transitions 5 * 6 * @package bbPress 7 * @subpackage Statuses 8 */ 9 10 // Exit if accessed directly 11 defined( 'ABSPATH' ) || exit; 12 13 /** Transition Reply Statuses *************************************************/ 14 15 /** 16 * Called when transitioning a reply post status to a public status from a 17 * draft/new status. 18 * 19 * @since 2.6.0 bbPress (rXXXX) 20 * 21 * @param string $new_status The new post status. 22 * @param string $old_status The old post status. 23 * @param WP_Post $reply The reply post object. 24 * 25 * @return bool 26 */ 27 function bbp_transition_reply_status_new_public( $new_status, $old_status, $reply ) { 28 29 // Is the new status public? 30 if ( ! in_array( $new_status, bbp_get_reply_statuses( $reply->ID, 'public', true ), true ) ) { 31 return false; 32 } 33 34 // Is the old status draft or new? 35 if ( ! in_array( $old_status, bbp_get_reply_statuses( $reply->ID, 'new', true ), true ) ) { 36 return false; 37 } 38 39 $reply_id = bbp_get_reply_id( $reply->ID ); 40 41 // Store the transitioned reply id. 42 bbp_stash_transitioned_post_status( $reply_id, 'new_public' ); 43 44 /** 45 * Fires when a reply post status is transitioned to a public status from 46 * a draft/new status. 47 * 48 * @since 2.6.0 bbPress (rXXXX) 49 * 50 * @param int $reply_id The reply id. 51 */ 52 do_action( 'bbp_transition_reply_status_new_public', $reply_id ); 53 54 return true; 55 } 56 57 /** 58 * Called when transitioning a reply post status to a moderated status from a 59 * draft/new status. 60 * 61 * @since 2.6.0 bbPress (rXXXX) 62 * 63 * @param string $new_status The new post status. 64 * @param string $old_status The old post status. 65 * @param WP_Post $reply The reply post object. 66 * 67 * @return bool 68 */ 69 function bbp_transition_reply_status_new_moderated( $new_status, $old_status, $reply ) { 70 71 // Is the new status moderated? 72 if ( ! in_array( $new_status, bbp_get_reply_statuses( $reply->ID, 'moderated', true ), true ) ) { 73 return false; 74 } 75 76 // Is the old status draft or new? 77 if ( ! in_array( $old_status, bbp_get_reply_statuses( $reply->ID, 'new', true ), true ) ) { 78 return false; 79 } 80 81 // Store the transitioned reply id. 82 bbp_stash_transitioned_post_status( $reply->ID, 'new_moderated' ); 83 84 /** 85 * Fires when a reply post status is transitioned to a public status from 86 * a draft/new status. 87 * 88 * @since 2.6.0 bbPress (rXXXX) 89 * 90 * @param int $reply_id The reply id. 91 */ 92 do_action( 'bbp_transition_reply_status_new_moderated', $reply->ID ); 93 94 return true; 95 } 96 97 /** 98 * Called when transitioning a reply post status to a public status from a 99 * moderated status. 100 * 101 * @since 2.6.0 bbPress (rXXXX) 102 * 103 * @param string $new_status The new post status. 104 * @param string $old_status The old post status. 105 * @param WP_Post $reply The reply post object. 106 * 107 * @return bool 108 */ 109 function bbp_transition_reply_status_public( $new_status, $old_status, $reply ) { 110 111 // Is the new status public? 112 if ( ! in_array( $new_status, bbp_get_reply_statuses( $reply->ID, 'public', true ), true ) ) { 113 return false; 114 } 115 116 // Is the old status moderated? 117 if ( ! in_array( $old_status, bbp_get_reply_statuses( $reply->ID, 'moderated', true ), true ) ) { 118 return false; 119 } 120 121 // Store the transitioned reply id. 122 bbp_stash_transitioned_post_status( $reply->ID, 'public' ); 123 124 /** 125 * Fires when a reply post status is transitioned to a public status from 126 * a moderated status. 127 * 128 * @since 2.6.0 bbPress (rXXXX) 129 * 130 * @param int $reply_id The reply id. 131 */ 132 do_action( 'bbp_transition_reply_status_public', $reply->ID ); 133 134 return true; 135 } 136 137 /** 138 * Called when transitioning a reply post status to a moderated status from a 139 * public status. 140 * 141 * @since 2.6.0 bbPress (rXXXX) 142 * 143 * @param string $new_status The new post status. 144 * @param string $old_status The old post status. 145 * @param WP_Post $reply The reply post object. 146 * 147 * @return bool 148 */ 149 function bbp_transition_reply_status_moderated( $new_status, $old_status, $reply ) { 150 151 // Is the new status moderated? 152 if ( ! in_array( $new_status, bbp_get_reply_statuses( $reply->ID, 'moderated', true ), true ) ) { 153 return false; 154 } 155 156 // Is the old status public? 157 if ( ! in_array( $old_status, bbp_get_reply_statuses( $reply->ID, 'public', true ), true ) ) { 158 return false; 159 } 160 161 // Store the transitioned reply id. 162 bbp_stash_transitioned_post_status( $reply->ID, 'moderated' ); 163 164 /** 165 * Fires when a reply post status is transitioned to a moderated status 166 * from a public status. 167 * 168 * @since 2.6.0 bbPress (rXXXX) 169 * 170 * @param int $reply_id The reply id. 171 */ 172 do_action( 'bbp_transition_reply_status_moderated', $reply->ID ); 173 174 return true; 175 } 176 177 /** 178 * Called after transitioning a reply post status to a public status from a 179 * draft/new status and it's post meta has been updated. 180 * 181 * @since 2.6.0 bbPress (rXXXX) 182 * 183 * @param int $reply_id The reply id. 184 * 185 * @return bool 186 */ 187 function bbp_transitioned_reply_status_new_public( $reply_id = 0 ) { 188 189 // Bail if the reply wasn't transitioned to a new public status. 190 if ( ! bbp_is_post_status_transitioned( $reply_id, 'new_public' ) ) { 191 return false; 192 } 193 194 /** 195 * Fires when a reply post status is transitioned to a public status from 196 * a draft/new status and it's post meta has been updated. 197 * 198 * @since 2.6.0 bbPress (rXXXX) 199 * 200 * @param int $reply_id The reply id. 201 */ 202 do_action( 'bbp_transitioned_reply_status_new_public', $reply_id ); 203 204 return true; 205 } 206 207 /** 208 * Called after transitioning a reply post status to a moderated status from a 209 * draft/new status and it's post meta has been updated. 210 * 211 * @since 2.6.0 bbPress (rXXXX) 212 * 213 * @param int $reply_id The reply id. 214 * 215 * @return bool 216 */ 217 function bbp_transitioned_reply_status_new_moderated( $reply_id = 0 ) { 218 219 // Bail if the reply wasn't transitioned to a new moderated status. 220 if ( ! bbp_is_post_status_transitioned( $reply_id, 'new_moderated' ) ) { 221 return false; 222 } 223 224 /** 225 * Fires when a reply post status is transitioned to a moderated status 226 * from a draft/new status and it's post meta has been updated. 227 * 228 * @since 2.6.0 bbPress (rXXXX) 229 * 230 * @param int $reply_id The reply id. 231 */ 232 do_action( 'bbp_transitioned_reply_status_new_moderated', $reply_id ); 233 234 return true; 235 } 236 237 /** 238 * Called after transitioning a reply post status to a public status from a 239 * moderated status and it's post meta has been updated. 240 * 241 * @since 2.6.0 bbPress (rXXXX) 242 * 243 * @param int $reply_id The reply id. 244 * 245 * @return bool 246 */ 247 function bbp_transitioned_reply_status_public( $reply_id = 0 ) { 248 249 // Bail if the reply wasn't transitioned to a public status. 250 if ( ! bbp_is_post_status_transitioned( $reply_id, 'public' ) ) { 251 return false; 252 } 253 254 /** 255 * Fires when a reply post status is transitioned to a public status from 256 * a public status and it's post meta has been updated. 257 * 258 * @since 2.6.0 bbPress (rXXXX) 259 * 260 * @param int $reply_id The reply id. 261 */ 262 do_action( 'bbp_transitioned_reply_status_public', $reply_id ); 263 264 return true; 265 } 266 267 /** 268 * Called after transitioning a reply post status to a moderated status from a 269 * public status and it's post meta has been updated. 270 * 271 * @since 2.6.0 bbPress (rXXXX) 272 * 273 * @param int $reply_id The reply id. 274 * 275 * @return bool 276 */ 277 function bbp_transitioned_reply_status_moderated( $reply_id = 0 ) { 278 279 // Bail if the reply wasn't transitioned to a moderated status. 280 if ( ! bbp_is_post_status_transitioned( $reply_id, 'moderated' ) ) { 281 return false; 282 } 283 284 /** 285 * Fires when a reply post status is transitioned to a moderated status 286 * from a public status and it's post meta has been updated. 287 * 288 * @since 2.6.0 bbPress (rXXXX) 289 * 290 * @param int $reply_id The reply id. 291 */ 292 do_action( 'bbp_transitioned_reply_status_moderated', $reply_id ); 293 294 return true; 295 } -
src/includes/topics/functions.php
2022 2022 /** Helpers *******************************************************************/ 2023 2023 2024 2024 /** 2025 * Return an associative array of available topic statuses2026 *2027 * @since 2.4.0 bbPress (r5059)2028 *2029 * @param int $topic_id Optional. Topic id.2030 *2031 * @return array2032 */2033 function bbp_get_topic_statuses( $topic_id = 0 ) {2034 return apply_filters( 'bbp_get_topic_statuses', array(2035 bbp_get_public_status_id() => _x( 'Open', 'Open the topic', 'bbpress' ),2036 bbp_get_closed_status_id() => _x( 'Closed', 'Close the topic', 'bbpress' ),2037 bbp_get_spam_status_id() => _x( 'Spam', 'Spam the topic', 'bbpress' ),2038 bbp_get_trash_status_id() => _x( 'Trash', 'Trash the topic', 'bbpress' ),2039 bbp_get_pending_status_id() => _x( 'Pending', 'Mark topic as pending', 'bbpress' ),2040 ), $topic_id );2041 }2042 2043 /**2044 2025 * Return an associative array of topic sticky types 2045 2026 * 2046 2027 * @since 2.4.0 bbPress (r5059) … … 2076 2057 ), $topic_id ); 2077 2058 } 2078 2059 2060 /** 2061 * Return an associative array of available topic statuses 2062 * 2063 * @since 2.4.0 bbPress (r5059) 2064 * @since 2.6.0 bbPress (rXXXX) Added $type and $keys_only parameters 2065 * 2066 * @param int $topic_id Optional. Topic id. 2067 * @param string $type Optional. all|new|public|moderated 2068 * @param bool $keys_only Optional. Just return array keys 2069 * 2070 * @return array 2071 */ 2072 function bbp_get_topic_statuses( $topic_id = 0, $type = 'all', $keys_only = false ) { 2073 static $all_statuses = null; 2074 2075 // All statuses 2076 if ( null === $all_statuses ) { 2077 $all_statuses = array( 2078 bbp_get_public_status_id() => _x( 'Open', 'Open the topic', 'bbpress' ), 2079 bbp_get_closed_status_id() => _x( 'Closed', 'Close the topic', 'bbpress' ), 2080 bbp_get_spam_status_id() => _x( 'Spam', 'Spam the topic', 'bbpress' ), 2081 bbp_get_trash_status_id() => _x( 'Trash', 'Trash the topic', 'bbpress' ), 2082 bbp_get_pending_status_id() => _x( 'Pending', 'Mark topic as pending', 'bbpress' ) 2083 ); 2084 } 2085 2086 // What type of statuses do we want? 2087 switch ( $type ) { 2088 case 'new' : 2089 $statuses = array( 2090 'auto-draft' => '', 2091 'draft' => '', 2092 'new' => '' 2093 ); 2094 break; 2095 case 'all' : 2096 $statuses = $all_statuses; 2097 break; 2098 case 'public' : 2099 $keys = array( bbp_get_public_status_id(), bbp_get_closed_status_id() ); 2100 $statuses = array_intersect_key( $all_statuses, array_flip( $keys ) ); 2101 break; 2102 case 'moderated' : 2103 $keys = array( bbp_get_spam_status_id(), bbp_get_trash_status_id(), bbp_get_pending_status_id() ); 2104 $statuses = array_intersect_key( $all_statuses, array_flip( $keys ) ); 2105 break; 2106 } 2107 2108 // Only return status keys 2109 if ( true === $keys_only ) { 2110 $statuses = array_keys( $statuses ); 2111 } 2112 2113 /** 2114 * Filter the returned topic statuses 2115 * 2116 * @since 2.0.0 bbPress (r2740) 2117 * 2118 * @param array $statuses Array of statuses 2119 * @param int $topic_id Topic ID 2120 * @param string $type Type of statuses 2121 */ 2122 return apply_filters( 'bbp_get_topic_statuses', $statuses, $topic_id, $type ); 2123 } 2124 2079 2125 /** Stickies ******************************************************************/ 2080 2126 2081 2127 /** … … 2631 2677 * Update counts after a topic is inserted via `bbp_insert_topic`. 2632 2678 * 2633 2679 * @since 2.6.0 bbPress (r6036) 2680 * @deprecated 2.6.0 bbPress (rXXXX) 2681 * @todo Do we completely remove, or add a deprecation notice? 2634 2682 * 2635 2683 * @param int $topic_id The topic id. 2636 2684 * @param int $forum_id The forum id. -
src/includes/topics/status.php
1 <?php 2 3 /** 4 * bbPress Topic Status Transitions 5 * 6 * @package bbPress 7 * @subpackage Statuses 8 */ 9 10 /** Transition Topic Statuses *************************************************/ 11 12 /** 13 * Called when transitioning a topic post status to a public status from a 14 * draft/new status. 15 * 16 * @since 2.6.0 bbPress (rXXXX) 17 * 18 * @param string $new_status The new post status. 19 * @param string $old_status The old post status. 20 * @param WP_Post $topic The topic post object. 21 * 22 * @return bool 23 */ 24 function bbp_transition_topic_status_new_public( $new_status, $old_status, $topic ) { 25 26 // Is the new status public? 27 if ( ! in_array( $new_status, bbp_get_topic_statuses( $topic->ID, 'public', true ), true ) ) { 28 return false; 29 } 30 31 // Is the old status draft or new? 32 if ( ! in_array( $old_status, bbp_get_topic_statuses( $topic->ID, 'new', true ), true ) ) { 33 return false; 34 } 35 36 $topic_id = bbp_get_topic_id( $topic->ID ); 37 38 // Store the transitioned topic id. 39 bbp_stash_transitioned_post_status( $topic_id, 'new_public' ); 40 41 /** 42 * Fires when a topic post status is transitioned to a public status from 43 * a draft/new status. 44 * 45 * @since 2.6.0 bbPress (rXXXX) 46 * 47 * @param int $topic_id The topic id. 48 */ 49 do_action( 'bbp_transition_topic_status_new_public', $topic_id ); 50 51 return true; 52 } 53 54 /** 55 * Called when transitioning a topic post status to a moderated status 56 * from a draft/new status. 57 * 58 * @since 2.6.0 bbPress (rXXXX) 59 * 60 * @param string $new_status The new post status. 61 * @param string $old_status The old post status. 62 * @param WP_Post $topic The topic post object. 63 * 64 * @return bool 65 */ 66 function bbp_transition_topic_status_new_moderated( $new_status, $old_status, $topic ) { 67 68 // Is the new status moderated? 69 if ( ! in_array( $new_status, bbp_get_topic_statuses( $topic->ID, 'moderated', true ), true ) ) { 70 return false; 71 } 72 73 // Is the old status draft or new? 74 if ( ! in_array( $old_status, bbp_get_topic_statuses( $topic->ID, 'new', true ), true ) ) { 75 return false; 76 } 77 78 // Store the transitioned topic id. 79 bbp_stash_transitioned_post_status( $topic->ID, 'new_moderated' ); 80 81 /** 82 * Fires when a topic post status is transitioned to a moderated status 83 * from a draft/new status. 84 * 85 * @since 2.6.0 bbPress (rXXXX) 86 * 87 * @param int $topic_id The topic id. 88 */ 89 do_action( 'bbp_transition_topic_status_new_moderated', $topic->ID ); 90 91 return true; 92 } 93 94 /** 95 * Called when transitioning a topic post status to a public status from a 96 * moderated status. 97 * 98 * @since 2.6.0 bbPress (rXXXX) 99 * 100 * @param string $new_status The new post status. 101 * @param string $old_status The old post status. 102 * @param WP_Post $topic The topic post object. 103 * 104 * @return bool 105 */ 106 function bbp_transition_topic_status_public( $new_status, $old_status, $topic ) { 107 108 // Is the new status public? 109 if ( ! in_array( $new_status, bbp_get_topic_statuses( $topic->ID, 'public', true ), true ) ) { 110 return false; 111 } 112 113 // Is the old status moderated? 114 if ( ! in_array( $old_status, bbp_get_topic_statuses( $topic->ID, 'moderated', true ), true ) ) { 115 return false; 116 } 117 118 // Store the transitioned topic id. 119 bbp_stash_transitioned_post_status( $topic->ID, 'public' ); 120 121 /** 122 * Fires when a topic post status is transitioned to a public status from 123 * a moderated status. 124 * 125 * @since 2.6.0 bbPress (rXXXX) 126 * 127 * @param int $topic_id The topic id. 128 */ 129 do_action( 'bbp_transition_topic_status_public', $topic->ID ); 130 131 return true; 132 } 133 134 /** 135 * Called when transitioning a topic post status to a moderated status from a 136 * public status. 137 * 138 * @since 2.6.0 bbPress (rXXXX) 139 * 140 * @param string $new_status The new post status. 141 * @param string $old_status The old post status. 142 * @param WP_Post $topic The topic post object. 143 * 144 * @return bool 145 */ 146 function bbp_transition_topic_status_moderated( $new_status, $old_status, $topic ) { 147 148 // Is the new status moderated? 149 if ( ! in_array( $new_status, bbp_get_topic_statuses( $topic->ID, 'moderated', true ), true ) ) { 150 return false; 151 } 152 153 // Is the old status public? 154 if ( ! in_array( $old_status, bbp_get_topic_statuses( $topic->ID, 'public', true ), true ) ) { 155 return false; 156 } 157 158 // Store the transitioned topic id. 159 bbp_stash_transitioned_post_status( $topic->ID, 'moderated' ); 160 161 /** 162 * Fires when a topic post status is transitioned to a moderated status 163 * from a public status. 164 * 165 * @since 2.6.0 bbPress (rXXXX) 166 * 167 * @param int $topic_id The topic id. 168 */ 169 do_action( 'bbp_transition_topic_status_moderated', $topic->ID ); 170 171 return true; 172 } 173 174 /** 175 * Called after transitioning a topic post status to a public status from a 176 * draft/new status and it's post meta has been updated. 177 * 178 * @since 2.6.0 bbPress (rXXXX) 179 * 180 * @param int $topic_id The topic id. 181 * 182 * @return bool 183 */ 184 function bbp_transitioned_topic_status_new_public( $topic_id = 0 ) { 185 186 // Bail if the topic wasn't transitioned to a new public status. 187 if ( ! bbp_is_post_status_transitioned( $topic_id, 'new_public' ) ) { 188 return false; 189 } 190 191 /** 192 * Fires when a topic post status is transitioned to a public status from 193 * a draft/new status and it's post meta has been updated. 194 * 195 * @since 2.6.0 bbPress (rXXXX) 196 * 197 * @param int $topic_id The topic id. 198 */ 199 do_action( 'bbp_transitioned_topic_status_new_public', $topic_id ); 200 201 return true; 202 } 203 204 /** 205 * Called after transitioning a topic post status to a moderated status from a 206 * draft/new status and it's post meta has been updated. 207 * 208 * @since 2.6.0 bbPress (rXXXX) 209 * 210 * @param int $topic_id The topic id. 211 * 212 * @return bool 213 */ 214 function bbp_transitioned_topic_status_new_moderated( $topic_id = 0 ) { 215 216 // Bail if the topic wasn't transitioned to a new moderated status. 217 if ( ! bbp_is_post_status_transitioned( $topic_id, 'new_moderated' ) ) { 218 return false; 219 } 220 221 /** 222 * Fires when a topic post status is transitioned to a moderated status 223 * from a draft/new status and it's post meta has been updated. 224 * 225 * @since 2.6.0 bbPress (rXXXX) 226 * 227 * @param int $topic_id The topic id. 228 */ 229 do_action( 'bbp_transitioned_topic_status_new_moderated', $topic_id ); 230 231 return true; 232 } 233 234 /** 235 * Called after transitioning a topic post status to a public status from a 236 * moderated status and it's post meta has been updated. 237 * 238 * @since 2.6.0 bbPress (rXXXX) 239 * 240 * @param int $topic_id The topic id. 241 * 242 * @return bool 243 */ 244 function bbp_transitioned_topic_status_public( $topic_id = 0 ) { 245 246 // Bail if the topic wasn't transitioned to a public status. 247 if ( ! bbp_is_post_status_transitioned( $topic_id, 'public' ) ) { 248 return false; 249 } 250 251 /** 252 * Fires when a topic post status is transitioned to a public status from 253 * a public status and it's post meta has been updated. 254 * 255 * @since 2.6.0 bbPress (rXXXX) 256 * 257 * @param int $topic_id The topic id. 258 */ 259 do_action( 'bbp_transitioned_topic_status_public', $topic_id ); 260 261 return true; 262 } 263 264 /** 265 * Called after transitioning a topic post status to a moderated status from a 266 * public status and it's post meta has been updated. 267 * 268 * @since 2.6.0 bbPress (rXXXX) 269 * 270 * @param int $topic_id The topic id. 271 * 272 * @return bool 273 */ 274 function bbp_transitioned_topic_status_moderated( $topic_id = 0 ) { 275 276 // Bail if the topic wasn't transitioned to a moderated status. 277 if ( ! bbp_is_post_status_transitioned( $topic_id, 'moderated' ) ) { 278 return false; 279 } 280 281 /** 282 * Fires when a topic post status is transitioned to a moderated status 283 * from a public status and it's post meta has been updated. 284 * 285 * @since 2.6.0 bbPress (rXXXX) 286 * 287 * @param int $topic_id The topic id. 288 */ 289 do_action( 'bbp_transitioned_topic_status_moderated', $topic_id ); 290 291 return true; 292 } -
src/includes/topics/template.php
1167 1167 } 1168 1168 1169 1169 /** 1170 * Return array of public topic statuses.1171 *1172 * @since 2.6.0 bbPress (r6383)1173 *1174 * @uses bbp_get_public_status_id()1175 * @uses bbp_get_closed_status_id()1176 *1177 * @return array1178 */1179 function bbp_get_public_topic_statuses() {1180 $statuses = array( bbp_get_public_status_id(), bbp_get_closed_status_id() );1181 1182 return (array) apply_filters( 'bbp_get_public_topic_statuses', $statuses );1183 }1184 1185 /**1186 1170 * Is the topic closed to new replies? 1187 1171 * 1188 1172 * @since 2.0.0 bbPress (r2746) … … 1230 1214 function bbp_is_topic_public( $topic_id = 0 ) { 1231 1215 $topic_id = bbp_get_topic_id( $topic_id ); 1232 1216 $status = bbp_get_topic_status( $topic_id ); 1233 $public = bbp_get_ public_topic_statuses();1217 $public = bbp_get_topic_statuses( null, 'public', true ); 1234 1218 $is_public = in_array( $status, $public, true ); 1235 1219 1236 1220 return (bool) apply_filters( 'bbp_is_topic_public', (bool) $is_public, $topic_id ); -
src/templates/default/bbpress/form-forum.php
118 118 <?php do_action( 'bbp_theme_before_forum_form_status' ); ?> 119 119 120 120 <p> 121 <label for="bbp_forum_status"><?php esc_html_e( ' Status:', 'bbpress' ); ?></label><br />122 <?php bbp_form_forum_ status_dropdown(); ?>121 <label for="bbp_forum_status"><?php esc_html_e( 'Lock:', 'bbpress' ); ?></label><br /> 122 <?php bbp_form_forum_lock_dropdown(); ?> 123 123 </p> 124 124 125 125 <?php do_action( 'bbp_theme_after_forum_form_status' ); ?> -
src/templates/default/bbpress/form-topic-merge.php
52 52 bbp_dropdown( array( 53 53 'post_type' => bbp_get_topic_post_type(), 54 54 'post_parent' => bbp_get_topic_forum_id( bbp_get_topic_id() ), 55 'post_status' => bbp_get_ public_topic_statuses(),55 'post_status' => bbp_get_topic_statuses( null, 'public', true ), 56 56 'selected' => -1, 57 57 'exclude' => bbp_get_topic_id(), 58 58 'select_id' => 'bbp_destination_topic' -
src/templates/default/bbpress/form-topic-split.php
59 59 bbp_dropdown( array( 60 60 'post_type' => bbp_get_topic_post_type(), 61 61 'post_parent' => bbp_get_topic_forum_id( bbp_get_topic_id() ), 62 'post_status' => bbp_get_ public_topic_statuses(),62 'post_status' => bbp_get_topic_statuses( null, 'public', true ), 63 63 'selected' => -1, 64 64 'exclude' => bbp_get_topic_id(), 65 65 'select_id' => 'bbp_destination_topic' -
tests/phpunit/testcases/common/functions.php
1221 1221 'This test has not been implemented yet.' 1222 1222 ); 1223 1223 } 1224 1225 /** 1226 * @covers ::bbp_stash_transitioned_post_status 1227 */ 1228 public function test_bbp_stash_transitioned_post_status() { 1229 $bbp = bbpress(); 1230 1231 // Reset transitioned posts. 1232 $bbp->transitioned_posts = array(); 1233 1234 bbp_stash_transitioned_post_status( 1, 'new' ); 1235 $this->assertArrayHasKey( 1, $bbp->transitioned_posts ); 1236 1237 bbp_stash_transitioned_post_status( 2, 'moderated' ); 1238 $this->assertArrayHasKey( 1, $bbp->transitioned_posts ); 1239 $this->assertArrayHasKey( 2, $bbp->transitioned_posts ); 1240 } 1241 1242 /** 1243 * @covers ::bbp_get_transitioned_post_status 1244 */ 1245 public function test_bbp_get_transitioned_post_status() { 1246 1247 // Reset transitioned posts. 1248 bbpress()->transitioned_posts = array(); 1249 1250 bbp_stash_transitioned_post_status( 1, 'new_public' ); 1251 1252 $status = bbp_get_transitioned_post_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_stash_transitioned_post_status( 1, 'new_public' ); 1265 $this->assertTrue( bbp_is_post_status_transitioned( 1, 'new_public' ) ); 1266 1267 bbp_stash_transitioned_post_status( 2, 'moderated' ); 1268 $this->assertFalse( bbp_is_post_status_transitioned( 2, 'new_public' ) ); 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_stash_transitioned_post_status( 1, 'new_moderated' ); 1280 $this->assertTrue( bbp_is_post_status_transitioned( 1, 'new_moderated' ) ); 1281 1282 bbp_stash_transitioned_post_status( 2, 'moderated' ); 1283 $this->assertFalse( bbp_is_post_status_transitioned( 2, 'new_moderated' ) ); 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_stash_transitioned_post_status( 1, 'public' ); 1295 $this->assertTrue( bbp_is_post_status_transitioned( 1, 'public' ) ); 1296 1297 bbp_stash_transitioned_post_status( 2, 'moderated' ); 1298 $this->assertFalse( bbp_is_post_status_transitioned( 2, 'public' ) ); 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_stash_transitioned_post_status( 1, 'moderated' ); 1310 $this->assertTrue( bbp_is_post_status_transitioned( 1, 'moderated' ) ); 1311 1312 bbp_stash_transitioned_post_status( 2, 'new' ); 1313 $this->assertFalse( bbp_is_post_status_transitioned( 2, 'moderated' ) ); 1314 } 1224 1315 } -
tests/phpunit/testcases/forums/functions/counts.php
13 13 * Generic function to test the forum counts with a new topic 14 14 */ 15 15 public function test_bbp_forum_new_topic_counts() { 16 remove_action( 'bbp_insert_topic', 'bbp_insert_topic_update_counts', 10 );17 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' ); 19 18 20 $f = $this->factory->forum->create(); 19 21 $t1 = $this->factory->topic->create( array( 20 22 'post_parent' => $f, … … 25 27 ) ); 26 28 $u = $this->factory->user->create(); 27 29 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 // Simulate the 'bbp_transitioned_topic_status_new' action. 31 do_action( 'bbp_transitioned_topic_status_new', $t1 ); 30 32 31 // Simulate the 'bbp_new_topic' action.32 do_action( 'bbp_new_topic', $t1, $f, false, bbp_get_current_user_id(), $t1 );33 34 33 $count = bbp_get_forum_topic_count( $f, true, true ); 35 34 $this->assertSame( 1, $count ); 36 35 … … 45 44 ), 46 45 ) ); 47 46 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 ); 50 49 51 50 $count = bbp_get_forum_topic_count( $f, true, true ); 52 51 $this->assertSame( 2, $count ); … … 54 53 $count = bbp_get_forum_topic_count_hidden( $f, true, true ); 55 54 $this->assertSame( 0, $count ); 56 55 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' ); 60 58 } 61 59 62 60 /** -
tests/phpunit/testcases/forums/functions/status.php
107 107 'This test has not been implemented yet.' 108 108 ); 109 109 } 110 111 /** 112 * @covers ::bbp_transition_forum_status_new_public 113 */ 114 public function test_bbp_transition_forum_status_new_public() { 115 $f = $this->factory->forum->create(); 116 117 $result = bbp_transition_forum_status_new_public( 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 $this->assertEquals( 'new_public', bbp_get_transitioned_post_status( $f ) ); 127 } 128 129 /** 130 * @covers ::bbp_transition_forum_status_new_moderated 131 */ 132 public function test_bbp_transition_forum_status_new_moderated() { 133 $f = $this->factory->forum->create(); 134 135 $result = bbp_transition_forum_status_new_moderated( 136 bbp_get_trash_status_id(), 137 'new', 138 bbp_get_forum( $f ) 139 ); 140 141 // A true result means the action was added, as failures return false. 142 $this->assertTrue( $result ); 143 144 $this->assertEquals( 'new_moderated', bbp_get_transitioned_post_status( $f ) ); 145 } 146 147 /** 148 * @covers ::bbp_transition_forum_status_public 149 */ 150 public function test_bbp_transition_forum_status_public() { 151 $f = $this->factory->forum->create(); 152 153 $result = bbp_transition_forum_status_public( 154 bbp_get_public_status_id(), 155 bbp_get_trash_status_id(), 156 bbp_get_forum( $f ) 157 ); 158 159 // A true result means the action was added, as failures return false. 160 $this->assertTrue( $result ); 161 162 $this->assertEquals( 'public', bbp_get_transitioned_post_status( $f ) ); 163 } 164 165 /** 166 * @covers ::bbp_transition_forum_status_moderated 167 */ 168 public function test_bbp_transition_forum_status_moderated() { 169 $f = $this->factory->forum->create(); 170 171 $result = bbp_transition_forum_status_moderated( 172 bbp_get_trash_status_id(), 173 bbp_get_public_status_id(), 174 bbp_get_forum( $f ) 175 ); 176 177 // A true result means the action was added, as failures return false. 178 $this->assertTrue( $result ); 179 180 $this->assertEquals( 'moderated', bbp_get_transitioned_post_status( $f ) ); 181 } 182 183 /** 184 * @covers ::bbp_transitioned_forum_status_new_public 185 */ 186 public function test_bbp_transitioned_forum_status_new_public() { 187 $f = $this->factory->forum->create(); 188 189 $result = bbp_transitioned_forum_status_new_public( $f ); 190 191 // A true result means the action was added, as failures return false. 192 $this->assertTrue( $result ); 193 } 194 195 /** 196 * @covers ::bbp_transitioned_forum_status_new_moderated 197 */ 198 public function test_bbp_transitioned_forum_status_new_moderated() { 199 $f = $this->factory->forum->create( array( 200 'post_status' => bbp_get_trash_status_id(), 201 ) ); 202 203 $result = bbp_transitioned_forum_status_new_moderated( $f ); 204 205 // A true result means the action was added, as failures return false. 206 $this->assertTrue( $result ); 207 } 208 209 /** 210 * @covers ::bbp_transitioned_forum_status_public 211 */ 212 public function test_bbp_transitioned_forum_status_public() { 213 $f = $this->factory->forum->create(); 214 215 wp_trash_post( $f ); 216 wp_untrash_post( $f ); 217 218 $result = bbp_transitioned_forum_status_public( $f ); 219 220 // A true result means the action was added, as failures return false. 221 $this->assertTrue( $result ); 222 } 223 224 /** 225 * @covers ::bbp_transitioned_forum_status_moderated 226 */ 227 public function test_bbp_transitioned_forum_status_moderated() { 228 $f = $this->factory->forum->create(); 229 230 wp_trash_post( $f ); 231 232 $result = bbp_transitioned_forum_status_moderated( $f ); 233 234 // A true result means the action was added, as failures return false. 235 $this->assertTrue( $result ); 236 } 110 237 } -
tests/phpunit/testcases/forums/template/forms.php
101 101 } 102 102 103 103 /** 104 * @covers ::bbp_form_forum_ status_dropdown105 * @covers ::bbp_get_form_forum_ status_dropdown106 * @todo Implement test_bbp_form_forum_ status_dropdown().107 * @todo Implement test_bbp_get_form_forum_ status_dropdown().104 * @covers ::bbp_form_forum_lock_dropdown 105 * @covers ::bbp_get_form_forum_lock_dropdown 106 * @todo Implement test_bbp_form_forum_lock_dropdown(). 107 * @todo Implement test_bbp_get_form_forum_lock_dropdown(). 108 108 */ 109 public function test_bbp_get_form_forum_ status_dropdown() {109 public function test_bbp_get_form_forum_lock_dropdown() { 110 110 // Remove the following lines when you implement this test. 111 111 $this->markTestIncomplete( 112 112 'This test has not been implemented yet.' -
tests/phpunit/testcases/forums/template/status.php
24 24 } 25 25 26 26 /** 27 * @covers ::bbp_get_forum_statuses 28 */ 29 public function test_bbp_get_forum_statuses() { 30 31 // New 32 $actual = bbp_get_forum_statuses( null, 'new', true ); 33 $expected = array( 'auto-draft', 'draft', 'new' ); 34 $this->assertEquals( $expected, $actual ); 35 36 // Public 37 $actual = bbp_get_forum_statuses( null, 'public', true ); 38 $expected = array( bbp_get_public_status_id(), bbp_get_closed_status_id() ); 39 $this->assertEquals( $expected, $actual ); 40 41 // Moderated 42 $actual = bbp_get_forum_statuses( null, 'moderated', true ); 43 $expected = array( 44 bbp_get_spam_status_id(), 45 bbp_get_trash_status_id(), 46 bbp_get_pending_status_id(), 47 ); 48 $this->assertEquals( $expected, $actual ); 49 } 50 51 /** 27 52 * @covers ::bbp_forum_type 28 53 * @covers ::bbp_get_forum_type 29 54 */ -
tests/phpunit/testcases/replies/functions/status.php
213 213 $topic_reply_count = bbp_get_topic_reply_count( $t ); 214 214 $this->assertSame( '1', $topic_reply_count ); 215 215 } 216 217 /** 218 * @covers ::bbp_transition_reply_status_new_public 219 */ 220 public function test_bbp_transition_reply_status_new_public() { 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_new_public( 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 $this->assertEquals( 'new_public', bbp_get_transitioned_post_status( $r ) ); 246 } 247 248 /** 249 * @covers ::bbp_transition_reply_status_new_moderated 250 */ 251 public function test_bbp_transition_reply_status_new_moderated() { 252 $f = $this->factory->forum->create(); 253 $t = $this->factory->topic->create( array( 254 'post_parent' => $f, 255 'topic_meta' => array( 256 'forum_id' => $f, 257 ), 258 ) ); 259 $r = $this->factory->reply->create( array( 260 'post_parent' => $t, 261 'reply_meta' => array( 262 'forum_id' => $f, 263 'topic_id' => $t, 264 ), 265 ) ); 266 267 $result = bbp_transition_reply_status_new_moderated( 268 bbp_get_pending_status_id(), 269 'new', 270 bbp_get_reply( $r ) 271 ); 272 273 // A true result means the action was added, as failures return false. 274 $this->assertTrue( $result ); 275 276 $this->assertEquals( 'new_moderated', bbp_get_transitioned_post_status( $r ) ); 277 } 278 279 /** 280 * @covers ::bbp_transition_reply_status_public 281 */ 282 public function test_bbp_transition_reply_status_public() { 283 $f = $this->factory->forum->create(); 284 $t = $this->factory->topic->create( array( 285 'post_parent' => $f, 286 'topic_meta' => array( 287 'forum_id' => $f, 288 ), 289 ) ); 290 $r = $this->factory->reply->create( array( 291 'post_parent' => $t, 292 'reply_meta' => array( 293 'forum_id' => $f, 294 'topic_id' => $t, 295 ), 296 ) ); 297 298 $result = bbp_transition_reply_status_public( 299 bbp_get_public_status_id(), 300 bbp_get_pending_status_id(), 301 bbp_get_reply( $r ) 302 ); 303 304 // A true result means the action was added, as failures return false. 305 $this->assertTrue( $result ); 306 307 $this->assertEquals( 'public', bbp_get_transitioned_post_status( $r ) ); 308 } 309 310 /** 311 * @covers ::bbp_transition_reply_status_moderated 312 */ 313 public function test_bbp_transition_reply_status_moderated() { 314 $f = $this->factory->forum->create(); 315 $t = $this->factory->topic->create( array( 316 'post_parent' => $f, 317 'topic_meta' => array( 318 'forum_id' => $f, 319 ), 320 ) ); 321 $r = $this->factory->reply->create( array( 322 'post_parent' => $t, 323 'reply_meta' => array( 324 'forum_id' => $f, 325 'topic_id' => $t, 326 ), 327 ) ); 328 329 $result = bbp_transition_reply_status_moderated( 330 bbp_get_pending_status_id(), 331 bbp_get_public_status_id(), 332 bbp_get_reply( $r ) 333 ); 334 335 // A true result means the action was added, as failures return false. 336 $this->assertTrue( $result ); 337 338 $this->assertEquals( 'moderated', bbp_get_transitioned_post_status( $r ) ); 339 } 340 341 /** 342 * @covers ::bbp_transitioned_reply_status_new_public 343 */ 344 public function test_bbp_transitioned_reply_status_new_public() { 345 $f = $this->factory->forum->create(); 346 $t = $this->factory->topic->create( array( 347 'post_parent' => $f, 348 'topic_meta' => array( 349 'forum_id' => $f, 350 ), 351 ) ); 352 $r = $this->factory->reply->create( array( 353 'post_parent' => $t, 354 'reply_meta' => array( 355 'forum_id' => $f, 356 'topic_id' => $t, 357 ), 358 ) ); 359 360 $result = bbp_transitioned_reply_status_new_public( $r ); 361 362 // A true result means the action was added, as failures return false. 363 $this->assertTrue( $result ); 364 } 365 366 /** 367 * @covers ::bbp_transitioned_reply_status_new_moderated 368 */ 369 public function test_bbp_transitioned_reply_status_new_moderated() { 370 $f = $this->factory->forum->create(); 371 $t = $this->factory->topic->create( array( 372 'post_parent' => $f, 373 'topic_meta' => array( 374 'forum_id' => $f, 375 ), 376 ) ); 377 $r = $this->factory->reply->create( array( 378 'post_parent' => $t, 379 'post_status' => bbp_get_pending_status_id(), 380 'reply_meta' => array( 381 'forum_id' => $f, 382 'topic_id' => $t, 383 ), 384 ) ); 385 386 $result = bbp_transitioned_reply_status_new_moderated( $r ); 387 388 // A true result means the action was added, as failures return false. 389 $this->assertTrue( $result ); 390 } 391 392 /** 393 * @covers ::bbp_transitioned_reply_status_public 394 */ 395 public function test_bbp_transitioned_reply_status_public() { 396 $f = $this->factory->forum->create(); 397 $t = $this->factory->topic->create( array( 398 'post_parent' => $f, 399 'topic_meta' => array( 400 'forum_id' => $f, 401 ), 402 ) ); 403 $r = $this->factory->reply->create( array( 404 'post_parent' => $t, 405 'post_status' => bbp_get_pending_status_id(), 406 'reply_meta' => array( 407 'forum_id' => $f, 408 'topic_id' => $t, 409 ), 410 ) ); 411 412 bbp_approve_reply( $r ); 413 414 $result = bbp_transitioned_reply_status_public( $r ); 415 416 // A true result means the action was added, as failures return false. 417 $this->assertTrue( $result ); 418 } 419 420 /** 421 * @covers ::bbp_transitioned_reply_status_moderated 422 */ 423 public function test_bbp_transitioned_reply_status_moderated() { 424 $f = $this->factory->forum->create(); 425 $t = $this->factory->topic->create( array( 426 'post_parent' => $f, 427 'topic_meta' => array( 428 'forum_id' => $f, 429 ), 430 ) ); 431 $r = $this->factory->reply->create( array( 432 'post_parent' => $t, 433 'reply_meta' => array( 434 'forum_id' => $f, 435 'topic_id' => $t, 436 ), 437 ) ); 438 439 bbp_unapprove_reply( $r ); 440 441 $result = bbp_transitioned_reply_status_moderated( $r ); 442 443 // A true result means the action was added, as failures return false. 444 $this->assertTrue( $result ); 445 } 216 446 } -
tests/phpunit/testcases/replies/template/status.php
37 37 } 38 38 39 39 /** 40 * @covers ::bbp_get_reply_statuses 41 */ 42 public function test_bbp_get_reply_statuses() { 43 44 // New 45 $actual = bbp_get_reply_statuses( null, 'new', true ); 46 $expected = array( 'auto-draft', 'draft', 'new' ); 47 $this->assertEquals( $expected, $actual ); 48 49 // Public 50 $actual = bbp_get_reply_statuses( null, 'public', true ); 51 $expected = array( bbp_get_public_status_id() ); 52 $this->assertEquals( $expected, $actual ); 53 54 // Moderated 55 $actual = bbp_get_reply_statuses( null, 'moderated', true ); 56 $expected = array( 57 bbp_get_spam_status_id(), 58 bbp_get_trash_status_id(), 59 bbp_get_pending_status_id(), 60 ); 61 $this->assertEquals( $expected, $actual ); 62 } 63 64 /** 40 65 * @covers ::bbp_is_reply_published 41 66 */ 42 67 public function test_bbp_is_reply_published() { -
tests/phpunit/testcases/topics/functions/counts.php
13 13 * Generic function to test the topics counts with a new reply 14 14 */ 15 15 public function test_bbp_topic_new_reply_counts() { 16 remove_action( 'bbp_insert_reply', 'bbp_insert_reply_update_counts', 10 );17 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' ); 19 18 20 $u = $this->factory->user->create(); 19 21 $u2 = $this->factory->user->create(); 20 22 $f = $this->factory->forum->create(); … … 34 36 ), 35 37 ) ); 36 38 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 // Simulate the 'bbp_transitioned_reply_status_new' action. 40 do_action( 'bbp_transitioned_reply_status_new', $r1 ); 39 41 40 // Simulate the 'bbp_new_reply' action.41 do_action( 'bbp_new_reply', $r1, $t, $f, false, bbp_get_current_user_id() );42 43 42 $count = bbp_get_topic_reply_count( $t, true ); 44 43 $this->assertSame( 1, $count ); 45 44 … … 58 57 ), 59 58 ) ); 60 59 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 ); 63 62 64 63 $count = bbp_get_topic_reply_count( $t, true ); 65 64 $this->assertSame( 2, $count ); … … 70 69 $count = bbp_get_topic_voice_count( $t, true ); 71 70 $this->assertSame( 2, $count ); 72 71 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' ); 76 74 } 77 75 78 76 /** -
tests/phpunit/testcases/topics/functions/status.php
419 419 'This test has not been implemented yet.' 420 420 ); 421 421 } 422 423 /** 424 * @covers ::bbp_transition_topic_status_new_public 425 */ 426 public function test_bbp_transition_topic_status_new_public() { 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_new_public( 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 $this->assertEquals( 'new_public', bbp_get_transitioned_post_status( $t ) ); 445 } 446 447 /** 448 * @covers ::bbp_transition_topic_status_new_moderated 449 */ 450 public function test_bbp_transition_topic_status_new_moderated() { 451 $f = $this->factory->forum->create(); 452 $t = $this->factory->topic->create( array( 453 'post_parent' => $f, 454 'topic_meta' => array( 455 'forum_id' => $f, 456 ), 457 ) ); 458 459 $result = bbp_transition_topic_status_new_moderated( 460 bbp_get_pending_status_id(), 461 'new', 462 bbp_get_topic( $t ) 463 ); 464 465 // A true result means the action was added, as failures return false. 466 $this->assertTrue( $result ); 467 468 $this->assertEquals( 'new_moderated', bbp_get_transitioned_post_status( $t ) ); 469 } 470 471 /** 472 * @covers ::bbp_transition_topic_status_public 473 */ 474 public function test_bbp_transition_topic_status_public() { 475 $f = $this->factory->forum->create(); 476 $t = $this->factory->topic->create( array( 477 'post_parent' => $f, 478 'topic_meta' => array( 479 'forum_id' => $f, 480 ), 481 ) ); 482 483 $result = bbp_transition_topic_status_public( 484 bbp_get_public_status_id(), 485 bbp_get_pending_status_id(), 486 bbp_get_topic( $t ) 487 ); 488 489 // A true result means the action was added, as failures return false. 490 $this->assertTrue( $result ); 491 492 $this->assertEquals( 'public', bbp_get_transitioned_post_status( $t ) ); 493 } 494 495 /** 496 * @covers ::bbp_transition_topic_status_moderated 497 */ 498 public function test_bbp_transition_topic_status_moderated() { 499 $f = $this->factory->forum->create(); 500 $t = $this->factory->topic->create( array( 501 'post_parent' => $f, 502 'topic_meta' => array( 503 'forum_id' => $f, 504 ), 505 ) ); 506 507 $result = bbp_transition_topic_status_moderated( 508 bbp_get_pending_status_id(), 509 bbp_get_public_status_id(), 510 bbp_get_topic( $t ) 511 ); 512 513 // A true result means the action was added, as failures return false. 514 $this->assertTrue( $result ); 515 516 $this->assertEquals( 'moderated', bbp_get_transitioned_post_status( $t ) ); 517 } 518 519 /** 520 * @covers ::bbp_transitioned_topic_status_new_public 521 */ 522 public function test_bbp_transitioned_topic_status_new_public() { 523 $f = $this->factory->forum->create(); 524 $t = $this->factory->topic->create( array( 525 'post_parent' => $f, 526 'topic_meta' => array( 527 'forum_id' => $f, 528 ), 529 ) ); 530 531 $result = bbp_transitioned_topic_status_new_public( $t ); 532 533 // A true result means the action was added, as failures return false. 534 $this->assertTrue( $result ); 535 } 536 537 /** 538 * @covers ::bbp_transitioned_topic_status_new_moderated 539 */ 540 public function test_bbp_transitioned_topic_status_new_moderated() { 541 $f = $this->factory->forum->create(); 542 $t = $this->factory->topic->create( array( 543 'post_parent' => $f, 544 'post_status' => bbp_get_pending_status_id(), 545 'topic_meta' => array( 546 'forum_id' => $f, 547 ), 548 ) ); 549 550 $result = bbp_transitioned_topic_status_new_moderated( $t ); 551 552 // A true result means the action was added, as failures return false. 553 $this->assertTrue( $result ); 554 } 555 556 /** 557 * @covers ::bbp_transitioned_topic_status_public 558 */ 559 public function test_bbp_transitioned_topic_status_public() { 560 $f = $this->factory->forum->create(); 561 $t = $this->factory->topic->create( array( 562 'post_parent' => $f, 563 'post_status' => bbp_get_pending_status_id(), 564 'topic_meta' => array( 565 'forum_id' => $f, 566 ), 567 ) ); 568 569 bbp_approve_topic( $t ); 570 571 $result = bbp_transitioned_topic_status_public( $t ); 572 573 // A true result means the action was added, as failures return false. 574 $this->assertTrue( $result ); 575 } 576 577 /** 578 * @covers ::bbp_transitioned_topic_status_moderated 579 */ 580 public function test_bbp_transitioned_topic_status_moderated() { 581 $f = $this->factory->forum->create(); 582 $t = $this->factory->topic->create( array( 583 'post_parent' => $f, 584 'topic_meta' => array( 585 'forum_id' => $f, 586 ), 587 ) ); 588 589 bbp_unapprove_topic( $t ); 590 591 $result = bbp_transitioned_topic_status_moderated( $t ); 592 593 // A true result means the action was added, as failures return false. 594 $this->assertTrue( $result ); 595 } 422 596 } -
tests/phpunit/testcases/topics/template/status.php
54 54 } 55 55 56 56 /** 57 * @covers ::bbp_get_topic_statuses 58 */ 59 public function test_bbp_get_topic_statuses() { 60 61 // New 62 $actual = bbp_get_topic_statuses( null, 'new', true ); 63 $expected = array( 'auto-draft', 'draft', 'new' ); 64 $this->assertEquals( $expected, $actual ); 65 66 // Public 67 $actual = bbp_get_topic_statuses( null, 'public', true ); 68 $expected = array( bbp_get_public_status_id(), bbp_get_closed_status_id() ); 69 $this->assertEquals( $expected, $actual ); 70 71 // Moderated 72 $actual = bbp_get_topic_statuses( null, 'moderated', true ); 73 $expected = array( 74 bbp_get_spam_status_id(), 75 bbp_get_trash_status_id(), 76 bbp_get_pending_status_id(), 77 ); 78 $this->assertEquals( $expected, $actual ); 79 } 80 81 /** 57 82 * @covers ::bbp_is_topic_closed 58 83 * @todo Implement test_bbp_is_topic_closed(). 59 84 */ -
tests/phpunit/testcases/users/functions/counts.php
266 266 * @covers ::bbp_increase_user_topic_count 267 267 */ 268 268 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 269 273 $u = $this->factory->user->create(); 270 274 $int_value = 3; 271 275 $integer = true; … … 283 287 284 288 $count = bbp_get_user_topic_count( $u, $integer ); 285 289 $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 ); 286 293 } 287 294 288 295 /** 289 296 * @covers ::bbp_increase_user_reply_count 290 297 */ 291 298 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 292 303 $u = $this->factory->user->create(); 293 304 $int_value = 3; 294 305 $integer = true; … … 312 323 313 324 $count = bbp_get_user_reply_count( $u, $integer ); 314 325 $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 ); 315 329 } 316 330 317 331 /** 318 332 * @covers ::bbp_decrease_user_topic_count 319 333 */ 320 334 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 321 339 $u = $this->factory->user->create(); 322 340 $int_value = 3; 323 341 $integer = true; … … 342 360 343 361 $count = bbp_get_user_topic_count( $u, $integer ); 344 362 $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 ); 345 366 } 346 367 347 368 /** 348 369 * @covers ::bbp_decrease_user_reply_count 349 370 */ 350 371 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 351 376 $u = $this->factory->user->create(); 352 377 $int_value = 3; 353 378 $integer = true; … … 378 403 379 404 $count = bbp_get_user_reply_count( $u, $integer ); 380 405 $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 ); 381 409 } 382 410 }