Skip to:
Content

bbPress.org

Ticket #1905: 1905.diff

File 1905.diff, 20.6 KB (added by MZAWeb, 12 years ago)
  • templates/default/js/topic.js

     
    1 bbpTopicJS = jQuery.extend( {
    2         // User and Topic
    3         currentUserId: '0',
    4         topicId: '0',
     1jQuery( document ).ready( function ( $ ) {
    52
    6         // Favorites
    7         favoritesLink: '',
    8         favoritesActive: 0,
    9         isFav: 0,
    10         favLinkYes: 'favorites',
    11         favLinkNo: '?',
    12         favYes: 'This topic is one of your %favLinkYes% [%favDel%]',
    13         favNo: '%favAdd% (%favLinkNo%)',
    14         favDel: 'x',
    15         favAdd: 'Add this topic to your favorites',
     3        function bbp_ajax_call( action, topic_id, nonce, update_selector ) {
    164
    17         // Subscriptions
    18         subsLink: '',
    19         subsActive: 0,
    20         isSubscribed: 0,
    21         subsSub: 'Subscribe',
    22         subsUns: 'Unsubscribe'
    23 }, bbpTopicJS );
     5                var $data = {
     6                        action:action,
     7                        id    :topic_id,
     8                        nonce :nonce
     9                };
    2410
    25 // Topic Global
    26 bbpTopicJS.favoritesActive = parseInt( bbpTopicJS.favoritesActive );
    27 bbpTopicJS.isFav           = parseInt( bbpTopicJS.isFav );
    28 bbpTopicJS.subsActive      = parseInt( bbpTopicJS.subsActive );
    29 bbpTopicJS.isSubscribed    = parseInt( bbpTopicJS.isSubscribed );
    30 
    31 // Run it
    32 jQuery(document).ready( function() {
    33 
    34         /** Favorites *************************************************************/
    35 
    36         if ( 1 == bbpTopicJS.favoritesActive ) {
    37                 var favoritesToggle = jQuery( '#favorite-toggle' )
    38                         .addClass( 'list:favorite' )
    39                         .wpList( { alt: '', dimAfter: favLinkSetup } );
    40 
    41                 var favoritesToggleSpan = favoritesToggle.children( 'span' )
    42                         [bbpTopicJS.isFav ? 'addClass' : 'removeClass' ]( 'is-favorite' );
    43         }
    44 
    45         function favLinkSetup() {
    46                 bbpTopicJS.isFav = favoritesToggleSpan.is( '.is-favorite' );
    47                 var aLink = "<a href='" + bbpTopicJS.favoritesLink + "'>";
    48                 var aDim  = "<a href='" + favoritesToggleSpan.find( 'a[class^="dim:"]' ).attr( 'href' ) + "' class='dim:favorite-toggle:" + favoritesToggleSpan.attr( 'id' ) + ":is-favorite'>";
    49                 if ( bbpTopicJS.isFav ) {
    50                         html = bbpTopicJS.favYes
    51                                 .replace( /%favLinkYes%/, aLink + bbpTopicJS.favLinkYes + "</a>" )
    52                                 .replace( /%favDel%/, aDim + bbpTopicJS.favDel + "</a>" );
     11                $.post( bbpTopicJS.ajaxurl, $data, function ( response ) {
     12                        if ( response.success ) {
     13                                $( update_selector ).html( response.content );
    5314                } else {
    54                         html = bbpTopicJS.favNo
    55                                 .replace( /%favLinkNo%/, aLink + bbpTopicJS.favLinkNo + "</a>" )
    56                                 .replace( /%favAdd%/, aDim + bbpTopicJS.favAdd + "</a>" );
     15                                if ( !response.content )
     16                                        response.content = '';
     17                                alert( response.content + ' ' + bbpTopicJS.generic_ajax_error );
    5718                }
    58                 favoritesToggleSpan.html( html );
    59                 favoritesToggle.get(0).wpList.process( favoritesToggle );
     19                } );
    6020        }
    6121
    62         /** Subscriptions *********************************************************/
     22        $( 'span#favorite-toggle' ).on( 'click', 'span a.favorite-toggle', function ( e ) {
     23                e.preventDefault();
     24                var topic_id = $( this ).attr( 'data-topic' );
    6325
    64         if ( 1 == bbpTopicJS.subsActive ) {
    65                 var subscriptionToggle = jQuery( '#subscription-toggle' )
    66                         .addClass( 'list:subscription' )
    67                         .wpList( { alt: '', dimAfter: subsLinkSetup } );
     26                bbp_ajax_call( 'dim-favorite', topic_id, bbpTopicJS.fav_nonce, 'span#favorite-toggle' );
    6827
    69                 var subscriptionToggleSpan = subscriptionToggle.children( 'span' )
    70                         [bbpTopicJS.isSubscribed ? 'addClass' : 'removeClass' ]( 'is-subscribed' );
    71         }
     28        } );
    7229
    73         function subsLinkSetup() {
    74                 bbpTopicJS.isSubscribed = subscriptionToggleSpan.is( '.is-subscribed' );
    75                 var aLink = "<a href='" + bbpTopicJS.subsLink + "'>";
    76                 var aDim  = "<a href='" + subscriptionToggleSpan.find( 'a[class^="dim:"]' ).attr( 'href' ) + "' class='dim:subscription-toggle:" + subscriptionToggleSpan.attr( 'id' ) + ":is-subscribed'>";
     30        $( 'span#subscription-toggle' ).on( 'click', 'span a.subscription-toggle', function ( e ) {
     31                e.preventDefault();
     32                var topic_id = $( this ).attr( 'data-topic' );
    7733
    78                 if ( bbpTopicJS.isSubscribed ) {
    79                         html = aDim + bbpTopicJS.subsUns + '</a>';
    80                 } else {
    81                         html = aDim + bbpTopicJS.subsSub + '</a>';
    82                 }
     34                bbp_ajax_call( 'dim-subscription', topic_id, bbpTopicJS.subs_nonce, 'span#subscription-toggle' );
    8335
    84                 subscriptionToggleSpan.html( html );
    85         }
    8636} );
     37
     38} );
  • templates/default/js/topic.min.js

     
    1 bbpTopicJS=jQuery.extend({currentUserId:"0",topicId:"0",favoritesLink:"",favoritesActive:0,isFav:0,favLinkYes:"favorites",favLinkNo:"?",favYes:"This topic is one of your %favLinkYes% [%favDel%]",favNo:"%favAdd% (%favLinkNo%)",favDel:"x",favAdd:"Add this topic to your favorites",subsLink:"",subsActive:0,isSubscribed:0,subsSub:"Subscribe",subsUns:"Unsubscribe"},bbpTopicJS);bbpTopicJS.favoritesActive=parseInt(bbpTopicJS.favoritesActive);bbpTopicJS.isFav=parseInt(bbpTopicJS.isFav);bbpTopicJS.subsActive=parseInt(bbpTopicJS.subsActive);bbpTopicJS.isSubscribed=parseInt(bbpTopicJS.isSubscribed);jQuery(document).ready(function(){if(1==bbpTopicJS.favoritesActive){var e=jQuery("#favorite-toggle").addClass("list:favorite").wpList({alt:"",dimAfter:d});var f=e.children("span")[bbpTopicJS.isFav?"addClass":"removeClass"]("is-favorite")}function d(){bbpTopicJS.isFav=f.is(".is-favorite");var g="<a href='"+bbpTopicJS.favoritesLink+"'>";var h="<a href='"+f.find('a[class^="dim:"]').attr("href")+"' class='dim:favorite-toggle:"+f.attr("id")+":is-favorite'>";if(bbpTopicJS.isFav){html=bbpTopicJS.favYes.replace(/%favLinkYes%/,g+bbpTopicJS.favLinkYes+"</a>").replace(/%favDel%/,h+bbpTopicJS.favDel+"</a>")}else{html=bbpTopicJS.favNo.replace(/%favLinkNo%/,g+bbpTopicJS.favLinkNo+"</a>").replace(/%favAdd%/,h+bbpTopicJS.favAdd+"</a>")}f.html(html);e.get(0).wpList.process(e)}if(1==bbpTopicJS.subsActive){var b=jQuery("#subscription-toggle").addClass("list:subscription").wpList({alt:"",dimAfter:c});var a=b.children("span")[bbpTopicJS.isSubscribed?"addClass":"removeClass"]("is-subscribed")}function c(){bbpTopicJS.isSubscribed=a.is(".is-subscribed");var g="<a href='"+bbpTopicJS.subsLink+"'>";var h="<a href='"+a.find('a[class^="dim:"]').attr("href")+"' class='dim:subscription-toggle:"+a.attr("id")+":is-subscribed'>";if(bbpTopicJS.isSubscribed){html=h+bbpTopicJS.subsUns+"</a>"}else{html=h+bbpTopicJS.subsSub+"</a>"}a.html(html)}});
    2  No newline at end of file
     1jQuery(document).ready(function($){function bbp_ajax_call(action,topic_id,nonce,update_selector){var $data={action:action,id:topic_id,nonce:nonce};$.post(bbpTopicJS.ajaxurl,$data,function(response){if(response.success){$(update_selector).html(response.content)}else{if(!response.content)response.content='';alert(response.content+' '+bbpTopicJS.generic_ajax_error)}})}$('span#favorite-toggle').on('click','span a.favorite-toggle',function(e){e.preventDefault();var topic_id=$(this).attr('data-topic');bbp_ajax_call('dim-favorite',topic_id,bbpTopicJS.fav_nonce,'span#favorite-toggle')});$('span#subscription-toggle').on('click','span a.subscription-toggle',function(e){e.preventDefault();var topic_id=$(this).attr('data-topic');bbp_ajax_call('dim-subscription',topic_id,bbpTopicJS.subs_nonce,'span#subscription-toggle')})});
     2 No newline at end of file
  • templates/default/bbpress-functions.php

     
    9191                add_action( 'wp_ajax_dim-favorite',     array( $this, 'ajax_favorite'         ) ); // Handles the ajax favorite/unfavorite
    9292                add_action( 'wp_ajax_dim-subscription', array( $this, 'ajax_subscription'     ) ); // Handles the ajax subscribe/unsubscribe
    9393
     94                /*
     95                 * The subscription and favorite functionality is only available
     96                 * for logged in users, but if the user loses his session whithout
     97                 * refreshing the page, we want to show him a nice error message for
     98                 * the ajax call, instead of failing sillently. So we add the _nopriv_
     99                 * ajax handlers, and deal with !is_user_logged_in in the ajax handler
     100                 */
     101                add_action( 'wp_ajax_nopriv_dim-favorite',     array( $this, 'ajax_favorite'         ) ); // Handles the ajax favorite/unfavorite
     102                add_action( 'wp_ajax_nopriv_dim-subscription', array( $this, 'ajax_subscription'     ) ); // Handles the ajax subscribe/unsubscribe
     103
    94104                /** Template Wrappers *************************************************/
    95105
    96106                add_action( 'bbp_before_main_content',  array( $this, 'before_main_content'   ) ); // Top wrapper HTML
     
    174184         */
    175185        public function enqueue_scripts() {
    176186
    177                 if ( bbp_is_single_topic() )
    178                         wp_enqueue_script( 'bbpress-topic', $this->url . 'js/topic.js', array( 'wp-lists' ), $this->version, true );
     187                if ( bbp_is_single_topic() ) {
     188                        wp_enqueue_script( 'bbpress-topic', $this->url . 'js/topic.js', array( 'jquery' ), $this->version, true );
     189                }
    179190
    180                 elseif ( bbp_is_single_user_edit() )
     191                if ( bbp_is_single_user_edit() )
    181192                        wp_enqueue_script( 'user-profile' );
    182193        }
    183194
     
    256267                if ( !bbp_is_single_topic() )
    257268                        return;
    258269
    259                 // Bail if user is not logged in
    260                 if ( !is_user_logged_in() )
    261                         return;
     270                $localizations = array( 'ajaxurl'            => admin_url( 'admin-ajax.php', ( is_ssl() ? 'https' : 'http' ) ),
     271                                        'generic_ajax_error' => __( 'Please refresh the page and try again.', 'bbpress' ),
     272                                        'is_user_logged_in'  => is_user_logged_in(),
     273                                        'fav_nonce'          => wp_create_nonce( 'toggle-favorite_' . get_the_ID() ),
     274                                        'subs_nonce'         => wp_create_nonce( 'toggle-subscription_' . get_the_ID() ) );
    262275
    263                 $user_id = bbp_get_current_user_id();
    264 
    265                 $localizations = array(
    266                         'currentUserId' => $user_id,
    267                         'topicId'       => bbp_get_topic_id(),
    268                 );
    269 
    270                 // Favorites
    271                 if ( bbp_is_favorites_active() ) {
    272                         $localizations['favoritesActive'] = 1;
    273                         $localizations['favoritesLink']   = bbp_get_favorites_permalink( $user_id );
    274                         $localizations['isFav']           = (int) bbp_is_user_favorite( $user_id );
    275                         $localizations['favLinkYes']      = __( 'favorites',                                         'bbpress' );
    276                         $localizations['favLinkNo']       = __( '?',                                                 'bbpress' );
    277                         $localizations['favYes']          = __( 'This topic is one of your %favLinkYes% [%favDel%]', 'bbpress' );
    278                         $localizations['favNo']           = __( '%favAdd% (%favLinkNo%)',                            'bbpress' );
    279                         $localizations['favDel']          = __( '&times;',                                           'bbpress' );
    280                         $localizations['favAdd']          = __( 'Add this topic to your favorites',                  'bbpress' );
    281                 } else {
    282                         $localizations['favoritesActive'] = 0;
     276                wp_localize_script( 'bbpress-topic', 'bbpTopicJS', $localizations );
    283277                }
    284278
    285                 // Subscriptions
    286                 if ( bbp_is_subscriptions_active() ) {
    287                         $localizations['subsActive']   = 1;
    288                         $localizations['isSubscribed'] = (int) bbp_is_user_subscribed( $user_id );
    289                         $localizations['subsSub']      = __( 'Subscribe',   'bbpress' );
    290                         $localizations['subsUns']      = __( 'Unsubscribe', 'bbpress' );
    291                         $localizations['subsLink']     = bbp_get_topic_permalink();
    292                 } else {
    293                         $localizations['subsActive'] = 0;
    294                 }
    295279
    296                 wp_localize_script( 'bbpress-topic', 'bbpTopicJS', $localizations );
    297         }
    298 
    299280        /**
    300          * Add or remove a topic from a user's favorites
     281         * AJAX handler to add or remove a topic from a user's favorites
    301282         *
    302283         * @since bbPress (r3732)
    303284         *
    304285         * @uses bbp_get_current_user_id() To get the current user id
    305286         * @uses current_user_can() To check if the current user can edit the user
    306287         * @uses bbp_get_topic() To get the topic
    307          * @uses check_ajax_referer() To verify the nonce & check the referer
     288         * @uses   wp_verify_nonce()          To verify the nonce & check the referer
    308289         * @uses bbp_is_user_favorite() To check if the topic is user's favorite
    309290         * @uses bbp_remove_user_favorite() To remove the topic from user's favorites
    310291         * @uses bbp_add_user_favorite() To add the topic from user's favorites
     292         * @uses   bbp_ajax_response()        To return JSON
    311293         */
    312294        public function ajax_favorite() {
     295                if ( !bbp_is_favorites_active() )
     296                        bbp_ajax_response( false, __( "Favorites are not active.", 'bbpress' ), 300 );
     297
     298                if ( !is_user_logged_in() )
     299                        bbp_ajax_response( false, __( "You're not logged in.", 'bbpress' ), 301 );
     300
    313301                $user_id = bbp_get_current_user_id();
    314302                $id      = intval( $_POST['id'] );
    315303
    316304                if ( !current_user_can( 'edit_user', $user_id ) )
    317                         die( '-1' );
     305                        bbp_ajax_response( false, __( "You don't have permission to do this.", 'bbpress' ), 302);
    318306
    319307                $topic = bbp_get_topic( $id );
    320308
    321309                if ( empty( $topic ) )
    322                         die( '0' );
     310                        bbp_ajax_response( false, __( "Invalid topic ID.", 'bbpress' ), 303 );
    323311
    324                 check_ajax_referer( 'toggle-favorite_' . $topic->ID );
     312                if ( !isset( $_POST['nonce'] ) || !wp_verify_nonce( $_POST['nonce'], 'toggle-favorite_' . $topic->ID ) )
     313                        bbp_ajax_response( false, __( "Invalid nonce.", 'bbpress' ), 304 );
    325314
    326                 if ( bbp_is_user_favorite( $user_id, $topic->ID ) ) {
    327                         if ( bbp_remove_user_favorite( $user_id, $topic->ID ) ) {
    328                                 die( '1' );
    329                         }
    330                 } else {
    331                         if ( bbp_add_user_favorite( $user_id, $topic->ID ) ) {
    332                                 die( '1' );
    333                         }
    334                 }
     315                $status = bbp_is_user_favorite( $user_id, $topic->ID ) ? bbp_remove_user_favorite( $user_id, $topic->ID ) : bbp_add_user_favorite( $user_id, $topic->ID );
    335316
    336                 die( '0' );
     317                if ( $status )
     318                        bbp_ajax_response( true, bbp_get_user_favorites_link( array(), array(), $user_id, $id, false ), 200 );
     319
     320
     321                bbp_ajax_response( false, __( "Unexpected error.", 'bbpress' ), 305 );
     322
    337323        }
    338324
    339325        /**
    340          * Subscribe/Unsubscribe a user from a topic
     326         * AJAX Hanlder to Subscribe/Unsubscribe a user from a topic
    341327         *
    342328         * @since bbPress (r3732)
    343329         *
     
    345331         * @uses bbp_get_current_user_id() To get the current user id
    346332         * @uses current_user_can() To check if the current user can edit the user
    347333         * @uses bbp_get_topic() To get the topic
    348          * @uses check_ajax_referer() To verify the nonce & check the referer
    349          * @uses bbp_is_user_subscribed() To check if the topic is in user's
    350          *                                 subscriptions
    351          * @uses bbp_remove_user_subscriptions() To remove the topic from user's
    352          *                                        subscriptions
     334         * @uses   wp_verify_nonce()               To verify the nonce
     335         * @uses   bbp_is_user_subscribed()        To check if the topic is in user's subscriptions
     336         * @uses   bbp_remove_user_subscriptions() To remove the topic from user's subscriptions
    353337         * @uses bbp_add_user_subscriptions() To add the topic from user's subscriptions
     338         * @uses   bbp_ajax_response()             To return JSON
    354339         */
    355340        public function ajax_subscription() {
    356341                if ( !bbp_is_subscriptions_active() )
    357                         return;
     342                        bbp_ajax_response( false, __( "Subscriptions are not active.", 'bbpress' ), 300 );
    358343
     344                if ( !is_user_logged_in() )
     345                        bbp_ajax_response( false, __( "You're not logged in.", 'bbpress' ), 301 );
     346
    359347                $user_id = bbp_get_current_user_id();
    360348                $id      = intval( $_POST['id'] );
    361349
    362350                if ( !current_user_can( 'edit_user', $user_id ) )
    363                         die( '-1' );
     351                        bbp_ajax_response( false, __( "You don't have permission to do this.", 'bbpress' ), 302 );
    364352
    365353                $topic = bbp_get_topic( $id );
    366354
    367355                if ( empty( $topic ) )
    368                         die( '0' );
     356                        bbp_ajax_response( false, __( "Invalid topic ID.", 'bbpress' ), 303 );
    369357
    370                 check_ajax_referer( 'toggle-subscription_' . $topic->ID );
     358                if ( !isset( $_POST['nonce'] ) || !wp_verify_nonce( $_POST['nonce'], 'toggle-subscription_' . $topic->ID ) )
     359                        bbp_ajax_response( false, __( "Invalid nonce.", 'bbpress' ), 304 );
    371360
    372                 if ( bbp_is_user_subscribed( $user_id, $topic->ID ) ) {
    373                         if ( bbp_remove_user_subscription( $user_id, $topic->ID ) ) {
    374                                 die( '1' );
    375                         }
    376                 } else {
    377                         if ( bbp_add_user_subscription( $user_id, $topic->ID ) ) {
    378                                 die( '1' );
    379                         }
    380                 }
     361                $status = bbp_is_user_subscribed( $user_id, $topic->ID ) ? bbp_remove_user_subscription( $user_id, $topic->ID ) : bbp_add_user_subscription( $user_id, $topic->ID );
    381362
    382                 die( '0' );
     363                if ( $status )
     364                        bbp_ajax_response( true, bbp_get_user_subscribe_link( array( 'topic_id' => $topic->ID,
     365                                                                                     'user_id'  => $user_id ), $user_id, false ), 200 );
     366
     367                bbp_ajax_response( false, __( "Unexpected error.", 'bbpress' ), 305 );
     368
    383369        }
    384370}
    385371new BBP_Default();
  • includes/common/functions.php

     
    16871687
    16881688        $wp_query->set_404();
    16891689}
     1690
     1691
     1692/**
     1693 * Helper method to return JSON response for the ajax calls
     1694 *
     1695 * @param bool   $success
     1696 * @param string $content
     1697 * @param array  $aditional_data
     1698 */
     1699function bbp_ajax_response( $success = false, $content = '', $status = -1, $aditional_data = array() ) {
     1700
     1701        if ( $success && $status === -1 )
     1702                $status = 200;
     1703
     1704        $response = array( 'success' => $success, 'status'=> $status, 'content'=> $content );
     1705
     1706        if ( !empty( $aditional_data ) )
     1707                $response = array_merge( $response, $aditional_data );
     1708
     1709        header( 'Content-type: application/json' );
     1710        echo json_encode( $response );
     1711        die();
     1712}
     1713 No newline at end of file
  • includes/users/template-tags.php

     
    639639         * @param array $rem Optional. Remove from favorites args
    640640         * @param int $user_id Optional. User id
    641641         * @param int $topic_id Optional. Topic id
     642         * @param bool  $wrap     Optional. If you want to wrap the link in <span id="favorite-toggle">. See ajax_favorite()
    642643         * @uses bbp_get_user_id() To get the user id
    643644         * @uses current_user_can() If the current user can edit the user
    644645         * @uses bbp_get_topic_id() To get the topic id
     
    650651         *                        html, add args, remove args, user & topic id
    651652         * @return string User favorites link
    652653         */
    653         function bbp_get_user_favorites_link( $add = array(), $rem = array(), $user_id = 0, $topic_id = 0 ) {
     654        function bbp_get_user_favorites_link( $add = array(), $rem = array(), $user_id = 0, $topic_id = 0, $wrap = true ) {
    654655                if ( !bbp_is_favorites_active() )
    655656                        return false;
    656657
     
    709710
    710711                $url    = esc_url( wp_nonce_url( add_query_arg( $favs, $permalink ), 'toggle-favorite_' . $topic_id ) );
    711712                $is_fav = $is_fav ? 'is-favorite' : '';
    712                 $html   = '<span id="favorite-toggle"><span id="favorite-' . $topic_id . '" class="' . $is_fav . '">' . $pre . '<a href="' . $url . '" class="dim:favorite-toggle:favorite-' . $topic_id . ':is-favorite">' . $mid . '</a>' . $_post . '</span></span>';
     713                $html = sprintf( '<span id="favorite-%d" class="%s">%s<a href="%s" class="favorite-toggle" data-topic="%d" >%s</a>%s</span>', $topic_id, $is_fav, $pre, $url, $topic_id, $mid, $_post );
    713714
     715                if ( $wrap )
     716                        $html = '<span id="favorite-toggle">' . $html . '</span>';
     717
    714718                // Return the link
    715719                return apply_filters( 'bbp_get_user_favorites_link', $html, $add, $rem, $user_id, $topic_id );
    716720        }
     
    800804         *  - before: Before the link
    801805         *  - after: After the link
    802806         * @param int $user_id Optional. User id
     807         * @param bool  $wrap     Optional. If you want to wrap the link in <span id="favorite-toggle">. See ajax_favorite()
    803808         * @uses bbp_get_user_id() To get the user id
    804809         * @uses current_user_can() To check if the current user can edit user
    805810         * @uses bbp_get_topic_id() To get the topic id
     
    811816         *                        link, args, user id & topic id
    812817         * @return string Permanent link to topic
    813818         */
    814         function bbp_get_user_subscribe_link( $args = '', $user_id = 0 ) {
     819        function bbp_get_user_subscribe_link( $args = '', $user_id = 0, $wrap = true ) {
    815820                if ( !bbp_is_subscriptions_active() )
    816821                        return;
    817822
     
    861866
    862867                $url        = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $topic_id ) );
    863868                $subscribed = $is_subscribed ? ' class="is_subscribed"' : '';
    864                 $html       = '<span id="subscription-toggle">' . $r['before'] . '<span id="subscribe-' . $topic_id . '"' . $subscribed . '><a href="' . $url . '" class="dim:subscription-toggle:subscribe-' . $topic_id . ':is-subscribed">' . $text . '</a></span>' . $r['after'] . '</span>';
     869                $html = sprintf( '%s <span id="subscribe-%d"  %s><a href="%s" class="subscription-toggle" data-topic="%d">%s</a></span>' . $r['after'] . '</span>', $r['before'], $topic_id, $subscribed, $url, $topic_id, $text );
    865870
     871                if ( $wrap )
     872                        $html = '<span id="subscription-toggle">' . $html . '</span>';
     873
    866874                // Return the link
    867875                return apply_filters( 'bbp_get_user_subscribe_link', $html, $r, $user_id, $topic_id );
    868876        }