Ticket #3389: 3389.2.patch
| File 3389.2.patch, 8.4 KB (added by , 5 years ago) |
|---|
-
src/includes/replies/functions.php
728 728 // Update counts, etc... 729 729 do_action( 'bbp_edit_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author, true, $reply_to ); 730 730 731 /** Revisions *********************************************************/732 733 // Update locks734 update_post_meta( $reply_id, '_edit_last', bbp_get_current_user_id() );735 delete_post_meta( $reply_id, '_edit_lock' );736 737 // Revision Reason738 if ( ! empty( $_POST['bbp_reply_edit_reason'] ) ) {739 $reply_edit_reason = sanitize_text_field( $_POST['bbp_reply_edit_reason'] );740 }741 742 // Update revision log743 if ( ! empty( $_POST['bbp_log_reply_edit'] ) && ( '1' === $_POST['bbp_log_reply_edit'] ) ) {744 $revision_id = wp_save_post_revision( $reply_id );745 if ( ! empty( $revision_id ) ) {746 bbp_update_reply_revision_log( array(747 'reply_id' => $reply_id,748 'revision_id' => $revision_id,749 'author_id' => bbp_get_current_user_id(),750 'reason' => $reply_edit_reason751 ) );752 }753 }754 755 731 /** Additional Actions (After Save) ***********************************/ 756 732 757 733 do_action( 'bbp_edit_reply_post_extras', $reply_id ); … … 800 776 $topic_id = bbp_get_topic_id( $topic_id ); 801 777 $forum_id = bbp_get_forum_id( $forum_id ); 802 778 $reply_to = bbp_validate_reply_to( $reply_to, $reply_id ); 779 $user_id = bbp_get_current_user_id(); 803 780 804 781 // Bail if there is no reply 805 782 if ( empty( $reply_id ) ) { … … 808 785 809 786 // Check author_id 810 787 if ( empty( $author_id ) ) { 811 $author_id = bbp_get_current_user_id();788 $author_id = $user_id; 812 789 } 813 790 814 791 // Check topic_id … … 821 798 $forum_id = bbp_get_topic_forum_id( $topic_id ); 822 799 } 823 800 801 // Update locks 802 update_post_meta( $reply_id, '_edit_last', $user_id ); 803 delete_post_meta( $reply_id, '_edit_lock' ); 804 805 // Reply meta relating to reply position in tree 806 bbp_update_reply_forum_id( $reply_id, $forum_id ); 807 bbp_update_reply_topic_id( $reply_id, $topic_id ); 808 bbp_update_reply_to ( $reply_id, $reply_to ); 809 824 810 // If anonymous post, store name, email, website and ip in post_meta. 825 811 if ( ! empty( $anonymous_data ) ) { 826 812 … … 854 840 } 855 841 } 856 842 857 // Reply meta relating to reply position in tree 858 bbp_update_reply_forum_id( $reply_id, $forum_id ); 859 bbp_update_reply_topic_id( $reply_id, $topic_id ); 860 bbp_update_reply_to ( $reply_id, $reply_to ); 843 // Only if revisions is allowed 844 if ( bbp_allow_revisions() ) { 861 845 846 // Always save the revision, even if not logging 847 $revision_id = wp_save_post_revision( $reply_id ); 848 849 // Revision succeeded 850 if ( ! empty( $revision_id ) ) { 851 852 // Update revision log 853 if ( ! empty( $_POST['bbp_log_reply_edit'] ) && ( '1' === $_POST['bbp_log_reply_edit'] ) ) { 854 855 // Revision Reason 856 $reply_edit_reason = ! empty( $_POST['bbp_reply_edit_reason'] ) 857 ? sanitize_text_field( $_POST['bbp_reply_edit_reason'] ) 858 : ''; 859 860 // Log it 861 bbp_update_reply_revision_log( array( 862 'reply_id' => $reply_id, 863 'revision_id' => $revision_id, 864 'author_id' => $user_id, 865 'reason' => $reply_edit_reason 866 ) ); 867 } 868 } 869 } 870 862 871 // Update associated topic values if this is a new reply 863 872 if ( empty( $is_edit ) ) { 864 873 -
src/includes/topics/functions.php
648 648 // Update counts, etc... 649 649 do_action( 'bbp_edit_topic', $topic_id, $forum_id, $anonymous_data, $topic_author, true /* Is edit */ ); 650 650 651 /** Revisions *********************************************************/652 653 // Update locks654 update_post_meta( $topic_id, '_edit_last', bbp_get_current_user_id() );655 delete_post_meta( $topic_id, '_edit_lock' );656 657 // Revision Reason658 if ( ! empty( $_POST['bbp_topic_edit_reason'] ) ) {659 $topic_edit_reason = sanitize_text_field( $_POST['bbp_topic_edit_reason'] );660 }661 662 // Update revision log663 if ( ! empty( $_POST['bbp_log_topic_edit'] ) && ( '1' === $_POST['bbp_log_topic_edit'] ) ) {664 $revision_id = wp_save_post_revision( $topic_id );665 if ( ! empty( $revision_id ) ) {666 bbp_update_topic_revision_log( array(667 'topic_id' => $topic_id,668 'revision_id' => $revision_id,669 'author_id' => bbp_get_current_user_id(),670 'reason' => $topic_edit_reason671 ) );672 }673 }674 675 651 /** Move Topic ********************************************************/ 676 652 677 653 // If the new forum id is not equal to the old forum id, run the … … 733 709 // Validate the ID's passed from 'bbp_new_topic' action 734 710 $topic_id = bbp_get_topic_id( $topic_id ); 735 711 $forum_id = bbp_get_forum_id( $forum_id ); 712 $user_id = bbp_get_current_user_id(); 736 713 737 714 // Bail if there is no topic 738 715 if ( empty( $topic_id ) ) { … … 741 718 742 719 // Check author_id 743 720 if ( empty( $author_id ) ) { 744 $author_id = bbp_get_current_user_id();721 $author_id = $user_id; 745 722 } 746 723 724 // Check forum_id 725 if ( empty( $forum_id ) ) { 726 $forum_id = bbp_get_topic_forum_id( $topic_id ); 727 } 728 729 // Update locks 730 update_post_meta( $topic_id, '_edit_last', $user_id ); 731 delete_post_meta( $topic_id, '_edit_lock' ); 732 747 733 // Forum/Topic meta (early, for use in downstream functions) 748 734 bbp_update_topic_forum_id( $topic_id, $forum_id ); 749 735 bbp_update_topic_topic_id( $topic_id, $topic_id ); 750 736 737 // If anonymous post, store name, email, website and ip in post_meta. 738 if ( ! empty( $anonymous_data ) ) { 739 740 // Update anonymous meta data (not cookies) 741 bbp_update_anonymous_post_author( $topic_id, $anonymous_data, bbp_get_topic_post_type() ); 742 743 // Set transient for throttle check (only on new, not edit) 744 if ( empty( $is_edit ) ) { 745 set_transient( '_bbp_' . bbp_current_author_ip() . '_last_posted', time(), HOUR_IN_SECONDS ); 746 } 747 } 748 749 // Handle Subscription Checkbox 750 if ( bbp_is_subscriptions_active() && ! empty( $author_id ) ) { 751 752 // Check if subscribed 753 $subscribed = bbp_is_user_subscribed( $author_id, $topic_id ); 754 755 // Check for action 756 $subscheck = ( ! empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' === $_POST['bbp_topic_subscription'] ) ) 757 ? true 758 : false; 759 760 // Subscribed and unsubscribing 761 if ( ( true === $subscribed ) && ( false === $subscheck ) ) { 762 bbp_remove_user_subscription( $author_id, $topic_id ); 763 764 // Not subscribed and subscribing 765 } elseif ( ( false === $subscribed ) && ( true === $subscheck ) ) { 766 bbp_add_user_subscription( $author_id, $topic_id ); 767 } 768 } 769 751 770 // Get the topic types 752 771 $topic_types = bbp_get_topic_types( $topic_id ); 753 772 … … 779 798 } 780 799 } 781 800 782 // If anonymous post, store name, email, website and ip in post_meta.783 if ( ! empty( $anonymous_data) ) {801 // Only if revisions is allowed 802 if ( bbp_allow_revisions() ) { 784 803 785 // Update anonymous meta data (not cookies)786 bbp_update_anonymous_post_author( $topic_id, $anonymous_data, bbp_get_topic_post_type());804 // Always save the revision, even if not logging 805 $revision_id = wp_save_post_revision( $topic_id ); 787 806 788 // Set transient for throttle check (only on new, not edit) 789 if ( empty( $is_edit ) ) { 790 set_transient( '_bbp_' . bbp_current_author_ip() . '_last_posted', time(), HOUR_IN_SECONDS ); 791 } 792 } 807 // Revision succeeded 808 if ( ! empty( $revision_id ) ) { 793 809 794 // Handle Subscription Checkbox795 if ( bbp_is_subscriptions_active() && ! empty( $author_id) ) {810 // Maybe logging revision 811 if ( ! empty( $_POST['bbp_log_topic_edit'] ) && ( '1' === $_POST['bbp_log_topic_edit'] ) ) { 796 812 797 // Check if subscribed 798 $subscribed = bbp_is_user_subscribed( $author_id, $topic_id ); 813 // Revision Reason 814 $topic_edit_reason = ! empty( $_POST['bbp_topic_edit_reason'] ) 815 ? sanitize_text_field( $_POST['bbp_topic_edit_reason'] ) 816 : ''; 799 817 800 // Check for action 801 $subscheck = ( ! empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' === $_POST['bbp_topic_subscription'] ) ) 802 ? true 803 : false; 804 805 // Subscribed and unsubscribing 806 if ( ( true === $subscribed ) && ( false === $subscheck ) ) { 807 bbp_remove_user_subscription( $author_id, $topic_id ); 808 809 // Not subscribed and subscribing 810 } elseif ( ( false === $subscribed ) && ( true === $subscheck ) ) { 811 bbp_add_user_subscription( $author_id, $topic_id ); 818 // Log it 819 bbp_update_topic_revision_log( array( 820 'topic_id' => $topic_id, 821 'revision_id' => $revision_id, 822 'author_id' => $user_id, 823 'reason' => $topic_edit_reason 824 ) ); 825 } 812 826 } 813 827 }