| @@ -17,31 +17,25 @@ | ||
| 17 | 17 | * for the forum to function properly. |
| 18 | 18 | * |
| 19 | 19 | * @since 2.0.0 bbPress (r3349) |
| 20 | 20 | * |
| 21 | - * @param array $forum_data Forum post data. | |
| 22 | - * @param array $forum_meta Forum meta data. | |
| 23 | - * | |
| 24 | - * @return int|false Forum ID on success, false on failure. | |
| 21 | + * @param array $forum_data Forum post data | |
| 22 | + * @param arrap $forum_meta Forum meta data | |
| 25 | 23 | */ |
| 26 | 24 | function bbp_insert_forum( $forum_data = array(), $forum_meta = array() ) { |
| 27 | 25 | |
| 28 | 26 | // Forum |
| 29 | - $forum_data = bbp_parse_args( | |
| 30 | - $forum_data, | |
| 31 | - array( | |
| 32 | - 'post_parent' => 0, // forum ID | |
| 33 | - 'post_status' => bbp_get_public_status_id(), | |
| 34 | - 'post_type' => bbp_get_forum_post_type(), | |
| 35 | - 'post_author' => bbp_get_current_user_id(), | |
| 36 | - 'post_password' => '', | |
| 37 | - 'post_content' => '', | |
| 38 | - 'post_title' => '', | |
| 39 | - 'menu_order' => 0, | |
| 40 | - 'comment_status' => 'closed' | |
| 41 | - ), | |
| 42 | - 'insert_forum' | |
| 43 | - ); | |
| 27 | + $forum_data = bbp_parse_args( $forum_data, array( | |
| 28 | + 'post_parent' => 0, // forum ID | |
| 29 | + 'post_status' => bbp_get_public_status_id(), | |
| 30 | + 'post_type' => bbp_get_forum_post_type(), | |
| 31 | + 'post_author' => bbp_get_current_user_id(), | |
| 32 | + 'post_password' => '', | |
| 33 | + 'post_content' => '', | |
| 34 | + 'post_title' => '', | |
| 35 | + 'menu_order' => 0, | |
| 36 | + 'comment_status' => 'closed' | |
| 37 | + ), 'insert_forum' ); | |
| 44 | 38 | |
| 45 | 39 | // Insert forum |
| 46 | 40 | $forum_id = wp_insert_post( $forum_data, false ); |
| 47 | 41 | |
| @@ -50,26 +44,22 @@ | ||
| 50 | 44 | return false; |
| 51 | 45 | } |
| 52 | 46 | |
| 53 | 47 | // Forum meta |
| 54 | - $forum_meta = bbp_parse_args( | |
| 55 | - $forum_meta, | |
| 56 | - array( | |
| 57 | - 'forum_type' => 'forum', | |
| 58 | - 'status' => 'open', | |
| 59 | - 'reply_count' => 0, | |
| 60 | - 'topic_count' => 0, | |
| 61 | - 'topic_count_hidden' => 0, | |
| 62 | - 'total_reply_count' => 0, | |
| 63 | - 'total_topic_count' => 0, | |
| 64 | - 'last_topic_id' => 0, | |
| 65 | - 'last_reply_id' => 0, | |
| 66 | - 'last_active_id' => 0, | |
| 67 | - 'last_active_time' => 0, | |
| 68 | - 'forum_subforum_count' => 0, | |
| 69 | - ), | |
| 70 | - 'insert_forum_meta' | |
| 71 | - ); | |
| 48 | + $forum_meta = bbp_parse_args( $forum_meta, array( | |
| 49 | + 'forum_type' => 'forum', | |
| 50 | + 'status' => 'open', | |
| 51 | + 'reply_count' => 0, | |
| 52 | + 'topic_count' => 0, | |
| 53 | + 'topic_count_hidden' => 0, | |
| 54 | + 'total_reply_count' => 0, | |
| 55 | + 'total_topic_count' => 0, | |
| 56 | + 'last_topic_id' => 0, | |
| 57 | + 'last_reply_id' => 0, | |
| 58 | + 'last_active_id' => 0, | |
| 59 | + 'last_active_time' => 0, | |
| 60 | + 'forum_subforum_count' => 0, | |
| 61 | + ), 'insert_forum_meta' ); | |
| 72 | 62 | |
| 73 | 63 | // Insert forum meta |
| 74 | 64 | foreach ( $forum_meta as $meta_key => $meta_value ) { |
| 75 | 65 | |
| @@ -82,14 +72,12 @@ | ||
| 82 | 72 | update_post_meta( $forum_id, $meta_key, $meta_value ); |
| 83 | 73 | } |
| 84 | 74 | |
| 85 | 75 | // Update the forum and hierarchy |
| 86 | - bbp_update_forum( | |
| 87 | - array( | |
| 88 | - 'forum_id' => $forum_id, | |
| 89 | - 'post_parent' => $forum_data['post_parent'] | |
| 90 | - ) | |
| 91 | - ); | |
| 76 | + bbp_update_forum( array( | |
| 77 | + 'forum_id' => $forum_id, | |
| 78 | + 'post_parent' => $forum_data['post_parent'] | |
| 79 | + ) ); | |
| 92 | 80 | |
| 93 | 81 | // Maybe make private |
| 94 | 82 | if ( bbp_is_forum_private( $forum_id, false ) ) { |
| 95 | 83 | bbp_privatize_forum( $forum_id ); |
| @@ -121,11 +109,11 @@ | ||
| 121 | 109 | |
| 122 | 110 | /** Post Form Handlers ********************************************************/ |
| 123 | 111 | |
| 124 | 112 | /** |
| 125 | - * Handles the front end forum submission. | |
| 113 | + * Handles the front end forum submission | |
| 126 | 114 | * |
| 127 | - * @param string $action The requested action to compare this function to. | |
| 115 | + * @param string $action The requested action to compare this function to | |
| 128 | 116 | */ |
| 129 | 117 | function bbp_new_forum_handler( $action = '' ) { |
| 130 | 118 | |
| 131 | 119 | // Bail if action is not bbp-new-forum |
| @@ -197,10 +185,10 @@ | ||
| 197 | 185 | } |
| 198 | 186 | |
| 199 | 187 | /** Forum Parent **********************************************************/ |
| 200 | 188 | |
| 201 | - // Forum parent is expected for theme-side submissions | |
| 202 | - if ( ! empty( $_POST['bbp_forum_parent_id'] ) && is_numeric( $_POST['bbp_forum_parent_id'] ) ) { | |
| 189 | + // Forum parent was passed (the norm) | |
| 190 | + if ( ! empty( $_POST['bbp_forum_parent_id'] ) ) { | |
| 203 | 191 | $forum_parent_id = bbp_get_forum_id( $_POST['bbp_forum_parent_id'] ); |
| 204 | 192 | } |
| 205 | 193 | |
| 206 | 194 | // Filter and sanitize |
| @@ -205,28 +193,34 @@ | ||
| 205 | 193 | |
| 206 | 194 | // Filter and sanitize |
| 207 | 195 | $forum_parent_id = apply_filters( 'bbp_new_forum_pre_parent_id', $forum_parent_id ); |
| 208 | 196 | |
| 209 | - // Forum parent was not passed (required for theme-side BuddyPress support) | |
| 197 | + // No forum parent was passed (should never happen) | |
| 210 | 198 | if ( empty( $forum_parent_id ) ) { |
| 211 | 199 | bbp_add_error( 'bbp_new_forum_missing_parent', __( '<strong>Error</strong>: Your forum must have a parent.', 'bbpress' ) ); |
| 212 | 200 | |
| 213 | - // Forum parent exists | |
| 201 | + // Forum exists | |
| 214 | 202 | } elseif ( ! empty( $forum_parent_id ) ) { |
| 215 | 203 | |
| 216 | - // Forum parent not editable by user | |
| 217 | - if ( ! current_user_can( 'edit_forum', $forum_parent_id ) ) { | |
| 204 | + // Forum is a category | |
| 205 | + if ( bbp_is_forum_category( $forum_parent_id ) ) { | |
| 206 | + bbp_add_error( 'bbp_new_forum_forum_category', __( '<strong>Error</strong>: This forum is a category. No forums can be created in this forum.', 'bbpress' ) ); | |
| 207 | + } | |
| 218 | 208 | |
| 219 | - // Forum parent is closed | |
| 220 | - if ( bbp_is_forum_closed( $forum_parent_id ) ) { | |
| 221 | - bbp_add_error( 'bbp_new_forum_forum_closed', __( '<strong>Error</strong>: This forum is closed to new forums.', 'bbpress' ) ); | |
| 222 | - } | |
| 209 | + // Forum is closed and user cannot access | |
| 210 | + if ( bbp_is_forum_closed( $forum_parent_id ) && ! current_user_can( 'edit_forum', $forum_parent_id ) ) { | |
| 211 | + bbp_add_error( 'bbp_new_forum_forum_closed', __( '<strong>Error</strong>: This forum has been closed to new forums.', 'bbpress' ) ); | |
| 223 | 212 | } |
| 224 | 213 | |
| 225 | - // Forum parent not readable by user | |
| 226 | - if ( ! current_user_can( 'read_forum', $forum_parent_id ) ) { | |
| 227 | - bbp_add_error( 'bbp_new_forum_forum_read', __( '<strong>Error</strong>: You do not have the capability to create new forums in this forum.', 'bbpress' ) ); | |
| 214 | + // Forum is private and user cannot access | |
| 215 | + if ( bbp_is_forum_private( $forum_parent_id ) && ! current_user_can( 'read_forum', $forum_parent_id ) ) { | |
| 216 | + bbp_add_error( 'bbp_new_forum_forum_private', __( '<strong>Error</strong>: This forum is private and you do not have the capability to read or create new forums in it.', 'bbpress' ) ); | |
| 228 | 217 | } |
| 218 | + | |
| 219 | + // Forum is hidden and user cannot access | |
| 220 | + if ( bbp_is_forum_hidden( $forum_parent_id ) && ! current_user_can( 'read_forum', $forum_parent_id ) ) { | |
| 221 | + bbp_add_error( 'bbp_new_forum_forum_hidden', __( '<strong>Error</strong>: This forum is hidden and you do not have the capability to read or create new forums in it.', 'bbpress' ) ); | |
| 222 | + } | |
| 229 | 223 | } |
| 230 | 224 | |
| 231 | 225 | /** Forum Flooding ********************************************************/ |
| 232 | 226 | |
| @@ -235,17 +229,9 @@ | ||
| 235 | 229 | } |
| 236 | 230 | |
| 237 | 231 | /** Forum Duplicate *******************************************************/ |
| 238 | 232 | |
| 239 | - $dupe_args = array( | |
| 240 | - 'post_type' => bbp_get_forum_post_type(), | |
| 241 | - 'post_author' => $forum_author, | |
| 242 | - 'post_content' => $forum_content, | |
| 243 | - 'post_parent' => $forum_parent_id, | |
| 244 | - 'anonymous_data' => $anonymous_data | |
| 245 | - ); | |
| 246 | - | |
| 247 | - if ( ! bbp_check_for_duplicate( $dupe_args ) ) { | |
| 233 | + if ( ! bbp_check_for_duplicate( array( 'post_type' => bbp_get_forum_post_type(), 'post_author' => $forum_author, 'post_content' => $forum_content, 'anonymous_data' => $anonymous_data ) ) ) { | |
| 248 | 234 | bbp_add_error( 'bbp_forum_duplicate', __( '<strong>Error</strong>: This forum already exists.', 'bbpress' ) ); |
| 249 | 235 | } |
| 250 | 236 | |
| 251 | 237 | /** Forum Bad Words *******************************************************/ |
| @@ -255,14 +241,11 @@ | ||
| 255 | 241 | } |
| 256 | 242 | |
| 257 | 243 | /** Forum Moderation ******************************************************/ |
| 258 | 244 | |
| 259 | - // Default to published | |
| 260 | - $forum_status = bbp_get_public_status_id(); | |
| 261 | - | |
| 262 | - // Maybe force into pending | |
| 245 | + $post_status = bbp_get_public_status_id(); | |
| 263 | 246 | if ( ! bbp_check_for_moderation( $anonymous_data, $forum_author, $forum_title, $forum_content ) ) { |
| 264 | - $forum_status = bbp_get_pending_status_id(); | |
| 247 | + $post_status = bbp_get_pending_status_id(); | |
| 265 | 248 | } |
| 266 | 249 | |
| 267 | 250 | /** Additional Actions (Before Save) **************************************/ |
| 268 | 251 | |
| @@ -276,20 +259,17 @@ | ||
| 276 | 259 | /** No Errors *************************************************************/ |
| 277 | 260 | |
| 278 | 261 | // Add the content of the form to $forum_data as an array |
| 279 | 262 | // Just in time manipulation of forum data before being created |
| 280 | - $forum_data = apply_filters( | |
| 281 | - 'bbp_new_forum_pre_insert', | |
| 282 | - array( | |
| 283 | - 'post_author' => $forum_author, | |
| 284 | - 'post_title' => $forum_title, | |
| 285 | - 'post_content' => $forum_content, | |
| 286 | - 'post_parent' => $forum_parent_id, | |
| 287 | - 'post_status' => $forum_status, | |
| 288 | - 'post_type' => bbp_get_forum_post_type(), | |
| 289 | - 'comment_status' => 'closed' | |
| 290 | - ) | |
| 291 | - ); | |
| 263 | + $forum_data = apply_filters( 'bbp_new_forum_pre_insert', array( | |
| 264 | + 'post_author' => $forum_author, | |
| 265 | + 'post_title' => $forum_title, | |
| 266 | + 'post_content' => $forum_content, | |
| 267 | + 'post_parent' => $forum_parent_id, | |
| 268 | + 'post_status' => $post_status, | |
| 269 | + 'post_type' => bbp_get_forum_post_type(), | |
| 270 | + 'comment_status' => 'closed' | |
| 271 | + ) ); | |
| 292 | 272 | |
| 293 | 273 | // Insert forum |
| 294 | 274 | $forum_id = wp_insert_post( $forum_data, true ); |
| 295 | 275 | |
| @@ -300,9 +280,9 @@ | ||
| 300 | 280 | /** Trash Check *******************************************************/ |
| 301 | 281 | |
| 302 | 282 | // If the forum is trash, or the forum_status is switched to |
| 303 | 283 | // trash, trash it properly |
| 304 | - if ( ( get_post_field( 'post_status', $forum_id ) === bbp_get_trash_status_id() ) || ( bbp_get_trash_status_id() === $forum_data['post_status'] ) ) { | |
| 284 | + if ( ( get_post_field( 'post_status', $forum_id ) === bbp_get_trash_status_id() ) || ( $forum_data['post_status'] === bbp_get_trash_status_id() ) ) { | |
| 305 | 285 | |
| 306 | 286 | // Trash the reply |
| 307 | 287 | wp_trash_post( $forum_id ); |
| 308 | 288 | |
| @@ -312,9 +292,9 @@ | ||
| 312 | 292 | |
| 313 | 293 | /** Spam Check ********************************************************/ |
| 314 | 294 | |
| 315 | 295 | // If reply or forum are spam, officially spam this reply |
| 316 | - if ( bbp_get_spam_status_id() === $forum_data['post_status'] ) { | |
| 296 | + if ( $forum_data['post_status'] === bbp_get_spam_status_id() ) { | |
| 317 | 297 | add_post_meta( $forum_id, '_bbp_spam_meta_status', bbp_get_public_status_id() ); |
| 318 | 298 | |
| 319 | 299 | // Force view=all |
| 320 | 300 | $view_all = true; |
| @@ -321,21 +301,18 @@ | ||
| 321 | 301 | } |
| 322 | 302 | |
| 323 | 303 | /** Update counts, etc... *********************************************/ |
| 324 | 304 | |
| 325 | - do_action( | |
| 326 | - 'bbp_new_forum', | |
| 327 | - array( | |
| 328 | - 'forum_id' => $forum_id, | |
| 329 | - 'post_parent' => $forum_data['post_parent'], | |
| 330 | - 'forum_author' => $forum_data['post_author'], | |
| 331 | - 'last_topic_id' => 0, | |
| 332 | - 'last_reply_id' => 0, | |
| 333 | - 'last_active_id' => 0, | |
| 334 | - 'last_active_time' => 0, | |
| 335 | - 'last_active_status' => bbp_get_public_status_id() | |
| 336 | - ) | |
| 337 | - ); | |
| 305 | + do_action( 'bbp_new_forum', array( | |
| 306 | + 'forum_id' => $forum_id, | |
| 307 | + 'post_parent' => $forum_parent_id, | |
| 308 | + 'forum_author' => $forum_author, | |
| 309 | + 'last_topic_id' => 0, | |
| 310 | + 'last_reply_id' => 0, | |
| 311 | + 'last_active_id' => 0, | |
| 312 | + 'last_active_time' => 0, | |
| 313 | + 'last_active_status' => bbp_get_public_status_id() | |
| 314 | + ) ); | |
| 338 | 315 | |
| 339 | 316 | /** Additional Actions (After Save) ***********************************/ |
| 340 | 317 | |
| 341 | 318 | do_action( 'bbp_new_forum_post_extras', $forum_id ); |
| @@ -371,27 +348,21 @@ | ||
| 371 | 348 | |
| 372 | 349 | /** Errors ****************************************************************/ |
| 373 | 350 | |
| 374 | 351 | // WP_Error |
| 352 | + } elseif ( is_wp_error( $forum_id ) ) { | |
| 353 | + bbp_add_error( 'bbp_forum_error', sprintf( __( '<strong>Error</strong>: The following problem(s) occurred: %s', 'bbpress' ), $forum_id->get_error_message() ) ); | |
| 375 | 354 | |
| 376 | - } elseif ( is_wp_error( $forum_id ) ) { | |
| 377 | - bbp_add_error( | |
| 378 | - 'bbp_forum_error', | |
| 379 | - sprintf( | |
| 380 | - /* translators: %s: Error message */ | |
| 381 | - esc_html__( '<strong>Error</strong>: The following problem(s) occurred: %s', 'bbpress' ), | |
| 382 | - $forum_id->get_error_message() | |
| 383 | - ) | |
| 384 | - ); | |
| 355 | + // Generic error | |
| 385 | 356 | } else { |
| 386 | - bbp_add_error( 'bbp_forum_error', __( '<strong>Error</strong>: The forum was not created.', 'bbpress' ) ); | |
| 387 | - } | |
| 357 | + bbp_add_error( 'bbp_forum_error', __( '<strong>Error</strong>: The forum was not created.', 'bbpress' ) ); | |
| 358 | + } | |
| 388 | 359 | } |
| 389 | 360 | |
| 390 | 361 | /** |
| 391 | - * Handles the front end edit forum submission. | |
| 362 | + * Handles the front end edit forum submission | |
| 392 | 363 | * |
| 393 | - * @param string $action The requested action to compare this function to. | |
| 364 | + * @param string $action The requested action to compare this function to | |
| 394 | 365 | */ |
| 395 | 366 | function bbp_edit_forum_handler( $action = '' ) { |
| 396 | 367 | |
| 397 | 368 | // Bail if action is not bbp-edit-forum |
| @@ -400,9 +371,9 @@ | ||
| 400 | 371 | } |
| 401 | 372 | |
| 402 | 373 | // Define local variable(s) |
| 403 | 374 | $anonymous_data = array(); |
| 404 | - $forum = $forum_id = $forum_author = $forum_parent_id = 0; | |
| 375 | + $forum = $forum_id = $forum_parent_id = 0; | |
| 405 | 376 | $forum_title = $forum_content = $forum_edit_reason = ''; |
| 406 | 377 | |
| 407 | 378 | /** Forum *****************************************************************/ |
| 408 | 379 | |
| @@ -439,15 +410,12 @@ | ||
| 439 | 410 | remove_filter( 'bbp_edit_forum_pre_content', 'bbp_encode_bad', 10 ); |
| 440 | 411 | remove_filter( 'bbp_edit_forum_pre_content', 'bbp_filter_kses', 30 ); |
| 441 | 412 | } |
| 442 | 413 | |
| 443 | - // Get forum author | |
| 444 | - $forum_author = bbp_get_forum_author_id( $forum_id ); | |
| 445 | - | |
| 446 | 414 | /** Forum Parent ***********************************************************/ |
| 447 | 415 | |
| 448 | 416 | // Forum parent id was passed |
| 449 | - if ( ! empty( $_POST['bbp_forum_parent_id'] ) && is_numeric( $_POST['bbp_forum_parent_id'] ) ) { | |
| 417 | + if ( ! empty( $_POST['bbp_forum_parent_id'] ) ) { | |
| 450 | 418 | $forum_parent_id = bbp_get_forum_id( $_POST['bbp_forum_parent_id'] ); |
| 451 | 419 | } |
| 452 | 420 | |
| 453 | 421 | // Current forum this forum is in |
| @@ -452,23 +420,24 @@ | ||
| 452 | 420 | |
| 453 | 421 | // Current forum this forum is in |
| 454 | 422 | $current_parent_forum_id = bbp_get_forum_parent_id( $forum_id ); |
| 455 | 423 | |
| 456 | - // Forum parent exists | |
| 424 | + // Forum exists | |
| 457 | 425 | if ( ! empty( $forum_parent_id ) && ( $forum_parent_id !== $current_parent_forum_id ) ) { |
| 458 | 426 | |
| 459 | - // Forum parent not editable by user | |
| 460 | - if ( ! current_user_can( 'edit_forum', $forum_parent_id ) ) { | |
| 427 | + // Forum is closed and user cannot access | |
| 428 | + if ( bbp_is_forum_closed( $forum_parent_id ) && ! current_user_can( 'edit_forum', $forum_parent_id ) ) { | |
| 429 | + bbp_add_error( 'bbp_edit_forum_forum_closed', __( '<strong>Error</strong>: This forum has been closed to new forums.', 'bbpress' ) ); | |
| 430 | + } | |
| 461 | 431 | |
| 462 | - // Forum is closed | |
| 463 | - if ( bbp_is_forum_closed( $forum_parent_id ) ) { | |
| 464 | - bbp_add_error( 'bbp_edit_forum_forum_closed', __( '<strong>Error</strong>: This forum is closed to new forums.', 'bbpress' ) ); | |
| 465 | - } | |
| 432 | + // Forum is private and user cannot access | |
| 433 | + if ( bbp_is_forum_private( $forum_parent_id ) && ! current_user_can( 'read_forum', $forum_parent_id ) ) { | |
| 434 | + bbp_add_error( 'bbp_edit_forum_forum_private', __( '<strong>Error</strong>: This forum is private and you do not have the capability to read or create new forums in it.', 'bbpress' ) ); | |
| 466 | 435 | } |
| 467 | 436 | |
| 468 | - // Forum parent not readable by user | |
| 469 | - if ( ! current_user_can( 'read_forum', $forum_parent_id ) ) { | |
| 470 | - bbp_add_error( 'bbp_edit_forum_forum_read', __( '<strong>Error</strong>: You do not have the capability to create new forums in this forum.', 'bbpress' ) ); | |
| 437 | + // Forum is hidden and user cannot access | |
| 438 | + if ( bbp_is_forum_hidden( $forum_parent_id ) && ! current_user_can( 'read_forum', $forum_parent_id ) ) { | |
| 439 | + bbp_add_error( 'bbp_edit_forum_forum_hidden', __( '<strong>Error</strong>: This forum is hidden and you do not have the capability to read or create new forums in it.', 'bbpress' ) ); | |
| 471 | 440 | } |
| 472 | 441 | } |
| 473 | 442 | |
| 474 | 443 | /** Forum Title ***********************************************************/ |
| @@ -511,14 +480,11 @@ | ||
| 511 | 480 | } |
| 512 | 481 | |
| 513 | 482 | /** Forum Moderation ******************************************************/ |
| 514 | 483 | |
| 515 | - // Use existing post_status | |
| 516 | - $forum_status = $forum->post_status; | |
| 517 | - | |
| 518 | - // Maybe force into pending | |
| 484 | + $post_status = bbp_get_public_status_id(); | |
| 519 | 485 | if ( ! bbp_check_for_moderation( $anonymous_data, bbp_get_forum_author_id( $forum_id ), $forum_title, $forum_content ) ) { |
| 520 | - $forum_status = bbp_get_pending_status_id(); | |
| 486 | + $post_status = bbp_get_pending_status_id(); | |
| 521 | 487 | } |
| 522 | 488 | |
| 523 | 489 | /** Additional Actions (Before Save) **************************************/ |
| 524 | 490 | |
| @@ -532,19 +498,15 @@ | ||
| 532 | 498 | /** No Errors *************************************************************/ |
| 533 | 499 | |
| 534 | 500 | // Add the content of the form to $forum_data as an array |
| 535 | 501 | // Just in time manipulation of forum data before being edited |
| 536 | - $forum_data = apply_filters( | |
| 537 | - 'bbp_edit_forum_pre_insert', | |
| 538 | - array( | |
| 539 | - 'ID' => $forum_id, | |
| 540 | - 'post_title' => $forum_title, | |
| 541 | - 'post_content' => $forum_content, | |
| 542 | - 'post_status' => $forum_status, | |
| 543 | - 'post_parent' => $forum_parent_id, | |
| 544 | - 'post_author' => $forum_author | |
| 545 | - ) | |
| 546 | - ); | |
| 502 | + $forum_data = apply_filters( 'bbp_edit_forum_pre_insert', array( | |
| 503 | + 'ID' => $forum_id, | |
| 504 | + 'post_title' => $forum_title, | |
| 505 | + 'post_content' => $forum_content, | |
| 506 | + 'post_status' => $post_status, | |
| 507 | + 'post_parent' => $forum_parent_id | |
| 508 | + ) ); | |
| 547 | 509 | |
| 548 | 510 | // Insert forum |
| 549 | 511 | $forum_id = wp_update_post( $forum_data ); |
| 550 | 512 | |
| @@ -552,21 +514,18 @@ | ||
| 552 | 514 | |
| 553 | 515 | if ( ! empty( $forum_id ) && ! is_wp_error( $forum_id ) ) { |
| 554 | 516 | |
| 555 | 517 | // Update counts, etc... |
| 556 | - do_action( | |
| 557 | - 'bbp_edit_forum', | |
| 558 | - array( | |
| 559 | - 'forum_id' => $forum_id, | |
| 560 | - 'post_parent' => $forum_data['post_parent'], | |
| 561 | - 'forum_author' => $forum_data['post_author'], | |
| 562 | - 'last_topic_id' => 0, | |
| 563 | - 'last_reply_id' => 0, | |
| 564 | - 'last_active_id' => 0, | |
| 565 | - 'last_active_time' => 0, | |
| 566 | - 'last_active_status' => bbp_get_public_status_id() | |
| 567 | - ) | |
| 568 | - ); | |
| 518 | + do_action( 'bbp_edit_forum', array( | |
| 519 | + 'forum_id' => $forum_id, | |
| 520 | + 'post_parent' => $forum_parent_id, | |
| 521 | + 'forum_author' => $forum->post_author, | |
| 522 | + 'last_topic_id' => 0, | |
| 523 | + 'last_reply_id' => 0, | |
| 524 | + 'last_active_id' => 0, | |
| 525 | + 'last_active_time' => 0, | |
| 526 | + 'last_active_status' => bbp_get_public_status_id() | |
| 527 | + ) ); | |
| 569 | 528 | |
| 570 | 529 | /** Revisions *********************************************************/ |
| 571 | 530 | |
| 572 | 531 | // Update locks |
| @@ -630,26 +589,19 @@ | ||
| 630 | 589 | /** Errors ****************************************************************/ |
| 631 | 590 | |
| 632 | 591 | } else { |
| 633 | 592 | $append_error = ( is_wp_error( $forum_id ) && $forum_id->get_error_message() ) ? $forum_id->get_error_message() . ' ' : ''; |
| 634 | - bbp_add_error( | |
| 635 | - 'bbp_forum_error', | |
| 636 | - sprintf( | |
| 637 | - /* translators: %s: Error message */ | |
| 638 | - __( '<strong>Error</strong>: The following problem(s) have been found with your forum: %s Please try again.', 'bbpress' ) | |
| 639 | - ), | |
| 640 | - $append_error | |
| 641 | - ); | |
| 593 | + bbp_add_error( 'bbp_forum_error', __( '<strong>Error</strong>: The following problem(s) have been found with your forum:' . $append_error . 'Please try again.', 'bbpress' ) ); | |
| 642 | 594 | } |
| 643 | 595 | } |
| 644 | 596 | |
| 645 | 597 | /** |
| 646 | - * Handle the saving of core forum metadata (Status, Visibility, and Type). | |
| 598 | + * Handle the saving of core forum metadata (Status, Visibility, and Type) | |
| 647 | 599 | * |
| 648 | 600 | * @since 2.1.0 bbPress (r3678) |
| 649 | 601 | * |
| 650 | - * @param int $forum_id. | |
| 651 | - * @return If forum ID is empty. | |
| 602 | + * @param int $forum_id | |
| 603 | + * @return If forum ID is empty | |
| 652 | 604 | */ |
| 653 | 605 | function bbp_save_forum_extras( $forum_id = 0 ) { |
| 654 | 606 | |
| 655 | 607 | // Validate the forum ID |
| @@ -714,15 +666,15 @@ | ||
| 714 | 666 | break; |
| 715 | 667 | } |
| 716 | 668 | |
| 717 | 669 | /** |
| 718 | - * Allow custom forum visibility save actions. | |
| 670 | + * Allow custom forum visibility save actions | |
| 719 | 671 | * |
| 720 | 672 | * @since 2.6.0 bbPress (r5855) |
| 721 | 673 | * |
| 722 | - * @param int $forum_id The forum ID. | |
| 723 | - * @param string $old_visibility The current forum visibility. | |
| 724 | - * @param string $new_visibility The new forum visibility. | |
| 674 | + * @param int $forum_id The forum ID | |
| 675 | + * @param string $old_visibility The current forum visibility | |
| 676 | + * @param string $new_visibility The new forum visibility | |
| 725 | 677 | */ |
| 726 | 678 | do_action( 'bbp_update_forum_visibility', $forum_id, $old_visibility, $new_visibility ); |
| 727 | 679 | } |
| 728 | 680 | |
| @@ -757,14 +709,14 @@ | ||
| 757 | 709 | |
| 758 | 710 | /** Forum Open/Close **********************************************************/ |
| 759 | 711 | |
| 760 | 712 | /** |
| 761 | - * Closes a forum. | |
| 713 | + * Closes a forum | |
| 762 | 714 | * |
| 763 | 715 | * @since 2.0.0 bbPress (r2746) |
| 764 | 716 | * |
| 765 | - * @param int $forum_id forum id. | |
| 766 | - * @return mixed False or {@link WP_Error} on failure, forum id on success. | |
| 717 | + * @param int $forum_id forum id | |
| 718 | + * @return mixed False or {@link WP_Error} on failure, forum id on success | |
| 767 | 719 | */ |
| 768 | 720 | function bbp_close_forum( $forum_id = 0 ) { |
| 769 | 721 | |
| 770 | 722 | $forum_id = bbp_get_forum_id( $forum_id ); |
| @@ -778,14 +730,14 @@ | ||
| 778 | 730 | return $forum_id; |
| 779 | 731 | } |
| 780 | 732 | |
| 781 | 733 | /** |
| 782 | - * Opens a forum. | |
| 734 | + * Opens a forum | |
| 783 | 735 | * |
| 784 | 736 | * @since 2.0.0 bbPress (r2746) |
| 785 | 737 | * |
| 786 | - * @param int $forum_id forum id. | |
| 787 | - * @return mixed False or {@link WP_Error} on failure, forum id on success. | |
| 738 | + * @param int $forum_id forum id | |
| 739 | + * @return mixed False or {@link WP_Error} on failure, forum id on success | |
| 788 | 740 | */ |
| 789 | 741 | function bbp_open_forum( $forum_id = 0 ) { |
| 790 | 742 | |
| 791 | 743 | $forum_id = bbp_get_forum_id( $forum_id ); |
| @@ -801,14 +753,14 @@ | ||
| 801 | 753 | |
| 802 | 754 | /** Forum Type ****************************************************************/ |
| 803 | 755 | |
| 804 | 756 | /** |
| 805 | - * Make the forum a category. | |
| 757 | + * Make the forum a category | |
| 806 | 758 | * |
| 807 | 759 | * @since 2.0.0 bbPress (r2746) |
| 808 | 760 | * |
| 809 | - * @param int $forum_id Optional. Forum id. | |
| 810 | - * @return bool False on failure, true on success. | |
| 761 | + * @param int $forum_id Optional. Forum id | |
| 762 | + * @return bool False on failure, true on success | |
| 811 | 763 | */ |
| 812 | 764 | function bbp_categorize_forum( $forum_id = 0 ) { |
| 813 | 765 | |
| 814 | 766 | $forum_id = bbp_get_forum_id( $forum_id ); |
| @@ -822,14 +774,14 @@ | ||
| 822 | 774 | return $forum_id; |
| 823 | 775 | } |
| 824 | 776 | |
| 825 | 777 | /** |
| 826 | - * Remove the category status from a forum. | |
| 778 | + * Remove the category status from a forum | |
| 827 | 779 | * |
| 828 | 780 | * @since 2.0.0 bbPress (r2746) |
| 829 | 781 | * |
| 830 | - * @param int $forum_id Optional. Forum id. | |
| 831 | - * @return bool False on failure, true on success. | |
| 782 | + * @param int $forum_id Optional. Forum id | |
| 783 | + * @return bool False on failure, true on success | |
| 832 | 784 | */ |
| 833 | 785 | function bbp_normalize_forum( $forum_id = 0 ) { |
| 834 | 786 | |
| 835 | 787 | $forum_id = bbp_get_forum_id( $forum_id ); |
| @@ -845,14 +797,14 @@ | ||
| 845 | 797 | |
| 846 | 798 | /** Forum Visibility **********************************************************/ |
| 847 | 799 | |
| 848 | 800 | /** |
| 849 | - * Mark the forum as public. | |
| 801 | + * Mark the forum as public | |
| 850 | 802 | * |
| 851 | 803 | * @since 2.0.0 bbPress (r2746) |
| 852 | 804 | * |
| 853 | - * @param int $forum_id Optional. Forum id. | |
| 854 | - * @return bool False on failure, true on success. | |
| 805 | + * @param int $forum_id Optional. Forum id | |
| 806 | + * @return bool False on failure, true on success | |
| 855 | 807 | */ |
| 856 | 808 | function bbp_publicize_forum( $forum_id = 0, $current_visibility = '' ) { |
| 857 | 809 | |
| 858 | 810 | $forum_id = bbp_get_forum_id( $forum_id ); |
| @@ -902,14 +854,14 @@ | ||
| 902 | 854 | return $forum_id; |
| 903 | 855 | } |
| 904 | 856 | |
| 905 | 857 | /** |
| 906 | - * Mark the forum as private. | |
| 858 | + * Mark the forum as private | |
| 907 | 859 | * |
| 908 | 860 | * @since 2.0.0 bbPress (r2746) |
| 909 | 861 | * |
| 910 | - * @param int $forum_id Optional. Forum id. | |
| 911 | - * @return bool False on failure, true on success. | |
| 862 | + * @param int $forum_id Optional. Forum id | |
| 863 | + * @return bool False on failure, true on success | |
| 912 | 864 | */ |
| 913 | 865 | function bbp_privatize_forum( $forum_id = 0, $current_visibility = '' ) { |
| 914 | 866 | |
| 915 | 867 | $forum_id = bbp_get_forum_id( $forum_id ); |
| @@ -951,14 +903,14 @@ | ||
| 951 | 903 | return $forum_id; |
| 952 | 904 | } |
| 953 | 905 | |
| 954 | 906 | /** |
| 955 | - * Mark the forum as hidden. | |
| 907 | + * Mark the forum as hidden | |
| 956 | 908 | * |
| 957 | 909 | * @since 2.0.0 bbPress (r2996) |
| 958 | 910 | * |
| 959 | - * @param int $forum_id Optional. Forum id. | |
| 960 | - * @return bool False on failure, true on success. | |
| 911 | + * @param int $forum_id Optional. Forum id | |
| 912 | + * @return bool False on failure, true on success | |
| 961 | 913 | */ |
| 962 | 914 | function bbp_hide_forum( $forum_id = 0, $current_visibility = '' ) { |
| 963 | 915 | |
| 964 | 916 | $forum_id = bbp_get_forum_id( $forum_id ); |
| @@ -1000,13 +952,13 @@ | ||
| 1000 | 952 | return $forum_id; |
| 1001 | 953 | } |
| 1002 | 954 | |
| 1003 | 955 | /** |
| 1004 | - * Re-caches the private and hidden forums. | |
| 956 | + * Recaches the private and hidden forums | |
| 1005 | 957 | * |
| 1006 | 958 | * @since 2.4.0 bbPress (r5017) |
| 1007 | 959 | * |
| 1008 | - * @return array An array of the status code and the message. | |
| 960 | + * @return array An array of the status code and the message | |
| 1009 | 961 | */ |
| 1010 | 962 | function bbp_repair_forum_visibility() { |
| 1011 | 963 | |
| 1012 | 964 | // First, delete everything. |
| @@ -1022,42 +974,39 @@ | ||
| 1022 | 974 | */ |
| 1023 | 975 | remove_action( 'pre_get_posts', 'bbp_pre_get_posts_normalize_forum_visibility', 4 ); |
| 1024 | 976 | |
| 1025 | 977 | // Query for private forums |
| 1026 | - $private_forums = new WP_Query( | |
| 1027 | - array( | |
| 1028 | - 'fields' => 'ids', | |
| 1029 | - 'post_type' => bbp_get_forum_post_type(), | |
| 1030 | - 'post_status' => bbp_get_private_status_id(), | |
| 1031 | - 'posts_per_page' => -1, | |
| 978 | + $private_forums = new WP_Query( array( | |
| 979 | + 'fields' => 'ids', | |
| 980 | + 'post_type' => bbp_get_forum_post_type(), | |
| 981 | + 'post_status' => bbp_get_private_status_id(), | |
| 982 | + 'posts_per_page' => -1, | |
| 1032 | 983 | |
| 1033 | - // Performance | |
| 1034 | - 'nopaging' => true, | |
| 1035 | - 'suppress_filters' => true, | |
| 1036 | - 'update_post_term_cache' => false, | |
| 1037 | - 'update_post_meta_cache' => false, | |
| 1038 | - 'ignore_sticky_posts' => true, | |
| 1039 | - 'no_found_rows' => true | |
| 1040 | - ) | |
| 1041 | - ); | |
| 984 | + // Performance | |
| 985 | + 'nopaging' => true, | |
| 986 | + 'suppress_filters' => true, | |
| 987 | + 'update_post_term_cache' => false, | |
| 988 | + 'update_post_meta_cache' => false, | |
| 989 | + 'ignore_sticky_posts' => true, | |
| 990 | + 'no_found_rows' => true | |
| 991 | + ) ); | |
| 1042 | 992 | |
| 1043 | 993 | // Query for hidden forums |
| 1044 | - $hidden_forums = new WP_Query( | |
| 1045 | - array( | |
| 1046 | - 'fields' => 'ids', | |
| 1047 | - 'post_type' => bbp_get_forum_post_type(), | |
| 1048 | - 'post_status' => bbp_get_hidden_status_id(), | |
| 1049 | - 'posts_per_page' => -1, | |
| 994 | + $hidden_forums = new WP_Query( array( | |
| 995 | + 'fields' => 'ids', | |
| 996 | + 'suppress_filters' => true, | |
| 997 | + 'post_type' => bbp_get_forum_post_type(), | |
| 998 | + 'post_status' => bbp_get_hidden_status_id(), | |
| 999 | + 'posts_per_page' => -1, | |
| 1050 | 1000 | |
| 1051 | - // Performance | |
| 1052 | - 'nopaging' => true, | |
| 1053 | - 'suppress_filters' => true, | |
| 1054 | - 'update_post_term_cache' => false, | |
| 1055 | - 'update_post_meta_cache' => false, | |
| 1056 | - 'ignore_sticky_posts' => true, | |
| 1057 | - 'no_found_rows' => true | |
| 1058 | - ) | |
| 1059 | - ); | |
| 1001 | + // Performance | |
| 1002 | + 'nopaging' => true, | |
| 1003 | + 'suppress_filters' => true, | |
| 1004 | + 'update_post_term_cache' => false, | |
| 1005 | + 'update_post_meta_cache' => false, | |
| 1006 | + 'ignore_sticky_posts' => true, | |
| 1007 | + 'no_found_rows' => true | |
| 1008 | + ) ); | |
| 1060 | 1009 | |
| 1061 | 1010 | // Enable forum visibilty normalization |
| 1062 | 1011 | add_action( 'pre_get_posts', 'bbp_pre_get_posts_normalize_forum_visibility', 4 ); |
| 1063 | 1012 | |
| @@ -1080,13 +1029,13 @@ | ||
| 1080 | 1029 | |
| 1081 | 1030 | /** Subscriptions *************************************************************/ |
| 1082 | 1031 | |
| 1083 | 1032 | /** |
| 1084 | - * Remove a deleted forum from all user subscriptions. | |
| 1033 | + * Remove a deleted forum from all user subscriptions | |
| 1085 | 1034 | * |
| 1086 | 1035 | * @since 2.5.0 bbPress (r5156) |
| 1087 | 1036 | * |
| 1088 | - * @param int $forum_id Get the forum ID to remove. | |
| 1037 | + * @param int $forum_id Get the forum ID to remove | |
| 1089 | 1038 | */ |
| 1090 | 1039 | function bbp_remove_forum_from_all_subscriptions( $forum_id = 0 ) { |
| 1091 | 1040 | |
| 1092 | 1041 | // Subscriptions are not active |
| @@ -1106,9 +1055,9 @@ | ||
| 1106 | 1055 | |
| 1107 | 1056 | /** Count Bumpers *************************************************************/ |
| 1108 | 1057 | |
| 1109 | 1058 | /** |
| 1110 | - * Bump the total topic count of a forum. | |
| 1059 | + * Bump the total topic count of a forum | |
| 1111 | 1060 | * |
| 1112 | 1061 | * @since 2.1.0 bbPress (r3825) |
| 1113 | 1062 | * |
| 1114 | 1063 | * @param int $forum_id Optional. Forum id. |
| @@ -1130,9 +1079,9 @@ | ||
| 1130 | 1079 | $total_topic_count = bbp_get_forum_topic_count( $forum_id, true, true ); |
| 1131 | 1080 | $difference = (int) $difference; |
| 1132 | 1081 | |
| 1133 | 1082 | // Update this forum id |
| 1134 | - update_post_meta( $forum_id, '_bbp_topic_count', (int) ( $topic_count + $difference ) ); | |
| 1083 | + update_post_meta( $forum_id, '_bbp_topic_count', (int) ( $topic_count + $difference ) ); | |
| 1135 | 1084 | update_post_meta( $forum_id, '_bbp_total_topic_count', (int) ( $total_topic_count + $difference ) ); |
| 1136 | 1085 | |
| 1137 | 1086 | // Check for ancestors |
| 1138 | 1087 | if ( true === $update_ancestors ) { |
| @@ -1170,8 +1119,9 @@ | ||
| 1170 | 1119 | * |
| 1171 | 1120 | * @since 2.6.0 bbPress (r6036) |
| 1172 | 1121 | * |
| 1173 | 1122 | * @param int $forum_id The forum id. |
| 1123 | + * @return void | |
| 1174 | 1124 | */ |
| 1175 | 1125 | function bbp_increase_forum_topic_count( $forum_id = 0 ) { |
| 1176 | 1126 | |
| 1177 | 1127 | // Bail early if no id is passed. |
| @@ -1200,8 +1150,10 @@ | ||
| 1200 | 1150 | * |
| 1201 | 1151 | * @since 2.6.0 bbPress (r6036) |
| 1202 | 1152 | * |
| 1203 | 1153 | * @param int $forum_id The forum id. |
| 1154 | + * | |
| 1155 | + * @return void | |
| 1204 | 1156 | */ |
| 1205 | 1157 | function bbp_decrease_forum_topic_count( $forum_id = 0 ) { |
| 1206 | 1158 | |
| 1207 | 1159 | // Bail early if no id is passed. |
| @@ -1225,9 +1177,9 @@ | ||
| 1225 | 1177 | bbp_bump_forum_topic_count( $forum_id, -1 ); |
| 1226 | 1178 | } |
| 1227 | 1179 | |
| 1228 | 1180 | /** |
| 1229 | - * Bump the total topic count of a forum. | |
| 1181 | + * Bump the total topic count of a forum | |
| 1230 | 1182 | * |
| 1231 | 1183 | * @since 2.1.0 bbPress (r3825) |
| 1232 | 1184 | * |
| 1233 | 1185 | * @param int $forum_id Optional. Forum id. |
| @@ -1249,9 +1201,9 @@ | ||
| 1249 | 1201 | $total_topic_count = bbp_get_forum_topic_count_hidden( $forum_id, true, true ); |
| 1250 | 1202 | $difference = (int) $difference; |
| 1251 | 1203 | |
| 1252 | 1204 | // Update this forum id |
| 1253 | - update_post_meta( $forum_id, '_bbp_topic_count_hidden', (int) ( $reply_count + $difference ) ); | |
| 1205 | + update_post_meta( $forum_id, '_bbp_topic_count_hidden', (int) ( $reply_count + $difference ) ); | |
| 1254 | 1206 | update_post_meta( $forum_id, '_bbp_total_topic_count_hidden', (int) ( $total_topic_count + $difference ) ); |
| 1255 | 1207 | |
| 1256 | 1208 | // Check for ancestors |
| 1257 | 1209 | if ( true === $update_ancestors ) { |
| @@ -1289,8 +1241,10 @@ | ||
| 1289 | 1241 | * |
| 1290 | 1242 | * @since 2.6.0 bbPress (r6036) |
| 1291 | 1243 | * |
| 1292 | 1244 | * @param int $forum_id The forum id. |
| 1245 | + * | |
| 1246 | + * @return void | |
| 1293 | 1247 | */ |
| 1294 | 1248 | function bbp_increase_forum_topic_count_hidden( $forum_id = 0 ) { |
| 1295 | 1249 | |
| 1296 | 1250 | // Bail early if no id is passed. |
| @@ -1319,8 +1273,10 @@ | ||
| 1319 | 1273 | * |
| 1320 | 1274 | * @since 2.6.0 bbPress (r6036) |
| 1321 | 1275 | * |
| 1322 | 1276 | * @param int $forum_id The forum id. |
| 1277 | + * | |
| 1278 | + * @return void | |
| 1323 | 1279 | */ |
| 1324 | 1280 | function bbp_decrease_forum_topic_count_hidden( $forum_id = 0 ) { |
| 1325 | 1281 | |
| 1326 | 1282 | // Bail early if no id is passed. |
| @@ -1344,15 +1300,15 @@ | ||
| 1344 | 1300 | bbp_bump_forum_topic_count_hidden( $forum_id, -1 ); |
| 1345 | 1301 | } |
| 1346 | 1302 | |
| 1347 | 1303 | /** |
| 1348 | - * Bump the total topic count of a forum. | |
| 1304 | + * Bump the total topic count of a forum | |
| 1349 | 1305 | * |
| 1350 | 1306 | * @since 2.1.0 bbPress (r3825) |
| 1351 | 1307 | * |
| 1352 | 1308 | * @param int $forum_id Optional. Forum id. |
| 1353 | - * @param int $difference Optional. Default 1. | |
| 1354 | - * @param bool $update_ancestors Optional. Default true. | |
| 1309 | + * @param int $difference Optional. Default 1 | |
| 1310 | + * @param bool $update_ancestors Optional. Default true | |
| 1355 | 1311 | * |
| 1356 | 1312 | * @return int Forum topic count |
| 1357 | 1313 | */ |
| 1358 | 1314 | function bbp_bump_forum_reply_count( $forum_id = 0, $difference = 1, $update_ancestors = true ) { |
| @@ -1368,9 +1324,9 @@ | ||
| 1368 | 1324 | $total_reply_count = bbp_get_forum_reply_count( $forum_id, true, true ); |
| 1369 | 1325 | $difference = (int) $difference; |
| 1370 | 1326 | |
| 1371 | 1327 | // Update this forum id |
| 1372 | - update_post_meta( $forum_id, '_bbp_reply_count', (int) ( $reply_count + $difference ) ); | |
| 1328 | + update_post_meta( $forum_id, '_bbp_reply_count', (int) ( $reply_count + $difference ) ); | |
| 1373 | 1329 | update_post_meta( $forum_id, '_bbp_total_reply_count', (int) ( $total_reply_count + $difference ) ); |
| 1374 | 1330 | |
| 1375 | 1331 | // Check for ancestors |
| 1376 | 1332 | if ( true === $update_ancestors ) { |
| @@ -1403,15 +1359,15 @@ | ||
| 1403 | 1359 | return (int) apply_filters( 'bbp_bump_forum_reply_count', $forum_reply_count, $forum_id, $difference, $update_ancestors ); |
| 1404 | 1360 | } |
| 1405 | 1361 | |
| 1406 | 1362 | /** |
| 1407 | - * Bump the total topic count of a forum. | |
| 1363 | + * Bump the total topic count of a forum | |
| 1408 | 1364 | * |
| 1409 | 1365 | * @since 2.6.0 bbPress (r6922) |
| 1410 | 1366 | * |
| 1411 | 1367 | * @param int $forum_id Optional. Forum id. |
| 1412 | - * @param int $difference Optional. Default 1. | |
| 1413 | - * @param bool $update_ancestors Optional. Default true. | |
| 1368 | + * @param int $difference Optional. Default 1 | |
| 1369 | + * @param bool $update_ancestors Optional. Default true | |
| 1414 | 1370 | * |
| 1415 | 1371 | * @return int Forum topic count |
| 1416 | 1372 | */ |
| 1417 | 1373 | function bbp_bump_forum_reply_count_hidden( $forum_id = 0, $difference = 1, $update_ancestors = true ) { |
| @@ -1427,9 +1383,9 @@ | ||
| 1427 | 1383 | $total_reply_count = bbp_get_forum_reply_count_hidden( $forum_id, true, true ); |
| 1428 | 1384 | $difference = (int) $difference; |
| 1429 | 1385 | |
| 1430 | 1386 | // Update this forum id |
| 1431 | - update_post_meta( $forum_id, '_bbp_reply_count_hidden', (int) ( $reply_count + $difference ) ); | |
| 1387 | + update_post_meta( $forum_id, '_bbp_reply_count_hidden', (int) ( $reply_count + $difference ) ); | |
| 1432 | 1388 | update_post_meta( $forum_id, '_bbp_total_reply_count_hidden', (int) ( $total_reply_count + $difference ) ); |
| 1433 | 1389 | |
| 1434 | 1390 | // Check for ancestors |
| 1435 | 1391 | if ( true === $update_ancestors ) { |
| @@ -1467,8 +1423,10 @@ | ||
| 1467 | 1423 | * |
| 1468 | 1424 | * @since 2.6.0 bbPress (r6036) |
| 1469 | 1425 | * |
| 1470 | 1426 | * @param int $forum_id The forum id. |
| 1427 | + * | |
| 1428 | + * @return void | |
| 1471 | 1429 | */ |
| 1472 | 1430 | function bbp_increase_forum_reply_count( $forum_id = 0 ) { |
| 1473 | 1431 | |
| 1474 | 1432 | // Bail early if no id is passed. |
| @@ -1497,8 +1455,10 @@ | ||
| 1497 | 1455 | * |
| 1498 | 1456 | * @since 2.6.0 bbPress (r6036) |
| 1499 | 1457 | * |
| 1500 | 1458 | * @param int $forum_id The forum id. |
| 1459 | + * | |
| 1460 | + * @return void | |
| 1501 | 1461 | */ |
| 1502 | 1462 | function bbp_decrease_forum_reply_count( $forum_id = 0 ) { |
| 1503 | 1463 | |
| 1504 | 1464 | // Bail early if no id is passed. |
| @@ -1527,8 +1487,10 @@ | ||
| 1527 | 1487 | * |
| 1528 | 1488 | * @since 2.6.0 bbPress (r6036) |
| 1529 | 1489 | * |
| 1530 | 1490 | * @param int $forum_id The forum id. |
| 1491 | + * | |
| 1492 | + * @return void | |
| 1531 | 1493 | */ |
| 1532 | 1494 | function bbp_increase_forum_reply_count_hidden( $forum_id = 0 ) { |
| 1533 | 1495 | |
| 1534 | 1496 | // Bail early if no id is passed. |
| @@ -1557,8 +1519,10 @@ | ||
| 1557 | 1519 | * |
| 1558 | 1520 | * @since 2.6.0 bbPress (r6036) |
| 1559 | 1521 | * |
| 1560 | 1522 | * @param int $forum_id The forum id. |
| 1523 | + * | |
| 1524 | + * @return void | |
| 1561 | 1525 | */ |
| 1562 | 1526 | function bbp_decrease_forum_reply_count_hidden( $forum_id = 0 ) { |
| 1563 | 1527 | |
| 1564 | 1528 | // Bail early if no id is passed. |
| @@ -1587,8 +1551,10 @@ | ||
| 1587 | 1551 | * |
| 1588 | 1552 | * @since 2.6.0 bbPress (r6036) |
| 1589 | 1553 | * |
| 1590 | 1554 | * @param int $topic_id The topic id. |
| 1555 | + * | |
| 1556 | + * @return void | |
| 1591 | 1557 | */ |
| 1592 | 1558 | function bbp_approved_unapproved_topic_update_forum_reply_count( $topic_id = 0 ) { |
| 1593 | 1559 | |
| 1594 | 1560 | // Bail early if we don't have a topic id. |
| @@ -1610,15 +1576,15 @@ | ||
| 1610 | 1576 | |
| 1611 | 1577 | /** Forum Updaters ************************************************************/ |
| 1612 | 1578 | |
| 1613 | 1579 | /** |
| 1614 | - * Update the forum last topic id. | |
| 1580 | + * Update the forum last topic id | |
| 1615 | 1581 | * |
| 1616 | 1582 | * @since 2.0.0 bbPress (r2625) |
| 1617 | 1583 | * |
| 1618 | 1584 | * @param int $forum_id Optional. Forum id. |
| 1619 | 1585 | * @param int $topic_id Optional. Topic id. |
| 1620 | - * @return int Id of the forums most recent topic. | |
| 1586 | + * @return int Id of the forums most recent topic | |
| 1621 | 1587 | */ |
| 1622 | 1588 | function bbp_update_forum_last_topic_id( $forum_id = 0, $topic_id = 0 ) { |
| 1623 | 1589 | $forum_id = bbp_get_forum_id( $forum_id ); |
| 1624 | 1590 | |
| @@ -1669,15 +1635,15 @@ | ||
| 1669 | 1635 | return (int) apply_filters( 'bbp_update_forum_last_topic_id', $topic_id, $forum_id ); |
| 1670 | 1636 | } |
| 1671 | 1637 | |
| 1672 | 1638 | /** |
| 1673 | - * Update the forum last reply id. | |
| 1639 | + * Update the forum last reply id | |
| 1674 | 1640 | * |
| 1675 | 1641 | * @since 2.0.0 bbPress (r2625) |
| 1676 | 1642 | * |
| 1677 | 1643 | * @param int $forum_id Optional. Forum id. |
| 1678 | 1644 | * @param int $reply_id Optional. Reply id. |
| 1679 | - * @return int Id of the forums most recent reply. | |
| 1645 | + * @return int Id of the forums most recent reply | |
| 1680 | 1646 | */ |
| 1681 | 1647 | function bbp_update_forum_last_reply_id( $forum_id = 0, $reply_id = 0 ) { |
| 1682 | 1648 | $forum_id = bbp_get_forum_id( $forum_id ); |
| 1683 | 1649 | |
| @@ -1725,15 +1691,15 @@ | ||
| 1725 | 1691 | return (int) apply_filters( 'bbp_update_forum_last_reply_id', $reply_id, $forum_id ); |
| 1726 | 1692 | } |
| 1727 | 1693 | |
| 1728 | 1694 | /** |
| 1729 | - * Update the forum last active post id. | |
| 1695 | + * Update the forum last active post id | |
| 1730 | 1696 | * |
| 1731 | 1697 | * @since 2.0.0 bbPress (r2860) |
| 1732 | 1698 | * |
| 1733 | 1699 | * @param int $forum_id Optional. Forum id. |
| 1734 | 1700 | * @param int $active_id Optional. Active post id. |
| 1735 | - * @return int Id of the forums last active post. | |
| 1701 | + * @return int Id of the forums last active post | |
| 1736 | 1702 | */ |
| 1737 | 1703 | function bbp_update_forum_last_active_id( $forum_id = 0, $active_id = 0 ) { |
| 1738 | 1704 | |
| 1739 | 1705 | $forum_id = bbp_get_forum_id( $forum_id ); |
| @@ -1783,9 +1749,9 @@ | ||
| 1783 | 1749 | return (int) apply_filters( 'bbp_update_forum_last_active_id', $active_id, $forum_id ); |
| 1784 | 1750 | } |
| 1785 | 1751 | |
| 1786 | 1752 | /** |
| 1787 | - * Update the forums last active date/time (aka freshness). | |
| 1753 | + * Update the forums last active date/time (aka freshness) | |
| 1788 | 1754 | * |
| 1789 | 1755 | * @since 2.0.0 bbPress (r2680) |
| 1790 | 1756 | * |
| 1791 | 1757 | * @param int $forum_id Optional. Topic id. |
| @@ -1790,9 +1756,9 @@ | ||
| 1790 | 1756 | * |
| 1791 | 1757 | * @param int $forum_id Optional. Topic id. |
| 1792 | 1758 | * @param string $new_time Optional. New time in mysql format. |
| 1793 | 1759 | * |
| 1794 | - * @return string MySQL timestamp of last active topic or reply. | |
| 1760 | + * @return string MySQL timestamp of last active topic or reply | |
| 1795 | 1761 | */ |
| 1796 | 1762 | function bbp_update_forum_last_active_time( $forum_id = 0, $new_time = '' ) { |
| 1797 | 1763 | $forum_id = bbp_get_forum_id( $forum_id ); |
| 1798 | 1764 | |
| @@ -1810,15 +1776,15 @@ | ||
| 1810 | 1776 | return apply_filters( 'bbp_update_forum_last_active', $new_time, $forum_id ); |
| 1811 | 1777 | } |
| 1812 | 1778 | |
| 1813 | 1779 | /** |
| 1814 | - * Update the forum sub-forum count. | |
| 1780 | + * Update the forum sub-forum count | |
| 1815 | 1781 | * |
| 1816 | 1782 | * @since 2.0.0 bbPress (r2625) |
| 1817 | 1783 | * |
| 1818 | - * @param int $forum_id Optional. Forum id. | |
| 1819 | - * @param int $subforums Optional. Number of subforums. | |
| 1820 | - * @return bool True on success, false on failure. | |
| 1784 | + * @param int $forum_id Optional. Forum id | |
| 1785 | + * @param int $subforums Optional. Number of subforums | |
| 1786 | + * @return bool True on success, false on failure | |
| 1821 | 1787 | */ |
| 1822 | 1788 | function bbp_update_forum_subforum_count( $forum_id = 0, $subforums = false ) { |
| 1823 | 1789 | $forum_id = bbp_get_forum_id( $forum_id ); |
| 1824 | 1790 | |
| @@ -1833,9 +1799,9 @@ | ||
| 1833 | 1799 | return (int) apply_filters( 'bbp_update_forum_subforum_count', $subforums, $forum_id ); |
| 1834 | 1800 | } |
| 1835 | 1801 | |
| 1836 | 1802 | /** |
| 1837 | - * Adjust the total topic count of a forum. | |
| 1803 | + * Adjust the total topic count of a forum | |
| 1838 | 1804 | * |
| 1839 | 1805 | * @since 2.0.0 bbPress (r2464) |
| 1840 | 1806 | * |
| 1841 | 1807 | * @param int $forum_id Optional. Forum id or topic id. It is checked whether it |
| @@ -1840,10 +1806,10 @@ | ||
| 1840 | 1806 | * |
| 1841 | 1807 | * @param int $forum_id Optional. Forum id or topic id. It is checked whether it |
| 1842 | 1808 | * is a topic or a forum. If it's a topic, its parent, |
| 1843 | 1809 | * i.e. the forum is automatically retrieved. |
| 1844 | - * @param bool $total_count Optional. To return the total count or normal count. | |
| 1845 | - * @return int Forum topic count. | |
| 1810 | + * @param bool $total_count Optional. To return the total count or normal count? | |
| 1811 | + * @return int Forum topic count | |
| 1846 | 1812 | */ |
| 1847 | 1813 | function bbp_update_forum_topic_count( $forum_id = 0 ) { |
| 1848 | 1814 | $forum_id = bbp_get_forum_id( $forum_id ); |
| 1849 | 1815 | $children_topic_count = 0; |
| @@ -1871,9 +1837,9 @@ | ||
| 1871 | 1837 | } |
| 1872 | 1838 | |
| 1873 | 1839 | /** |
| 1874 | 1840 | * Adjust the total hidden topic count of a forum (hidden includes trashed, |
| 1875 | - * spammed and pending topics). | |
| 1841 | + * spammed and pending topics) | |
| 1876 | 1842 | * |
| 1877 | 1843 | * @since 2.0.0 bbPress (r2888) |
| 1878 | 1844 | * @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects |
| 1879 | 1845 | * |
| @@ -1879,9 +1845,9 @@ | ||
| 1879 | 1845 | * |
| 1880 | 1846 | * @param int $forum_id Optional. Topic id to update. |
| 1881 | 1847 | * @param int $topic_count Optional. Set the topic count manually. |
| 1882 | 1848 | * |
| 1883 | - * @return int Topic hidden topic count. | |
| 1849 | + * @return int Topic hidden topic count | |
| 1884 | 1850 | */ |
| 1885 | 1851 | function bbp_update_forum_topic_count_hidden( $forum_id = 0, $topic_count = false ) { |
| 1886 | 1852 | |
| 1887 | 1853 | // If topic_id was passed as $forum_id, then get its forum |
| @@ -1898,28 +1864,24 @@ | ||
| 1898 | 1864 | if ( ! empty( $forum_id ) ) { |
| 1899 | 1865 | |
| 1900 | 1866 | // Get topics of forum |
| 1901 | 1867 | if ( ! is_int( $topic_count ) ) { |
| 1902 | - $query = new WP_Query( | |
| 1903 | - array( | |
| 1904 | - 'fields' => 'ids', | |
| 1905 | - 'post_parent' => $forum_id, | |
| 1906 | - 'post_status' => bbp_get_non_public_topic_statuses(), | |
| 1907 | - 'post_type' => bbp_get_topic_post_type(), | |
| 1908 | - 'posts_per_page' => -1, | |
| 1868 | + $query = new WP_Query( array( | |
| 1869 | + 'fields' => 'ids', | |
| 1870 | + 'post_parent' => $forum_id, | |
| 1871 | + 'post_status' => bbp_get_non_public_topic_statuses(), | |
| 1872 | + 'post_type' => bbp_get_topic_post_type(), | |
| 1873 | + 'posts_per_page' => -1, | |
| 1909 | 1874 | |
| 1910 | - // Performance | |
| 1911 | - 'nopaging' => true, | |
| 1912 | - 'suppress_filters' => true, | |
| 1913 | - 'update_post_term_cache' => false, | |
| 1914 | - 'update_post_meta_cache' => false, | |
| 1915 | - 'ignore_sticky_posts' => true, | |
| 1916 | - 'no_found_rows' => true | |
| 1917 | - ) | |
| 1918 | - ); | |
| 1919 | - | |
| 1875 | + // Performance | |
| 1876 | + 'nopaging' => true, | |
| 1877 | + 'suppress_filters' => true, | |
| 1878 | + 'update_post_term_cache' => false, | |
| 1879 | + 'update_post_meta_cache' => false, | |
| 1880 | + 'ignore_sticky_posts' => true, | |
| 1881 | + 'no_found_rows' => true | |
| 1882 | + ) ); | |
| 1920 | 1883 | $topic_count = $query->post_count; |
| 1921 | - | |
| 1922 | 1884 | unset( $query ); |
| 1923 | 1885 | } |
| 1924 | 1886 | |
| 1925 | 1887 | $topic_count = (int) $topic_count; |
| @@ -1932,18 +1894,18 @@ | ||
| 1932 | 1894 | return (int) apply_filters( 'bbp_update_forum_topic_count_hidden', $topic_count, $forum_id ); |
| 1933 | 1895 | } |
| 1934 | 1896 | |
| 1935 | 1897 | /** |
| 1936 | - * Adjust the total reply count of a forum. | |
| 1898 | + * Adjust the total reply count of a forum | |
| 1937 | 1899 | * |
| 1938 | 1900 | * @since 2.0.0 bbPress (r2464) |
| 1939 | - * @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects. | |
| 1901 | + * @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects | |
| 1940 | 1902 | * |
| 1941 | 1903 | * @param int $forum_id Optional. Forum id or topic id. It is checked whether it |
| 1942 | 1904 | * is a topic or a forum. If it's a topic, its parent, |
| 1943 | 1905 | * i.e. the forum is automatically retrieved. |
| 1944 | 1906 | * |
| 1945 | - * @return int Forum reply count. | |
| 1907 | + * @return int Forum reply count | |
| 1946 | 1908 | */ |
| 1947 | 1909 | function bbp_update_forum_reply_count( $forum_id = 0 ) { |
| 1948 | 1910 | |
| 1949 | 1911 | $forum_id = bbp_get_forum_id( $forum_id ); |
| @@ -1973,9 +1935,9 @@ | ||
| 1973 | 1935 | return (int) apply_filters( 'bbp_update_forum_reply_count', $total_replies, $forum_id ); |
| 1974 | 1936 | } |
| 1975 | 1937 | |
| 1976 | 1938 | /** |
| 1977 | - * Adjust the total hidden reply count of a forum. | |
| 1939 | + * Adjust the total hidden reply count of a forum | |
| 1978 | 1940 | * |
| 1979 | 1941 | * @since 2.6.0 bbPress (r6922) |
| 1980 | 1942 | * |
| 1981 | 1943 | * @param int $forum_id Optional. Forum id or topic id. It is checked whether it |
| @@ -1981,9 +1943,9 @@ | ||
| 1981 | 1943 | * @param int $forum_id Optional. Forum id or topic id. It is checked whether it |
| 1982 | 1944 | * is a topic or a forum. If it's a topic, its parent, |
| 1983 | 1945 | * i.e. the forum is automatically retrieved. |
| 1984 | 1946 | * |
| 1985 | - * @return int Forum reply count. | |
| 1947 | + * @return int Forum reply count | |
| 1986 | 1948 | */ |
| 1987 | 1949 | function bbp_update_forum_reply_count_hidden( $forum_id = 0 ) { |
| 1988 | 1950 | |
| 1989 | 1951 | $forum_id = bbp_get_forum_id( $forum_id ); |
| @@ -2031,21 +1993,17 @@ | ||
| 2031 | 1993 | */ |
| 2032 | 1994 | function bbp_update_forum( $args = array() ) { |
| 2033 | 1995 | |
| 2034 | 1996 | // Parse arguments against default values |
| 2035 | - $r = bbp_parse_args( | |
| 2036 | - $args, | |
| 2037 | - array( | |
| 2038 | - 'forum_id' => 0, | |
| 2039 | - 'post_parent' => 0, | |
| 2040 | - 'last_topic_id' => 0, | |
| 2041 | - 'last_reply_id' => 0, | |
| 2042 | - 'last_active_id' => 0, | |
| 2043 | - 'last_active_time' => 0, | |
| 2044 | - 'last_active_status' => bbp_get_public_status_id() | |
| 2045 | - ), | |
| 2046 | - 'update_forum' | |
| 2047 | - ); | |
| 1997 | + $r = bbp_parse_args( $args, array( | |
| 1998 | + 'forum_id' => 0, | |
| 1999 | + 'post_parent' => 0, | |
| 2000 | + 'last_topic_id' => 0, | |
| 2001 | + 'last_reply_id' => 0, | |
| 2002 | + 'last_active_id' => 0, | |
| 2003 | + 'last_active_time' => 0, | |
| 2004 | + 'last_active_status' => bbp_get_public_status_id() | |
| 2005 | + ), 'update_forum' ); | |
| 2048 | 2006 | |
| 2049 | 2007 | // Update the forum parent |
| 2050 | 2008 | bbp_update_forum_id( $r['forum_id'], $r['post_parent'] ); |
| 2051 | 2009 | |
| @@ -2077,14 +2035,12 @@ | ||
| 2077 | 2035 | } |
| 2078 | 2036 | |
| 2079 | 2037 | // Update the parent forum if one was passed |
| 2080 | 2038 | if ( ! empty( $r['post_parent'] ) && is_numeric( $r['post_parent'] ) ) { |
| 2081 | - bbp_update_forum( | |
| 2082 | - array( | |
| 2083 | - 'forum_id' => $r['post_parent'], | |
| 2084 | - 'post_parent' => get_post_field( 'post_parent', $r['post_parent'] ) | |
| 2085 | - ) | |
| 2086 | - ); | |
| 2039 | + bbp_update_forum( array( | |
| 2040 | + 'forum_id' => $r['post_parent'], | |
| 2041 | + 'post_parent' => get_post_field( 'post_parent', $r['post_parent'] ) | |
| 2042 | + ) ); | |
| 2087 | 2043 | } |
| 2088 | 2044 | |
| 2089 | 2045 | // Bump the custom query cache |
| 2090 | 2046 | wp_cache_set( 'last_changed', microtime(), 'bbpress_posts' ); |
| @@ -2092,9 +2048,9 @@ | ||
| 2092 | 2048 | |
| 2093 | 2049 | /** Helpers *******************************************************************/ |
| 2094 | 2050 | |
| 2095 | 2051 | /** |
| 2096 | - * Return an associative array of available topic statuses. | |
| 2052 | + * Return an associative array of available topic statuses | |
| 2097 | 2053 | * |
| 2098 | 2054 | * Developers note: these statuses are actually stored as meta data, and |
| 2099 | 2055 | * Visibilities are stored in post_status. |
| 2100 | 2056 | * |
| @@ -2099,9 +2055,9 @@ | ||
| 2099 | 2055 | * Visibilities are stored in post_status. |
| 2100 | 2056 | * |
| 2101 | 2057 | * @since 2.4.0 bbPress (r5059) |
| 2102 | 2058 | * |
| 2103 | - * @param int $forum_id Optional. Forum id. | |
| 2059 | + * @param int $forum_id Optional. Forum id. | |
| 2104 | 2060 | * |
| 2105 | 2061 | * @return array |
| 2106 | 2062 | */ |
| 2107 | 2063 | function bbp_get_forum_statuses( $forum_id = 0 ) { |
| @@ -2106,24 +2062,20 @@ | ||
| 2106 | 2062 | */ |
| 2107 | 2063 | function bbp_get_forum_statuses( $forum_id = 0 ) { |
| 2108 | 2064 | |
| 2109 | 2065 | // Filter & return |
| 2110 | - return (array) apply_filters( | |
| 2111 | - 'bbp_get_forum_statuses', | |
| 2112 | - array( | |
| 2113 | - 'open' => _x( 'Open', 'Open the forum', 'bbpress' ), | |
| 2114 | - 'closed' => _x( 'Closed', 'Close the forum', 'bbpress' ) | |
| 2115 | - ), | |
| 2116 | - $forum_id | |
| 2117 | - ); | |
| 2066 | + return (array) apply_filters( 'bbp_get_forum_statuses', array( | |
| 2067 | + 'open' => _x( 'Open', 'Open the forum', 'bbpress' ), | |
| 2068 | + 'closed' => _x( 'Closed', 'Close the forum', 'bbpress' ) | |
| 2069 | + ), $forum_id ); | |
| 2118 | 2070 | } |
| 2119 | 2071 | |
| 2120 | 2072 | /** |
| 2121 | - * Return an associative array of forum type. | |
| 2073 | + * Return an associative array of forum types | |
| 2122 | 2074 | * |
| 2123 | 2075 | * @since 2.4.0 bbPress (r5059) |
| 2124 | 2076 | * |
| 2125 | - * @param int $forum_id Optional. Forum id. | |
| 2077 | + * @param int $forum_id Optional. Forum id. | |
| 2126 | 2078 | * |
| 2127 | 2079 | * @return array |
| 2128 | 2080 | */ |
| 2129 | 2081 | function bbp_get_forum_types( $forum_id = 0 ) { |
| @@ -2128,16 +2080,12 @@ | ||
| 2128 | 2080 | */ |
| 2129 | 2081 | function bbp_get_forum_types( $forum_id = 0 ) { |
| 2130 | 2082 | |
| 2131 | 2083 | // Filter & return |
| 2132 | - return (array) apply_filters( | |
| 2133 | - 'bbp_get_forum_types', | |
| 2134 | - array( | |
| 2135 | - 'forum' => _x( 'Forum', 'Forum accepts new topics', 'bbpress' ), | |
| 2136 | - 'category' => _x( 'Category', 'Forum is a category', 'bbpress' ) | |
| 2137 | - ), | |
| 2138 | - $forum_id | |
| 2139 | - ); | |
| 2084 | + return (array) apply_filters( 'bbp_get_forum_types', array( | |
| 2085 | + 'forum' => _x( 'Forum', 'Forum accepts new topics', 'bbpress' ), | |
| 2086 | + 'category' => _x( 'Category', 'Forum is a category', 'bbpress' ) | |
| 2087 | + ), $forum_id ); | |
| 2140 | 2088 | } |
| 2141 | 2089 | |
| 2142 | 2090 | /** |
| 2143 | 2091 | * Return an associative array of forum visibility |
| @@ -2146,24 +2094,20 @@ | ||
| 2146 | 2094 | * Statuses are stored in meta data. |
| 2147 | 2095 | * |
| 2148 | 2096 | * @since 2.4.0 bbPress (r5059) |
| 2149 | 2097 | * |
| 2150 | - * @param int $forum_id Optional. Forum id. | |
| 2098 | + * @param int $forum_id Optional. Forum id. | |
| 2151 | 2099 | * |
| 2152 | 2100 | * @return array |
| 2153 | 2101 | */ |
| 2154 | -function bbp_get_forum_visibilities( $forum_id = 0 ) { | |
| 2102 | +function bbp_get_forum_visibilities( $forum_id = 0) { | |
| 2155 | 2103 | |
| 2156 | 2104 | // Filter & return |
| 2157 | - return (array) apply_filters( | |
| 2158 | - 'bbp_get_forum_visibilities', | |
| 2159 | - array( | |
| 2160 | - bbp_get_public_status_id() => _x( 'Public', 'Make forum public', 'bbpress' ), | |
| 2161 | - bbp_get_private_status_id() => _x( 'Private', 'Make forum private', 'bbpress' ), | |
| 2162 | - bbp_get_hidden_status_id() => _x( 'Hidden', 'Make forum hidden', 'bbpress' ) | |
| 2163 | - ), | |
| 2164 | - $forum_id | |
| 2165 | - ); | |
| 2105 | + return (array) apply_filters( 'bbp_get_forum_visibilities', array( | |
| 2106 | + bbp_get_public_status_id() => _x( 'Public', 'Make forum public', 'bbpress' ), | |
| 2107 | + bbp_get_private_status_id() => _x( 'Private', 'Make forum private', 'bbpress' ), | |
| 2108 | + bbp_get_hidden_status_id() => _x( 'Hidden', 'Make forum hidden', 'bbpress' ) | |
| 2109 | + ), $forum_id ); | |
| 2166 | 2110 | } |
| 2167 | 2111 | |
| 2168 | 2112 | /** |
| 2169 | 2113 | * Return array of public forum statuses. |
| @@ -2200,9 +2144,9 @@ | ||
| 2200 | 2144 | |
| 2201 | 2145 | /** Queries *******************************************************************/ |
| 2202 | 2146 | |
| 2203 | 2147 | /** |
| 2204 | - * Returns the hidden forum ids. | |
| 2148 | + * Returns the hidden forum ids | |
| 2205 | 2149 | * |
| 2206 | 2150 | * Only hidden forum ids are returned. Public and private ids are not. |
| 2207 | 2151 | * |
| 2208 | 2152 | * @since 2.0.0 bbPress (r3007) |
| @@ -2217,9 +2161,9 @@ | ||
| 2217 | 2161 | return (array) apply_filters( 'bbp_get_hidden_forum_ids', $forum_ids ); |
| 2218 | 2162 | } |
| 2219 | 2163 | |
| 2220 | 2164 | /** |
| 2221 | - * Returns the private forum ids. | |
| 2165 | + * Returns the private forum ids | |
| 2222 | 2166 | * |
| 2223 | 2167 | * Only private forum ids are returned. Public and hidden ids are not. |
| 2224 | 2168 | * |
| 2225 | 2169 | * @since 2.0.0 bbPress (r3007) |
| @@ -2237,11 +2181,18 @@ | ||
| 2237 | 2181 | /** |
| 2238 | 2182 | * Returns the forum IDs that should be excluded from various views & queries, |
| 2239 | 2183 | * based on the current user's capabilities. |
| 2240 | 2184 | * |
| 2185 | + * These results are automatically filtered by bbp_allow_forums_of_user(), to | |
| 2186 | + * allow per-forum moderators to see forums that would otherwise be private or | |
| 2187 | + * hidden to them. | |
| 2188 | + * | |
| 2189 | + * If you have a need to filter these results based on your own custom | |
| 2190 | + * engagements API usages, please see: bbp_allow_forums_of_user() | |
| 2191 | + * | |
| 2241 | 2192 | * @since 2.6.0 bbPress (r6425) |
| 2242 | 2193 | * |
| 2243 | - * @return array Forum IDs to exclude, or an empty array. | |
| 2194 | + * @return array Forum IDs to exclude, or an empty array | |
| 2244 | 2195 | */ |
| 2245 | 2196 | function bbp_get_excluded_forum_ids() { |
| 2246 | 2197 | |
| 2247 | 2198 | // Private forums |
| @@ -2268,9 +2219,9 @@ | ||
| 2268 | 2219 | * from a query. |
| 2269 | 2220 | * |
| 2270 | 2221 | * @since 2.0.0 bbPress (r3291) |
| 2271 | 2222 | * |
| 2272 | - * @param string Optional. The type of value to return (string|array|meta_query). | |
| 2223 | + * @param string Optional. The type of value to return. (string|array|meta_query) | |
| 2273 | 2224 | */ |
| 2274 | 2225 | function bbp_exclude_forum_ids( $type = 'string' ) { |
| 2275 | 2226 | |
| 2276 | 2227 | // Setup arrays |
| @@ -2291,16 +2242,21 @@ | ||
| 2291 | 2242 | |
| 2292 | 2243 | // Store return values in static types array |
| 2293 | 2244 | if ( ! empty( $forum_ids ) ) { |
| 2294 | 2245 | |
| 2246 | + // Comparison | |
| 2247 | + $compare = ( 1 < count( $forum_ids ) ) | |
| 2248 | + ? 'NOT IN' | |
| 2249 | + : '!='; | |
| 2250 | + | |
| 2295 | 2251 | // Setup types |
| 2296 | 2252 | $types['array'] = $forum_ids; |
| 2297 | 2253 | $types['string'] = implode( ',', $forum_ids ); |
| 2298 | 2254 | $types['meta_query'] = array( |
| 2299 | 2255 | 'key' => '_bbp_forum_id', |
| 2300 | - 'value' => $forum_ids, | |
| 2256 | + 'value' => $types['string'], | |
| 2301 | 2257 | 'type' => 'NUMERIC', |
| 2302 | - 'compare' => 'NOT IN' | |
| 2258 | + 'compare' => $compare | |
| 2303 | 2259 | ); |
| 2304 | 2260 | } |
| 2305 | 2261 | } |
| 2306 | 2262 | |
| @@ -2337,222 +2293,71 @@ | ||
| 2337 | 2293 | if ( ! is_object( $posts_query ) || ! is_a( $posts_query, 'WP_Query' ) ) { |
| 2338 | 2294 | return; |
| 2339 | 2295 | } |
| 2340 | 2296 | |
| 2341 | - // Bail to prevent unintended wp-admin post_row overrides | |
| 2342 | - if ( is_admin() && isset( $_REQUEST['post_status'] ) ) { | |
| 2343 | - return; | |
| 2344 | - } | |
| 2297 | + // Get query post types array . | |
| 2298 | + $post_types = (array) $posts_query->get( 'post_type' ); | |
| 2345 | 2299 | |
| 2346 | - // Get the raw query post types. | |
| 2347 | - $post_type_query_var = $posts_query->get( 'post_type' ); | |
| 2348 | - $post_types = array_filter( (array) $post_type_query_var ); | |
| 2349 | - | |
| 2350 | - // Resolve the post types included in "any" and implicit search queries. | |
| 2351 | - if ( ( 'any' === $post_type_query_var ) || ( empty( $post_types ) && $posts_query->is_search() ) ) { | |
| 2352 | - $post_types = get_post_types( array( 'exclude_from_search' => false ) ); | |
| 2353 | - } | |
| 2354 | - | |
| 2355 | - // Bail if no post types to normalize | |
| 2356 | - if ( empty( $post_types ) ) { | |
| 2357 | - return; | |
| 2358 | - } | |
| 2359 | - | |
| 2360 | - // Compare queried post-types to supported post-types | |
| 2361 | - $bbp_post_types = array_intersect( $post_types, bbp_get_post_types() ); | |
| 2362 | - | |
| 2363 | - // Bail if no bbPress post type is being queried | |
| 2364 | - if ( empty( $bbp_post_types ) ) { | |
| 2365 | - return; | |
| 2366 | - } | |
| 2367 | - | |
| 2368 | - // Bail if this query has already been normalized | |
| 2369 | - if ( $posts_query->get( '_bbp_forum_visibility_normalized' ) ) { | |
| 2370 | - return; | |
| 2371 | - } | |
| 2372 | - | |
| 2373 | - // Mark this query as normalized | |
| 2374 | - $posts_query->set( '_bbp_forum_visibility_normalized', true ); | |
| 2375 | - | |
| 2376 | - // Separate non-bbPress post types from supported bbPress post types. | |
| 2377 | - $non_bbp_post_types = array_diff( $post_types, $bbp_post_types ); | |
| 2378 | - | |
| 2379 | - /** | |
| 2380 | - * Clause filters do not run when a query suppresses filters. Remove bbPress | |
| 2381 | - * post types from mixed queries so protected content continues to fail closed | |
| 2382 | - * without changing the requested non-bbPress post types. | |
| 2383 | - */ | |
| 2384 | - if ( ! empty( $non_bbp_post_types ) && $posts_query->get( 'suppress_filters' ) ) { | |
| 2385 | - $posts_query->set( 'post_type', array_values( $non_bbp_post_types ) ); | |
| 2386 | - return; | |
| 2387 | - } | |
| 2388 | - | |
| 2389 | - // Get forums to exclude. | |
| 2390 | - $forum_ids = bbp_exclude_forum_ids( 'array' ); | |
| 2391 | - | |
| 2392 | 2300 | // Forums |
| 2393 | - if ( in_array( bbp_get_forum_post_type(), $post_types, true ) ) { | |
| 2301 | + if ( bbp_get_forum_post_type() === implode( '', $post_types ) ) { | |
| 2394 | 2302 | |
| 2395 | - // Add all supported forum visibilities to bbPress-only queries. | |
| 2396 | - if ( empty( $non_bbp_post_types ) ) { | |
| 2397 | - $posts_query->set( 'post_status', array_keys( bbp_get_forum_visibilities() ) ); | |
| 2303 | + // Prevent accidental wp-admin post_row override | |
| 2304 | + if ( is_admin() && isset( $_REQUEST['post_status'] ) ) { | |
| 2305 | + return; | |
| 2398 | 2306 | } |
| 2399 | 2307 | |
| 2400 | - // Excluding some forums | |
| 2401 | - if ( ! empty( $forum_ids ) ) { | |
| 2308 | + /** Default ***********************************************************/ | |
| 2402 | 2309 | |
| 2403 | - // Get any existing not-in queries | |
| 2404 | - $not_in = (array) $posts_query->get( 'post__not_in', array() ); | |
| 2310 | + // Add all supported forum visibilities | |
| 2311 | + $posts_query->set( 'post_status', array_keys( bbp_get_forum_visibilities() ) ); | |
| 2405 | 2312 | |
| 2406 | - // Add our not-in to existing | |
| 2407 | - $not_in = wp_parse_id_list( array_merge( $not_in, $forum_ids ) ); | |
| 2313 | + // Get forums to exclude | |
| 2314 | + $hidden_ids = bbp_exclude_forum_ids( 'array' ); | |
| 2408 | 2315 | |
| 2409 | - // Set the new not-in val | |
| 2410 | - $posts_query->set( 'post__not_in', $not_in ); | |
| 2316 | + // Bail if no forums to exclude | |
| 2317 | + if ( empty( $hidden_ids ) ) { | |
| 2318 | + return; | |
| 2411 | 2319 | } |
| 2412 | - } | |
| 2413 | 2320 | |
| 2414 | - // Bail if there are no forums to exclude. | |
| 2415 | - if ( empty( $forum_ids ) ) { | |
| 2416 | - return; | |
| 2417 | - } | |
| 2321 | + // Get any existing meta queries | |
| 2322 | + $not_in = $posts_query->get( 'post__not_in', array() ); | |
| 2418 | 2323 | |
| 2419 | - /** | |
| 2420 | - * Mixed queries need a post-type-aware SQL clause. A meta query would use an | |
| 2421 | - * inner join and unintentionally remove non-bbPress posts that do not have | |
| 2422 | - * bbPress forum metadata. | |
| 2423 | - */ | |
| 2424 | - if ( ! empty( $non_bbp_post_types ) ) { | |
| 2425 | - $content_post_types = array_intersect( | |
| 2426 | - $bbp_post_types, | |
| 2427 | - array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) | |
| 2428 | - ); | |
| 2324 | + // Add our meta query to existing | |
| 2325 | + $not_in = array_unique( array_merge( $not_in, $hidden_ids ) ); | |
| 2429 | 2326 | |
| 2430 | - $posts_query->set( '_bbp_forum_visibility_post_types', $content_post_types ); | |
| 2431 | - $posts_query->set( '_bbp_forum_visibility_forum_ids', $forum_ids ); | |
| 2432 | - return; | |
| 2433 | - } | |
| 2327 | + // Set the meta_query var | |
| 2328 | + $posts_query->set( 'post__not_in', $not_in ); | |
| 2434 | 2329 | |
| 2435 | - // Get forum meta query. | |
| 2436 | - $forum_meta_query = bbp_exclude_forum_ids( 'meta_query' ); | |
| 2330 | + // Some other post type besides Forums, Topics, or Replies | |
| 2331 | + } elseif ( ! array_diff( $post_types, bbp_get_post_types() ) ) { | |
| 2437 | 2332 | |
| 2438 | - // Excluding some forums | |
| 2439 | - if ( is_array( $forum_meta_query ) && ! empty( $forum_meta_query['key'] ) && ! empty( $forum_meta_query['value'] ) ) { | |
| 2333 | + // Get forums to exclude | |
| 2334 | + $forum_ids = bbp_exclude_forum_ids( 'meta_query' ); | |
| 2440 | 2335 | |
| 2336 | + // Bail if no forums to exclude | |
| 2337 | + if ( empty( $forum_ids ) ) { | |
| 2338 | + return; | |
| 2339 | + } | |
| 2340 | + | |
| 2441 | 2341 | // Get any existing meta queries |
| 2442 | 2342 | $meta_query = (array) $posts_query->get( 'meta_query', array() ); |
| 2443 | 2343 | |
| 2444 | 2344 | // Add our meta query to existing |
| 2445 | - $meta_query[] = $forum_meta_query; | |
| 2345 | + $meta_query[] = $forum_ids; | |
| 2446 | 2346 | |
| 2447 | - // Set the new meta_query val | |
| 2347 | + // Set the meta_query var | |
| 2448 | 2348 | $posts_query->set( 'meta_query', $meta_query ); |
| 2449 | 2349 | } |
| 2450 | 2350 | } |
| 2451 | 2351 | |
| 2452 | 2352 | /** |
| 2453 | - * Excludes protected bbPress content from mixed post-type queries. | |
| 2353 | + * Returns the forum's topic ids | |
| 2454 | 2354 | * |
| 2455 | - * A normal meta query cannot scope its join to bbPress post types, causing | |
| 2456 | - * unrelated WordPress posts and third-party post types without `_bbp_forum_id` | |
| 2457 | - * metadata to be removed. This clause leaves forums and non-bbPress rows | |
| 2458 | - * untouched while requiring topic and reply rows to have forum metadata that | |
| 2459 | - * does not reference an excluded forum. Forums are excluded by ID before this | |
| 2460 | - * clause runs. | |
| 2355 | + * Only topics with published and closed statuses are returned | |
| 2461 | 2356 | * |
| 2462 | - * Queries with `suppress_filters` enabled are handled conservatively in | |
| 2463 | - * bbp_pre_get_posts_normalize_forum_visibility(), because this filter will not | |
| 2464 | - * run for those queries. | |
| 2465 | - * | |
| 2466 | - * @since 2.7.0 bbPress | |
| 2467 | - * | |
| 2468 | - * @param string $where SQL WHERE clause. | |
| 2469 | - * @param WP_Query $posts_query WordPress posts query. | |
| 2470 | - * @return string SQL WHERE clause. | |
| 2471 | - */ | |
| 2472 | -function _bbp_forum_visibility_where( $where = '', $posts_query = null ) { | |
| 2473 | - | |
| 2474 | - // Bail if $posts_query is not an object or of incorrect class | |
| 2475 | - if ( ! is_object( $posts_query ) || ! is_a( $posts_query, 'WP_Query' ) ) { | |
| 2476 | - return $where; | |
| 2477 | - } | |
| 2478 | - | |
| 2479 | - // Get the query-specific visibility constraints. | |
| 2480 | - $post_types = array_filter( (array) $posts_query->get( '_bbp_forum_visibility_post_types' ) ); | |
| 2481 | - $forum_ids = wp_parse_id_list( $posts_query->get( '_bbp_forum_visibility_forum_ids' ) ); | |
| 2482 | - | |
| 2483 | - // Bail if this query does not need a post-type-aware visibility clause. | |
| 2484 | - if ( empty( $post_types ) || empty( $forum_ids ) ) { | |
| 2485 | - return $where; | |
| 2486 | - } | |
| 2487 | - | |
| 2488 | - // Get the database object. | |
| 2489 | - $bbp_db = bbp_db(); | |
| 2490 | - | |
| 2491 | - // Prepare post-type and forum-ID placeholders. | |
| 2492 | - $post_type_placeholders = implode( ', ', array_fill( 0, count( $post_types ), '%s' ) ); | |
| 2493 | - $forum_id_placeholders = implode( ', ', array_fill( 0, count( $forum_ids ), '%d' ) ); | |
| 2494 | - | |
| 2495 | - // Prepare values in the same order as their placeholders. | |
| 2496 | - $values = array_merge( $post_types, $forum_ids ); | |
| 2497 | - | |
| 2498 | - /** | |
| 2499 | - * Require topic and reply rows to have forum metadata, and exclude rows with | |
| 2500 | - * forum metadata pointing at a forum the current user cannot view. All other | |
| 2501 | - * rows bypass these checks and retain their original query behavior. | |
| 2502 | - */ | |
| 2503 | - $visibility_where = $bbp_db->prepare( | |
| 2504 | - " AND ( | |
| 2505 | - {$bbp_db->posts}.post_type NOT IN ({$post_type_placeholders}) | |
| 2506 | - OR ( | |
| 2507 | - EXISTS ( | |
| 2508 | - SELECT 1 | |
| 2509 | - FROM {$bbp_db->postmeta} AS bbp_forum_visibility_exists | |
| 2510 | - WHERE bbp_forum_visibility_exists.post_id = {$bbp_db->posts}.ID | |
| 2511 | - AND bbp_forum_visibility_exists.meta_key = '_bbp_forum_id' | |
| 2512 | - ) | |
| 2513 | - AND NOT EXISTS ( | |
| 2514 | - SELECT 1 | |
| 2515 | - FROM {$bbp_db->postmeta} AS bbp_forum_visibility_excluded | |
| 2516 | - WHERE bbp_forum_visibility_excluded.post_id = {$bbp_db->posts}.ID | |
| 2517 | - AND bbp_forum_visibility_excluded.meta_key = '_bbp_forum_id' | |
| 2518 | - AND CAST( bbp_forum_visibility_excluded.meta_value AS UNSIGNED ) IN ({$forum_id_placeholders}) | |
| 2519 | - ) | |
| 2520 | - ) | |
| 2521 | - )", | |
| 2522 | - $values | |
| 2523 | - ); | |
| 2524 | - | |
| 2525 | - /** | |
| 2526 | - * Filters the forum visibility SQL appended to mixed post-type queries. | |
| 2527 | - * | |
| 2528 | - * @since 2.7.0 bbPress | |
| 2529 | - * | |
| 2530 | - * @param string $visibility_where Forum visibility SQL clause. | |
| 2531 | - * @param WP_Query $posts_query WordPress posts query. | |
| 2532 | - * @param string[] $post_types bbPress post types protected by the clause. | |
| 2533 | - * @param int[] $forum_ids Forum IDs excluded from the query. | |
| 2534 | - */ | |
| 2535 | - $visibility_where = apply_filters( | |
| 2536 | - 'bbp_forum_visibility_posts_where', | |
| 2537 | - $visibility_where, | |
| 2538 | - $posts_query, | |
| 2539 | - $post_types, | |
| 2540 | - $forum_ids | |
| 2541 | - ); | |
| 2542 | - | |
| 2543 | - // Append the visibility clause. | |
| 2544 | - return $where . $visibility_where; | |
| 2545 | -} | |
| 2546 | - | |
| 2547 | -/** | |
| 2548 | - * Returns the forum's topic ids. | |
| 2549 | - * | |
| 2550 | - * Only topics with published and closed statuses are returned. | |
| 2551 | - * | |
| 2552 | 2357 | * @since 2.0.0 bbPress (r2908) |
| 2553 | 2358 | * |
| 2554 | - * @param int $forum_id Forum id. | |
| 2359 | + * @param int $forum_id Forum id | |
| 2555 | 2360 | */ |
| 2556 | 2361 | function bbp_forum_query_topic_ids( $forum_id ) { |
| 2557 | 2362 | $topic_ids = bbp_get_public_child_ids( $forum_id, bbp_get_topic_post_type() ); |
| 2558 | 2363 | |
| @@ -2560,15 +2365,15 @@ | ||
| 2560 | 2365 | return (array) apply_filters( 'bbp_forum_query_topic_ids', $topic_ids, $forum_id ); |
| 2561 | 2366 | } |
| 2562 | 2367 | |
| 2563 | 2368 | /** |
| 2564 | - * Returns the forum's subforum ids. | |
| 2369 | + * Returns the forum's subforum ids | |
| 2565 | 2370 | * |
| 2566 | - * Only forums with published status are returned. | |
| 2371 | + * Only forums with published status are returned | |
| 2567 | 2372 | * |
| 2568 | 2373 | * @since 2.0.0 bbPress (r2908) |
| 2569 | 2374 | * |
| 2570 | - * @param int $forum_id Forum id. | |
| 2375 | + * @param int $forum_id Forum id | |
| 2571 | 2376 | */ |
| 2572 | 2377 | function bbp_forum_query_subforum_ids( $forum_id ) { |
| 2573 | 2378 | $subforum_ids = bbp_get_all_child_ids( $forum_id, bbp_get_forum_post_type() ); |
| 2574 | 2379 | |
| @@ -2576,12 +2381,12 @@ | ||
| 2576 | 2381 | return (array) apply_filters( 'bbp_forum_query_subforum_ids', $subforum_ids, $forum_id ); |
| 2577 | 2382 | } |
| 2578 | 2383 | |
| 2579 | 2384 | /** |
| 2580 | - * Returns the forum's last reply id. | |
| 2385 | + * Returns the forum's last reply id | |
| 2581 | 2386 | * |
| 2582 | 2387 | * @since 2.0.0 bbPress (r2908) |
| 2583 | - * @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects. | |
| 2388 | + * @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects | |
| 2584 | 2389 | * |
| 2585 | 2390 | * @param int $forum_id Forum id. |
| 2586 | 2391 | * @param int $topic_ids Optional. Topic ids. |
| 2587 | 2392 | */ |
| @@ -2594,28 +2399,26 @@ | ||
| 2594 | 2399 | if ( empty( $topic_ids ) ) { |
| 2595 | 2400 | $topic_ids = bbp_forum_query_topic_ids( $forum_id ); |
| 2596 | 2401 | } |
| 2597 | 2402 | |
| 2598 | - $query = new WP_Query( | |
| 2599 | - array( | |
| 2600 | - 'fields' => 'ids', | |
| 2601 | - 'suppress_filters' => true, | |
| 2602 | - 'post_parent__in' => $topic_ids, | |
| 2603 | - 'post_status' => bbp_get_public_status_id(), | |
| 2604 | - 'post_type' => bbp_get_reply_post_type(), | |
| 2605 | - 'posts_per_page' => 1, | |
| 2606 | - 'orderby' => array( | |
| 2607 | - 'post_date' => 'DESC', | |
| 2608 | - 'ID' => 'DESC' | |
| 2609 | - ), | |
| 2403 | + $query = new WP_Query( array( | |
| 2404 | + 'fields' => 'ids', | |
| 2405 | + 'suppress_filters' => true, | |
| 2406 | + 'post_parent__in' => $topic_ids, | |
| 2407 | + 'post_status' => bbp_get_public_status_id(), | |
| 2408 | + 'post_type' => bbp_get_reply_post_type(), | |
| 2409 | + 'posts_per_page' => 1, | |
| 2410 | + 'orderby' => array( | |
| 2411 | + 'post_date' => 'DESC', | |
| 2412 | + 'ID' => 'DESC' | |
| 2413 | + ), | |
| 2610 | 2414 | |
| 2611 | - // Performance | |
| 2612 | - 'update_post_term_cache' => false, | |
| 2613 | - 'update_post_meta_cache' => false, | |
| 2614 | - 'ignore_sticky_posts' => true, | |
| 2615 | - 'no_found_rows' => true | |
| 2616 | - ) | |
| 2617 | - ); | |
| 2415 | + // Performance | |
| 2416 | + 'update_post_term_cache' => false, | |
| 2417 | + 'update_post_meta_cache' => false, | |
| 2418 | + 'ignore_sticky_posts' => true, | |
| 2419 | + 'no_found_rows' => true | |
| 2420 | + ) ); | |
| 2618 | 2421 | |
| 2619 | 2422 | $reply_id = array_shift( $query->posts ); |
| 2620 | 2423 | |
| 2621 | 2424 | unset( $query ); |
| @@ -2627,9 +2430,9 @@ | ||
| 2627 | 2430 | /** Listeners *****************************************************************/ |
| 2628 | 2431 | |
| 2629 | 2432 | /** |
| 2630 | 2433 | * Check if it's a hidden forum or a topic or reply of a hidden forum and if |
| 2631 | - * the user can't view it, then sets a 404. | |
| 2434 | + * the user can't view it, then sets a 404 | |
| 2632 | 2435 | * |
| 2633 | 2436 | * @since 2.0.0 bbPress (r2996) |
| 2634 | 2437 | */ |
| 2635 | 2438 | function bbp_forum_enforce_hidden() { |
| @@ -2641,11 +2444,8 @@ | ||
| 2641 | 2444 | |
| 2642 | 2445 | // Define local variables |
| 2643 | 2446 | $forum_id = 0; |
| 2644 | 2447 | $wp_query = bbp_get_wp_query(); |
| 2645 | - $post_id = ! empty( $wp_query->post->ID ) | |
| 2646 | - ? $wp_query->post->ID | |
| 2647 | - : 0; | |
| 2648 | 2448 | |
| 2649 | 2449 | // Check post type |
| 2650 | 2450 | switch ( $wp_query->get( 'post_type' ) ) { |
| 2651 | 2451 | |
| @@ -2650,26 +2450,24 @@ | ||
| 2650 | 2450 | switch ( $wp_query->get( 'post_type' ) ) { |
| 2651 | 2451 | |
| 2652 | 2452 | // Forum |
| 2653 | 2453 | case bbp_get_forum_post_type() : |
| 2654 | - $forum_id = bbp_get_forum_id( $post_id ); | |
| 2454 | + $forum_id = bbp_get_forum_id( $wp_query->post->ID ); | |
| 2655 | 2455 | break; |
| 2656 | 2456 | |
| 2657 | 2457 | // Topic |
| 2658 | 2458 | case bbp_get_topic_post_type() : |
| 2659 | - $forum_id = bbp_get_topic_forum_id( $post_id ); | |
| 2459 | + $forum_id = bbp_get_topic_forum_id( $wp_query->post->ID ); | |
| 2660 | 2460 | break; |
| 2661 | 2461 | |
| 2662 | 2462 | // Reply |
| 2663 | 2463 | case bbp_get_reply_post_type() : |
| 2664 | - $forum_id = bbp_get_reply_forum_id( $post_id ); | |
| 2464 | + $forum_id = bbp_get_reply_forum_id( $wp_query->post->ID ); | |
| 2665 | 2465 | break; |
| 2666 | 2466 | } |
| 2667 | 2467 | |
| 2668 | - // If forum is explicitly hidden and user not capable... | |
| 2468 | + // If forum is explicitly hidden and user not capable, set 404 | |
| 2669 | 2469 | if ( ! empty( $forum_id ) && bbp_is_forum_hidden( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { |
| 2670 | - | |
| 2671 | - // Set 404 status | |
| 2672 | 2470 | bbp_set_404( $wp_query ); |
| 2673 | 2471 | } |
| 2674 | 2472 | } |
| 2675 | 2473 | |
| @@ -2674,9 +2472,9 @@ | ||
| 2674 | 2472 | } |
| 2675 | 2473 | |
| 2676 | 2474 | /** |
| 2677 | 2475 | * Check if it's a private forum or a topic or reply of a private forum and if |
| 2678 | - * the user can't view it, then sets a 404. | |
| 2476 | + * the user can't view it, then sets a 404 | |
| 2679 | 2477 | * |
| 2680 | 2478 | * @since 2.0.0 bbPress (r2996) |
| 2681 | 2479 | */ |
| 2682 | 2480 | function bbp_forum_enforce_private() { |
| @@ -2688,11 +2486,8 @@ | ||
| 2688 | 2486 | |
| 2689 | 2487 | // Define local variables |
| 2690 | 2488 | $forum_id = 0; |
| 2691 | 2489 | $wp_query = bbp_get_wp_query(); |
| 2692 | - $post_id = ! empty( $wp_query->post->ID ) | |
| 2693 | - ? $wp_query->post->ID | |
| 2694 | - : 0; | |
| 2695 | 2490 | |
| 2696 | 2491 | // Check post type |
| 2697 | 2492 | switch ( $wp_query->get( 'post_type' ) ) { |
| 2698 | 2493 | |
| @@ -2697,26 +2492,25 @@ | ||
| 2697 | 2492 | switch ( $wp_query->get( 'post_type' ) ) { |
| 2698 | 2493 | |
| 2699 | 2494 | // Forum |
| 2700 | 2495 | case bbp_get_forum_post_type() : |
| 2701 | - $forum_id = bbp_get_forum_id( $post_id ); | |
| 2496 | + $forum_id = bbp_get_forum_id( $wp_query->post->ID ); | |
| 2702 | 2497 | break; |
| 2703 | 2498 | |
| 2704 | 2499 | // Topic |
| 2705 | 2500 | case bbp_get_topic_post_type() : |
| 2706 | - $forum_id = bbp_get_topic_forum_id( $post_id ); | |
| 2501 | + $forum_id = bbp_get_topic_forum_id( $wp_query->post->ID ); | |
| 2707 | 2502 | break; |
| 2708 | 2503 | |
| 2709 | 2504 | // Reply |
| 2710 | 2505 | case bbp_get_reply_post_type() : |
| 2711 | - $forum_id = bbp_get_reply_forum_id( $post_id ); | |
| 2506 | + $forum_id = bbp_get_reply_forum_id( $wp_query->post->ID ); | |
| 2712 | 2507 | break; |
| 2508 | + | |
| 2713 | 2509 | } |
| 2714 | 2510 | |
| 2715 | - // If forum is explicitly private and user not capable | |
| 2511 | + // If forum is explicitly hidden and user not capable, set 404 | |
| 2716 | 2512 | if ( ! empty( $forum_id ) && bbp_is_forum_private( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { |
| 2717 | - | |
| 2718 | - // Set 404 status | |
| 2719 | 2513 | bbp_set_404( $wp_query ); |
| 2720 | 2514 | } |
| 2721 | 2515 | } |
| 2722 | 2516 | |
| @@ -2722,9 +2516,9 @@ | ||
| 2722 | 2516 | |
| 2723 | 2517 | /** Permissions ***************************************************************/ |
| 2724 | 2518 | |
| 2725 | 2519 | /** |
| 2726 | - * Redirect if unauthorized user is attempting to edit a forum. | |
| 2520 | + * Redirect if unauthorized user is attempting to edit a forum | |
| 2727 | 2521 | * |
| 2728 | 2522 | * @since 2.1.0 bbPress (r3607) |
| 2729 | 2523 | */ |
| 2730 | 2524 | function bbp_check_forum_edit() { |
| @@ -2740,13 +2534,14 @@ | ||
| 2740 | 2534 | } |
| 2741 | 2535 | } |
| 2742 | 2536 | |
| 2743 | 2537 | /** |
| 2744 | - * Delete all topics (and their replies) for a specific forum ID. | |
| 2538 | + * Delete all topics (and their replies) for a specific forum ID | |
| 2745 | 2539 | * |
| 2746 | 2540 | * @since 2.1.0 bbPress (r3668) |
| 2747 | 2541 | * |
| 2748 | 2542 | * @param int $forum_id |
| 2543 | + * @return If forum is not valid | |
| 2749 | 2544 | */ |
| 2750 | 2545 | function bbp_delete_forum_topics( $forum_id = 0 ) { |
| 2751 | 2546 | |
| 2752 | 2547 | // Validate forum ID |
| @@ -2756,25 +2551,23 @@ | ||
| 2756 | 2551 | } |
| 2757 | 2552 | |
| 2758 | 2553 | // Forum is being permanently deleted, so its content has go too |
| 2759 | 2554 | // Note that we get all post statuses here |
| 2760 | - $topics = new WP_Query( | |
| 2761 | - array( | |
| 2762 | - 'fields' => 'id=>parent', | |
| 2763 | - 'post_type' => bbp_get_topic_post_type(), | |
| 2764 | - 'post_parent' => $forum_id, | |
| 2765 | - 'post_status' => array_keys( get_post_stati() ), | |
| 2766 | - 'posts_per_page' => -1, | |
| 2555 | + $topics = new WP_Query( array( | |
| 2556 | + 'fields' => 'id=>parent', | |
| 2557 | + 'post_type' => bbp_get_topic_post_type(), | |
| 2558 | + 'post_parent' => $forum_id, | |
| 2559 | + 'post_status' => array_keys( get_post_stati() ), | |
| 2560 | + 'posts_per_page' => -1, | |
| 2767 | 2561 | |
| 2768 | - // Performance | |
| 2769 | - 'nopaging' => true, | |
| 2770 | - 'suppress_filters' => true, | |
| 2771 | - 'update_post_term_cache' => false, | |
| 2772 | - 'update_post_meta_cache' => false, | |
| 2773 | - 'ignore_sticky_posts' => true, | |
| 2774 | - 'no_found_rows' => true | |
| 2775 | - ) | |
| 2776 | - ); | |
| 2562 | + // Performance | |
| 2563 | + 'nopaging' => true, | |
| 2564 | + 'suppress_filters' => true, | |
| 2565 | + 'update_post_term_cache' => false, | |
| 2566 | + 'update_post_meta_cache' => false, | |
| 2567 | + 'ignore_sticky_posts' => true, | |
| 2568 | + 'no_found_rows' => true | |
| 2569 | + ) ); | |
| 2777 | 2570 | |
| 2778 | 2571 | // Loop through and delete child topics. Topic replies will get deleted by |
| 2779 | 2572 | // the bbp_delete_topic() action. |
| 2780 | 2573 | if ( ! empty( $topics->posts ) ) { |
| @@ -2790,13 +2583,14 @@ | ||
| 2790 | 2583 | unset( $topics ); |
| 2791 | 2584 | } |
| 2792 | 2585 | |
| 2793 | 2586 | /** |
| 2794 | - * Trash all topics inside a forum. | |
| 2587 | + * Trash all topics inside a forum | |
| 2795 | 2588 | * |
| 2796 | 2589 | * @since 2.1.0 bbPress (r3668) |
| 2797 | 2590 | * |
| 2798 | 2591 | * @param int $forum_id |
| 2592 | + * @return If forum is not valid | |
| 2799 | 2593 | */ |
| 2800 | 2594 | function bbp_trash_forum_topics( $forum_id = 0 ) { |
| 2801 | 2595 | |
| 2802 | 2596 | // Validate forum ID |
| @@ -2812,25 +2606,23 @@ | ||
| 2812 | 2606 | bbp_get_pending_status_id() |
| 2813 | 2607 | ); |
| 2814 | 2608 | |
| 2815 | 2609 | // Forum is being trashed, so its topics (and replies) are trashed too |
| 2816 | - $topics = new WP_Query( | |
| 2817 | - array( | |
| 2818 | - 'fields' => 'id=>parent', | |
| 2819 | - 'post_type' => bbp_get_topic_post_type(), | |
| 2820 | - 'post_parent' => $forum_id, | |
| 2821 | - 'post_status' => $post_stati, | |
| 2822 | - 'posts_per_page' => -1, | |
| 2610 | + $topics = new WP_Query( array( | |
| 2611 | + 'fields' => 'id=>parent', | |
| 2612 | + 'post_type' => bbp_get_topic_post_type(), | |
| 2613 | + 'post_parent' => $forum_id, | |
| 2614 | + 'post_status' => $post_stati, | |
| 2615 | + 'posts_per_page' => -1, | |
| 2823 | 2616 | |
| 2824 | - // Performance | |
| 2825 | - 'nopaging' => true, | |
| 2826 | - 'suppress_filters' => true, | |
| 2827 | - 'update_post_term_cache' => false, | |
| 2828 | - 'update_post_meta_cache' => false, | |
| 2829 | - 'ignore_sticky_posts' => true, | |
| 2830 | - 'no_found_rows' => true | |
| 2831 | - ) | |
| 2832 | - ); | |
| 2617 | + // Performance | |
| 2618 | + 'nopaging' => true, | |
| 2619 | + 'suppress_filters' => true, | |
| 2620 | + 'update_post_term_cache' => false, | |
| 2621 | + 'update_post_meta_cache' => false, | |
| 2622 | + 'ignore_sticky_posts' => true, | |
| 2623 | + 'no_found_rows' => true | |
| 2624 | + ) ); | |
| 2833 | 2625 | |
| 2834 | 2626 | // Loop through and trash child topics. Topic replies will get trashed by |
| 2835 | 2627 | // the bbp_trash_topic() action. |
| 2836 | 2628 | if ( ! empty( $topics->posts ) ) { |
| @@ -2857,13 +2649,14 @@ | ||
| 2857 | 2649 | unset( $topics ); |
| 2858 | 2650 | } |
| 2859 | 2651 | |
| 2860 | 2652 | /** |
| 2861 | - * Untrash all topics inside a forum. | |
| 2653 | + * Untrash all topics inside a forum | |
| 2862 | 2654 | * |
| 2863 | 2655 | * @since 2.1.0 bbPress (r3668) |
| 2864 | 2656 | * |
| 2865 | 2657 | * @param int $forum_id |
| 2658 | + * @return If forum is not valid | |
| 2866 | 2659 | */ |
| 2867 | 2660 | function bbp_untrash_forum_topics( $forum_id = 0 ) { |
| 2868 | 2661 | |
| 2869 | 2662 | // Validate forum ID |
| @@ -2912,9 +2705,9 @@ | ||
| 2912 | 2705 | do_action( 'bbp_delete_forum', $forum_id ); |
| 2913 | 2706 | } |
| 2914 | 2707 | |
| 2915 | 2708 | /** |
| 2916 | - * Called before trashing a forum. | |
| 2709 | + * Called before trashing a forum | |
| 2917 | 2710 | * |
| 2918 | 2711 | * This function is supplemental to the actual forum being trashed which is |
| 2919 | 2712 | * handled by WordPress core API functions. It is used to clean up after |
| 2920 | 2713 | * a forum that is being trashed. |
| @@ -2931,9 +2724,9 @@ | ||
| 2931 | 2724 | do_action( 'bbp_trash_forum', $forum_id ); |
| 2932 | 2725 | } |
| 2933 | 2726 | |
| 2934 | 2727 | /** |
| 2935 | - * Called before untrashing a forum. | |
| 2728 | + * Called before untrashing a forum | |
| 2936 | 2729 | * |
| 2937 | 2730 | * @since 2.1.0 bbPress (r3668) |
| 2938 | 2731 | */ |
| 2939 | 2732 | function bbp_untrash_forum( $forum_id = 0 ) { |
| @@ -2948,9 +2741,9 @@ | ||
| 2948 | 2741 | |
| 2949 | 2742 | /** After Delete/Trash/Untrash ************************************************/ |
| 2950 | 2743 | |
| 2951 | 2744 | /** |
| 2952 | - * Called after deleting a forum. | |
| 2745 | + * Called after deleting a forum | |
| 2953 | 2746 | * |
| 2954 | 2747 | * Try not to use this action. All meta & taxonomy terms have already been |
| 2955 | 2748 | * deleted, making them impossible to use. |
| 2956 | 2749 | * |
| @@ -2967,9 +2760,9 @@ | ||
| 2967 | 2760 | do_action( 'bbp_deleted_forum', $forum_id ); |
| 2968 | 2761 | } |
| 2969 | 2762 | |
| 2970 | 2763 | /** |
| 2971 | - * Called after trashing a forum. | |
| 2764 | + * Called after trashing a forum | |
| 2972 | 2765 | * |
| 2973 | 2766 | * @since 2.1.0 bbPress (r3668) |
| 2974 | 2767 | */ |
| 2975 | 2768 | function bbp_trashed_forum( $forum_id = 0 ) { |
| @@ -2982,9 +2775,9 @@ | ||
| 2982 | 2775 | do_action( 'bbp_trashed_forum', $forum_id ); |
| 2983 | 2776 | } |
| 2984 | 2777 | |
| 2985 | 2778 | /** |
| 2986 | - * Called after untrashing a forum. | |
| 2779 | + * Called after untrashing a forum | |
| 2987 | 2780 | * |
| 2988 | 2781 | * @since 2.1.0 bbPress (r3668) |
| 2989 | 2782 | */ |
| 2990 | 2783 | function bbp_untrashed_forum( $forum_id = 0 ) { |