Ticket #3328: 3328.2.patch
| File 3328.2.patch, 16.0 KB (added by , 5 years ago) |
|---|
-
src/includes/common/functions.php
2633 2633 // Filter & return 2634 2634 return (bool) apply_filters( 'bbp_is_title_too_long', $result, $title, $max, $len ); 2635 2635 } 2636 2637 /** Revisions *****************************************************************/ 2638 2639 /** 2640 * Update a forum/topic/reply without creating a subsequent revision. 2641 * 2642 * This is particularly handy when toggling specific attributes (like statuses) 2643 * where you _do_ want all of the related hooks to fire but you _do not_ want to 2644 * generate a new revision when doing so. 2645 * 2646 * @since 2.6.7 bbPress (r7188) 2647 * 2648 * @param array $post 2649 * @return mixed 2650 */ 2651 function bbp_update_post_without_revision( $post = array() ) { 2652 2653 // Default return value 2654 $retval = false; 2655 2656 // Default post data 2657 $to_save = array(); 2658 2659 // Maybe cast to array 2660 if ( is_object( $post ) || is_array( $post ) ) { 2661 $to_save = (array) $post; 2662 } 2663 2664 // Bail if no "post_type" in array 2665 if ( ! empty( $to_save['post_type'] ) ) { 2666 2667 // Set a post type variable so code is cleaner below 2668 $post_type = $to_save['post_type']; 2669 2670 // Are revisions supported? 2671 $supported = post_type_supports( $post_type, 'revisions' ); 2672 2673 // Maybe remove revision support 2674 if ( true === $supported ) { 2675 remove_post_type_support( $post_type, 'revisions' ); 2676 } 2677 2678 // Update the post 2679 $retval = wp_update_post( $to_save ); 2680 2681 // Toggle revisions back on 2682 if ( true === $supported ) { 2683 add_post_type_support( $post_type, 'revisions' ); 2684 } 2685 } 2686 2687 // Filter & return 2688 return apply_filters( 'bbp_update_post_without_revision', $retval, $post ); 2689 } -
src/includes/core/template-functions.php
722 722 $posts_query->bbp_is_404 = false; 723 723 } 724 724 725 // We save post revisions on our own726 remove_action( 'pre_post_update', 'wp_save_post_revision' );727 728 725 // Topic tag page 729 726 } elseif ( bbp_is_topic_tag() ) { 730 727 $posts_query->set( 'bbp_topic_tag', get_query_var( 'term' ) ); -
src/includes/extend/buddypress/activity.php
211 211 */ 212 212 private function record_activity( $args = array() ) { 213 213 214 // Default activity args214 // Parse arguments 215 215 $activity = bbp_parse_args( $args, array( 216 'id' => null,216 'id' => false, 217 217 'user_id' => bbp_get_current_user_id(), 218 218 'type' => '', 219 219 'action' => '', … … 227 227 ), 'record_activity' ); 228 228 229 229 // Add the activity 230 return bp_activity_add( $activity ); 230 $activity_id = bp_activity_add( $activity ); 231 232 // Add the activity entry ID as a meta value to the topic 233 if ( ! empty( $activity_id ) && ! empty( $activity['item_id'] ) ) { 234 update_post_meta( $activity['item_id'], '_bbp_activity_id', $activity_id ); 235 } 236 237 // Return the activity ID 238 return $activity_id; 231 239 } 232 240 233 241 /** … … 235 243 * 236 244 * @since 2.0.0 bbPress (r3395) 237 245 * 238 * @param array $args Array of arguments for bp_activity_ add()246 * @param array $args Array of arguments for bp_activity_delete_by_item_id() 239 247 * 240 248 * @return int Activity ID if successful, false if not 241 249 */ 242 250 public function delete_activity( $args = array() ) { 243 251 244 // Default activity args252 // Parse arguments 245 253 $activity = bbp_parse_args( $args, array( 246 254 'item_id' => false, 247 255 'component' => $this->component, … … 257 265 /** 258 266 * Check for an existing activity stream entry for a given post_id 259 267 * 268 * @since 2.0.0 bbPress (r3395) 269 * 260 270 * @param int $post_id ID of the topic or reply 261 271 * @return int if an activity id is verified, false if not 262 272 */ … … 267 277 268 278 // Bail if no activity ID is in post meta 269 279 if ( empty( $activity_id ) ) { 270 return null;280 return false; 271 281 } 272 282 273 // Get the activity stream item , bail if it doesn't exist283 // Get the activity stream item 274 284 $existing = new BP_Activity_Activity( $activity_id ); 285 286 // Bail if activity does not exist 275 287 if ( empty( $existing->component ) ) { 276 return null; 288 289 // Remove orphaned meta data 290 delete_post_meta( $post_id, '_bbp_activity_id' ); 291 292 return false; 277 293 } 278 294 279 295 // Return the activity ID since we've verified the connection … … 348 364 /** 349 365 * Record an activity stream entry when a topic is created or updated 350 366 * 367 * Despite the method name, it is also used when Editing a Topic, which will 368 * update the subsequent related activity stream entry. 369 * 351 370 * @since 2.0.0 bbPress (r3395) 352 371 * 353 372 * @param int $topic_id … … 402 421 $activity_action = apply_filters( 'bbp_activity_topic_create', $activity_text, $user_id, $topic_id, $forum_id ); 403 422 $activity_content = apply_filters( 'bbp_activity_topic_create_excerpt', $topic_content ); 404 423 424 // ID, time, and visibility 425 $activity_id = $this->get_activity_id( $topic_id ); 426 $recorded_time = get_post_time( 'Y-m-d H:i:s', true, $topic_id ); 427 $hide_sitewide = ! bbp_is_forum_public( $forum_id, false ); 428 405 429 // Compile and record the activity stream results 406 $ activity_id = $this->record_activity( array(407 'id' => $ this->get_activity_id( $topic_id ),430 $this->record_activity( array( 431 'id' => $activity_id, 408 432 'user_id' => $user_id, 409 433 'action' => $activity_action, 410 434 'content' => $activity_content, … … 412 436 'type' => $this->topic_create, 413 437 'item_id' => $topic_id, 414 438 'secondary_item_id' => $forum_id, 415 'recorded_time' => get_post_time( 'Y-m-d H:i:s', true, $topic_id ),416 'hide_sitewide' => ! bbp_is_forum_public( $forum_id, false )439 'recorded_time' => $recorded_time, 440 'hide_sitewide' => $hide_sitewide 417 441 ) ); 418 419 // Add the activity entry ID as a meta value to the topic420 if ( ! empty( $activity_id ) ) {421 update_post_meta( $topic_id, '_bbp_activity_id', $activity_id );422 }423 442 } 424 443 425 444 /** … … 452 471 return; 453 472 } 454 473 455 // Bail early if revisions are off456 if ( ! bbp_allow_revisions() || ! post_type_supports( bbp_get_topic_post_type(), 'revisions' ) ) {457 return;458 }459 460 474 $topic_id = bbp_get_topic_id( $topic_id ); 461 475 462 476 // Bail early if topic is by anonymous user … … 480 494 /** Replies ***************************************************************/ 481 495 482 496 /** 483 * Record an activity stream entry when a reply is created 497 * Record an activity stream entry when a reply is created or updated 484 498 * 499 * Despite the method name, it is also used when Editing a Reply, which will 500 * update the subsequent related activity stream entry. 501 * 485 502 * @since 2.0.0 bbPress (r3395) 486 503 * 487 504 * @param int $topic_id … … 540 557 $activity_action = apply_filters( 'bbp_activity_reply_create', $activity_text, $user_id, $reply_id, $topic_id ); 541 558 $activity_content = apply_filters( 'bbp_activity_reply_create_excerpt', $reply_content ); 542 559 560 // ID, time, and visibility 561 $activity_id = $this->get_activity_id( $reply_id ); 562 $recorded_time = get_post_time( 'Y-m-d H:i:s', true, $reply_id ); 563 $hide_sitewide = ! bbp_is_forum_public( $forum_id, false ); 564 543 565 // Compile and record the activity stream results 544 $ activity_id = $this->record_activity( array(545 'id' => $ this->get_activity_id( $reply_id ),566 $this->record_activity( array( 567 'id' => $activity_id, 546 568 'user_id' => $user_id, 547 569 'action' => $activity_action, 548 570 'content' => $activity_content, … … 550 572 'type' => $this->reply_create, 551 573 'item_id' => $reply_id, 552 574 'secondary_item_id' => $topic_id, 553 'recorded_time' => get_post_time( 'Y-m-d H:i:s', true, $reply_id ),554 'hide_sitewide' => ! bbp_is_forum_public( $forum_id, false )575 'recorded_time' => $recorded_time, 576 'hide_sitewide' => $hide_sitewide 555 577 ) ); 556 557 // Add the activity entry ID as a meta value to the reply558 if ( ! empty( $activity_id ) ) {559 update_post_meta( $reply_id, '_bbp_activity_id', $activity_id );560 }561 578 } 562 579 563 580 /** … … 583 600 * @param obj $post 584 601 * @return Bail early if not a reply, or reply is by anonymous user 585 602 */ 586 public function reply_update( $reply_id , $post) {603 public function reply_update( $reply_id = 0, $post = null) { 587 604 588 605 // Bail early if not a reply 589 606 if ( get_post_type( $post ) !== bbp_get_reply_post_type() ) { 590 607 return; 591 608 } 592 609 593 // Bail early if revisions are off594 if ( ! bbp_allow_revisions() || ! post_type_supports( bbp_get_reply_post_type(), 'revisions' ) ) {595 return;596 }597 598 610 $reply_id = bbp_get_reply_id( $reply_id ); 599 611 600 612 // Bail early if reply is by anonymous user -
src/includes/forums/functions.php
507 507 'post_parent' => $forum_parent_id 508 508 ) ); 509 509 510 // Insertforum511 $forum_id = wp_update_post( $forum_data );510 // Update forum 511 $forum_id = bbp_update_post_without_revision( $forum_data ); 512 512 513 513 /** No Errors *************************************************************/ 514 514 -
src/includes/replies/functions.php
504 504 } 505 505 506 506 // Define local variable(s) 507 $revisions_removed = false;508 507 $reply = $reply_id = $reply_to = $reply_author = $topic_id = $forum_id = 0; 509 508 $reply_title = $reply_content = $reply_edit_reason = $terms = ''; 510 509 $anonymous_data = array(); … … 693 692 'post_type' => bbp_get_reply_post_type() 694 693 ) ); 695 694 696 // Toggle revisions to avoid duplicates 697 if ( post_type_supports( bbp_get_reply_post_type(), 'revisions' ) ) { 698 $revisions_removed = true; 699 remove_post_type_support( bbp_get_reply_post_type(), 'revisions' ); 700 } 695 // Update reply 696 $reply_id = bbp_update_post_without_revision( $reply_data ); 701 697 702 // Insert reply703 $reply_id = wp_update_post( $reply_data );704 705 // Toggle revisions back on706 if ( true === $revisions_removed ) {707 $revisions_removed = false;708 add_post_type_support( bbp_get_reply_post_type(), 'revisions' );709 }710 711 698 /** Topic Tags ************************************************************/ 712 699 713 700 // Just in time manipulation of reply terms before being edited … … 1742 1729 // Set post status to spam 1743 1730 $reply->post_status = bbp_get_spam_status_id(); 1744 1731 1745 // No revisions1746 remove_action( 'pre_post_update', 'wp_save_post_revision');1732 // Update reply 1733 $reply_id = bbp_update_post_without_revision( $reply ); 1747 1734 1748 // Update the reply1749 $reply_id = wp_update_post( $reply );1750 1751 1735 // Execute post spam code 1752 1736 do_action( 'bbp_spammed_reply', $reply_id ); 1753 1737 … … 1790 1774 // Delete pre spam meta 1791 1775 delete_post_meta( $reply_id, '_bbp_spam_meta_status' ); 1792 1776 1793 // No revisions1794 remove_action( 'pre_post_update', 'wp_save_post_revision');1777 // Update reply 1778 $reply_id = bbp_update_post_without_revision( $reply ); 1795 1779 1796 // Update the reply1797 $reply_id = wp_update_post( $reply );1798 1799 1780 // Execute post unspam code 1800 1781 do_action( 'bbp_unspammed_reply', $reply_id ); 1801 1782 … … 1836 1817 // Set post date GMT - prevents post_date override in wp_update_post() 1837 1818 $reply->post_date_gmt = get_gmt_from_date( $reply->post_date ); 1838 1819 1839 // No revisions1840 remove_action( 'pre_post_update', 'wp_save_post_revision' );1841 1842 1820 // Update reply 1843 $reply_id = wp_update_post( $reply );1821 $reply_id = bbp_update_post_without_revision( $reply ); 1844 1822 1845 1823 // Execute post pending code 1846 1824 do_action( 'bbp_approved_reply', $reply_id ); … … 1879 1857 // Set pending status 1880 1858 $reply->post_status = $status; 1881 1859 1882 // No revisions1883 remove_action( 'pre_post_update', 'wp_save_post_revision' );1884 1885 1860 // Update reply 1886 $reply_id = wp_update_post( $reply );1861 $reply_id = bbp_update_post_without_revision( $reply ); 1887 1862 1888 1863 // Execute post open code 1889 1864 do_action( 'bbp_unapproved_reply', $reply_id ); -
src/includes/topics/functions.php
418 418 } 419 419 420 420 // Define local variable(s) 421 $revisions_removed = false;422 421 $topic = $topic_id = $topic_author = $forum_id = 0; 423 422 $topic_title = $topic_content = $topic_edit_reason = ''; 424 423 $anonymous_data = array(); … … 626 625 'tax_input' => $terms, 627 626 ) ); 628 627 629 // Toggle revisions to avoid duplicates 630 if ( post_type_supports( bbp_get_topic_post_type(), 'revisions' ) ) { 631 $revisions_removed = true; 632 remove_post_type_support( bbp_get_topic_post_type(), 'revisions' ); 633 } 628 // Update topic 629 $topic_id = bbp_update_post_without_revision( $topic_data ); 634 630 635 // Insert topic636 $topic_id = wp_update_post( $topic_data );637 638 // Toggle revisions back on639 if ( true === $revisions_removed ) {640 $revisions_removed = false;641 add_post_type_support( bbp_get_topic_post_type(), 'revisions' );642 }643 644 631 /** No Errors *************************************************************/ 645 632 646 633 if ( ! empty( $topic_id ) && ! is_wp_error( $topic_id ) ) { … … 2815 2802 // Set closed status 2816 2803 $topic->post_status = $status; 2817 2804 2818 // Toggle revisions off as we are not altering content2819 if ( post_type_supports( bbp_get_topic_post_type(), 'revisions' ) ) {2820 $revisions_removed = true;2821 remove_post_type_support( bbp_get_topic_post_type(), 'revisions' );2822 }2823 2824 2805 // Update topic 2825 $topic_id = wp_update_post( $topic );2806 $topic_id = bbp_update_post_without_revision( $topic ); 2826 2807 2827 // Toggle revisions back on2828 if ( true === $revisions_removed ) {2829 $revisions_removed = false;2830 add_post_type_support( bbp_get_topic_post_type(), 'revisions' );2831 }2832 2833 2808 // Execute post close code 2834 2809 do_action( 'bbp_closed_topic', $topic_id ); 2835 2810 … … 2869 2844 $topic_status = bbp_get_public_status_id(); 2870 2845 } 2871 2846 2872 // Set previous status2873 $topic->post_status = $topic_status;2874 2875 2847 // Remove old status meta 2876 2848 delete_post_meta( $topic_id, '_bbp_status' ); 2877 2849 2878 // Toggle revisions off as we are not altering content 2879 if ( post_type_supports( bbp_get_topic_post_type(), 'revisions' ) ) { 2880 $revisions_removed = true; 2881 remove_post_type_support( bbp_get_topic_post_type(), 'revisions' ); 2882 } 2850 // Set previous status 2851 $topic->post_status = $topic_status; 2883 2852 2884 2853 // Update topic 2885 $topic_id = wp_update_post( $topic );2854 $topic_id = bbp_update_post_without_revision( $topic ); 2886 2855 2887 // Toggle revisions back on2888 if ( true === $revisions_removed ) {2889 $revisions_removed = false;2890 add_post_type_support( bbp_get_topic_post_type(), 'revisions' );2891 }2892 2893 2856 // Execute post open code 2894 2857 do_action( 'bbp_opened_topic', $topic_id ); 2895 2858 … … 2933 2896 // Empty the topic of its tags 2934 2897 $topic->tax_input = bbp_spam_topic_tags( $topic_id ); 2935 2898 2936 // No revisions2937 remove_action( 'pre_post_update', 'wp_save_post_revision');2899 // Update topic 2900 $topic_id = bbp_update_post_without_revision( $topic ); 2938 2901 2939 // Update the topic2940 $topic_id = wp_update_post( $topic );2941 2942 2902 // Execute post spam code 2943 2903 do_action( 'bbp_spammed_topic', $topic_id ); 2944 2904 … … 3077 3037 // Delete pre spam meta 3078 3038 delete_post_meta( $topic_id, '_bbp_spam_meta_status' ); 3079 3039 3080 // No revisions3081 remove_action( 'pre_post_update', 'wp_save_post_revision');3040 // Update topic 3041 $topic_id = bbp_update_post_without_revision( $topic ); 3082 3042 3083 // Update the topic3084 $topic_id = wp_update_post( $topic );3085 3086 3043 // Execute post unspam code 3087 3044 do_action( 'bbp_unspammed_topic', $topic_id ); 3088 3045 … … 3238 3195 // Set post date GMT - prevents post_date override in wp_update_post() 3239 3196 $topic->post_date_gmt = get_gmt_from_date( $topic->post_date ); 3240 3197 3241 // No revisions3242 remove_action( 'pre_post_update', 'wp_save_post_revision' );3243 3244 3198 // Update topic 3245 $topic_id = wp_update_post( $topic );3199 $topic_id = bbp_update_post_without_revision( $topic ); 3246 3200 3247 3201 // Execute post pending code 3248 3202 do_action( 'bbp_approved_topic', $topic_id ); … … 3281 3235 // Set pending status 3282 3236 $topic->post_status = $status; 3283 3237 3284 // No revisions3285 remove_action( 'pre_post_update', 'wp_save_post_revision' );3286 3287 3238 // Update topic 3288 $topic_id = wp_update_post( $topic );3239 $topic_id = bbp_update_post_without_revision( $topic ); 3289 3240 3290 3241 // Execute post open code 3291 3242 do_action( 'bbp_unapproved_topic', $topic_id );