| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * bbPress Common Functions. | |
| 4 | + * bbPress Common Functions | |
| 5 | 5 | * |
| 6 | 6 | * Common functions are ones that are used by more than one component, like |
| 7 | 7 | * forums, topics, replies, users, topic tags, etc... |
| 8 | 8 | * |
| @@ -13,13 +13,13 @@ | ||
| 13 | 13 | // Exit if accessed directly |
| 14 | 14 | defined( 'ABSPATH' ) || exit; |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * Return array of bbPress registered post type names. | |
| 17 | + * Return array of bbPress registered post types | |
| 18 | 18 | * |
| 19 | 19 | * @since 2.6.0 bbPress (r6813) |
| 20 | 20 | * |
| 21 | - * @param array $args Array of arguments to pass into `get_post_types()`. | |
| 21 | + * @param array $args Array of arguments to pass into `get_post_types()` | |
| 22 | 22 | * |
| 23 | 23 | * @return array |
| 24 | 24 | */ |
| 25 | 25 | function bbp_get_post_types( $args = array() ) { |
| @@ -24,15 +24,11 @@ | ||
| 24 | 24 | */ |
| 25 | 25 | function bbp_get_post_types( $args = array() ) { |
| 26 | 26 | |
| 27 | 27 | // Parse args |
| 28 | - $r = bbp_parse_args( | |
| 29 | - $args, | |
| 30 | - array( | |
| 31 | - 'source' => 'bbpress' | |
| 32 | - ), | |
| 33 | - 'get_post_types' | |
| 34 | - ); | |
| 28 | + $r = bbp_parse_args( $args, array( | |
| 29 | + 'source' => 'bbpress' | |
| 30 | + ), 'get_post_types' ); | |
| 35 | 31 | |
| 36 | 32 | // Return post types |
| 37 | 33 | return get_post_types( $r ); |
| 38 | 34 | } |
| @@ -39,13 +35,13 @@ | ||
| 39 | 35 | |
| 40 | 36 | /** URLs **********************************************************************/ |
| 41 | 37 | |
| 42 | 38 | /** |
| 43 | - * Return the unescaped redirect_to request value. | |
| 39 | + * Return the unescaped redirect_to request value | |
| 44 | 40 | * |
| 45 | - * @since bbPress (r4655) | |
| 41 | + * @bbPress (r4655) | |
| 46 | 42 | * |
| 47 | - * @return string The URL to redirect to, if set. | |
| 43 | + * @return string The URL to redirect to, if set | |
| 48 | 44 | */ |
| 49 | 45 | function bbp_get_redirect_to() { |
| 50 | 46 | |
| 51 | 47 | // Check 'redirect_to' request parameter |
| @@ -61,11 +57,11 @@ | ||
| 61 | 57 | * Append 'view=all' to query string if it's already there from referer |
| 62 | 58 | * |
| 63 | 59 | * @since 2.0.0 bbPress (r3325) |
| 64 | 60 | * |
| 65 | - * @param string $original_link Original Link to be modified. | |
| 66 | - * @param bool $force Override bbp_get_view_all() check. | |
| 67 | - * @return string The link with 'view=all' appended if necessary. | |
| 61 | + * @param string $original_link Original Link to be modified | |
| 62 | + * @param bool $force Override bbp_get_view_all() check | |
| 63 | + * @return string The link with 'view=all' appended if necessary | |
| 68 | 64 | */ |
| 69 | 65 | function bbp_add_view_all( $original_link = '', $force = false ) { |
| 70 | 66 | |
| 71 | 67 | // Are we appending the view=all vars? |
| @@ -77,14 +73,14 @@ | ||
| 77 | 73 | return apply_filters( 'bbp_add_view_all', $link, $original_link ); |
| 78 | 74 | } |
| 79 | 75 | |
| 80 | 76 | /** |
| 81 | - * Remove 'view=all' from query string. | |
| 77 | + * Remove 'view=all' from query string | |
| 82 | 78 | * |
| 83 | 79 | * @since 2.0.0 bbPress (r3325) |
| 84 | 80 | * |
| 85 | - * @param string $original_link Original Link to be modified. | |
| 86 | - * @return string The link with 'view=all' appended if necessary. | |
| 81 | + * @param string $original_link Original Link to be modified | |
| 82 | + * @return string The link with 'view=all' appended if necessary | |
| 87 | 83 | */ |
| 88 | 84 | function bbp_remove_view_all( $original_link = '' ) { |
| 89 | 85 | |
| 90 | 86 | // Remove `view' argument |
| @@ -94,14 +90,15 @@ | ||
| 94 | 90 | return apply_filters( 'bbp_remove_view_all', $link, $original_link ); |
| 95 | 91 | } |
| 96 | 92 | |
| 97 | 93 | /** |
| 98 | - * If current user can and is viewing all topics/replies. | |
| 94 | + * If current user can and is viewing all topics/replies | |
| 99 | 95 | * |
| 100 | 96 | * @since 2.0.0 bbPress (r3325) |
| 101 | 97 | * |
| 102 | - * @param string $cap Capability used to ensure user can view all. | |
| 103 | - * @return bool Whether current user can and is viewing all. | |
| 98 | + * @param string $cap Capability used to ensure user can view all | |
| 99 | + * | |
| 100 | + * @return bool Whether current user can and is viewing all | |
| 104 | 101 | */ |
| 105 | 102 | function bbp_get_view_all( $cap = 'moderate' ) { |
| 106 | 103 | $retval = ( ( ! empty( $_GET['view'] ) && ( 'all' === $_GET['view'] ) && current_user_can( $cap ) ) ); |
| 107 | 104 | |
| @@ -109,13 +106,13 @@ | ||
| 109 | 106 | return (bool) apply_filters( 'bbp_get_view_all', (bool) $retval, $cap ); |
| 110 | 107 | } |
| 111 | 108 | |
| 112 | 109 | /** |
| 113 | - * Assist pagination by returning correct page number. | |
| 110 | + * Assist pagination by returning correct page number | |
| 114 | 111 | * |
| 115 | 112 | * @since 2.0.0 bbPress (r2628) |
| 116 | 113 | * |
| 117 | - * @return int Current page number. | |
| 114 | + * @return int Current page number | |
| 118 | 115 | */ |
| 119 | 116 | function bbp_get_paged() { |
| 120 | 117 | $wp_query = bbp_get_wp_query(); |
| 121 | 118 | |
| @@ -139,55 +136,22 @@ | ||
| 139 | 136 | |
| 140 | 137 | /** Misc **********************************************************************/ |
| 141 | 138 | |
| 142 | 139 | /** |
| 143 | - * Filters whether or not to use the block editor for bbPress post types. | |
| 144 | - * | |
| 145 | - * As of 2.7.0 this is explicitly false, because the `show_in_rest` property | |
| 146 | - * of each post type is now set to true, and because support for blocks in | |
| 147 | - * user-facing forum content is not properly handled yet. | |
| 148 | - * | |
| 149 | - * The default return value of this function is highly likely to change once | |
| 150 | - * the block editor is integrated into the Forum/Topic/Reply experience. | |
| 151 | - * | |
| 152 | - * If you're feeling adventurous or working on this feature, override this | |
| 153 | - * filter with | |
| 154 | - * | |
| 155 | - * @since 2.7.0 bbPress (r7388) | |
| 156 | - * | |
| 157 | - * @param bool $using Optional. Default false. If using. | |
| 158 | - * @param string $post_type Optional. Default empty string. The post type to check. | |
| 159 | - * | |
| 160 | - * @return bool | |
| 161 | - */ | |
| 162 | -function bbp_filter_use_block_editor_for_post_type( $using = false, $post_type = '' ) { | |
| 163 | - | |
| 164 | - // Get bbPress post types | |
| 165 | - $bbp_post_types = bbp_get_post_types(); | |
| 166 | - | |
| 167 | - // Compare post types | |
| 168 | - $is_post_type = in_array( $post_type, $bbp_post_types, true ); | |
| 169 | - $retval = ! $is_post_type; | |
| 170 | - | |
| 171 | - // Filter & return | |
| 172 | - return (bool) apply_filters( 'bbp_filter_use_block_editor_for_post_type', $retval, $is_post_type, $using, $post_type ); | |
| 173 | -} | |
| 174 | - | |
| 175 | -/** | |
| 176 | 140 | * Return the unique non-empty values of an array. |
| 177 | 141 | * |
| 178 | 142 | * @since 2.6.0 bbPress (r6481) |
| 179 | 143 | * |
| 180 | - * @param array $arr Array to get values of. | |
| 144 | + * @param array $array Array to get values of | |
| 181 | 145 | * |
| 182 | 146 | * @return array |
| 183 | 147 | */ |
| 184 | -function bbp_get_unique_array_values( $arr = array() ) { | |
| 185 | - return array_unique( array_filter( array_values( $arr ) ) ); | |
| 148 | +function bbp_get_unique_array_values( $array = array() ) { | |
| 149 | + return array_unique( array_filter( array_values( $array ) ) ); | |
| 186 | 150 | } |
| 187 | 151 | |
| 188 | 152 | /** |
| 189 | - * Fix post author id on post save. | |
| 153 | + * Fix post author id on post save | |
| 190 | 154 | * |
| 191 | 155 | * When a logged in user changes the status of an anonymous reply or topic, or |
| 192 | 156 | * edits it, the post_author field is set to the logged in user's id. This |
| 193 | 157 | * function fixes that. |
| @@ -193,11 +157,11 @@ | ||
| 193 | 157 | * function fixes that. |
| 194 | 158 | * |
| 195 | 159 | * @since 2.0.0 bbPress (r2734) |
| 196 | 160 | * |
| 197 | - * @param array $data Post data. | |
| 198 | - * @param array $postarr Original post array (includes post id). | |
| 199 | - * @return array Data. | |
| 161 | + * @param array $data Post data | |
| 162 | + * @param array $postarr Original post array (includes post id) | |
| 163 | + * @return array Data | |
| 200 | 164 | */ |
| 201 | 165 | function bbp_fix_post_author( $data = array(), $postarr = array() ) { |
| 202 | 166 | |
| 203 | 167 | // Post is not being updated or the post_author is already 0, return |
| @@ -210,13 +174,10 @@ | ||
| 210 | 174 | return $data; |
| 211 | 175 | } |
| 212 | 176 | |
| 213 | 177 | // Is the post by an anonymous user? |
| 214 | - if ( | |
| 215 | - ( bbp_get_topic_post_type() === $data['post_type'] && ! bbp_is_topic_anonymous( $postarr['ID'] ) ) | |
| 216 | - || | |
| 217 | - ( bbp_get_reply_post_type() === $data['post_type'] && ! bbp_is_reply_anonymous( $postarr['ID'] ) ) | |
| 218 | - ) { | |
| 178 | + if ( ( bbp_get_topic_post_type() === $data['post_type'] && ! bbp_is_topic_anonymous( $postarr['ID'] ) ) || | |
| 179 | + ( bbp_get_reply_post_type() === $data['post_type'] && ! bbp_is_reply_anonymous( $postarr['ID'] ) ) ) { | |
| 219 | 180 | return $data; |
| 220 | 181 | } |
| 221 | 182 | |
| 222 | 183 | // The post is being updated. It is a topic or a reply and is written by an anonymous user. |
| @@ -226,35 +187,8 @@ | ||
| 226 | 187 | return $data; |
| 227 | 188 | } |
| 228 | 189 | |
| 229 | 190 | /** |
| 230 | - * Use the previous status when restoring a topic or reply. | |
| 231 | - * | |
| 232 | - * Fixes an issue since WordPress 5.6.0. See | |
| 233 | - * {@link https://bbpress.trac.wordpress.org/ticket/3433}. | |
| 234 | - * | |
| 235 | - * @since 2.6.10 bbPress (r7233) | |
| 236 | - * | |
| 237 | - * @param string $new_status New status to use when untrashing. Default: 'draft'. | |
| 238 | - * @param int $post_id Post ID. | |
| 239 | - * @param string $previous_status Previous post status from '_wp_trash_meta_status' meta key. Default: 'pending'. | |
| 240 | - */ | |
| 241 | -function bbp_fix_untrash_post_status( $new_status = 'draft', $post_id = 0, $previous_status = 'pending' ) { | |
| 242 | - | |
| 243 | - // Bail if not Topic or Reply | |
| 244 | - if ( ! bbp_is_topic( $post_id ) && ! bbp_is_reply( $post_id ) ) { | |
| 245 | - return $new_status; | |
| 246 | - } | |
| 247 | - | |
| 248 | - // Prefer the previous status, falling back to the new status | |
| 249 | - $retval = ! empty( $previous_status ) | |
| 250 | - ? $previous_status | |
| 251 | - : $new_status; | |
| 252 | - | |
| 253 | - return $retval; | |
| 254 | -} | |
| 255 | - | |
| 256 | -/** | |
| 257 | 191 | * Check a date against the length of time something can be edited. |
| 258 | 192 | * |
| 259 | 193 | * It is recommended to leave $utc set to true and to work with UTC/GMT dates. |
| 260 | 194 | * Turning this off will use the WordPress offset which is likely undesirable. |
| @@ -261,9 +195,9 @@ | ||
| 261 | 195 | * |
| 262 | 196 | * @since 2.0.0 bbPress (r3133) |
| 263 | 197 | * @since 2.6.0 bbPress (r6868) Inverted some logic and added unit tests |
| 264 | 198 | * |
| 265 | - * @param string $datetime Gets run through strtotime(). | |
| 199 | + * @param string $datetime Gets run through strtotime() | |
| 266 | 200 | * @param boolean $utc Default true. Is the timestamp in UTC? |
| 267 | 201 | * |
| 268 | 202 | * @return bool True by default, if date is past, or editing is disabled. |
| 269 | 203 | */ |
| @@ -287,15 +221,13 @@ | ||
| 287 | 221 | |
| 288 | 222 | // Period of time |
| 289 | 223 | $lockable = "+{$minutes} minutes"; |
| 290 | 224 | if ( true === $utc ) { |
| 291 | - $lockable .= ' UTC'; | |
| 225 | + $lockable .= " UTC"; | |
| 292 | 226 | } |
| 293 | 227 | |
| 294 | 228 | // Now |
| 295 | - $cur_time = empty( $utc ) | |
| 296 | - ? (int) wp_date( 'U' ) | |
| 297 | - : time(); | |
| 229 | + $cur_time = current_time( 'timestamp', $utc ); | |
| 298 | 230 | |
| 299 | 231 | // Get the duration in seconds |
| 300 | 232 | $duration = strtotime( $lockable ) - $cur_time; |
| 301 | 233 | |
| @@ -321,10 +253,10 @@ | ||
| 321 | 253 | * immediately. |
| 322 | 254 | * |
| 323 | 255 | * @since 2.6.0 bbPress (r6424) |
| 324 | 256 | * |
| 325 | - * @param string $context Provide context for additional filtering. | |
| 326 | - * @return int Number of days items remain in trash. | |
| 257 | + * @param string $context Provide context for additional filtering | |
| 258 | + * @return int Number of days items remain in trash | |
| 327 | 259 | */ |
| 328 | 260 | function bbp_get_trash_days( $context = 'forum' ) { |
| 329 | 261 | |
| 330 | 262 | // Sanitize the context |
| @@ -341,110 +273,79 @@ | ||
| 341 | 273 | |
| 342 | 274 | /** Statistics ****************************************************************/ |
| 343 | 275 | |
| 344 | 276 | /** |
| 345 | - * Get the forum statistics. | |
| 277 | + * Get the forum statistics | |
| 346 | 278 | * |
| 347 | 279 | * @since 2.0.0 bbPress (r2769) |
| 348 | - * @since 2.6.0 bbPress (r6055) Added: | |
| 349 | - * `count_pending_topics` | |
| 350 | - * `count_pending_replies` | |
| 351 | - * @since 2.6.10 bbPress (r7235) Renamed: | |
| 352 | - * `count_trashed_topics` to `count_trash_topics` | |
| 353 | - * `count_trashed_replies` to `count_trash_replies` | |
| 354 | - * `count_spammed_topics` to `count_spam_topics` | |
| 355 | - * `count_spammed_replies` to `count_spam_replies` | |
| 356 | - * Added: | |
| 357 | - * `count_hidden_topics` | |
| 358 | - * `count_hidden_replies` | |
| 280 | + * @since 2.6.0 bbPress (r6055) Introduced the `count_pending_topics` and | |
| 281 | + * `count_pending_replies` arguments. | |
| 359 | 282 | * |
| 360 | 283 | * @param array $args Optional. The function supports these arguments (all |
| 361 | - * default to true): | |
| 362 | - * | |
| 363 | - * - count_users: Count users? | |
| 364 | - * - count_forums: Count forums? | |
| 365 | - * - count_topics: Count topics? If set to false, private, spam and | |
| 366 | - * trash topics are also not counted. | |
| 367 | - * - count_pending_topics: Count pending topics? (only counted if the current | |
| 284 | + * default to true): | |
| 285 | + * - count_users: Count users? | |
| 286 | + * - count_forums: Count forums? | |
| 287 | + * - count_topics: Count topics? If set to false, private, spammed and trashed | |
| 288 | + * topics are also not counted. | |
| 289 | + * - count_pending_topics: Count pending topics? (only counted if the current | |
| 368 | 290 | * user has edit_others_topics cap) |
| 369 | - * - count_private_topics: Count private topics? (only counted if the current | |
| 291 | + * - count_private_topics: Count private topics? (only counted if the current | |
| 370 | 292 | * user has read_private_topics cap) |
| 371 | - * - count_hidden_topics: Count hidden topics? (only counted if the current | |
| 372 | - * user has read_hidden_topics cap) | |
| 373 | - * - count_spam_topics: Count spam topics? (only counted if the current | |
| 293 | + * - count_spammed_topics: Count spammed topics? (only counted if the current | |
| 374 | 294 | * user has edit_others_topics cap) |
| 375 | - * - count_trash_topics: Count trash topics? (only counted if the current | |
| 295 | + * - count_trashed_topics: Count trashed topics? (only counted if the current | |
| 376 | 296 | * user has view_trash cap) |
| 377 | - * - count_replies: Count replies? If set to false, private, spam and | |
| 378 | - * trash replies are also not counted. | |
| 297 | + * - count_replies: Count replies? If set to false, private, spammed and | |
| 298 | + * trashed replies are also not counted. | |
| 379 | 299 | * - count_pending_replies: Count pending replies? (only counted if the current |
| 380 | 300 | * user has edit_others_replies cap) |
| 381 | 301 | * - count_private_replies: Count private replies? (only counted if the current |
| 382 | 302 | * user has read_private_replies cap) |
| 383 | - * - count_hidden_replies: Count hidden replies? (only counted if the current | |
| 384 | - * user has read_hidden_replies cap) | |
| 385 | - * - count_spam_replies: Count spam replies? (only counted if the current | |
| 303 | + * - count_spammed_replies: Count spammed replies? (only counted if the current | |
| 386 | 304 | * user has edit_others_replies cap) |
| 387 | - * - count_trash_replies: Count trash replies? (only counted if the current | |
| 305 | + * - count_trashed_replies: Count trashed replies? (only counted if the current | |
| 388 | 306 | * user has view_trash cap) |
| 389 | - * - count_tags: Count tags? If set to false, empty tags are also | |
| 390 | - * not counted | |
| 391 | - * - count_empty_tags: Count empty tags? | |
| 392 | - * | |
| 393 | - * @return array Array of statistics | |
| 307 | + * - count_tags: Count tags? If set to false, empty tags are also not counted | |
| 308 | + * - count_empty_tags: Count empty tags? | |
| 309 | + * @return object Walked forum tree | |
| 394 | 310 | */ |
| 395 | 311 | function bbp_get_statistics( $args = array() ) { |
| 396 | 312 | |
| 397 | 313 | // Parse arguments against default values |
| 398 | - $r = bbp_parse_args( | |
| 399 | - $args, | |
| 400 | - array( | |
| 314 | + $r = bbp_parse_args( $args, array( | |
| 401 | 315 | |
| 402 | - // Users | |
| 403 | - 'count_users' => true, | |
| 316 | + // Users | |
| 317 | + 'count_users' => true, | |
| 404 | 318 | |
| 405 | - // Forums | |
| 406 | - 'count_forums' => true, | |
| 319 | + // Forums | |
| 320 | + 'count_forums' => true, | |
| 407 | 321 | |
| 408 | - // Topics | |
| 409 | - 'count_topics' => true, | |
| 410 | - 'count_pending_topics' => true, | |
| 411 | - 'count_private_topics' => true, | |
| 412 | - 'count_spam_topics' => true, | |
| 413 | - 'count_trash_topics' => true, | |
| 414 | - 'count_hidden_topics' => true, | |
| 322 | + // Topics | |
| 323 | + 'count_topics' => true, | |
| 324 | + 'count_pending_topics' => true, | |
| 325 | + 'count_private_topics' => true, | |
| 326 | + 'count_spammed_topics' => true, | |
| 327 | + 'count_trashed_topics' => true, | |
| 415 | 328 | |
| 416 | - // Replies | |
| 417 | - 'count_replies' => true, | |
| 418 | - 'count_pending_replies' => true, | |
| 419 | - 'count_private_replies' => true, | |
| 420 | - 'count_spam_replies' => true, | |
| 421 | - 'count_trash_replies' => true, | |
| 422 | - 'count_hidden_replies' => true, | |
| 329 | + // Replies | |
| 330 | + 'count_replies' => true, | |
| 331 | + 'count_pending_replies' => true, | |
| 332 | + 'count_private_replies' => true, | |
| 333 | + 'count_spammed_replies' => true, | |
| 334 | + 'count_trashed_replies' => true, | |
| 423 | 335 | |
| 424 | - // Topic tags | |
| 425 | - 'count_tags' => true, | |
| 426 | - 'count_empty_tags' => true | |
| 336 | + // Topic tags | |
| 337 | + 'count_tags' => true, | |
| 338 | + 'count_empty_tags' => true | |
| 427 | 339 | |
| 428 | - ), | |
| 429 | - 'get_statistics' | |
| 430 | - ); | |
| 340 | + ), 'get_statistics' ); | |
| 431 | 341 | |
| 432 | 342 | // Defaults |
| 433 | - $topic_count = $topic_count_hidden = 0; | |
| 434 | - $reply_count = $reply_count_hidden = 0; | |
| 435 | - $topic_tag_count = $empty_topic_tag_count = 0; | |
| 436 | - $hidden_topic_title = $hidden_reply_title = ''; | |
| 343 | + $topic_count = $topic_count_hidden = 0; | |
| 344 | + $reply_count = $reply_count_hidden = 0; | |
| 345 | + $topic_tag_count = $empty_topic_tag_count = 0; | |
| 346 | + $hidden_topic_title = $hidden_reply_title = ''; | |
| 437 | 347 | |
| 438 | - // Post statuses | |
| 439 | - $publish = bbp_get_public_status_id(); | |
| 440 | - $closed = bbp_get_closed_status_id(); | |
| 441 | - $pending = bbp_get_pending_status_id(); | |
| 442 | - $private = bbp_get_private_status_id(); | |
| 443 | - $hidden = bbp_get_hidden_status_id(); | |
| 444 | - $spam = bbp_get_spam_status_id(); | |
| 445 | - $trash = bbp_get_trash_status_id(); | |
| 446 | - | |
| 447 | 348 | // Users |
| 448 | 349 | $user_count = ! empty( $r['count_users'] ) |
| 449 | 350 | ? bbp_get_total_users() |
| 450 | 351 | : 0; |
| @@ -450,180 +351,168 @@ | ||
| 450 | 351 | : 0; |
| 451 | 352 | |
| 452 | 353 | // Forums |
| 453 | 354 | $forum_count = ! empty( $r['count_forums'] ) |
| 454 | - ? wp_count_posts( bbp_get_forum_post_type() )->{$publish} | |
| 355 | + ? wp_count_posts( bbp_get_forum_post_type() )->publish | |
| 455 | 356 | : 0; |
| 456 | 357 | |
| 457 | - // Default capabilities | |
| 458 | - $caps = array( | |
| 459 | - 'view_trash' => false, | |
| 460 | - 'read_private_topics' => false, | |
| 461 | - 'edit_others_topics' => false, | |
| 462 | - 'read_private_replies' => false, | |
| 463 | - 'edit_others_replies' => false, | |
| 464 | - 'edit_topic_tags' => false | |
| 465 | - ); | |
| 358 | + // Post statuses | |
| 359 | + $pending = bbp_get_pending_status_id(); | |
| 360 | + $private = bbp_get_private_status_id(); | |
| 361 | + $spam = bbp_get_spam_status_id(); | |
| 362 | + $trash = bbp_get_trash_status_id(); | |
| 363 | + $closed = bbp_get_closed_status_id(); | |
| 466 | 364 | |
| 467 | - // Get capabilities | |
| 468 | - foreach ( $caps as $key => $cap ) { | |
| 469 | - $caps[ $key ] = current_user_can( $cap ); | |
| 470 | - } | |
| 471 | - | |
| 472 | 365 | // Topics |
| 473 | 366 | if ( ! empty( $r['count_topics'] ) ) { |
| 474 | - | |
| 475 | - // Count all topics | |
| 476 | 367 | $all_topics = wp_count_posts( bbp_get_topic_post_type() ); |
| 477 | 368 | |
| 478 | 369 | // Published (publish + closed) |
| 479 | - $topic_count = $all_topics->{$publish} + $all_topics->{$closed}; | |
| 370 | + $topic_count = $all_topics->publish + $all_topics->{$closed}; | |
| 480 | 371 | |
| 481 | - // Declare empty arrays | |
| 482 | - $topics = $topic_titles = array_fill_keys( bbp_get_non_public_topic_statuses(), '' ); | |
| 372 | + if ( current_user_can( 'read_private_topics' ) || current_user_can( 'edit_others_topics' ) || current_user_can( 'view_trash' ) ) { | |
| 483 | 373 | |
| 484 | - // Pending | |
| 485 | - if ( ! empty( $r['count_pending_topics'] ) && ! empty( $caps['edit_others_topics'] ) ) { | |
| 486 | - $topics[ $pending ] = bbp_number_not_negative( $all_topics->{$pending} ); | |
| 487 | - /* translators: %s: Number of pending topics */ | |
| 488 | - $topic_titles[ $pending ] = sprintf( esc_html__( 'Pending: %s', 'bbpress' ), bbp_number_format_i18n( $topics[ $pending ] ) ); | |
| 489 | - } | |
| 374 | + // Declare empty arrays | |
| 375 | + $topics = $topic_titles = array(); | |
| 490 | 376 | |
| 491 | - // Private | |
| 492 | - if ( ! empty( $r['count_private_topics'] ) && ! empty( $caps['read_private_topics'] ) ) { | |
| 493 | - $topics[ $private ] = bbp_number_not_negative( $all_topics->{$private} ); | |
| 494 | - /* translators: %s: Number of private topics */ | |
| 495 | - $topic_titles[ $private ] = sprintf( esc_html__( 'Private: %s', 'bbpress' ), bbp_number_format_i18n( $topics[ $private ] ) ); | |
| 496 | - } | |
| 377 | + // Pending | |
| 378 | + $topics['pending'] = ( ! empty( $r['count_pending_topics'] ) && current_user_can( 'edit_others_topics' ) ) | |
| 379 | + ? (int) $all_topics->{$pending} | |
| 380 | + : 0; | |
| 497 | 381 | |
| 498 | - // Hidden | |
| 499 | - if ( ! empty( $r['count_hidden_topics'] ) && ! empty( $caps['read_hidden_topics'] ) ) { | |
| 500 | - $topics[ $hidden ] = bbp_number_not_negative( $all_topics->{$hidden} ); | |
| 501 | - /* translators: %s: Number of hidden topics */ | |
| 502 | - $topic_titles[ $hidden ] = sprintf( esc_html__( 'Hidden: %s', 'bbpress' ), bbp_number_format_i18n( $topics[ $hidden ] ) ); | |
| 503 | - } | |
| 382 | + // Private | |
| 383 | + $topics['private'] = ( ! empty( $r['count_private_topics'] ) && current_user_can( 'read_private_topics' ) ) | |
| 384 | + ? (int) $all_topics->{$private} | |
| 385 | + : 0; | |
| 504 | 386 | |
| 505 | - // Spam | |
| 506 | - if ( ! empty( $r['count_spam_topics'] ) && ! empty( $caps['edit_others_topics'] ) ) { | |
| 507 | - $topics[ $spam ] = bbp_number_not_negative( $all_topics->{$spam} ); | |
| 508 | - /* translators: %s: Number of spam topics */ | |
| 509 | - $topic_titles[ $spam ] = sprintf( esc_html__( 'Spammed: %s', 'bbpress' ), bbp_number_format_i18n( $topics[ $spam ] ) ); | |
| 510 | - } | |
| 387 | + // Spam | |
| 388 | + $topics['spammed'] = ( ! empty( $r['count_spammed_topics'] ) && current_user_can( 'edit_others_topics' ) ) | |
| 389 | + ? (int) $all_topics->{$spam} | |
| 390 | + : 0; | |
| 511 | 391 | |
| 512 | - // Trash | |
| 513 | - if ( ! empty( $r['count_trash_topics'] ) && ! empty( $caps['view_trash'] ) ) { | |
| 514 | - $topics[ $trash ] = bbp_number_not_negative( $all_topics->{$trash} ); | |
| 515 | - /* translators: %s: Number of trashed topics */ | |
| 516 | - $topic_titles[ $trash ] = sprintf( esc_html__( 'Trashed: %s', 'bbpress' ), bbp_number_format_i18n( $topics[ $trash ] ) ); | |
| 517 | - } | |
| 392 | + // Trash | |
| 393 | + $topics['trashed'] = ( ! empty( $r['count_trashed_topics'] ) && current_user_can( 'view_trash' ) ) | |
| 394 | + ? (int) $all_topics->{$trash} | |
| 395 | + : 0; | |
| 518 | 396 | |
| 519 | - // Total hidden (pending, private, hidden, spam, trash) | |
| 520 | - $topic_count_hidden = array_sum( array_filter( $topics ) ); | |
| 397 | + // Total hidden (pending + private + spam + trash) | |
| 398 | + $topic_count_hidden = $topics['pending'] + $topics['private'] + $topics['spammed'] + $topics['trashed']; | |
| 521 | 399 | |
| 522 | - // Compile the hidden topic title | |
| 523 | - $hidden_topic_title = implode( ' | ', array_filter( $topic_titles ) ); | |
| 400 | + // Generate the hidden topic count's title attribute | |
| 401 | + $topic_titles[] = ! empty( $topics['pending'] ) | |
| 402 | + ? sprintf( esc_html__( 'Pending: %s', 'bbpress' ), bbp_number_format_i18n( $topics['pending'] ) ) | |
| 403 | + : ''; | |
| 404 | + | |
| 405 | + $topic_titles[] = ! empty( $topics['private'] ) | |
| 406 | + ? ''//sprintf( esc_html__( 'Private: %s', 'bbpress' ), bbp_number_format_i18n( $topics['private'] ) ) | |
| 407 | + : ''; | |
| 408 | + | |
| 409 | + $topic_titles[] = ! empty( $topics['spammed'] ) | |
| 410 | + ? sprintf( esc_html__( 'Spammed: %s', 'bbpress' ), bbp_number_format_i18n( $topics['spammed'] ) ) | |
| 411 | + : ''; | |
| 412 | + | |
| 413 | + $topic_titles[] = ! empty( $topics['trashed'] ) | |
| 414 | + ? sprintf( esc_html__( 'Trashed: %s', 'bbpress' ), bbp_number_format_i18n( $topics['trashed'] ) ) | |
| 415 | + : ''; | |
| 416 | + | |
| 417 | + // Compile the hidden topic title | |
| 418 | + $hidden_topic_title = implode( ' | ', array_filter( $topic_titles ) ); | |
| 419 | + } | |
| 524 | 420 | } |
| 525 | 421 | |
| 526 | 422 | // Replies |
| 527 | 423 | if ( ! empty( $r['count_replies'] ) ) { |
| 528 | 424 | |
| 529 | - // Count all replies | |
| 530 | 425 | $all_replies = wp_count_posts( bbp_get_reply_post_type() ); |
| 531 | 426 | |
| 532 | 427 | // Published |
| 533 | - $reply_count = $all_replies->{$publish}; | |
| 428 | + $reply_count = $all_replies->publish; | |
| 534 | 429 | |
| 535 | - // Declare empty arrays | |
| 536 | - $replies = $reply_titles = array_fill_keys( bbp_get_non_public_reply_statuses(), '' ); | |
| 430 | + if ( current_user_can( 'read_private_replies' ) || current_user_can( 'edit_others_replies' ) || current_user_can( 'view_trash' ) ) { | |
| 537 | 431 | |
| 538 | - // Pending | |
| 539 | - if ( ! empty( $r['count_pending_replies'] ) && ! empty( $caps['edit_others_replies'] ) ) { | |
| 540 | - $replies[ $pending ] = bbp_number_not_negative( $all_replies->{$pending} ); | |
| 541 | - /* translators: %s: Number of pending replies */ | |
| 542 | - $reply_titles[ $pending ] = sprintf( esc_html__( 'Pending: %s', 'bbpress' ), bbp_number_format_i18n( $replies[ $pending ] ) ); | |
| 543 | - } | |
| 432 | + // Declare empty arrays | |
| 433 | + $replies = $reply_titles = array(); | |
| 544 | 434 | |
| 545 | - // Private | |
| 546 | - if ( ! empty( $r['count_private_replies'] ) && ! empty( $caps['read_private_replies'] ) ) { | |
| 547 | - $replies[ $private ] = bbp_number_not_negative( $all_replies->{$private} ); | |
| 548 | - /* translators: %s: Number of private replies */ | |
| 549 | - $reply_titles[ $private ] = sprintf( esc_html__( 'Private: %s', 'bbpress' ), bbp_number_format_i18n( $replies[ $private ] ) ); | |
| 550 | - } | |
| 435 | + // Pending | |
| 436 | + $replies['pending'] = ( ! empty( $r['count_pending_replies'] ) && current_user_can( 'edit_others_replies' ) ) | |
| 437 | + ? (int) $all_replies->{$pending} | |
| 438 | + : 0; | |
| 551 | 439 | |
| 552 | - // Hidden | |
| 553 | - if ( ! empty( $r['count_hidden_replies'] ) && ! empty( $caps['read_hidden_replies'] ) ) { | |
| 554 | - $replies[ $hidden ] = bbp_number_not_negative( $all_replies->{$hidden} ); | |
| 555 | - /* translators: %s: Number of hidden replies */ | |
| 556 | - $reply_titles[ $hidden ] = sprintf( esc_html__( 'Hidden: %s', 'bbpress' ), bbp_number_format_i18n( $replies[ $hidden ] ) ); | |
| 557 | - } | |
| 440 | + // Private | |
| 441 | + $replies['private'] = ( ! empty( $r['count_private_replies'] ) && current_user_can( 'read_private_replies' ) ) | |
| 442 | + ? (int) $all_replies->{$private} | |
| 443 | + : 0; | |
| 558 | 444 | |
| 559 | - // Spam | |
| 560 | - if ( ! empty( $r['count_spam_replies'] ) && ! empty( $caps['edit_others_replies'] ) ) { | |
| 561 | - $replies[ $spam ] = bbp_number_not_negative( $all_replies->{$spam} ); | |
| 562 | - /* translators: %s: Number of spam replies */ | |
| 563 | - $reply_titles[ $spam ] = sprintf( esc_html__( 'Spammed: %s', 'bbpress' ), bbp_number_format_i18n( $replies[ $spam ] ) ); | |
| 564 | - } | |
| 445 | + // Spam | |
| 446 | + $replies['spammed'] = ( ! empty( $r['count_spammed_replies'] ) && current_user_can( 'edit_others_replies' ) ) | |
| 447 | + ? (int) $all_replies->{$spam} | |
| 448 | + : 0; | |
| 565 | 449 | |
| 566 | - // Trash | |
| 567 | - if ( ! empty( $r['count_trash_replies'] ) && ! empty( $caps['view_trash'] ) ) { | |
| 568 | - $replies[ $trash ] = bbp_number_not_negative( $all_replies->{$trash} ); | |
| 569 | - /* translators: %s: Number of trashed replies */ | |
| 570 | - $reply_titles[ $trash ] = sprintf( esc_html__( 'Trashed: %s', 'bbpress' ), bbp_number_format_i18n( $replies[ $trash ] ) ); | |
| 571 | - } | |
| 450 | + // Trash | |
| 451 | + $replies['trashed'] = ( ! empty( $r['count_trashed_replies'] ) && current_user_can( 'view_trash' ) ) | |
| 452 | + ? (int) $all_replies->{$trash} | |
| 453 | + : 0; | |
| 572 | 454 | |
| 573 | - // Total hidden (pending, private, hidden, spam, trash) | |
| 574 | - $reply_count_hidden = array_sum( array_filter( $replies ) ); | |
| 455 | + // Total hidden (pending + private + spam + trash) | |
| 456 | + $reply_count_hidden = $replies['pending'] + $replies['private'] + $replies['spammed'] + $replies['trashed']; | |
| 575 | 457 | |
| 576 | - // Compile the hidden replies title | |
| 577 | - $hidden_reply_title = implode( ' | ', $reply_titles ); | |
| 458 | + // Generate the hidden topic count's title attribute | |
| 459 | + $reply_titles[] = ! empty( $replies['pending'] ) | |
| 460 | + ? sprintf( esc_html__( 'Pending: %s', 'bbpress' ), bbp_number_format_i18n( $replies['pending'] ) ) | |
| 461 | + : ''; | |
| 462 | + | |
| 463 | + $reply_titles[] = ! empty( $replies['private'] ) | |
| 464 | + ? sprintf( esc_html__( 'Private: %s', 'bbpress' ), bbp_number_format_i18n( $replies['private'] ) ) | |
| 465 | + : ''; | |
| 466 | + | |
| 467 | + $reply_titles[] = ! empty( $replies['spammed'] ) | |
| 468 | + ? sprintf( esc_html__( 'Spammed: %s', 'bbpress' ), bbp_number_format_i18n( $replies['spammed'] ) ) | |
| 469 | + : ''; | |
| 470 | + | |
| 471 | + $reply_titles[] = ! empty( $replies['trashed'] ) | |
| 472 | + ? sprintf( esc_html__( 'Trashed: %s', 'bbpress' ), bbp_number_format_i18n( $replies['trashed'] ) ) | |
| 473 | + : ''; | |
| 474 | + | |
| 475 | + // Compile the hidden replies title | |
| 476 | + $hidden_reply_title = implode( ' | ', array_filter( $reply_titles ) ); | |
| 477 | + } | |
| 578 | 478 | } |
| 579 | 479 | |
| 580 | 480 | // Topic Tags |
| 581 | 481 | if ( ! empty( $r['count_tags'] ) && bbp_allow_topic_tags() ) { |
| 582 | 482 | |
| 583 | - // Get the topic-tag taxonomy ID | |
| 584 | - $tt_id = bbp_get_topic_tag_tax_id(); | |
| 585 | - | |
| 586 | 483 | // Get the count |
| 587 | - $topic_tag_count = wp_count_terms( | |
| 588 | - array( | |
| 589 | - 'taxonomy' => $tt_id, | |
| 590 | - 'hide_empty' => true | |
| 591 | - ) | |
| 592 | - ); | |
| 484 | + $topic_tag_count = wp_count_terms( bbp_get_topic_tag_tax_id(), array( 'hide_empty' => true ) ); | |
| 593 | 485 | |
| 594 | 486 | // Empty tags |
| 595 | - if ( ! empty( $r['count_empty_tags'] ) && ! empty( 'edit_topic_tags' ) ) { | |
| 596 | - $empty_topic_tag_count = wp_count_terms( $tt_id ) - $topic_tag_count; | |
| 487 | + if ( ! empty( $r['count_empty_tags'] ) && current_user_can( 'edit_topic_tags' ) ) { | |
| 488 | + $empty_topic_tag_count = wp_count_terms( bbp_get_topic_tag_tax_id() ) - $topic_tag_count; | |
| 597 | 489 | } |
| 598 | 490 | } |
| 599 | 491 | |
| 600 | 492 | // Tally the tallies |
| 601 | - $counts = array_map( | |
| 602 | - 'absint', | |
| 603 | - compact( | |
| 604 | - 'user_count', | |
| 605 | - 'forum_count', | |
| 606 | - 'topic_count', | |
| 607 | - 'topic_count_hidden', | |
| 608 | - 'reply_count', | |
| 609 | - 'reply_count_hidden', | |
| 610 | - 'topic_tag_count', | |
| 611 | - 'empty_topic_tag_count' | |
| 612 | - ) | |
| 613 | - ); | |
| 493 | + $counts = array_filter( array_map( 'absint', compact( | |
| 494 | + 'user_count', | |
| 495 | + 'forum_count', | |
| 496 | + 'topic_count', | |
| 497 | + 'topic_count_hidden', | |
| 498 | + 'reply_count', | |
| 499 | + 'reply_count_hidden', | |
| 500 | + 'topic_tag_count', | |
| 501 | + 'empty_topic_tag_count' | |
| 502 | + ) ) ); | |
| 614 | 503 | |
| 615 | 504 | // Define return value |
| 616 | 505 | $statistics = array(); |
| 617 | 506 | |
| 618 | - // Loop through and store the integer and i18n formatted counts | |
| 507 | + // Loop through and store the integer and i18n formatted counts. | |
| 619 | 508 | foreach ( $counts as $key => $count ) { |
| 620 | - $not_negative = bbp_number_not_negative( $count ); | |
| 621 | - $statistics[ $key ] = bbp_number_format_i18n( $not_negative ); | |
| 622 | - $statistics[ "{$key}_int" ] = $not_negative; | |
| 509 | + $statistics[ $key ] = bbp_number_format_i18n( $count ); | |
| 510 | + $statistics[ "{$key}_int" ] = $count; | |
| 623 | 511 | } |
| 624 | 512 | |
| 625 | - // Add the hidden (topic/reply) count title attribute strings | |
| 513 | + // Add the hidden (topic/reply) count title attribute strings because we | |
| 514 | + // don't need to run the math functions on these (see above) | |
| 626 | 515 | $statistics['hidden_topic_title'] = $hidden_topic_title; |
| 627 | 516 | $statistics['hidden_reply_title'] = $hidden_reply_title; |
| 628 | 517 | |
| 629 | 518 | // Filter & return |
| @@ -632,9 +521,9 @@ | ||
| 632 | 521 | |
| 633 | 522 | /** New/edit topic/reply helpers **********************************************/ |
| 634 | 523 | |
| 635 | 524 | /** |
| 636 | - * Filter anonymous post data. | |
| 525 | + * Filter anonymous post data | |
| 637 | 526 | * |
| 638 | 527 | * We use REMOTE_ADDR here directly. If you are behind a proxy, you should |
| 639 | 528 | * ensure that it is properly set, such as in wp-config.php, for your |
| 640 | 529 | * environment. See {@link https://core.trac.wordpress.org/ticket/9235} |
| @@ -645,23 +534,19 @@ | ||
| 645 | 534 | * If there are any errors, those are directly added to {@link bbPress:errors} |
| 646 | 535 | * |
| 647 | 536 | * @since 2.0.0 bbPress (r2734) |
| 648 | 537 | * |
| 649 | - * @param array $args Optional. If no args are there, then $_POST values are. | |
| 650 | - * @return bool|array False on errors, values in an array on success. | |
| 538 | + * @param array $args Optional. If no args are there, then $_POST values are | |
| 539 | + * @return bool|array False on errors, values in an array on success | |
| 651 | 540 | */ |
| 652 | 541 | function bbp_filter_anonymous_post_data( $args = array() ) { |
| 653 | 542 | |
| 654 | 543 | // Parse arguments against default values |
| 655 | - $r = bbp_parse_args( | |
| 656 | - $args, | |
| 657 | - array( | |
| 658 | - 'bbp_anonymous_name' => ! empty( $_POST['bbp_anonymous_name'] ) ? $_POST['bbp_anonymous_name'] : false, | |
| 659 | - 'bbp_anonymous_email' => ! empty( $_POST['bbp_anonymous_email'] ) ? $_POST['bbp_anonymous_email'] : false, | |
| 660 | - 'bbp_anonymous_website' => ! empty( $_POST['bbp_anonymous_website'] ) ? $_POST['bbp_anonymous_website'] : false, | |
| 661 | - ), | |
| 662 | - 'filter_anonymous_post_data' | |
| 663 | - ); | |
| 544 | + $r = bbp_parse_args( $args, array( | |
| 545 | + 'bbp_anonymous_name' => ! empty( $_POST['bbp_anonymous_name'] ) ? $_POST['bbp_anonymous_name'] : false, | |
| 546 | + 'bbp_anonymous_email' => ! empty( $_POST['bbp_anonymous_email'] ) ? $_POST['bbp_anonymous_email'] : false, | |
| 547 | + 'bbp_anonymous_website' => ! empty( $_POST['bbp_anonymous_website'] ) ? $_POST['bbp_anonymous_website'] : false, | |
| 548 | + ), 'filter_anonymous_post_data' ); | |
| 664 | 549 | |
| 665 | 550 | // Strip invalid characters |
| 666 | 551 | $r = bbp_sanitize_anonymous_post_author( $r ); |
| 667 | 552 | |
| @@ -684,9 +569,9 @@ | ||
| 684 | 569 | return (array) apply_filters( 'bbp_filter_anonymous_post_data', $r, $args ); |
| 685 | 570 | } |
| 686 | 571 | |
| 687 | 572 | /** |
| 688 | - * Sanitize an array of anonymous post author data. | |
| 573 | + * Sanitize an array of anonymous post author data | |
| 689 | 574 | * |
| 690 | 575 | * @since 2.6.0 bbPress (r6400) |
| 691 | 576 | * |
| 692 | 577 | * @param array $anonymous_data |
| @@ -723,9 +608,9 @@ | ||
| 723 | 608 | return (array) apply_filters( 'bbp_sanitize_anonymous_post_author', $r, $anonymous_data ); |
| 724 | 609 | } |
| 725 | 610 | |
| 726 | 611 | /** |
| 727 | - * Update the relevant meta-data for an anonymous post author. | |
| 612 | + * Update the relevant meta-data for an anonymous post author | |
| 728 | 613 | * |
| 729 | 614 | * @since 2.6.0 bbPress (r6400) |
| 730 | 615 | * |
| 731 | 616 | * @param int $post_id |
| @@ -748,17 +633,13 @@ | ||
| 748 | 633 | return; |
| 749 | 634 | } |
| 750 | 635 | |
| 751 | 636 | // Parse arguments against default values |
| 752 | - $r = bbp_parse_args( | |
| 753 | - $anonymous_data, | |
| 754 | - array( | |
| 755 | - 'bbp_anonymous_name' => '', | |
| 756 | - 'bbp_anonymous_email' => '', | |
| 757 | - 'bbp_anonymous_website' => '', | |
| 758 | - ), | |
| 759 | - "update_{$post_type}" | |
| 760 | - ); | |
| 637 | + $r = bbp_parse_args( $anonymous_data, array( | |
| 638 | + 'bbp_anonymous_name' => '', | |
| 639 | + 'bbp_anonymous_email' => '', | |
| 640 | + 'bbp_anonymous_website' => '', | |
| 641 | + ), "update_{$post_type}" ); | |
| 761 | 642 | |
| 762 | 643 | // Update all anonymous metas |
| 763 | 644 | foreach ( $r as $anon_key => $anon_value ) { |
| 764 | 645 | |
| @@ -769,32 +650,28 @@ | ||
| 769 | 650 | } |
| 770 | 651 | } |
| 771 | 652 | |
| 772 | 653 | /** |
| 773 | - * Check for duplicate topics/replies. | |
| 654 | + * Check for duplicate topics/replies | |
| 774 | 655 | * |
| 775 | - * Check to make sure that a user is not making a duplicate post. | |
| 656 | + * Check to make sure that a user is not making a duplicate post | |
| 776 | 657 | * |
| 777 | 658 | * @since 2.0.0 bbPress (r2763) |
| 778 | 659 | * |
| 779 | - * @param array $post_data Contains information about the comment. | |
| 780 | - * @return bool True if it is not a duplicate, false if it is. | |
| 660 | + * @param array $post_data Contains information about the comment | |
| 661 | + * @return bool True if it is not a duplicate, false if it is | |
| 781 | 662 | */ |
| 782 | 663 | function bbp_check_for_duplicate( $post_data = array() ) { |
| 783 | 664 | |
| 784 | 665 | // Parse arguments against default values |
| 785 | - $r = bbp_parse_args( | |
| 786 | - $post_data, | |
| 787 | - array( | |
| 788 | - 'post_author' => 0, | |
| 789 | - 'post_type' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ), | |
| 790 | - 'post_parent' => 0, | |
| 791 | - 'post_content' => '', | |
| 792 | - 'post_status' => bbp_get_trash_status_id(), | |
| 793 | - 'anonymous_data' => array() | |
| 794 | - ), | |
| 795 | - 'check_for_duplicate' | |
| 796 | - ); | |
| 666 | + $r = bbp_parse_args( $post_data, array( | |
| 667 | + 'post_author' => 0, | |
| 668 | + 'post_type' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ), | |
| 669 | + 'post_parent' => 0, | |
| 670 | + 'post_content' => '', | |
| 671 | + 'post_status' => bbp_get_trash_status_id(), | |
| 672 | + 'anonymous_data' => array() | |
| 673 | + ), 'check_for_duplicate' ); | |
| 797 | 674 | |
| 798 | 675 | // No duplicate checks for those who can throttle |
| 799 | 676 | if ( user_can( (int) $r['post_author'], 'throttle' ) ) { |
| 800 | 677 | return true; |
| @@ -815,19 +692,12 @@ | ||
| 815 | 692 | // Only proceed |
| 816 | 693 | if ( ! empty( $email ) && is_email( $email ) ) { |
| 817 | 694 | |
| 818 | 695 | // Get the meta SQL |
| 819 | - $clauses = get_meta_sql( | |
| 820 | - array( | |
| 821 | - array( | |
| 822 | - 'key' => '_bbp_anonymous_email', | |
| 823 | - 'value' => $email, | |
| 824 | - ) | |
| 825 | - ), | |
| 826 | - 'post', | |
| 827 | - $bbp_db->posts, | |
| 828 | - 'ID' | |
| 829 | - ); | |
| 696 | + $clauses = get_meta_sql( array( array( | |
| 697 | + 'key' => '_bbp_anonymous_email', | |
| 698 | + 'value' => $email, | |
| 699 | + ) ), 'post', $bbp_db->posts, 'ID' ); | |
| 830 | 700 | |
| 831 | 701 | // Set clauses |
| 832 | 702 | $join = $clauses['join']; |
| 833 | 703 | |
| @@ -843,14 +713,14 @@ | ||
| 843 | 713 | $r = wp_unslash( $r ); |
| 844 | 714 | |
| 845 | 715 | // Prepare duplicate check query |
| 846 | 716 | $query = "SELECT ID FROM {$bbp_db->posts} {$join}"; |
| 847 | - $query .= $bbp_db->prepare('WHERE post_type = %s AND post_status != %s AND post_author = %d AND post_content = %s', $r['post_type'], $r['post_status'], $r['post_author'], $r['post_content'] ); | |
| 717 | + $query .= $bbp_db->prepare( "WHERE post_type = %s AND post_status != %s AND post_author = %d AND post_content = %s", $r['post_type'], $r['post_status'], $r['post_author'], $r['post_content'] ); | |
| 848 | 718 | $query .= ! empty( $r['post_parent'] ) |
| 849 | - ? $bbp_db->prepare( ' AND post_parent = %d', $r['post_parent'] ) | |
| 719 | + ? $bbp_db->prepare( " AND post_parent = %d", $r['post_parent'] ) | |
| 850 | 720 | : ''; |
| 851 | 721 | $query .= $where; |
| 852 | - $query .= ' LIMIT 1'; | |
| 722 | + $query .= " LIMIT 1"; | |
| 853 | 723 | $dupe = apply_filters( 'bbp_check_for_duplicate_query', $query, $r ); |
| 854 | 724 | |
| 855 | 725 | // Dupe found |
| 856 | 726 | if ( $bbp_db->get_var( $dupe ) ) { |
| @@ -862,9 +732,9 @@ | ||
| 862 | 732 | return true; |
| 863 | 733 | } |
| 864 | 734 | |
| 865 | 735 | /** |
| 866 | - * Check for flooding. | |
| 736 | + * Check for flooding | |
| 867 | 737 | * |
| 868 | 738 | * Check to make sure that a user is not making too many posts in a short amount |
| 869 | 739 | * of time. |
| 870 | 740 | * |
| @@ -871,12 +741,12 @@ | ||
| 871 | 741 | * @since 2.0.0 bbPress (r2734) |
| 872 | 742 | * |
| 873 | 743 | * @param array $anonymous_data Optional - if it's an anonymous post. Do not |
| 874 | 744 | * supply if supplying $author_id. Should be |
| 875 | - * sanitized (see {@link bbp_filter_anonymous_post_data()}. | |
| 745 | + * sanitized (see {@link bbp_filter_anonymous_post_data()} | |
| 876 | 746 | * @param int $author_id Optional. Supply if it's a post by a logged in user. |
| 877 | 747 | * Do not supply if supplying $anonymous_data. |
| 878 | - * @return bool True if there is no flooding, false if there is. | |
| 748 | + * @return bool True if there is no flooding, false if there is | |
| 879 | 749 | */ |
| 880 | 750 | function bbp_check_for_flood( $anonymous_data = array(), $author_id = 0 ) { |
| 881 | 751 | |
| 882 | 752 | // Allow for flood check to be skipped |
| @@ -913,9 +783,9 @@ | ||
| 913 | 783 | return true; |
| 914 | 784 | } |
| 915 | 785 | |
| 916 | 786 | /** |
| 917 | - * Checks topics and replies against the discussion moderation of blocked keys. | |
| 787 | + * Checks topics and replies against the discussion moderation of blocked keys | |
| 918 | 788 | * |
| 919 | 789 | * @since 2.1.0 bbPress (r3581) |
| 920 | 790 | * |
| 921 | 791 | * @param array $anonymous_data Optional - if it's an anonymous post. Do not |
| @@ -920,14 +790,14 @@ | ||
| 920 | 790 | * |
| 921 | 791 | * @param array $anonymous_data Optional - if it's an anonymous post. Do not |
| 922 | 792 | * supply if supplying $author_id. Should be |
| 923 | 793 | * sanitized (see {@link bbp_filter_anonymous_post_data()} |
| 924 | - * @param int $author_id Topic or reply author ID. | |
| 925 | - * @param string $title The title of the content. | |
| 926 | - * @param string $content The content being posted. | |
| 927 | - * @param mixed $strict False for moderation_keys. True for disallowed_keys. | |
| 794 | + * @param int $author_id Topic or reply author ID | |
| 795 | + * @param string $title The title of the content | |
| 796 | + * @param string $content The content being posted | |
| 797 | + * @param mixed $strict False for moderation_keys. True for blacklist_keys. | |
| 928 | 798 | * String for custom keys. |
| 929 | - * @return bool True if test is passed, false if fail. | |
| 799 | + * @return bool True if test is passed, false if fail | |
| 930 | 800 | */ |
| 931 | 801 | function bbp_check_for_moderation( $anonymous_data = array(), $author_id = 0, $title = '', $content = '', $strict = false ) { |
| 932 | 802 | |
| 933 | 803 | // Custom moderation option key |
| @@ -944,12 +814,12 @@ | ||
| 944 | 814 | $strict = false; |
| 945 | 815 | } |
| 946 | 816 | } |
| 947 | 817 | |
| 948 | - // Strict mode uses WordPress "disallow" settings | |
| 818 | + // Strict mode uses WordPress "blacklist" settings | |
| 949 | 819 | if ( true === $strict ) { |
| 950 | 820 | $hook_name = 'blacklist'; |
| 951 | - $option_name = 'disallowed_keys'; | |
| 821 | + $option_name = 'blacklist_keys'; | |
| 952 | 822 | |
| 953 | 823 | // Non-strict uses WordPress "moderation" settings |
| 954 | 824 | } elseif ( false === $strict ) { |
| 955 | 825 | $hook_name = 'moderation'; |
| @@ -1068,9 +938,9 @@ | ||
| 1068 | 938 | |
| 1069 | 939 | // Do some escaping magic so that '#' chars in the |
| 1070 | 940 | // spam words don't break things: |
| 1071 | 941 | $word = preg_quote( $word, '#' ); |
| 1072 | - $pattern = "#{$word}#iu"; | |
| 942 | + $pattern = "#{$word}#i"; | |
| 1073 | 943 | |
| 1074 | 944 | // Loop through post data |
| 1075 | 945 | foreach ( $_post as $post_data ) { |
| 1076 | 946 | |
| @@ -1129,12 +999,12 @@ | ||
| 1129 | 999 | return apply_filters( 'bbp_get_do_not_reply_address', 'noreply@' . $sitename ); |
| 1130 | 1000 | } |
| 1131 | 1001 | |
| 1132 | 1002 | /** |
| 1133 | - * Sends notification emails for new replies to subscribed topics. | |
| 1003 | + * Sends notification emails for new replies to subscribed topics | |
| 1134 | 1004 | * |
| 1135 | 1005 | * Gets new post ID and check if there are subscribed users to that topic, and |
| 1136 | - * if there are, send notifications. | |
| 1006 | + * if there are, send notifications | |
| 1137 | 1007 | * |
| 1138 | 1008 | * Note: in bbPress 2.6, we've moved away from 1 email per subscriber to 1 email |
| 1139 | 1009 | * with everyone BCC'd. This may have negative repercussions for email services |
| 1140 | 1010 | * that limit the number of addresses in a BCC field (often to around 500.) In |
| @@ -1142,16 +1012,16 @@ | ||
| 1142 | 1012 | * custom email script. |
| 1143 | 1013 | * |
| 1144 | 1014 | * @since 2.6.0 bbPress (r5413) |
| 1145 | 1015 | * |
| 1146 | - * @param int $reply_id ID of the newly made reply. | |
| 1147 | - * @param int $topic_id ID of the topic of the reply. | |
| 1148 | - * @param int $forum_id ID of the forum of the reply. | |
| 1016 | + * @param int $reply_id ID of the newly made reply | |
| 1017 | + * @param int $topic_id ID of the topic of the reply | |
| 1018 | + * @param int $forum_id ID of the forum of the reply | |
| 1149 | 1019 | * @param array $anonymous_data Optional - if it's an anonymous post. Do not |
| 1150 | 1020 | * supply if supplying $author_id. Should be |
| 1151 | - * sanitized (see {@link bbp_filter_anonymous_post_data()}. | |
| 1152 | - * @param int $reply_author ID of the topic author ID. | |
| 1153 | - * @return bool True on success, false on failure. | |
| 1021 | + * sanitized (see {@link bbp_filter_anonymous_post_data()} | |
| 1022 | + * @param int $reply_author ID of the topic author ID | |
| 1023 | + * @return bool True on success, false on failure | |
| 1154 | 1024 | */ |
| 1155 | 1025 | function bbp_notify_topic_subscribers( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = array(), $reply_author = 0 ) { |
| 1156 | 1026 | |
| 1157 | 1027 | // Bail if subscriptions are turned off |
| @@ -1220,21 +1090,17 @@ | ||
| 1220 | 1090 | bbp_remove_all_filters( 'bbp_get_topic_title' ); |
| 1221 | 1091 | bbp_remove_all_filters( 'the_title' ); |
| 1222 | 1092 | |
| 1223 | 1093 | // Strip tags from text and setup mail data |
| 1224 | - $forum_title = wp_specialchars_decode( wp_strip_all_tags( bbp_get_forum_title( $forum_id ) ), ENT_QUOTES ); | |
| 1225 | - $topic_title = wp_specialchars_decode( wp_strip_all_tags( bbp_get_topic_title( $topic_id ) ), ENT_QUOTES ); | |
| 1226 | - $reply_author_name = wp_specialchars_decode( wp_strip_all_tags( $reply_author_name ), ENT_QUOTES ); | |
| 1227 | - $reply_content = wp_specialchars_decode( wp_strip_all_tags( bbp_get_reply_content( $reply_id ) ), ENT_QUOTES ); | |
| 1094 | + $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); | |
| 1095 | + $topic_title = wp_specialchars_decode( strip_tags( bbp_get_topic_title( $topic_id ) ), ENT_QUOTES ); | |
| 1096 | + $reply_author_name = wp_specialchars_decode( strip_tags( $reply_author_name ), ENT_QUOTES ); | |
| 1097 | + $reply_content = wp_specialchars_decode( strip_tags( bbp_get_reply_content( $reply_id ) ), ENT_QUOTES ); | |
| 1228 | 1098 | $reply_url = bbp_get_reply_url( $reply_id ); |
| 1229 | 1099 | |
| 1230 | 1100 | // For plugins to filter messages per reply/topic/user |
| 1231 | - $message = sprintf( | |
| 1101 | + $message = sprintf( esc_html__( '%1$s wrote: | |
| 1232 | 1102 | |
| 1233 | - /* translators: 1: Reply author name, 2: Reply content, 3: Reply URL */ | |
| 1234 | - esc_html__( | |
| 1235 | - '%1$s wrote: | |
| 1236 | - | |
| 1237 | 1103 | %2$s |
| 1238 | 1104 | |
| 1239 | 1105 | Post Link: %3$s |
| 1240 | 1106 | |
| @@ -1241,11 +1107,10 @@ | ||
| 1241 | 1107 | ----------- |
| 1242 | 1108 | |
| 1243 | 1109 | You are receiving this email because you subscribed to a forum topic. |
| 1244 | 1110 | |
| 1245 | -Login and visit the topic to unsubscribe from these emails.', | |
| 1246 | - 'bbpress' | |
| 1247 | - ), | |
| 1111 | +Login and visit the topic to unsubscribe from these emails.', 'bbpress' ), | |
| 1112 | + | |
| 1248 | 1113 | $reply_author_name, |
| 1249 | 1114 | $reply_content, |
| 1250 | 1115 | $reply_url |
| 1251 | 1116 | ); |
| @@ -1255,9 +1120,9 @@ | ||
| 1255 | 1120 | return; |
| 1256 | 1121 | } |
| 1257 | 1122 | |
| 1258 | 1123 | // For plugins to filter titles per reply/topic/user |
| 1259 | - $subject = apply_filters( 'bbp_subscription_mail_title', '[' . $forum_title . '] ' . $topic_title, $reply_id, $topic_id ); | |
| 1124 | + $subject = apply_filters( 'bbp_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $reply_id, $topic_id ); | |
| 1260 | 1125 | if ( empty( $subject ) ) { |
| 1261 | 1126 | return; |
| 1262 | 1127 | } |
| 1263 | 1128 | |
| @@ -1283,9 +1148,9 @@ | ||
| 1283 | 1148 | /** Send it ***************************************************************/ |
| 1284 | 1149 | |
| 1285 | 1150 | // Custom headers |
| 1286 | 1151 | $headers = apply_filters( 'bbp_subscription_mail_headers', $headers ); |
| 1287 | - $to_email = apply_filters( 'bbp_subscription_to_email', $no_reply ); | |
| 1152 | + $to_email = apply_filters( 'bbp_subscription_to_email', $no_reply ); | |
| 1288 | 1153 | |
| 1289 | 1154 | // Before |
| 1290 | 1155 | do_action( 'bbp_pre_notify_subscribers', $reply_id, $topic_id, $user_ids ); |
| 1291 | 1156 | |
| @@ -1303,12 +1168,12 @@ | ||
| 1303 | 1168 | return true; |
| 1304 | 1169 | } |
| 1305 | 1170 | |
| 1306 | 1171 | /** |
| 1307 | - * Sends notification emails for new topics to subscribed forums. | |
| 1172 | + * Sends notification emails for new topics to subscribed forums | |
| 1308 | 1173 | * |
| 1309 | 1174 | * Gets new post ID and check if there are subscribed users to that forum, and |
| 1310 | - * if there are, send notifications. | |
| 1175 | + * if there are, send notifications | |
| 1311 | 1176 | * |
| 1312 | 1177 | * Note: in bbPress 2.6, we've moved away from 1 email per subscriber to 1 email |
| 1313 | 1178 | * with everyone BCC'd. This may have negative repercussions for email services |
| 1314 | 1179 | * that limit the number of addresses in a BCC field (often to around 500.) In |
| @@ -1316,15 +1181,15 @@ | ||
| 1316 | 1181 | * custom email script. |
| 1317 | 1182 | * |
| 1318 | 1183 | * @since 2.5.0 bbPress (r5156) |
| 1319 | 1184 | * |
| 1320 | - * @param int $topic_id ID of the newly made reply. | |
| 1321 | - * @param int $forum_id ID of the forum for the topic. | |
| 1185 | + * @param int $topic_id ID of the newly made reply | |
| 1186 | + * @param int $forum_id ID of the forum for the topic | |
| 1322 | 1187 | * @param array $anonymous_data Optional - if it's an anonymous post. Do not |
| 1323 | 1188 | * supply if supplying $author_id. Should be |
| 1324 | 1189 | * sanitized (see {@link bbp_filter_anonymous_post_data()} |
| 1325 | - * @param int $topic_author ID of the topic author ID. | |
| 1326 | - * @return bool True on success, false on failure. | |
| 1190 | + * @param int $topic_author ID of the topic author ID | |
| 1191 | + * @return bool True on success, false on failure | |
| 1327 | 1192 | */ |
| 1328 | 1193 | function bbp_notify_forum_subscribers( $topic_id = 0, $forum_id = 0, $anonymous_data = array(), $topic_author = 0 ) { |
| 1329 | 1194 | |
| 1330 | 1195 | // Bail if subscriptions are turned off |
| @@ -1350,9 +1215,9 @@ | ||
| 1350 | 1215 | $user_id = 0; |
| 1351 | 1216 | |
| 1352 | 1217 | /** Topic *****************************************************************/ |
| 1353 | 1218 | |
| 1354 | - // Bail if topic is not public (both open/closed are public) | |
| 1219 | + // Bail if topic is not public (includes closed) | |
| 1355 | 1220 | if ( ! bbp_is_topic_public( $topic_id ) ) { |
| 1356 | 1221 | return false; |
| 1357 | 1222 | } |
| 1358 | 1223 | |
| @@ -1392,21 +1257,17 @@ | ||
| 1392 | 1257 | bbp_remove_all_filters( 'bbp_get_topic_title' ); |
| 1393 | 1258 | bbp_remove_all_filters( 'the_title' ); |
| 1394 | 1259 | |
| 1395 | 1260 | // Strip tags from text and setup mail data |
| 1396 | - $forum_title = wp_specialchars_decode( wp_strip_all_tags( bbp_get_forum_title( $forum_id ) ), ENT_QUOTES ); | |
| 1397 | - $topic_title = wp_specialchars_decode( wp_strip_all_tags( bbp_get_topic_title( $topic_id ) ), ENT_QUOTES ); | |
| 1398 | - $topic_author_name = wp_specialchars_decode( wp_strip_all_tags( $topic_author_name ), ENT_QUOTES ); | |
| 1399 | - $topic_content = wp_specialchars_decode( wp_strip_all_tags( bbp_get_topic_content( $topic_id ) ), ENT_QUOTES ); | |
| 1400 | - $topic_url = bbp_get_topic_permalink( $topic_id ); | |
| 1261 | + $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); | |
| 1262 | + $topic_title = wp_specialchars_decode( strip_tags( bbp_get_topic_title( $topic_id ) ), ENT_QUOTES ); | |
| 1263 | + $topic_author_name = wp_specialchars_decode( strip_tags( $topic_author_name ), ENT_QUOTES ); | |
| 1264 | + $topic_content = wp_specialchars_decode( strip_tags( bbp_get_topic_content( $topic_id ) ), ENT_QUOTES ); | |
| 1265 | + $topic_url = get_permalink( $topic_id ); | |
| 1401 | 1266 | |
| 1402 | 1267 | // For plugins to filter messages per reply/topic/user |
| 1403 | - $message = sprintf( | |
| 1268 | + $message = sprintf( esc_html__( '%1$s wrote: | |
| 1404 | 1269 | |
| 1405 | - /* translators: 1: Topic author name, 2: Topic content, 3: Topic URL */ | |
| 1406 | - esc_html__( | |
| 1407 | - '%1$s wrote: | |
| 1408 | - | |
| 1409 | 1270 | %2$s |
| 1410 | 1271 | |
| 1411 | 1272 | Topic Link: %3$s |
| 1412 | 1273 | |
| @@ -1413,11 +1274,10 @@ | ||
| 1413 | 1274 | ----------- |
| 1414 | 1275 | |
| 1415 | 1276 | You are receiving this email because you subscribed to a forum. |
| 1416 | 1277 | |
| 1417 | -Login and visit the topic to unsubscribe from these emails.', | |
| 1418 | - 'bbpress' | |
| 1419 | - ), | |
| 1278 | +Login and visit the topic to unsubscribe from these emails.', 'bbpress' ), | |
| 1279 | + | |
| 1420 | 1280 | $topic_author_name, |
| 1421 | 1281 | $topic_content, |
| 1422 | 1282 | $topic_url |
| 1423 | 1283 | ); |
| @@ -1427,9 +1287,9 @@ | ||
| 1427 | 1287 | return; |
| 1428 | 1288 | } |
| 1429 | 1289 | |
| 1430 | 1290 | // For plugins to filter titles per reply/topic/user |
| 1431 | - $subject = apply_filters( 'bbp_forum_subscription_mail_title', '[' . $forum_title . '] ' . $topic_title, $topic_id, $forum_id, $user_id ); | |
| 1291 | + $subject = apply_filters( 'bbp_forum_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $topic_id, $forum_id, $user_id ); | |
| 1432 | 1292 | if ( empty( $subject ) ) { |
| 1433 | 1293 | return; |
| 1434 | 1294 | } |
| 1435 | 1295 | |
| @@ -1475,25 +1335,25 @@ | ||
| 1475 | 1335 | return true; |
| 1476 | 1336 | } |
| 1477 | 1337 | |
| 1478 | 1338 | /** |
| 1479 | - * Sends notification emails for new replies to subscribed topics. | |
| 1339 | + * Sends notification emails for new replies to subscribed topics | |
| 1480 | 1340 | * |
| 1481 | - * This function is deprecated. Please use: bbp_notify_topic_subscribers(). | |
| 1341 | + * This function is deprecated. Please use: bbp_notify_topic_subscribers() | |
| 1482 | 1342 | * |
| 1483 | 1343 | * @since 2.0.0 bbPress (r2668) |
| 1484 | 1344 | * |
| 1485 | 1345 | * @deprecated 2.6.0 bbPress (r5412) |
| 1486 | 1346 | * |
| 1487 | - * @param int $reply_id ID of the newly made reply. | |
| 1488 | - * @param int $topic_id ID of the topic of the reply. | |
| 1489 | - * @param int $forum_id ID of the forum of the reply. | |
| 1347 | + * @param int $reply_id ID of the newly made reply | |
| 1348 | + * @param int $topic_id ID of the topic of the reply | |
| 1349 | + * @param int $forum_id ID of the forum of the reply | |
| 1490 | 1350 | * @param array $anonymous_data Optional - if it's an anonymous post. Do not |
| 1491 | 1351 | * supply if supplying $author_id. Should be |
| 1492 | - * sanitized (see {@link bbp_filter_anonymous_post_data()}. | |
| 1493 | - * @param int $reply_author ID of the topic author ID. | |
| 1352 | + * sanitized (see {@link bbp_filter_anonymous_post_data()} | |
| 1353 | + * @param int $reply_author ID of the topic author ID | |
| 1494 | 1354 | * |
| 1495 | - * @return bool True on success, false on failure. | |
| 1355 | + * @return bool True on success, false on failure | |
| 1496 | 1356 | */ |
| 1497 | 1357 | function bbp_notify_subscribers( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = array(), $reply_author = 0 ) { |
| 1498 | 1358 | return bbp_notify_topic_subscribers( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author ); |
| 1499 | 1359 | } |
| @@ -1498,9 +1358,9 @@ | ||
| 1498 | 1358 | return bbp_notify_topic_subscribers( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author ); |
| 1499 | 1359 | } |
| 1500 | 1360 | |
| 1501 | 1361 | /** |
| 1502 | - * Return an array of user email addresses from an array of user IDs. | |
| 1362 | + * Return an array of user email addresses from an array of user IDs | |
| 1503 | 1363 | * |
| 1504 | 1364 | * @since 2.6.0 bbPress (r6722) |
| 1505 | 1365 | * |
| 1506 | 1366 | * @param array $user_ids |
| @@ -1535,15 +1395,13 @@ | ||
| 1535 | 1395 | continue; |
| 1536 | 1396 | } |
| 1537 | 1397 | |
| 1538 | 1398 | // Call get_users() in a way that users are cached |
| 1539 | - $loop_users = get_users( | |
| 1540 | - array( | |
| 1541 | - 'blog_id' => 0, | |
| 1542 | - 'fields' => 'all_with_meta', | |
| 1543 | - 'include' => $loop_ids | |
| 1544 | - ) | |
| 1545 | - ); | |
| 1399 | + $loop_users = get_users( array( | |
| 1400 | + 'blog_id' => 0, | |
| 1401 | + 'fields' => 'all_with_meta', | |
| 1402 | + 'include' => $loop_ids | |
| 1403 | + ) ); | |
| 1546 | 1404 | |
| 1547 | 1405 | // Pluck emails from users |
| 1548 | 1406 | $loop_emails = wp_list_pluck( $loop_users, 'user_email' ); |
| 1549 | 1407 | |
| @@ -1641,9 +1499,9 @@ | ||
| 1641 | 1499 | |
| 1642 | 1500 | /** Login *********************************************************************/ |
| 1643 | 1501 | |
| 1644 | 1502 | /** |
| 1645 | - * Return a clean and reliable logout URL. | |
| 1503 | + * Return a clean and reliable logout URL | |
| 1646 | 1504 | * |
| 1647 | 1505 | * This function is used to filter `logout_url`. If no $redirect_to value is |
| 1648 | 1506 | * passed, it will default to the request uri, then the forum root. |
| 1649 | 1507 | * |
| @@ -1650,12 +1508,12 @@ | ||
| 1650 | 1508 | * See: `wp_logout_url()` |
| 1651 | 1509 | * |
| 1652 | 1510 | * @since 2.1.0 bbPress (2815) |
| 1653 | 1511 | * |
| 1654 | - * @param string $url URL used to log out. | |
| 1512 | + * @param string $url URL used to log out | |
| 1655 | 1513 | * @param string $redirect_to Where to redirect to? |
| 1656 | 1514 | * |
| 1657 | - * @return string The url. | |
| 1515 | + * @return string The url | |
| 1658 | 1516 | */ |
| 1659 | 1517 | function bbp_logout_url( $url = '', $redirect_to = '' ) { |
| 1660 | 1518 | |
| 1661 | 1519 | // If there is no redirect in the URL, let's add one... |
| @@ -1669,16 +1527,11 @@ | ||
| 1669 | 1527 | |
| 1670 | 1528 | // Check for a valid referer |
| 1671 | 1529 | $redirect_to = wp_get_referer(); |
| 1672 | 1530 | |
| 1673 | - // Maybe use current host | |
| 1674 | - if ( ( false === $redirect_to ) && ! empty( $_SERVER['HTTP_HOST'] ) ) { | |
| 1675 | - $redirect_to = bbp_get_url_scheme() . $_SERVER['HTTP_HOST']; | |
| 1676 | - | |
| 1677 | - // Maybe also use request URI | |
| 1678 | - if ( ! empty( $_SERVER['REQUEST_URI'] ) ) { | |
| 1679 | - $redirect_to .= $_SERVER['REQUEST_URI']; | |
| 1680 | - } | |
| 1531 | + // Fallback to request uri if invalid referer | |
| 1532 | + if ( false === $redirect_to ) { | |
| 1533 | + $redirect_to = bbp_get_url_scheme() . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | |
| 1681 | 1534 | } |
| 1682 | 1535 | } |
| 1683 | 1536 | |
| 1684 | 1537 | // Filter the $redirect_to destination |
| @@ -1687,11 +1540,11 @@ | ||
| 1687 | 1540 | // Validate $redirect_to, default to root |
| 1688 | 1541 | $validated = wp_validate_redirect( $filtered, $forum_root ); |
| 1689 | 1542 | |
| 1690 | 1543 | // Assemble $redirect_to and add it (encoded) to full $url |
| 1691 | - $appended = add_query_arg( array( 'loggedout' => 'true' ), $validated ); | |
| 1544 | + $appended = add_query_arg( array( 'loggedout' => 'true' ), $validated ); | |
| 1692 | 1545 | $encoded = urlencode( $appended ); |
| 1693 | - $url = add_query_arg( array( 'redirect_to' => $encoded ), $url ); | |
| 1546 | + $url = add_query_arg( array( 'redirect_to' => $encoded ), $url ); | |
| 1694 | 1547 | } |
| 1695 | 1548 | |
| 1696 | 1549 | // Filter & return |
| 1697 | 1550 | return apply_filters( 'bbp_logout_url', $url, $redirect_to ); |
| @@ -1708,11 +1561,11 @@ | ||
| 1708 | 1561 | * optional $filter_key parameter. |
| 1709 | 1562 | * |
| 1710 | 1563 | * @since 2.1.0 bbPress (r3839) |
| 1711 | 1564 | * |
| 1712 | - * @param string|array $args Value to merge with $defaults. | |
| 1565 | + * @param string|array $args Value to merge with $defaults | |
| 1713 | 1566 | * @param array $defaults Array that serves as the defaults. |
| 1714 | - * @param string $filter_key String to key the filters from. | |
| 1567 | + * @param string $filter_key String to key the filters from | |
| 1715 | 1568 | * @return array Merged user defined values with defaults. |
| 1716 | 1569 | */ |
| 1717 | 1570 | function bbp_parse_args( $args, $defaults = array(), $filter_key = '' ) { |
| 1718 | 1571 | |
| @@ -1744,9 +1597,9 @@ | ||
| 1744 | 1597 | return $r; |
| 1745 | 1598 | } |
| 1746 | 1599 | |
| 1747 | 1600 | /** |
| 1748 | - * Adds ability to include or exclude specific post_parent ID's. | |
| 1601 | + * Adds ability to include or exclude specific post_parent ID's | |
| 1749 | 1602 | * |
| 1750 | 1603 | * @since 2.0.0 bbPress (r2996) |
| 1751 | 1604 | * |
| 1752 | 1605 | * @deprecated 2.5.8 bbPress (r5814) |
| @@ -1752,12 +1605,12 @@ | ||
| 1752 | 1605 | * @deprecated 2.5.8 bbPress (r5814) |
| 1753 | 1606 | * |
| 1754 | 1607 | * @global WP $wp |
| 1755 | 1608 | * @param string $where |
| 1756 | - * @param WP_Query $query | |
| 1609 | + * @param WP_Query $object | |
| 1757 | 1610 | * @return string |
| 1758 | 1611 | */ |
| 1759 | -function bbp_query_post_parent__in( $where, $query = '' ) { | |
| 1612 | +function bbp_query_post_parent__in( $where, $object = '' ) { | |
| 1760 | 1613 | global $wp; |
| 1761 | 1614 | |
| 1762 | 1615 | // Noop if WP core supports this already |
| 1763 | 1616 | if ( in_array( 'post_parent__in', $wp->private_query_vars, true ) ) { |
| @@ -1764,14 +1617,14 @@ | ||
| 1764 | 1617 | return $where; |
| 1765 | 1618 | } |
| 1766 | 1619 | |
| 1767 | 1620 | // Bail if no object passed |
| 1768 | - if ( empty( $query ) ) { | |
| 1621 | + if ( empty( $object ) ) { | |
| 1769 | 1622 | return $where; |
| 1770 | 1623 | } |
| 1771 | 1624 | |
| 1772 | 1625 | // Only 1 post_parent so return $where |
| 1773 | - if ( is_numeric( $query->query_vars['post_parent'] ) ) { | |
| 1626 | + if ( is_numeric( $object->query_vars['post_parent'] ) ) { | |
| 1774 | 1627 | return $where; |
| 1775 | 1628 | } |
| 1776 | 1629 | |
| 1777 | 1630 | // Get the DB |
| @@ -1777,15 +1630,15 @@ | ||
| 1777 | 1630 | // Get the DB |
| 1778 | 1631 | $bbp_db = bbp_db(); |
| 1779 | 1632 | |
| 1780 | 1633 | // Including specific post_parent's |
| 1781 | - if ( ! empty( $query->query_vars['post_parent__in'] ) ) { | |
| 1782 | - $ids = implode( ',', wp_parse_id_list( $query->query_vars['post_parent__in'] ) ); | |
| 1634 | + if ( ! empty( $object->query_vars['post_parent__in'] ) ) { | |
| 1635 | + $ids = implode( ',', wp_parse_id_list( $object->query_vars['post_parent__in'] ) ); | |
| 1783 | 1636 | $where .= " AND {$bbp_db->posts}.post_parent IN ($ids)"; |
| 1784 | 1637 | |
| 1785 | 1638 | // Excluding specific post_parent's |
| 1786 | - } elseif ( ! empty( $query->query_vars['post_parent__not_in'] ) ) { | |
| 1787 | - $ids = implode( ',', wp_parse_id_list( $query->query_vars['post_parent__not_in'] ) ); | |
| 1639 | + } elseif ( ! empty( $object->query_vars['post_parent__not_in'] ) ) { | |
| 1640 | + $ids = implode( ',', wp_parse_id_list( $object->query_vars['post_parent__not_in'] ) ); | |
| 1788 | 1641 | $where .= " AND {$bbp_db->posts}.post_parent NOT IN ($ids)"; |
| 1789 | 1642 | } |
| 1790 | 1643 | |
| 1791 | 1644 | // Return possibly modified $where |
| @@ -1792,9 +1645,9 @@ | ||
| 1792 | 1645 | return $where; |
| 1793 | 1646 | } |
| 1794 | 1647 | |
| 1795 | 1648 | /** |
| 1796 | - * Query the DB and get the last public post_id that has parent_id as post_parent. | |
| 1649 | + * Query the DB and get the last public post_id that has parent_id as post_parent | |
| 1797 | 1650 | * |
| 1798 | 1651 | * @since 2.0.0 bbPress (r2868) |
| 1799 | 1652 | * @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects |
| 1800 | 1653 | * |
| @@ -1799,9 +1652,9 @@ | ||
| 1799 | 1652 | * @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects |
| 1800 | 1653 | * |
| 1801 | 1654 | * @param int $parent_id Parent id. |
| 1802 | 1655 | * @param string $post_type Post type. Defaults to 'post'. |
| 1803 | - * @return int The last active post_id. | |
| 1656 | + * @return int The last active post_id | |
| 1804 | 1657 | */ |
| 1805 | 1658 | function bbp_get_public_child_last_id( $parent_id = 0, $post_type = 'post' ) { |
| 1806 | 1659 | |
| 1807 | 1660 | // Bail if nothing passed |
| @@ -1828,28 +1681,26 @@ | ||
| 1828 | 1681 | $post_status = bbp_get_public_reply_statuses(); |
| 1829 | 1682 | break; |
| 1830 | 1683 | } |
| 1831 | 1684 | |
| 1832 | - $query = new WP_Query( | |
| 1833 | - array( | |
| 1834 | - 'fields' => 'ids', | |
| 1835 | - 'post_parent' => $parent_id, | |
| 1836 | - 'post_status' => $post_status, | |
| 1837 | - 'post_type' => $post_type, | |
| 1838 | - 'posts_per_page' => 1, | |
| 1839 | - 'orderby' => array( | |
| 1840 | - 'post_date' => 'DESC', | |
| 1841 | - 'ID' => 'DESC' | |
| 1842 | - ), | |
| 1685 | + $query = new WP_Query( array( | |
| 1686 | + 'fields' => 'ids', | |
| 1687 | + 'post_parent' => $parent_id, | |
| 1688 | + 'post_status' => $post_status, | |
| 1689 | + 'post_type' => $post_type, | |
| 1690 | + 'posts_per_page' => 1, | |
| 1691 | + 'orderby' => array( | |
| 1692 | + 'post_date' => 'DESC', | |
| 1693 | + 'ID' => 'DESC' | |
| 1694 | + ), | |
| 1843 | 1695 | |
| 1844 | - // Performance | |
| 1845 | - 'suppress_filters' => true, | |
| 1846 | - 'update_post_term_cache' => false, | |
| 1847 | - 'update_post_meta_cache' => false, | |
| 1848 | - 'ignore_sticky_posts' => true, | |
| 1849 | - 'no_found_rows' => true | |
| 1850 | - ) | |
| 1851 | - ); | |
| 1696 | + // Performance | |
| 1697 | + 'suppress_filters' => true, | |
| 1698 | + 'update_post_term_cache' => false, | |
| 1699 | + 'update_post_meta_cache' => false, | |
| 1700 | + 'ignore_sticky_posts' => true, | |
| 1701 | + 'no_found_rows' => true | |
| 1702 | + ) ); | |
| 1852 | 1703 | $child_id = array_shift( $query->posts ); |
| 1853 | 1704 | unset( $query ); |
| 1854 | 1705 | |
| 1855 | 1706 | // Filter & return |
| @@ -1856,9 +1707,9 @@ | ||
| 1856 | 1707 | return (int) apply_filters( 'bbp_get_public_child_last_id', $child_id, $parent_id, $post_type ); |
| 1857 | 1708 | } |
| 1858 | 1709 | |
| 1859 | 1710 | /** |
| 1860 | - * Query the database for child counts, grouped by type & status. | |
| 1711 | + * Query the database for child counts, grouped by type & status | |
| 1861 | 1712 | * |
| 1862 | 1713 | * @since 2.6.0 bbPress (r6826) |
| 1863 | 1714 | * |
| 1864 | 1715 | * @param int $parent_id |
| @@ -1866,16 +1717,9 @@ | ||
| 1866 | 1717 | function bbp_get_child_counts( $parent_id = 0 ) { |
| 1867 | 1718 | |
| 1868 | 1719 | // Create cache key |
| 1869 | 1720 | $parent_id = absint( $parent_id ); |
| 1870 | - $key = md5( | |
| 1871 | - serialize( | |
| 1872 | - array( | |
| 1873 | - 'parent_id' => $parent_id, | |
| 1874 | - 'post_type' => bbp_get_post_types() | |
| 1875 | - ) | |
| 1876 | - ) | |
| 1877 | - ); | |
| 1721 | + $key = md5( serialize( array( 'parent_id' => $parent_id, 'post_type' => bbp_get_post_types() ) ) ); | |
| 1878 | 1722 | $last_changed = wp_cache_get_last_changed( 'bbpress_posts' ); |
| 1879 | 1723 | $cache_key = "bbp_child_counts:{$key}:{$last_changed}"; |
| 1880 | 1724 | |
| 1881 | 1725 | // Check for cache and set if needed |
| @@ -1927,15 +1771,15 @@ | ||
| 1927 | 1771 | return (array) apply_filters( 'bbp_get_child_counts', $retval, $parent_id ); |
| 1928 | 1772 | } |
| 1929 | 1773 | |
| 1930 | 1774 | /** |
| 1931 | - * Filter a list of child counts, from `bbp_get_child_counts()`. | |
| 1775 | + * Filter a list of child counts, from `bbp_get_child_counts()` | |
| 1932 | 1776 | * |
| 1933 | 1777 | * @since 2.6.0 bbPress (r6826) |
| 1934 | 1778 | * |
| 1935 | - * @param int $parent_id ID of post to get child counts from. | |
| 1936 | - * @param array $types Optional. An array of post types to filter by. | |
| 1937 | - * @param array $statuses Optional. An array of post statuses to filter by. | |
| 1779 | + * @param int $parent_id ID of post to get child counts from | |
| 1780 | + * @param array $types Optional. An array of post types to filter by | |
| 1781 | + * @param array $statuses Optional. An array of post statuses to filter by | |
| 1938 | 1782 | * |
| 1939 | 1783 | * @return array A list of objects or object fields. |
| 1940 | 1784 | */ |
| 1941 | 1785 | function bbp_filter_child_counts_list( $parent_id = 0, $types = array( 'post' ), $statuses = array() ) { |
| @@ -1967,9 +1811,9 @@ | ||
| 1967 | 1811 | return (array) apply_filters( 'bbp_filter_child_counts_list', $retval, $parent_id, $types, $statuses ); |
| 1968 | 1812 | } |
| 1969 | 1813 | |
| 1970 | 1814 | /** |
| 1971 | - * Query the DB and get a count of public children. | |
| 1815 | + * Query the DB and get a count of public children | |
| 1972 | 1816 | * |
| 1973 | 1817 | * @since 2.0.0 bbPress (r2868) |
| 1974 | 1818 | * @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects |
| 1975 | 1819 | * |
| @@ -1974,9 +1818,9 @@ | ||
| 1974 | 1818 | * @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects |
| 1975 | 1819 | * |
| 1976 | 1820 | * @param int $parent_id Parent id. |
| 1977 | 1821 | * @param string $post_type Post type. Defaults to 'post'. |
| 1978 | - * @return int The number of children. | |
| 1822 | + * @return int The number of children | |
| 1979 | 1823 | */ |
| 1980 | 1824 | function bbp_get_public_child_count( $parent_id = 0, $post_type = 'post' ) { |
| 1981 | 1825 | |
| 1982 | 1826 | // Bail if nothing passed |
| @@ -2013,16 +1857,16 @@ | ||
| 2013 | 1857 | // Filter & return |
| 2014 | 1858 | return (int) apply_filters( 'bbp_get_public_child_count', $child_count, $parent_id, $post_type ); |
| 2015 | 1859 | } |
| 2016 | 1860 | /** |
| 2017 | - * Query the DB and get a count of public children. | |
| 1861 | + * Query the DB and get a count of public children | |
| 2018 | 1862 | * |
| 2019 | 1863 | * @since 2.0.0 bbPress (r2868) |
| 2020 | - * @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects. | |
| 1864 | + * @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects | |
| 2021 | 1865 | * |
| 2022 | 1866 | * @param int $parent_id Parent id. |
| 2023 | 1867 | * @param string $post_type Post type. Defaults to 'post'. |
| 2024 | - * @return int The number of children. | |
| 1868 | + * @return int The number of children | |
| 2025 | 1869 | */ |
| 2026 | 1870 | function bbp_get_non_public_child_count( $parent_id = 0, $post_type = 'post' ) { |
| 2027 | 1871 | |
| 2028 | 1872 | // Bail if nothing passed |
| @@ -2064,9 +1908,9 @@ | ||
| 2064 | 1908 | return (int) apply_filters( 'bbp_get_non_public_child_count', $child_count, $parent_id, $post_type ); |
| 2065 | 1909 | } |
| 2066 | 1910 | |
| 2067 | 1911 | /** |
| 2068 | - * Query the DB and get the child id's of public children. | |
| 1912 | + * Query the DB and get the child id's of public children | |
| 2069 | 1913 | * |
| 2070 | 1914 | * @since 2.0.0 bbPress (r2868) |
| 2071 | 1915 | * @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects |
| 2072 | 1916 | * |
| @@ -2072,9 +1916,9 @@ | ||
| 2072 | 1916 | * |
| 2073 | 1917 | * @param int $parent_id Parent id. |
| 2074 | 1918 | * @param string $post_type Post type. Defaults to 'post'. |
| 2075 | 1919 | * |
| 2076 | - * @return array The array of children. | |
| 1920 | + * @return array The array of children | |
| 2077 | 1921 | */ |
| 2078 | 1922 | function bbp_get_public_child_ids( $parent_id = 0, $post_type = 'post' ) { |
| 2079 | 1923 | |
| 2080 | 1924 | // Bail if nothing passed |
| @@ -2101,29 +1945,27 @@ | ||
| 2101 | 1945 | $post_status = bbp_get_public_reply_statuses(); |
| 2102 | 1946 | break; |
| 2103 | 1947 | } |
| 2104 | 1948 | |
| 2105 | - $query = new WP_Query( | |
| 2106 | - array( | |
| 2107 | - 'fields' => 'ids', | |
| 2108 | - 'post_parent' => $parent_id, | |
| 2109 | - 'post_status' => $post_status, | |
| 2110 | - 'post_type' => $post_type, | |
| 2111 | - 'posts_per_page' => -1, | |
| 2112 | - 'orderby' => array( | |
| 2113 | - 'post_date' => 'DESC', | |
| 2114 | - 'ID' => 'DESC' | |
| 2115 | - ), | |
| 1949 | + $query = new WP_Query( array( | |
| 1950 | + 'fields' => 'ids', | |
| 1951 | + 'post_parent' => $parent_id, | |
| 1952 | + 'post_status' => $post_status, | |
| 1953 | + 'post_type' => $post_type, | |
| 1954 | + 'posts_per_page' => -1, | |
| 1955 | + 'orderby' => array( | |
| 1956 | + 'post_date' => 'DESC', | |
| 1957 | + 'ID' => 'DESC' | |
| 1958 | + ), | |
| 2116 | 1959 | |
| 2117 | - // Performance | |
| 2118 | - 'nopaging' => true, | |
| 2119 | - 'suppress_filters' => true, | |
| 2120 | - 'update_post_term_cache' => false, | |
| 2121 | - 'update_post_meta_cache' => false, | |
| 2122 | - 'ignore_sticky_posts' => true, | |
| 2123 | - 'no_found_rows' => true | |
| 2124 | - ) | |
| 2125 | - ); | |
| 1960 | + // Performance | |
| 1961 | + 'nopaging' => true, | |
| 1962 | + 'suppress_filters' => true, | |
| 1963 | + 'update_post_term_cache' => false, | |
| 1964 | + 'update_post_meta_cache' => false, | |
| 1965 | + 'ignore_sticky_posts' => true, | |
| 1966 | + 'no_found_rows' => true | |
| 1967 | + ) ); | |
| 2126 | 1968 | |
| 2127 | 1969 | $child_ids = ! empty( $query->posts ) |
| 2128 | 1970 | ? $query->posts |
| 2129 | 1971 | : array(); |
| @@ -2134,16 +1976,16 @@ | ||
| 2134 | 1976 | return (array) apply_filters( 'bbp_get_public_child_ids', $child_ids, $parent_id, $post_type ); |
| 2135 | 1977 | } |
| 2136 | 1978 | |
| 2137 | 1979 | /** |
| 2138 | - * Query the DB and get the child id's of all children. | |
| 1980 | + * Query the DB and get the child id's of all children | |
| 2139 | 1981 | * |
| 2140 | 1982 | * @since 2.0.0 bbPress (r3325) |
| 2141 | 1983 | * |
| 2142 | - * @param int $parent_id Parent id. | |
| 2143 | - * @param string $post_type Post type. Defaults to 'post'. | |
| 1984 | + * @param int $parent_id Parent id | |
| 1985 | + * @param string $post_type Post type. Defaults to 'post' | |
| 2144 | 1986 | * |
| 2145 | - * @return array The array of children. | |
| 1987 | + * @return array The array of children | |
| 2146 | 1988 | */ |
| 2147 | 1989 | function bbp_get_all_child_ids( $parent_id = 0, $post_type = 'post' ) { |
| 2148 | 1990 | |
| 2149 | 1991 | // Bail if nothing passed |
| @@ -2152,17 +1994,13 @@ | ||
| 2152 | 1994 | } |
| 2153 | 1995 | |
| 2154 | 1996 | // Make cache key |
| 2155 | 1997 | $not_in = array( 'draft', 'future' ); |
| 2156 | - $key = md5( | |
| 2157 | - serialize( | |
| 2158 | - array( | |
| 2159 | - 'parent_id' => $parent_id, | |
| 2160 | - 'post_type' => $post_type, | |
| 2161 | - 'post_status' => $not_in | |
| 2162 | - ) | |
| 2163 | - ) | |
| 2164 | - ); | |
| 1998 | + $key = md5( serialize( array( | |
| 1999 | + 'parent_id' => $parent_id, | |
| 2000 | + 'post_type' => $post_type, | |
| 2001 | + 'post_status' => $not_in | |
| 2002 | + ) ) ); | |
| 2165 | 2003 | |
| 2166 | 2004 | // Check last changed |
| 2167 | 2005 | $last_changed = wp_cache_get_last_changed( 'bbpress_posts' ); |
| 2168 | 2006 | $cache_key = "bbp_child_ids:{$key}:{$last_changed}"; |
| @@ -2204,11 +2042,11 @@ | ||
| 2204 | 2042 | * Also see: bbp_update_post_author_caches() |
| 2205 | 2043 | * |
| 2206 | 2044 | * @since 2.6.0 bbPress (r6699) |
| 2207 | 2045 | * |
| 2208 | - * @param array $objects Array of objects, fresh from a query. | |
| 2046 | + * @param array $objects Array of objects, fresh from a query | |
| 2209 | 2047 | * |
| 2210 | - * @return bool True if some IDs were cached. | |
| 2048 | + * @return bool True if some IDs were cached | |
| 2211 | 2049 | */ |
| 2212 | 2050 | function bbp_update_post_family_caches( $objects = array() ) { |
| 2213 | 2051 | |
| 2214 | 2052 | // Bail if no posts |
| @@ -2219,18 +2057,14 @@ | ||
| 2219 | 2057 | // Default value |
| 2220 | 2058 | $post_ids = array(); |
| 2221 | 2059 | |
| 2222 | 2060 | // Filter the types of IDs to prime |
| 2223 | - $ids = apply_filters( | |
| 2224 | - 'bbp_update_post_family_caches', | |
| 2225 | - array( | |
| 2226 | - '_bbp_last_active_id', | |
| 2227 | - '_bbp_last_reply_id', | |
| 2228 | - '_bbp_last_topic_id', | |
| 2229 | - '_bbp_reply_to' | |
| 2230 | - ), | |
| 2231 | - $objects | |
| 2232 | - ); | |
| 2061 | + $ids = apply_filters( 'bbp_update_post_family_caches', array( | |
| 2062 | + '_bbp_last_active_id', | |
| 2063 | + '_bbp_last_reply_id', | |
| 2064 | + '_bbp_last_topic_id', | |
| 2065 | + '_bbp_reply_to' | |
| 2066 | + ), $objects ); | |
| 2233 | 2067 | |
| 2234 | 2068 | // Get the last active IDs |
| 2235 | 2069 | foreach ( $objects as $object ) { |
| 2236 | 2070 | $object = get_post( $object ); |
| @@ -2277,11 +2111,11 @@ | ||
| 2277 | 2111 | * This is triggered when a `update_post_author_cache` argument is set to true. |
| 2278 | 2112 | * |
| 2279 | 2113 | * @since 2.6.0 bbPress (r6699) |
| 2280 | 2114 | * |
| 2281 | - * @param array $objects Array of objects, fresh from a query. | |
| 2115 | + * @param array $objects Array of objects, fresh from a query | |
| 2282 | 2116 | * |
| 2283 | - * @return bool True if some IDs were cached. | |
| 2117 | + * @return bool True if some IDs were cached | |
| 2284 | 2118 | */ |
| 2285 | 2119 | function bbp_update_post_author_caches( $objects = array() ) { |
| 2286 | 2120 | |
| 2287 | 2121 | // Bail if no posts |
| @@ -2322,17 +2156,17 @@ | ||
| 2322 | 2156 | |
| 2323 | 2157 | /** Globals *******************************************************************/ |
| 2324 | 2158 | |
| 2325 | 2159 | /** |
| 2326 | - * Get the unfiltered value of a global $post's key. | |
| 2160 | + * Get the unfiltered value of a global $post's key | |
| 2327 | 2161 | * |
| 2328 | - * Used most frequently when editing a forum/topic/reply. | |
| 2162 | + * Used most frequently when editing a forum/topic/reply | |
| 2329 | 2163 | * |
| 2330 | 2164 | * @since 2.1.0 bbPress (r3694) |
| 2331 | 2165 | * |
| 2332 | - * @param string $field Name of the key. | |
| 2333 | - * @param string $context How to sanitize - raw|edit|db|display|attribute|js. | |
| 2334 | - * @return string Field value. | |
| 2166 | + * @param string $field Name of the key | |
| 2167 | + * @param string $context How to sanitize - raw|edit|db|display|attribute|js | |
| 2168 | + * @return string Field value | |
| 2335 | 2169 | */ |
| 2336 | 2170 | function bbp_get_global_post_field( $field = 'ID', $context = 'edit' ) { |
| 2337 | 2171 | |
| 2338 | 2172 | // Get the post, and maybe get a field from it |
| @@ -2353,10 +2187,10 @@ | ||
| 2353 | 2187 | * To avoid security exploits within the theme. |
| 2354 | 2188 | * |
| 2355 | 2189 | * @since 2.1.0 bbPress (r4022) |
| 2356 | 2190 | * |
| 2357 | - * @param string $action Action nonce. | |
| 2358 | - * @param string $query_arg where to look for nonce in $_REQUEST. | |
| 2191 | + * @param string $action Action nonce | |
| 2192 | + * @param string $query_arg where to look for nonce in $_REQUEST | |
| 2359 | 2193 | */ |
| 2360 | 2194 | function bbp_verify_nonce_request( $action = '', $query_arg = '_wpnonce' ) { |
| 2361 | 2195 | |
| 2362 | 2196 | /** Home URL **************************************************************/ |
| @@ -2362,9 +2196,9 @@ | ||
| 2362 | 2196 | /** Home URL **************************************************************/ |
| 2363 | 2197 | |
| 2364 | 2198 | // Parse home_url() into pieces to remove query-strings, strange characters, |
| 2365 | 2199 | // and other funny things that plugins might to do to it. |
| 2366 | - $parsed_home = wp_parse_url( home_url( '/', ( is_ssl() ? 'https' : 'http' ) ) ); | |
| 2200 | + $parsed_home = parse_url( home_url( '/', ( is_ssl() ? 'https' : 'http' ) ) ); | |
| 2367 | 2201 | |
| 2368 | 2202 | // Maybe include the port, if it's included |
| 2369 | 2203 | if ( isset( $parsed_home['port'] ) ) { |
| 2370 | 2204 | $parsed_host = $parsed_home['host'] . ':' . $parsed_home['port']; |
| @@ -2497,28 +2331,20 @@ | ||
| 2497 | 2331 | // Single forum |
| 2498 | 2332 | if ( ! empty( $select_query_vars ) ) { |
| 2499 | 2333 | |
| 2500 | 2334 | // Load up our own query |
| 2501 | - // phpcs:ignore WordPress.WP.DiscouragedFunctions.query_posts_query_posts | |
| 2502 | - query_posts( | |
| 2503 | - array_merge( | |
| 2504 | - array( | |
| 2505 | - 'post_type' => bbp_get_forum_post_type(), | |
| 2506 | - 'feed' => true | |
| 2507 | - ), | |
| 2508 | - $select_query_vars | |
| 2509 | - ) | |
| 2510 | - ); | |
| 2335 | + query_posts( array_merge( array( | |
| 2336 | + 'post_type' => bbp_get_forum_post_type(), | |
| 2337 | + 'feed' => true | |
| 2338 | + ), $select_query_vars ) ); | |
| 2511 | 2339 | |
| 2512 | 2340 | // Restrict to specific forum ID |
| 2513 | - $meta_query = array( | |
| 2514 | - array( | |
| 2515 | - 'key' => '_bbp_forum_id', | |
| 2516 | - 'value' => bbp_get_forum_id(), | |
| 2517 | - 'type' => 'NUMERIC', | |
| 2518 | - 'compare' => '=' | |
| 2519 | - ) | |
| 2520 | - ); | |
| 2341 | + $meta_query = array( array( | |
| 2342 | + 'key' => '_bbp_forum_id', | |
| 2343 | + 'value' => bbp_get_forum_id(), | |
| 2344 | + 'type' => 'NUMERIC', | |
| 2345 | + 'compare' => '=' | |
| 2346 | + ) ); | |
| 2521 | 2347 | } |
| 2522 | 2348 | |
| 2523 | 2349 | // Only forum replies |
| 2524 | 2350 | if ( ! empty( $_GET['type'] ) && ( bbp_get_reply_post_type() === $_GET['type'] ) ) { |
| @@ -2587,18 +2413,12 @@ | ||
| 2587 | 2413 | // Single topic |
| 2588 | 2414 | if ( ! empty( $select_query_vars ) ) { |
| 2589 | 2415 | |
| 2590 | 2416 | // Load up our own query |
| 2591 | - // phpcs:ignore WordPress.WP.DiscouragedFunctions.query_posts_query_posts | |
| 2592 | - query_posts( | |
| 2593 | - array_merge( | |
| 2594 | - array( | |
| 2595 | - 'post_type' => bbp_get_topic_post_type(), | |
| 2596 | - 'feed' => true | |
| 2597 | - ), | |
| 2598 | - $select_query_vars | |
| 2599 | - ) | |
| 2600 | - ); | |
| 2417 | + query_posts( array_merge( array( | |
| 2418 | + 'post_type' => bbp_get_topic_post_type(), | |
| 2419 | + 'feed' => true | |
| 2420 | + ), $select_query_vars ) ); | |
| 2601 | 2421 | |
| 2602 | 2422 | // Output the feed |
| 2603 | 2423 | bbp_display_replies_feed_rss2( array( 'feed' => true ) ); |
| 2604 | 2424 | |
| @@ -2625,9 +2445,9 @@ | ||
| 2625 | 2445 | |
| 2626 | 2446 | // The query |
| 2627 | 2447 | $the_query = array( |
| 2628 | 2448 | 'posts_per_page' => bbp_get_replies_per_rss_page(), |
| 2629 | - 'meta_query' => array( array() ), | |
| 2449 | + 'meta_query' => array( array( ) ), | |
| 2630 | 2450 | 'feed' => true |
| 2631 | 2451 | ); |
| 2632 | 2452 | |
| 2633 | 2453 | // All replies |
| @@ -2650,12 +2470,10 @@ | ||
| 2650 | 2470 | |
| 2651 | 2471 | // Get the view query |
| 2652 | 2472 | $the_query = bbp_get_view_query_args( $view ); |
| 2653 | 2473 | |
| 2654 | - // Output the feed if view exists | |
| 2655 | - if ( ! empty( $the_query ) ) { | |
| 2656 | - bbp_display_topics_feed_rss2( $the_query ); | |
| 2657 | - } | |
| 2474 | + // Output the feed | |
| 2475 | + bbp_display_topics_feed_rss2( $the_query ); | |
| 2658 | 2476 | } |
| 2659 | 2477 | } |
| 2660 | 2478 | |
| 2661 | 2479 | // @todo User profile feeds |
| @@ -2667,14 +2485,14 @@ | ||
| 2667 | 2485 | |
| 2668 | 2486 | /** Templates ******************************************************************/ |
| 2669 | 2487 | |
| 2670 | 2488 | /** |
| 2671 | - * Used to guess if page exists at requested path. | |
| 2489 | + * Used to guess if page exists at requested path | |
| 2672 | 2490 | * |
| 2673 | 2491 | * @since 2.0.0 bbPress (r3304) |
| 2674 | 2492 | * |
| 2675 | 2493 | * @param string $path |
| 2676 | - * @return mixed False if no page, Page object if true. | |
| 2494 | + * @return mixed False if no page, Page object if true | |
| 2677 | 2495 | */ |
| 2678 | 2496 | function bbp_get_page_by_path( $path = '' ) { |
| 2679 | 2497 | |
| 2680 | 2498 | // Default to false |
| @@ -2700,11 +2518,11 @@ | ||
| 2700 | 2518 | * |
| 2701 | 2519 | * @since 2.0.0 bbPress (r3051) |
| 2702 | 2520 | * @since 2.6.0 bbPress (r6583) Use status_header() & nocache_headers() |
| 2703 | 2521 | * |
| 2704 | - * @param WP_Query $query The query being checked. | |
| 2522 | + * @param WP_Query $query The query being checked | |
| 2705 | 2523 | * |
| 2706 | - * @return bool Always returns true. | |
| 2524 | + * @return bool Always returns true | |
| 2707 | 2525 | */ |
| 2708 | 2526 | function bbp_set_404( $query = null ) { |
| 2709 | 2527 | |
| 2710 | 2528 | // Global fallback |
| @@ -2729,9 +2547,9 @@ | ||
| 2729 | 2547 | status_header( 200 ); |
| 2730 | 2548 | } |
| 2731 | 2549 | |
| 2732 | 2550 | /** |
| 2733 | - * Maybe handle the default 404 handling for some bbPress conditions. | |
| 2551 | + * Maybe handle the default 404 handling for some bbPress conditions | |
| 2734 | 2552 | * |
| 2735 | 2553 | * Some conditions (like private/hidden forums and edits) have their own checks |
| 2736 | 2554 | * on `bbp_template_redirect` and are not currently 404s. |
| 2737 | 2555 | * |
| @@ -2736,12 +2554,12 @@ | ||
| 2736 | 2554 | * on `bbp_template_redirect` and are not currently 404s. |
| 2737 | 2555 | * |
| 2738 | 2556 | * @since 2.6.0 bbPress (r6555) |
| 2739 | 2557 | * |
| 2740 | - * @param bool $override Whether to override the default handler. | |
| 2741 | - * @param WP_Query $wp_query The posts query being referenced. | |
| 2558 | + * @param bool $override Whether to override the default handler | |
| 2559 | + * @param WP_Query $wp_query The posts query being referenced | |
| 2742 | 2560 | * |
| 2743 | - * @return bool False to leave alone, true to override. | |
| 2561 | + * @return bool False to leave alone, true to override | |
| 2744 | 2562 | */ |
| 2745 | 2563 | function bbp_pre_handle_404( $override = false, $wp_query = false ) { |
| 2746 | 2564 | |
| 2747 | 2565 | // Handle a bbPress 404 condition |
| @@ -2747,16 +2565,11 @@ | ||
| 2747 | 2565 | // Handle a bbPress 404 condition |
| 2748 | 2566 | if ( isset( $wp_query->bbp_is_404 ) ) { |
| 2749 | 2567 | |
| 2750 | 2568 | // Either force a 404 when 200, or a 200 when 404 |
| 2751 | - if ( true === $wp_query->bbp_is_404 ) { | |
| 2752 | - bbp_set_404( $wp_query ); | |
| 2753 | - } else { | |
| 2754 | - bbp_set_200(); | |
| 2755 | - } | |
| 2756 | - | |
| 2757 | - // Overridden | |
| 2758 | - $override = true; | |
| 2569 | + $override = ( true === $wp_query->bbp_is_404 ) | |
| 2570 | + ? bbp_set_404( $wp_query ) | |
| 2571 | + : bbp_set_200(); | |
| 2759 | 2572 | } |
| 2760 | 2573 | |
| 2761 | 2574 | // Return, maybe overridden |
| 2762 | 2575 | return $override; |
| @@ -2769,9 +2582,9 @@ | ||
| 2769 | 2582 | * currently only used to avoid calling the main query when it's not necessary. |
| 2770 | 2583 | * |
| 2771 | 2584 | * @since 2.6.0 bbPress (r6580) |
| 2772 | 2585 | * |
| 2773 | - * @param mixed $posts Default null. Array of posts (possibly empty). | |
| 2586 | + * @param mixed $posts Default null. Array of posts (possibly empty) | |
| 2774 | 2587 | * @param WP_Query $wp_query |
| 2775 | 2588 | * |
| 2776 | 2589 | * @return mixed Null if no override. Array if overridden. |
| 2777 | 2590 | */ |
| @@ -2803,12 +2616,10 @@ | ||
| 2803 | 2616 | |
| 2804 | 2617 | /** |
| 2805 | 2618 | * Is a title longer that the maximum title length? |
| 2806 | 2619 | * |
| 2807 | - * Uses mb_strlen() in `utf-8` mode to treat strings as is. This differs from | |
| 2808 | - * the behavior present in Comments, PHPMailer, RandomCompat, and others, | |
| 2809 | - * because the database column used by titles (posts.post_title) is | |
| 2810 | - * TEXT (characters) and not VARCHAR (bytes). | |
| 2620 | + * Uses mb_strlen() in `8bit` mode to treat strings as raw. This matches the | |
| 2621 | + * behavior present in Comments, PHPMailer, RandomCompat, and others. | |
| 2811 | 2622 | * |
| 2812 | 2623 | * @since 2.6.0 bbPress (r6783) |
| 2813 | 2624 | * |
| 2814 | 2625 | * @param string $title |
| @@ -2815,9 +2626,9 @@ | ||
| 2815 | 2626 | * @return bool |
| 2816 | 2627 | */ |
| 2817 | 2628 | function bbp_is_title_too_long( $title = '' ) { |
| 2818 | 2629 | $max = bbp_get_title_max_length(); |
| 2819 | - $len = mb_strlen( $title, 'utf-8' ); | |
| 2630 | + $len = mb_strlen( $title, '8bit' ); | |
| 2820 | 2631 | $result = ( $len > $max ); |
| 2821 | 2632 | |
| 2822 | 2633 | // Filter & return |
| 2823 | 2634 | return (bool) apply_filters( 'bbp_is_title_too_long', $result, $title, $max, $len ); |