Skip to:
Content

bbPress.org

Ticket #2299: forum-subscriptions.patch

File forum-subscriptions.patch, 24.6 KB (added by mordauk, 10 years ago)
  • includes/users/template-tags.php

     
    866866                        'unsubscribe' => __( 'Unsubscribe', 'bbpress' ),
    867867                        'user_id'     => 0,
    868868                        'topic_id'    => 0,
     869                        'forum_id'    => 0,
    869870                        'before'      => ' | ',
    870871                        'after'       => ''
    871872                ), 'get_user_subscribe_link' );
     
    873874                // Validate user and topic ID's
    874875                $user_id  = bbp_get_user_id( $r['user_id'], true, true );
    875876                $topic_id = bbp_get_topic_id( $r['topic_id'] );
    876                 if ( empty( $user_id ) || empty( $topic_id ) ) {
     877                $forum_id = bbp_get_forum_id( $r['forum_id'] );
     878
     879                if ( empty( $user_id ) || ( empty( $topic_id ) && empty( $forum_id ) ) ) {
    877880                        return false;
    878881                }
    879882
     
    882885                        return false;
    883886                }
    884887
     888                $id   = bbp_is_single_forum() ? $forum_id : $topic_id;
     889                $type = bbp_is_single_forum() ? 'forum'   : 'topic';
     890
    885891                // Decide which link to show
    886                 $is_subscribed = bbp_is_user_subscribed( $user_id, $topic_id );
     892                $is_subscribed = bbp_is_user_subscribed( $user_id, $topic_id, $forum_id );
    887893                if ( !empty( $is_subscribed ) ) {
    888894                        $text       = $r['unsubscribe'];
    889                         $query_args = array( 'action' => 'bbp_unsubscribe', 'topic_id' => $topic_id );
     895                        $query_args = array( 'action' => 'bbp_unsubscribe', $type . '_id' => $id );
    890896                } else {
    891897                        $text       = $r['subscribe'];
    892                         $query_args = array( 'action' => 'bbp_subscribe', 'topic_id' => $topic_id );
     898                        $query_args = array( 'action' => 'bbp_subscribe', $type . '_id' => $id );
    893899                }
    894900
    895901                // Create the link based where the user is and if the user is
    896902                // subscribed already
    897903                if ( bbp_is_subscriptions() ) {
    898904                        $permalink = bbp_get_subscriptions_permalink( $user_id );
     905                } elseif ( bbp_is_single_forum() ) {
     906                        $permalink = bbp_get_forum_permalink( $forum_id );
    899907                } elseif ( bbp_is_single_topic() || bbp_is_single_reply() ) {
    900908                        $permalink = bbp_get_topic_permalink( $topic_id );
    901909                } else {
    902910                        $permalink = get_permalink();
    903911                }
    904912
    905                 $url  = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $topic_id ) );
     913                $url  = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $id ) );
    906914                $sub  = $is_subscribed ? ' class="is-subscribed"' : '';
    907                 $html = sprintf( '%s<span id="subscribe-%d"  %s><a href="%s" class="subscription-toggle" data-topic="%d">%s</a></span>%s', $r['before'], $topic_id, $sub, $url, $topic_id, $text, $r['after'] );
     915                $html = sprintf( '%s<span id="subscribe-%d"  %s><a href="%s" class="subscription-toggle" data-%s="%d">%s</a></span>%s', $r['before'], $topic_id, $sub, $url, $type, $id, $text, $r['after'] );
    908916
    909917                // Initial output is wrapped in a span, ajax output is hooked to this
    910918                if ( !empty( $wrap ) ) {
     
    912920                }
    913921
    914922                // Return the link
    915                 return apply_filters( 'bbp_get_user_subscribe_link', $html, $r, $user_id, $topic_id );
     923                return apply_filters( 'bbp_get_user_subscribe_link', $html, $r, $user_id, $topic_id, $forum_id );
    916924        }
    917925
    918926
  • includes/users/functions.php

     
    316316        $favorites = bbp_get_user_favorites_topic_ids( $user_id );
    317317
    318318        if ( !empty( $favorites ) ) {
    319                
     319
    320320                // Checking a specific topic id
    321321                if ( !empty( $topic_id ) ) {
    322322                        $topic    = bbp_get_topic( $topic_id );
     
    516516/** Subscriptions *************************************************************/
    517517
    518518/**
     519 * Get the users who have subscribed to the forum
     520 *
     521 * @param int $forum_id Optional. Topic id
     522 * @uses wpdb::get_col() To execute our query and get the column back
     523 * @uses apply_filters() Calls 'bbp_get_forum_subscribers' with the subscribers
     524 * @return array|bool Results if the forum has any subscribers, otherwise false
     525 */
     526function bbp_get_forum_subscribers( $forum_id = 0 ) {
     527        if ( empty( $forum_id ) ) return;
     528
     529        global $wpdb;
     530
     531        $key   = $wpdb->prefix . '_bbp_subscriptions';
     532        $users = wp_cache_get( 'bbp_get_forum_subscribers_' . $forum_id, 'bbpress_users' );
     533        if ( empty( $users ) ) {
     534                $users = $wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '{$key}' and FIND_IN_SET('{$forum_id}', meta_value) > 0" );
     535                wp_cache_set( 'bbp_get_forum_subscribers_' . $forum_id, $users, 'bbpress_users' );
     536        }
     537
     538        if ( !empty( $users ) ) {
     539                $users = apply_filters( 'bbp_get_forum_subscribers', $users );
     540                return $users;
     541        }
     542
     543        return false;
     544}
     545
     546/**
    519547 * Get the users who have subscribed to the topic
    520548 *
    521549 * @since bbPress (r2668)
     
    551579 * @since bbPress (r2668)
    552580 *
    553581 * @param int $user_id Optional. User id
    554  * @uses bbp_get_user_subscribed_topic_ids() To get the user's subscriptions
     582 * @uses bbp_get_user_subscribed_ids() To get the user's subscriptions
    555583 * @uses bbp_has_topics() To get the topics
    556584 * @uses apply_filters() Calls 'bbp_get_user_subscriptions' with the topic query
    557585 *                        and user id
     
    565593                return false;
    566594
    567595        // If user has subscriptions, load them
    568         $subscriptions = bbp_get_user_subscribed_topic_ids( $user_id );
     596        $subscriptions = bbp_get_user_subscribed_ids( $user_id );
    569597        if ( !empty( $subscriptions ) ) {
    570598                $query = bbp_has_topics( array( 'post__in' => $subscriptions ) );
    571599                return apply_filters( 'bbp_get_user_subscriptions', $query, $user_id );
     
    574602        return false;
    575603}
    576604
     605
    577606/**
    578  * Get a user's subscribed topics' ids
     607 * Get a user's subscribed topic/forum ids
    579608 *
    580609 * @since bbPress (r2668)
    581610 *
    582611 * @param int $user_id Optional. User id
    583612 * @uses bbp_get_user_id() To get the user id
    584613 * @uses get_user_option() To get the user's subscriptions
    585  * @uses apply_filters() Calls 'bbp_get_user_subscribed_topic_ids' with
     614 * @uses apply_filters() Calls 'bbp_get_user_subscribed_ids' with
    586615 *                        the subscriptions and user id
    587616 * @return array|bool Results if user has subscriptions, otherwise false
    588617 */
    589 function bbp_get_user_subscribed_topic_ids( $user_id = 0 ) {
     618function bbp_get_user_subscribed_ids( $user_id = 0 ) {
    590619        $user_id = bbp_get_user_id( $user_id );
    591620        if ( empty( $user_id ) )
    592621                return false;
     
    595624        $subscriptions = (array) explode( ',', $subscriptions );
    596625        $subscriptions = array_filter( $subscriptions );
    597626
    598         return apply_filters( 'bbp_get_user_subscribed_topic_ids', $subscriptions, $user_id );
     627        return apply_filters( 'bbp_get_user_subscribed_ids', $subscriptions, $user_id );
    599628}
    600629
    601630/**
     
    605634 *
    606635 * @param int $user_id Optional. User id
    607636 * @param int $topic_id Optional. Topic id
     637 * @param int $forum_id Optional. Topic id
    608638 * @uses bbp_get_user_id() To get the user id
    609  * @uses bbp_get_user_subscribed_topic_ids() To get the user's subscriptions
     639 * @uses bbp_get_user_subscribed_ids() To get the user's subscriptions
    610640 * @uses bbp_get_topic() To get the topic
    611641 * @uses bbp_get_topic_id() To get the topic id
    612642 * @uses apply_filters() Calls 'bbp_is_user_subscribed' with the bool, user id,
    613643 *                        topic id and subsriptions
    614  * @return bool True if the topic is in user's subscriptions, otherwise false
     644 * @return bool True if the topic or forum is in user's subscriptions, otherwise false
    615645 */
    616 function bbp_is_user_subscribed( $user_id = 0, $topic_id = 0 ) {
     646function bbp_is_user_subscribed( $user_id = 0, $topic_id = 0, $forum_id = 0 ) {
    617647
    618648        // Validate user
    619649        $user_id = bbp_get_user_id( $user_id, true, true );
     
    621651                return false;
    622652
    623653        $retval        = false;
    624         $subscriptions = bbp_get_user_subscribed_topic_ids( $user_id );
     654        $subscriptions = (array) bbp_get_user_subscribed_ids( $user_id );
    625655
    626656        if ( !empty( $subscriptions ) ) {
    627657
    628                 // Checking a specific topic id
    629                 if ( !empty( $topic_id ) ) {
    630                         $topic     = bbp_get_topic( $topic_id );
    631                         $topic_id = !empty( $topic ) ? $topic->ID : 0;
     658                if( ! empty( $topic_id ) ) {
    632659
    633                 // Using the global topic id
    634                 } elseif ( bbp_get_topic_id() ) {
    635                         $topic_id = bbp_get_topic_id();
     660                        // Checking a specific topic id
     661                        if ( !empty( $topic_id ) ) {
     662                                $topic     = bbp_get_topic( $topic_id );
     663                                $topic_id = !empty( $topic ) ? $topic->ID : 0;
    636664
    637                 // Use the current post id
    638                 } elseif ( !bbp_get_topic_id() ) {
    639                         $topic_id = get_the_ID();
    640                 }
     665                        // Using the global topic id
     666                        } elseif ( bbp_get_topic_id() ) {
     667                                $topic_id = bbp_get_topic_id();
    641668
    642                 // Is topic_id in the user's favorites
    643                 if ( !empty( $topic_id ) ) {
    644                         $retval = in_array( $topic_id, $subscriptions );
     669                        // Use the current post id
     670                        } elseif ( !bbp_get_topic_id() ) {
     671                                $topic_id = get_the_ID();
     672                        }
     673
     674                        // Is topic_id in the user's favorites
     675                        if ( !empty( $topic_id ) ) {
     676                                $retval = in_array( $topic_id, $subscriptions );
     677                        }
     678
     679                } else {
     680
     681                        // Checking a specific forum id
     682                        if ( !empty( $forum_id ) ) {
     683                                $forum     = bbp_get_forum( $forum_id );
     684                                $forum_id = !empty( $forum ) ? $forum->ID : 0;
     685
     686                        // Using the global forum id
     687                        } elseif ( bbp_get_forum_id() ) {
     688                                $forum_id = bbp_get_forum_id();
     689
     690                        // Use the current post id
     691                        } elseif ( !bbp_get_forum_id() ) {
     692                                $forum_id = get_the_ID();
     693                        }
     694
     695                        // Is forum_id in the user's favorites
     696                        if ( !empty( $forum_id ) ) {
     697                                $retval = in_array( $forum_id, $subscriptions );
     698                        }
     699
    645700                }
    646701        }
    647702
    648         return (bool) apply_filters( 'bbp_is_user_subscribed', (bool) $retval, $user_id, $topic_id, $subscriptions );
     703        return (bool) apply_filters( 'bbp_is_user_subscribed', (bool) $retval, $user_id, $topic_id, $forum_id, $subscriptions );
    649704}
    650705
    651706/**
     
    655710 *
    656711 * @param int $user_id Optional. User id
    657712 * @param int $topic_id Optional. Topic id
    658  * @uses bbp_get_user_subscribed_topic_ids() To get the user's subscriptions
     713 * @uses bbp_get_user_subscribed_ids() To get the user's subscriptions
    659714 * @uses bbp_get_topic() To get the topic
    660715 * @uses update_user_option() To update the user's subscriptions
    661716 * @uses do_action() Calls 'bbp_add_user_subscription' with the user & topic id
    662717 * @return bool Always true
    663718 */
    664 function bbp_add_user_subscription( $user_id = 0, $topic_id = 0 ) {
    665         if ( empty( $user_id ) || empty( $topic_id ) )
     719function bbp_add_user_subscription( $user_id = 0, $topic_id = 0, $forum_id = 0 ) {
     720        if ( empty( $user_id ) || ( empty( $topic_id ) && empty( $forum_id ) ) )
    666721                return false;
    667722
    668         $subscriptions = (array) bbp_get_user_subscribed_topic_ids( $user_id );
     723        $retval        = false;
     724        $subscriptions = (array) bbp_get_user_subscribed_ids( $user_id );
    669725
     726        $forum = bbp_get_forum( $forum_id );
    670727        $topic = bbp_get_topic( $topic_id );
    671         if ( empty( $topic ) )
     728
     729        if ( empty( $topic ) && empty( $forum ) )
    672730                return false;
    673731
    674         if ( !in_array( $topic_id, $subscriptions ) ) {
    675                 $subscriptions[] = $topic_id;
     732        $id = ! empty( $topic ) ? $topic_id : $forum_id;
     733
     734        if ( !in_array( $id, $subscriptions ) ) {
     735                $subscriptions[] = $id;
    676736                $subscriptions   = array_filter( $subscriptions );
    677737                $subscriptions   = (string) implode( ',', $subscriptions );
    678738                update_user_option( $user_id, '_bbp_subscriptions', $subscriptions );
    679739
    680                 wp_cache_delete( 'bbp_get_topic_subscribers_' . $topic_id, 'bbpress' );
     740                wp_cache_delete( 'bbp_get_topic_subscribers_' . $id, 'bbpress' );
    681741        }
    682742
    683         do_action( 'bbp_add_user_subscription', $user_id, $topic_id );
     743        do_action( 'bbp_add_user_subscription', $user_id, $id );
    684744
    685745        return true;
    686746}
     
    692752 *
    693753 * @param int $user_id Optional. User id
    694754 * @param int $topic_id Optional. Topic id
    695  * @uses bbp_get_user_subscribed_topic_ids() To get the user's subscriptions
     755 * @uses bbp_get_user_subscribed_ids() To get the user's subscriptions
    696756 * @uses update_user_option() To update the user's subscriptions
    697757 * @uses delete_user_option() To delete the user's subscriptions meta
    698758 * @uses do_action() Calls 'bbp_remove_user_subscription' with the user id and
     
    700760 * @return bool True if the topic was removed from user's subscriptions,
    701761 *               otherwise false
    702762 */
    703 function bbp_remove_user_subscription( $user_id, $topic_id ) {
    704         if ( empty( $user_id ) || empty( $topic_id ) )
     763function bbp_remove_user_subscription( $user_id = 0, $topic_id = 0, $forum_id = 0 ) {
     764        if ( empty( $user_id ) || ( empty( $topic_id ) && empty( $forum_id ) ) )
    705765                return false;
    706766
    707         $subscriptions = (array) bbp_get_user_subscribed_topic_ids( $user_id );
     767        $subscriptions = (array) bbp_get_user_subscribed_ids( $user_id );
    708768
    709         if ( empty( $subscriptions ) )
     769        $forum = bbp_get_forum( $forum_id );
     770        $topic = bbp_get_topic( $topic_id );
     771
     772        if ( empty( $topic ) && empty( $forum ) )
    710773                return false;
    711774
    712         $pos = array_search( $topic_id, $subscriptions );
     775        $id   = ! empty( $topic ) ? $topic_id : $forum_id;
     776        $type = ! empty( $forum ) ? 'topic' : 'forum';
     777        $pos  = array_search( $id, $subscriptions );
     778
    713779        if ( is_numeric( $pos ) ) {
     780
    714781                array_splice( $subscriptions, $pos, 1 );
    715782                $subscriptions = array_filter( $subscriptions );
    716 
    717783                if ( !empty( $subscriptions ) ) {
    718784                        $subscriptions = implode( ',', $subscriptions );
    719785                        update_user_option( $user_id, '_bbp_subscriptions', $subscriptions );
     
    721787                        delete_user_option( $user_id, '_bbp_subscriptions' );
    722788                }
    723789
    724                 wp_cache_delete( 'bbp_get_topic_subscribers_' . $topic_id, 'bbpress' );
     790                wp_cache_delete( 'bbp_get_' . $type . '_subscribers_' . $id, 'bbpress' );
    725791        }
    726792
    727         do_action( 'bbp_remove_user_subscription', $user_id, $topic_id );
     793        do_action( 'bbp_remove_user_subscription', $user_id, $topic_id, $forum_id );
    728794
    729795        return true;
    730796}
     
    755821                return false;
    756822
    757823        // Bail if no topic ID is passed
    758         if ( empty( $_GET['topic_id'] ) )
     824        if ( empty( $_GET['topic_id'] ) && empty( $_GET['forum_id'] ) )
    759825                return;
    760826
    761827        // Setup possible get actions
     
    770836
    771837        // Get required data
    772838        $user_id  = bbp_get_user_id( 0, true, true );
    773         $topic_id = intval( $_GET['topic_id'] );
     839        $topic_id = ! empty( $_GET['topic_id'] ) ? intval( $_GET['topic_id'] ) : 0 ;
     840        $forum_id = ! empty( $_GET['forum_id'] ) ? intval( $_GET['forum_id'] ) : 0 ;
    774841
    775842        // Check for empty topic
    776         if ( empty( $topic_id ) ) {
     843        if ( empty( $topic_id ) && empty( $forum_id ) ) {
    777844                bbp_add_error( 'bbp_subscription_topic_id', __( '<strong>ERROR</strong>: No topic was found! Which topic are you subscribing/unsubscribing to?', 'bbpress' ) );
    778845
    779         // Check nonce
    780         } elseif ( ! bbp_verify_nonce_request( 'toggle-subscription_' . $topic_id ) ) {
     846        // Check forum nonce
     847        } elseif ( ! empty( $forum_id ) && ! bbp_verify_nonce_request( 'toggle-subscription_' . $forum_id ) ) {
     848                bbp_add_error( 'bbp_subscription_forum_id', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress' ) );
     849
     850        // Check topic nonce
     851        } elseif ( ! empty( $topic_id ) && ! bbp_verify_nonce_request( 'toggle-subscription_' . $topic_id ) ) {
    781852                bbp_add_error( 'bbp_subscription_topic_id', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress' ) );
    782853
    783854        // Check current user's ability to edit the user
     
    791862
    792863        /** No errors *************************************************************/
    793864
    794         $is_subscription = bbp_is_user_subscribed( $user_id, $topic_id );
     865        $is_subscription = bbp_is_user_subscribed( $user_id, $topic_id, $forum_id );
    795866        $success         = false;
    796867
    797868        if ( true == $is_subscription && 'bbp_unsubscribe' == $action )
    798                 $success = bbp_remove_user_subscription( $user_id, $topic_id );
     869                $success = bbp_remove_user_subscription( $user_id, $topic_id, $forum_id );
    799870        elseif ( false == $is_subscription && 'bbp_subscribe' == $action )
    800                 $success = bbp_add_user_subscription( $user_id, $topic_id );
     871                $success = bbp_add_user_subscription( $user_id, $topic_id, $forum_id );
    801872
    802873        // Do additional subscriptions actions
    803         do_action( 'bbp_subscriptions_handler', $success, $user_id, $topic_id, $action );
     874        do_action( 'bbp_subscriptions_handler', $success, $user_id, $topic_id, $forum_id, $action );
    804875
    805876        // Success!
    806877        if ( true == $success ) {
     
    810881                        $redirect = bbp_get_subscriptions_permalink( $user_id );
    811882                } elseif ( bbp_is_single_user() ) {
    812883                        $redirect = bbp_get_user_profile_url();
     884                } elseif ( is_singular( bbp_get_forum_post_type() ) ) {
     885                        $redirect = bbp_get_forum_permalink( $topic_id );
    813886                } elseif ( is_singular( bbp_get_topic_post_type() ) ) {
    814887                        $redirect = bbp_get_topic_permalink( $topic_id );
    815888                } elseif ( is_single() || is_page() ) {
     
    9721045 * @return array|bool Results if the user has created topics, otherwise false
    9731046 */
    9741047function bbp_get_user_topics_started( $user_id = 0 ) {
    975        
     1048
    9761049        // Validate user
    9771050        $user_id = bbp_get_user_id( $user_id );
    9781051        if ( empty( $user_id ) )
     
    10041077 * @return array|bool Results if the user has created topics, otherwise false
    10051078 */
    10061079function bbp_get_user_replies_created( $user_id = 0 ) {
    1007        
     1080
    10081081        // Validate user
    10091082        $user_id = bbp_get_user_id( $user_id );
    10101083        if ( empty( $user_id ) )
     
    10471120 * which a user can edit another user (or themselves.) If these conditions are
    10481121 * met. We assume a user cannot perform this task, and look for ways they can
    10491122 * earn the ability to access this template.
    1050  * 
     1123 *
    10511124 * @since bbPress (r3605)
    10521125 *
    10531126 * @uses bbp_is_topic_edit()
  • includes/replies/functions.php

     
    731731
    732732        // Handle Subscription Checkbox
    733733        if ( bbp_is_subscriptions_active() && !empty( $author_id ) && !empty( $topic_id ) ) {
    734                 $subscribed = bbp_is_user_subscribed( $author_id, $topic_id );
     734                $subscribed = bbp_is_user_subscribed( $author_id, $topic_id, $forum_id );
    735735                $subscheck  = ( !empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' == $_POST['bbp_topic_subscription'] ) ) ? true : false;
    736736
    737737                // Subscribed and unsubscribing
  • includes/common/functions.php

     
    980980/** Subscriptions *************************************************************/
    981981
    982982/**
     983 * Sends notification emails for new topics
     984 *
     985 * Gets new post's ID and check if there are subscribed users to that forum, and
     986 * if there are, send notifications
     987 *
     988 * @param int $topic_id ID of the newly made reply
     989 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
     990 * @uses bbp_get_topic_id() To validate the topic ID
     991 * @uses get_the_author_meta() To get the author's display name
     992 * @uses do_action() Calls 'bbp_pre_notify_subscribers' with the reply id and
     993 *                    topic id
     994 * @uses bbp_get_topic_subscribers() To get the topic subscribers
     995 * @uses apply_filters() Calls 'bbp_subscription_mail_message' with the
     996 *                        message, reply id, topic id and user id
     997 * @uses get_userdata() To get the user data
     998 * @uses wp_mail() To send the mail
     999 * @uses do_action() Calls 'bbp_post_notify_subscribers' with the reply id
     1000 *                    and topic id
     1001 * @return bool True on success, false on failure
     1002 */
     1003function bbp_notify_forum_subscribers( $topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0 ) {
     1004
     1005        // Bail if subscriptions are turned off
     1006        if ( !bbp_is_subscriptions_active() )
     1007                return false;
     1008
     1009        /** Validation ************************************************************/
     1010
     1011        $topic_id = bbp_get_topic_id( $topic_id );
     1012        $forum_id = bbp_get_forum_id( $forum_id );
     1013
     1014        /** User ******************************************************************/
     1015
     1016        // Get subscribers and bail if empty
     1017        $user_ids = bbp_get_forum_subscribers( $forum_id, true );
     1018        if ( empty( $user_ids ) )
     1019                return false;
     1020
     1021        // Poster name
     1022        $topic_author_name = bbp_get_topic_author_display_name( $topic_id );
     1023
     1024        /** Mail ******************************************************************/
     1025
     1026        do_action( 'bbp_pre_notify_subscribers', $topic_id, $forum_id, $user_ids );
     1027
     1028        // Remove filters from reply content and topic title to prevent content
     1029        // from being encoded with HTML entities, wrapped in paragraph tags, etc...
     1030        remove_all_filters( 'bbp_get_topic_content' );
     1031        remove_all_filters( 'bbp_get_forum_title'   );
     1032
     1033        // Strip tags from text
     1034        $forum_title   = strip_tags( bbp_get_forum_title( $forum_id ) );
     1035        $topic_content = strip_tags( bbp_get_topic_content( $topic_id ) );
     1036        $topic_url     = bbp_remove_view_all( bbp_get_topic_permalink( $topic_id ) );
     1037        $blog_name     = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     1038
     1039        // Loop through users
     1040        foreach ( (array) $user_ids as $user_id ) {
     1041
     1042                // Don't send notifications to the person who made the post
     1043                if ( !empty( $topic_author ) && (int) $user_id == (int) $topic_author )
     1044                        continue;
     1045
     1046                // For plugins to filter messages per reply/topic/user
     1047                $message = sprintf( __( '%1$s wrote:
     1048
     1049%2$s
     1050
     1051Post Link: %3$s
     1052
     1053-----------
     1054
     1055You are receiving this email because you subscribed to a forum.
     1056
     1057Login and visit the topic to unsubscribe from these emails.', 'bbpress' ),
     1058
     1059                        $topic_author_name,
     1060                        $topic_content,
     1061                        $topic_url
     1062                );
     1063
     1064                $message = apply_filters( 'bbp_subscription_mail_message', $message, $topic_id, $forum_id, $user_id );
     1065                if ( empty( $message ) )
     1066                        continue;
     1067
     1068                // For plugins to filter titles per reply/topic/user
     1069                $subject = apply_filters( 'bbp_subscription_mail_title', '[' . $blog_name . '] ' . $forum_title, $topic_id, $forum_id, $user_id );
     1070                if ( empty( $subject ) )
     1071                        continue;
     1072
     1073                // Custom headers
     1074                $headers = apply_filters( 'bbp_subscription_mail_headers', array() );
     1075
     1076                // Get user data of this user
     1077                $user = get_userdata( $user_id );
     1078
     1079                // Send notification email
     1080                wp_mail( $user->user_email, $subject, $message, $headers );
     1081        }
     1082
     1083        do_action( 'bbp_post_notify_subscribers', $topic_id, $forum_id, $user_ids );
     1084
     1085        return true;
     1086}
     1087
     1088/**
    9831089 * Sends notification emails for new posts
    9841090 *
    9851091 * Gets new post's ID and check if there are subscribed users to that topic, and
     
    14941600
    14951601                // Forum/Topic/Reply Feed
    14961602                if ( isset( $query_vars['post_type'] ) ) {
    1497                    
     1603
    14981604                        // Supported select query vars
    14991605                        $select_query_vars = array(
    15001606                                'p'                      => false,
  • includes/core/actions.php

     
    220220add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_favorites' );
    221221
    222222// Subscriptions
     223add_action( 'bbp_trash_forum',  'bbp_remove_forum_from_all_subscriptions'       );
    223224add_action( 'bbp_trash_topic',  'bbp_remove_topic_from_all_subscriptions'       );
     225add_action( 'bbp_delete_forum', 'bbp_remove_forum_from_all_subscriptions'       );
    224226add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_subscriptions'       );
     227add_action( 'bbp_new_topic',    'bbp_notify_forum_subscribers',           11, 4 );
    225228add_action( 'bbp_new_reply',    'bbp_notify_subscribers',                 11, 5 );
    226229
    227230// Sticky
  • includes/forums/functions.php

     
    22122212
    22132213        do_action( 'bbp_untrashed_forum', $forum_id );
    22142214}
     2215
     2216
     2217/**
     2218 * Remove a deleted forum from all users' subscriptions
     2219 *
     2220 * @param int $forum_id Topic ID to remove
     2221 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
     2222 * @uses bbp_get_forum_subscribers() To get the topic subscribers
     2223 * @uses bbp_remove_user_subscription() To remove the user subscription
     2224 */
     2225function bbp_remove_forum_from_all_subscriptions( $forum_id = 0 ) {
     2226
     2227        // Subscriptions are not active
     2228        if ( !bbp_is_subscriptions_active() )
     2229                return;
     2230
     2231        $forum_id = bbp_get_forum_id( $forum_id );
     2232
     2233        // Bail if no topic
     2234        if ( empty( $forum_id ) )
     2235                return;
     2236
     2237        // Get users
     2238        $users = (array) bbp_get_forum_subscribers( $forum_id );
     2239
     2240        // Users exist
     2241        if ( !empty( $users ) ) {
     2242
     2243                // Loop through users
     2244                foreach ( $users as $user ) {
     2245
     2246                        // Remove each user
     2247                        bbp_remove_user_subscription( $user, 0, $forum_id );
     2248                }
     2249        }
     2250}
  • templates/default/bbpress/loop-topics.php

     
    1616        <li class="bbp-header">
    1717
    1818                <ul class="forum-titles">
    19                         <li class="bbp-topic-title"><?php _e( 'Topic', 'bbpress' ); ?></li>
     19                        <li class="bbp-topic-title"><?php _e( 'Topic', 'bbpress' ); ?><?php bbp_user_subscribe_link(); ?></li>
    2020                        <li class="bbp-topic-voice-count"><?php _e( 'Voices', 'bbpress' ); ?></li>
    2121                        <li class="bbp-topic-reply-count"><?php bbp_show_lead_topic() ? _e( 'Replies', 'bbpress' ) : _e( 'Posts', 'bbpress' ); ?></li>
    2222                        <li class="bbp-topic-freshness"><?php _e( 'Freshness', 'bbpress' ); ?></li>