Skip to:
Content

bbPress.org

Changeset 7166


Ignore:
Timestamp:
11/09/2020 09:42:52 PM (11 months ago)
Author:
johnjamesjacoby
Message:

Updates: clean-up & normalize topic & reply update functions.

This commit is non-functional, but rearranges some code so that _update_ functions are more predictable and easier to work with in the future.

See #3389.

Location:
trunk/src/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/replies/functions.php

    r7142 r7166  
    731731        /** Revisions *********************************************************/
    732732
    733         // Update locks
    734         update_post_meta( $reply_id, '_edit_last', bbp_get_current_user_id() );
    735         delete_post_meta( $reply_id, '_edit_lock' );
    736 
    737733        // Revision Reason
    738734        if ( ! empty( $_POST['bbp_reply_edit_reason'] ) ) {
     
    802798    $reply_to = bbp_validate_reply_to( $reply_to, $reply_id );
    803799
     800    // Get the current user ID
     801    $user_id  = bbp_get_current_user_id();
     802
    804803    // Bail if there is no reply
    805804    if ( empty( $reply_id ) ) {
     
    807806    }
    808807
    809     // Check author_id
     808    // Check author_id, fallback to current user ID
    810809    if ( empty( $author_id ) ) {
    811         $author_id = bbp_get_current_user_id();
    812     }
    813 
    814     // Check topic_id
     810        $author_id = $user_id;
     811    }
     812
     813    // Check topic_id, fallback to post_parent or meta
    815814    if ( empty( $topic_id ) ) {
    816815        $topic_id = bbp_get_reply_topic_id( $reply_id );
    817816    }
    818817
    819     // Check forum_id
     818    // Check forum_id, fallback to post_parent or meta
    820819    if ( ! empty( $topic_id ) && empty( $forum_id ) ) {
    821820        $forum_id = bbp_get_topic_forum_id( $topic_id );
    822821    }
     822
     823    // Update locks
     824    update_post_meta( $reply_id, '_edit_last', $user_id );
     825    delete_post_meta( $reply_id, '_edit_lock' );
     826
     827    // Forum/Topic meta (early, for use in downstream functions)
     828    bbp_update_reply_forum_id( $reply_id, $forum_id );
     829    bbp_update_reply_topic_id( $reply_id, $topic_id );
     830    bbp_update_reply_to      ( $reply_id, $reply_to );
    823831
    824832    // If anonymous post, store name, email, website and ip in post_meta.
     
    854862        }
    855863    }
    856 
    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 );
    861864
    862865    // Update associated topic values if this is a new reply
  • trunk/src/includes/topics/functions.php

    r7154 r7166  
    651651        /** Revisions *********************************************************/
    652652
    653         // Update locks
    654         update_post_meta( $topic_id, '_edit_last', bbp_get_current_user_id() );
    655         delete_post_meta( $topic_id, '_edit_lock' );
    656 
    657653        // Revision Reason
    658654        if ( ! empty( $_POST['bbp_topic_edit_reason'] ) ) {
     
    735731    $forum_id = bbp_get_forum_id( $forum_id );
    736732
     733    // Get the current user ID
     734    $user_id  = bbp_get_current_user_id();
     735
    737736    // Bail if there is no topic
    738737    if ( empty( $topic_id ) ) {
     
    740739    }
    741740
    742     // Check author_id
     741    // Check author_id, fallback to current user ID
    743742    if ( empty( $author_id ) ) {
    744         $author_id = bbp_get_current_user_id();
    745     }
     743        $author_id = $user_id;
     744    }
     745
     746    // Check forum_id, fallback to post_parent or meta
     747    if ( empty( $forum_id ) ) {
     748        $forum_id = bbp_get_topic_forum_id( $topic_id );
     749    }
     750
     751    // Update locks
     752    update_post_meta( $topic_id, '_edit_last', $user_id );
     753    delete_post_meta( $topic_id, '_edit_lock' );
    746754
    747755    // Forum/Topic meta (early, for use in downstream functions)
    748756    bbp_update_topic_forum_id( $topic_id, $forum_id );
    749757    bbp_update_topic_topic_id( $topic_id, $topic_id );
     758
     759    // If anonymous post, store name, email, website and ip in post_meta.
     760    if ( ! empty( $anonymous_data ) ) {
     761
     762        // Update anonymous meta data (not cookies)
     763        bbp_update_anonymous_post_author( $topic_id, $anonymous_data, bbp_get_topic_post_type() );
     764
     765        // Set transient for throttle check (only on new, not edit)
     766        if ( empty( $is_edit ) ) {
     767            set_transient( '_bbp_' . bbp_current_author_ip() . '_last_posted', time(), HOUR_IN_SECONDS );
     768        }
     769    }
     770
     771    // Handle Subscription Checkbox
     772    if ( bbp_is_subscriptions_active() && ! empty( $author_id ) ) {
     773
     774        // Check if subscribed
     775        $subscribed = bbp_is_user_subscribed( $author_id, $topic_id );
     776
     777        // Check for action
     778        $subscheck  = ( ! empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' === $_POST['bbp_topic_subscription'] ) )
     779            ? true
     780            : false;
     781
     782        // Subscribed and unsubscribing
     783        if ( ( true === $subscribed ) && ( false === $subscheck ) ) {
     784            bbp_remove_user_subscription( $author_id, $topic_id );
     785
     786        // Not subscribed and subscribing
     787        } elseif ( ( false === $subscribed ) && ( true === $subscheck ) ) {
     788            bbp_add_user_subscription( $author_id, $topic_id );
     789        }
     790    }
    750791
    751792    // Get the topic types
     
    777818                    break;
    778819            }
    779         }
    780     }
    781 
    782     // If anonymous post, store name, email, website and ip in post_meta.
    783     if ( ! empty( $anonymous_data ) ) {
    784 
    785         // Update anonymous meta data (not cookies)
    786         bbp_update_anonymous_post_author( $topic_id, $anonymous_data, bbp_get_topic_post_type() );
    787 
    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     }
    793 
    794     // Handle Subscription Checkbox
    795     if ( bbp_is_subscriptions_active() && ! empty( $author_id ) ) {
    796 
    797         // Check if subscribed
    798         $subscribed = bbp_is_user_subscribed( $author_id, $topic_id );
    799 
    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 );
    812820        }
    813821    }
Note: See TracChangeset for help on using the changeset viewer.