Changeset 6529
- Timestamp:
- 06/12/2017 05:41:49 PM (8 years ago)
- Location:
- trunk/src/includes
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/common/functions.php
r6497 r6529 78 78 79 79 /** 80 * If current user can and is v ewing all topics/replies80 * If current user can and is viewing all topics/replies 81 81 * 82 82 * @since 2.0.0 bbPress (r3325) -
trunk/src/includes/core/actions.php
r6369 r6529 155 155 156 156 // Before Delete/Trash/Untrash Forum 157 add_action( 'wp_trash_post', 'bbp_trash_forum' );158 add_action( 'trash_post', 'bbp_trash_forum' );159 add_action( 'untrash_post', 'bbp_untrash_forum' );160 add_action( ' delete_post','bbp_delete_forum' );157 add_action( 'wp_trash_post', 'bbp_trash_forum' ); 158 add_action( 'trash_post', 'bbp_trash_forum' ); 159 add_action( 'untrash_post', 'bbp_untrash_forum' ); 160 add_action( 'before_delete_post', 'bbp_delete_forum' ); 161 161 162 162 // After Deleted/Trashed/Untrashed Forum … … 184 184 185 185 // Before Delete/Trash/Untrash Reply 186 add_action( 'wp_trash_post', 'bbp_trash_reply' );187 add_action( 'trash_post', 'bbp_trash_reply' );188 add_action( 'untrash_post', 'bbp_untrash_reply' );189 add_action( ' delete_post','bbp_delete_reply' );186 add_action( 'wp_trash_post', 'bbp_trash_reply' ); 187 add_action( 'trash_post', 'bbp_trash_reply' ); 188 add_action( 'untrash_post', 'bbp_untrash_reply' ); 189 add_action( 'before_delete_post', 'bbp_delete_reply' ); 190 190 191 191 // After Deleted/Trashed/Untrashed Reply … … 206 206 207 207 // Before Delete/Trash/Untrash Topic 208 add_action( 'wp_trash_post', 'bbp_trash_topic' );209 add_action( 'trash_post', 'bbp_trash_topic' );210 add_action( 'untrash_post', 'bbp_untrash_topic' );211 add_action( ' delete_post','bbp_delete_topic' );208 add_action( 'wp_trash_post', 'bbp_trash_topic' ); 209 add_action( 'trash_post', 'bbp_trash_topic' ); 210 add_action( 'untrash_post', 'bbp_untrash_topic' ); 211 add_action( 'before_delete_post', 'bbp_delete_topic' ); 212 212 213 213 // After Deleted/Trashed/Untrashed Topic … … 293 293 add_action( 'bbp_unapproved_reply', 'bbp_decrease_topic_reply_count' ); 294 294 add_action( 'bbp_unapproved_reply', 'bbp_increase_topic_reply_count_hidden' ); 295 add_action( 'bbp_deleted_reply', 'bbp_decrease_topic_reply_count_hidden' ); 295 296 296 297 // Users topic & reply counts. … … 310 311 add_action( 'bbp_insert_reply', 'bbp_insert_reply_update_counts', 10, 3 ); 311 312 312 // Update topic voice counts. 313 // Update engagements. 314 add_action( 'bbp_new_topic', 'bbp_update_topic_engagements' ); 315 add_action( 'bbp_new_reply', 'bbp_update_topic_engagements' ); 316 317 // Recalculate engagements. 318 add_action( 'bbp_deleted_topic', 'bbp_recalculate_topic_engagements' ); 319 add_action( 'bbp_deleted_reply', 'bbp_recalculate_topic_engagements' ); 320 321 // Update engagement counts. 313 322 add_action( 'bbp_new_reply', 'bbp_update_topic_voice_count' ); 314 323 add_action( 'bbp_trashed_reply', 'bbp_update_topic_voice_count' ); … … 318 327 add_action( 'bbp_approved_reply', 'bbp_update_topic_voice_count' ); 319 328 add_action( 'bbp_unapproved_reply', 'bbp_update_topic_voice_count' ); 329 add_action( 'bbp_deleted_reply', 'bbp_update_topic_voice_count' ); 320 330 321 331 // Insert reply voice counts. -
trunk/src/includes/forums/functions.php
r6499 r6529 1990 1990 1991 1991 // Only update topic count if we're deleting a topic, or in the dashboard. 1992 if ( in_array( current_filter(), array( 'bbp_delete d_topic', 'save_post' ), true ) ) {1992 if ( in_array( current_filter(), array( 'bbp_delete_topic', 'save_post' ), true ) ) { 1993 1993 bbp_update_forum_reply_count( $r['forum_id'] ); 1994 1994 bbp_update_forum_topic_count( $r['forum_id'] ); … … 2771 2771 * Called after deleting a forum 2772 2772 * 2773 * Try not to use this action. All meta & taxonomy terms have already been 2774 * deleted, making them impossible to use. 2775 * 2773 2776 * @since 2.1.0 bbPress (r3668) 2777 * @since 2.6.0 bbPress (r6526) Not recommend for usage 2774 2778 * 2775 2779 * @uses bbp_get_forum_id() To get the forum id -
trunk/src/includes/replies/functions.php
r6526 r6529 964 964 if ( empty( $topic_id ) ) { 965 965 $topic_id = bbp_get_reply_topic_id( $reply_id ); 966 967 // Make every effort to get topic id968 // https://bbpress.trac.wordpress.org/ticket/2529969 if ( empty( $topic_id ) && ( current_filter() === 'bbp_deleted_reply' ) ) {970 $topic_id = get_post_field( 'post_parent', $reply_id );971 }972 966 } 973 967 … … 2065 2059 * Called after deleting a reply 2066 2060 * 2061 * @since 2.0.0 bbPress (r2993) 2062 * 2067 2063 * @uses bbp_get_reply_id() To get the reply id 2068 2064 * @uses bbp_is_reply() To check if the passed id is a reply … … 2082 2078 * Called after trashing a reply 2083 2079 * 2080 * @since 2.0.0 bbPress (r2993) 2081 * 2084 2082 * @uses bbp_get_reply_id() To get the reply id 2085 2083 * @uses bbp_is_reply() To check if the passed id is a reply … … 2098 2096 /** 2099 2097 * Called after untrashing (restoring) a reply 2098 * 2099 * @since 2.0.0 bbPress (r2993) 2100 2100 * 2101 2101 * @uses bbp_get_reply_id() To get the reply id -
trunk/src/includes/topics/functions.php
r6516 r6529 944 944 if ( empty( $forum_id ) ) { 945 945 $forum_id = bbp_get_topic_forum_id( $topic_id ); 946 947 // Make every effort to get forum id948 // https://bbpress.trac.wordpress.org/ticket/2529949 if ( empty( $forum_id ) && ( current_filter() === 'bbp_deleted_topic' ) ) {950 $forum_id = get_post_field( 'post_parent', $topic_id );951 }952 946 } 953 947 … … 2983 2977 function bbp_update_topic_voice_count( $topic_id = 0 ) { 2984 2978 2985 // Get the old voices 2979 // If it's a reply, then get the parent (topic id) 2980 $topic_id = bbp_is_reply( $topic_id ) 2981 ? bbp_get_reply_topic_id( $topic_id ) 2982 : bbp_get_topic_id( $topic_id ); 2983 2984 // Bail if no topic ID 2985 if ( empty( $topic_id ) ) { 2986 return; 2987 } 2988 2989 // Count the engagements 2986 2990 $count = count( bbp_get_topic_engagements( $topic_id ) ); 2987 2991 … … 3874 3878 * Called after deleting a topic 3875 3879 * 3880 * @since 2.0.0 bbPress (r2993) 3881 * 3876 3882 * @uses bbp_get_topic_id() To get the topic id 3877 3883 * @uses bbp_is_topic() To check if the passed id is a topic … … 3891 3897 * Called after trashing a topic 3892 3898 * 3899 * @since 2.0.0 bbPress (r2993) 3900 * 3893 3901 * @uses bbp_get_topic_id() To get the topic id 3894 3902 * @uses bbp_is_topic() To check if the passed id is a topic … … 3907 3915 /** 3908 3916 * Called after untrashing a topic 3917 * 3918 * @since 2.0.0 bbPress (r2993) 3909 3919 * 3910 3920 * @uses bbp_get_topic_id() To get the topic id -
trunk/src/includes/users/engagements.php
r6525 r6529 22 22 * @param string $meta_key The relationship key 23 23 * @param string $meta_type The relationship type (usually 'post') 24 * @param bool $unique Whether meta datashould be unique to the object24 * @param bool $unique Whether meta key should be unique to the object 25 25 * 26 26 * @uses add_metadata() To add the user to an object … … 28 28 * @return bool Returns true on success, false on failure 29 29 */ 30 function bbp_add_user_to_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post', $unique = true ) {30 function bbp_add_user_to_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post', $unique = false ) { 31 31 $retval = add_metadata( $meta_type, $object_id, $meta_key, $user_id, $unique ); 32 32 … … 375 375 * Recalculate all of the users who have engaged in a topic. 376 376 * 377 * You may need to do this when deleting a reply 377 * This happens when permanently deleting a reply, because that reply author may 378 * have authored other replies to that same topic, or the topic itself. 379 * 380 * You may need to do this manually on heavily active forums where engagement 381 * count accuracy is important. 378 382 * 379 383 * @since 2.6.0 bbPress (r6522) 380 384 * 381 * @param int $topic_id 385 * @param int $topic_id 386 * @param bool $force 382 387 * 383 388 * @return boolean True if any engagements are added, false otherwise 384 389 */ 385 function bbp_recalculate_topic_engagements( $topic_id = 0 ) {390 function bbp_recalculate_topic_engagements( $topic_id = 0, $force = false ) { 386 391 387 392 // Default return value 388 393 $retval = false; 389 394 390 // Bail if not enough info 391 $topic_id = bbp_get_topic_id( $topic_id ); 395 // Check post type 396 $topic_id = bbp_is_reply( $topic_id ) 397 ? bbp_get_reply_topic_id( $topic_id ) 398 : bbp_get_topic_id( $topic_id ); 399 400 // Bail if no topic ID 392 401 if ( empty( $topic_id ) ) { 393 402 return $retval; … … 395 404 396 405 // Query for engagements 397 $engagements = bbp_get_topic_engagements_raw( $topic_id ); 398 399 // Delete all engagements 400 bbp_remove_all_users_from_object( $topic_id, '_bbp_engagement' ); 401 402 // Update the voice count for this topic id 403 foreach ( $engagements as $user_id ) { 404 $retval = bbp_add_user_engagement( $user_id, $topic_id ); 406 $old_engagements = bbp_get_topic_engagements( $topic_id ); 407 $new_engagements = bbp_get_topic_engagements_raw( $topic_id ); 408 409 // Sort arrays 410 sort( $old_engagements, SORT_NUMERIC ); 411 sort( $new_engagements, SORT_NUMERIC ); 412 413 // Only recalculate on change 414 if ( ( true === $force ) || ( $old_engagements !== $new_engagements ) ) { 415 416 // Delete all engagements 417 bbp_remove_all_users_from_object( $topic_id, '_bbp_engagement' ); 418 419 // Update the voice count for this topic id 420 foreach ( $new_engagements as $user_id ) { 421 $retval = bbp_add_user_engagement( $user_id, $topic_id ); 422 } 405 423 } 406 424 407 425 // Filter & return 408 426 return (bool) apply_filters( 'bbp_recalculate_user_engagements', $retval, $topic_id ); 427 } 428 429 /** 430 * Update the engagements of a topic. 431 * 432 * Hooked to 'bbp_new_topic' and 'bbp_new_reply', this gets the post author and 433 * if not anonymous, passes it into bbp_add_user_engagement(). 434 * 435 * @since 2.6.0 bbPress (r6526) 436 * 437 * @param int $topic_id 438 */ 439 function bbp_update_topic_engagements( $topic_id = 0 ) { 440 441 // Check post type 442 if ( bbp_is_reply( $topic_id ) ) { 443 $author_id = bbp_get_reply_author_id( $topic_id ); 444 $topic_id = bbp_get_reply_topic_id( $topic_id ); 445 } elseif ( bbp_is_topic( $topic_id ) ) { 446 $author_id = bbp_get_topic_author_id( $topic_id ); 447 $topic_id = bbp_get_topic_id( $topic_id ); 448 } else { 449 return; 450 } 451 452 // Return whether engagement was added 453 return bbp_add_user_engagement( $author_id, $topic_id ); 409 454 } 410 455
Note: See TracChangeset
for help on using the changeset viewer.