Skip to:
Content

bbPress.org

Changeset 7765


Ignore:
Timestamp:
10/02/2026 07:41:28 AM (6 weeks ago)
Author:
johnjamesjacoby
Message:

Subscriptions: Preserve subscriptions on admin edits.

Move topic-subscription handling out of the generic topic and reply update functions and into the front-end form actions. This prevents WordPress admin edits and programmatic updates from changing an author's subscription without an explicit form choice.

Remove the obsolete hidden admin metabox field and add regression coverage for topic and reply saves.

In trunk, for 2.7.

Props wpturk.
See #3362.

Location:
trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/CHANGELOG.md

    r7763 r7765  
    4545### Fixed
    4646
     47- Preserved topic subscriptions when topics and replies are edited in administration.
    4748- Cache a distinct count of current-site forum-role holders for forum statistics,
    4849  invalidating it when users or their capabilities change. Use the WordPress
  • trunk/src/includes/admin/metaboxes.php

    r7651 r7765  
    794794function bbp_topic_subscriptions_metabox( $post ) {
    795795
    796         // Current user subscription
    797         $input_value = bbp_is_user_subscribed( bbp_get_current_user_id(), $post->ID )
    798                 ? 'bbp_subscribe' // maintain existing subscription
    799                 : '';             // do not add or remove subscription
    800 
    801796        // Get user IDs
    802797        $user_ids = bbp_get_subscribers( $post->ID );
    803798
    804799        // Output
    805         ?>
    806         <input name="bbp_topic_subscription" id="bbp_topic_subscription" type="hidden" value="<?php echo esc_attr( $input_value ); ?>" />
    807         <p><?php
     800        ?><p><?php
    808801
    809802                // Relationships
  • trunk/src/includes/core/actions.php

    r7671 r7765  
    213213add_action( 'bbp_new_reply',  'bbp_update_reply', 10, 7 );
    214214add_action( 'bbp_edit_reply', 'bbp_update_reply', 10, 7 );
     215add_action( 'bbp_new_reply',  'bbp_update_reply_subscription', 10, 5 );
     216add_action( 'bbp_edit_reply', 'bbp_update_reply_subscription', 10, 5 );
    215217
    216218// Before Delete/Trash/Untrash Reply
    … …  
    228230add_action( 'bbp_new_topic',  'bbp_update_topic', 10, 5 );
    229231add_action( 'bbp_edit_topic', 'bbp_update_topic', 10, 5 );
     232add_action( 'bbp_new_topic',  'bbp_update_topic_subscription', 10, 4 );
     233add_action( 'bbp_edit_topic', 'bbp_update_topic_subscription', 10, 4 );
    230234
    231235// Split/Merge Topic
  • trunk/src/includes/replies/functions.php

    r7727 r7765  
    908908        }
    909909
    910         // Handle Subscription Checkbox
    911         if ( bbp_is_subscriptions_active() && ! empty( $author_id ) && ! empty( $topic_id ) ) {
    912 
    913                 // Check if subscribed
    914                 $subscribed = bbp_is_user_subscribed( $author_id, $topic_id );
    915 
    916                 // Check for action
    917                 $subscheck  = ( ! empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' === $_POST['bbp_topic_subscription'] ) )
    918                         ? true
    919                         : false;
    920 
    921                 // Subscribed and unsubscribing
    922                 if ( ( true === $subscribed ) && ( false === $subscheck ) ) {
    923                         bbp_remove_user_subscription( $author_id, $topic_id );
    924 
    925                 // Not subscribed and subscribing
    926                 } elseif ( ( false === $subscribed ) && ( true === $subscheck ) ) {
    927                         bbp_add_user_subscription( $author_id, $topic_id );
    928                 }
    929         }
    930 
    931910        // Update associated topic values if this is a new reply
    932911        if ( empty( $is_edit ) ) {
  • trunk/src/includes/topics/functions.php

    r7731 r7765  
    826826        }
    827827
    828         // Handle Subscription Checkbox
    829         if ( bbp_is_subscriptions_active() && ! empty( $author_id ) ) {
    830 
    831                 // Check if subscribed
    832                 $subscribed = bbp_is_user_subscribed( $author_id, $topic_id );
    833 
    834                 // Check for action
    835                 $subscheck  = ( ! empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' === $_POST['bbp_topic_subscription'] ) )
    836                         ? true
    837                         : false;
    838 
    839                 // Subscribed and unsubscribing
    840                 if ( ( true === $subscribed ) && ( false === $subscheck ) ) {
    841                         bbp_remove_user_subscription( $author_id, $topic_id );
    842 
    843                 // Not subscribed and subscribing
    844                 } elseif ( ( false === $subscribed ) && ( true === $subscheck ) ) {
    845                         bbp_add_user_subscription( $author_id, $topic_id );
    846                 }
    847         }
    848 
    849828        // Get the topic types
    850829        $topic_types = bbp_get_topic_types( $topic_id );
  • trunk/src/includes/users/engagements.php

    r7658 r7765  
    857857
    858858        return true;
     859}
     860
     861/**
     862 * Apply a topic form's subscription choice for its author.
     863 *
     864 * @since 2.6.20 bbPress (r7765)
     865 *
     866 * @param int $author_id Topic or reply author ID.
     867 * @param int $topic_id Topic ID.
     868 */
     869function bbp_update_user_topic_subscription( $author_id = 0, $topic_id = 0 ) {
     870
     871        // Bail if subscriptions are disabled or the form has no valid target
     872        if ( ! bbp_is_subscriptions_active() || empty( $author_id ) || empty( $topic_id ) ) {
     873                return;
     874        }
     875
     876        $subscribed = bbp_is_user_subscribed( $author_id, $topic_id );
     877        $subscheck  = ! empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' === $_POST['bbp_topic_subscription'] );
     878
     879        if ( $subscribed && ! $subscheck ) {
     880                bbp_remove_user_subscription( $author_id, $topic_id );
     881        } elseif ( ! $subscribed && $subscheck ) {
     882                bbp_add_user_subscription( $author_id, $topic_id );
     883        }
     884}
     885
     886/**
     887 * Apply a topic form's subscription choice after saving the topic.
     888 *
     889 * @since 2.6.20 bbPress (r7765)
     890 *
     891 * @param int   $topic_id Topic ID.
     892 * @param int   $forum_id Forum ID.
     893 * @param array $anonymous_data Anonymous author data.
     894 * @param int   $author_id Topic author ID.
     895 */
     896function bbp_update_topic_subscription( $topic_id = 0, $forum_id = 0, $anonymous_data = array(), $author_id = 0 ) {
     897        bbp_update_user_topic_subscription( $author_id, $topic_id );
     898}
     899
     900/**
     901 * Apply a reply form's subscription choice after saving the reply.
     902 *
     903 * @since 2.6.20 bbPress (r7765)
     904 *
     905 * @param int   $reply_id Reply ID.
     906 * @param int   $topic_id Topic ID.
     907 * @param int   $forum_id Forum ID.
     908 * @param array $anonymous_data Anonymous author data.
     909 * @param int   $author_id Reply author ID.
     910 */
     911function bbp_update_reply_subscription( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = array(), $author_id = 0 ) {
     912        bbp_update_user_topic_subscription( $author_id, $topic_id );
    859913}
    860914
Note: See TracChangeset for help on using the changeset viewer.