Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to enable Unsubscription link only to Topic ?

  • @sub0810

    Participant

    I would like to make it so that the Users of my Forum can
    only Unsubscribe to Topics.
    In short, subscribe link is not to display in reply page.
    Unsubscribe link is shown in reply page.

    Is that possible? Thank you.

    In profile page, the delete icon [×] does not work due to buddypress conflict.

Viewing 6 replies - 1 through 6 (of 6 total)
  • @robin-w

    Moderator

    can you define what you mean by ‘reply page’ please

    @sub0810

    Participant

    ‘reply page’ means content-single-topic.php .

    
    <?php bbp_topic_subscription_link(); ?>
    

    includes> topics > template.php

    
    function bbp_topic_subscription_link( $args = array() ) {
    	echo bbp_get_topic_subscription_link( $args );
    }
    
    	/**
    	 * Get the topic subscription link
    	 *
    	 * A custom wrapper for bbp_get_user_subscribe_link()
    	 *
    	 * @since 2.5.0 bbPress (r5156)
    	 * @since 2.6.0 bbPress (r6308) Add 'redirect_to' support
    	 */
    	function bbp_get_topic_subscription_link( $args = array() ) {
    
    		// Defaults
    		$retval      = false;
    		$user_id     = bbp_get_current_user_id();
    		$redirect_to = bbp_is_subscriptions()
    			? bbp_get_subscriptions_permalink( $user_id )
    			: '';
    
    		// Parse the arguments
    		$r = bbp_parse_args( $args, array(
    			'user_id'     => $user_id,
    			'object_id'   => bbp_get_topic_id(),
    			'object_type' => 'post',
    			'before'      => '&nbsp;|&nbsp;',
    			'after'       => '',
    			'subscribe'   => esc_html__( 'Subscribe',   'bbpress' ),
    			'unsubscribe' => esc_html__( 'Unsubscribe', 'bbpress' ),
    			'redirect_to' => $redirect_to
    		), 'get_topic_subscribe_link' );
    
    		// Get the link
    		$retval = bbp_get_user_subscribe_link( $r );
    
    		// Filter & return
    		return apply_filters( 'bbp_get_topic_subscribe_link', $retval, $r, $args );
    	}
    

    @robin-w

    Moderator

    without getting complicated, this will work quite well

    add_filter ('bbp_get_topic_subscribe_link' , 'julia_unubsribe') ;
    
    function julia_unubsribe($retval) {
    	if (strpos($retval, 'Subscribe') !== FALSE) {
    		$retval = '' ;
    	}
    return $retval ;
    }

    Put this in your child theme’s function file –

    ie wp-content/themes/%your-theme-name%/functions.php

    where %your-theme-name% is the name of your theme

    or use

    Code Snippets

    it will let someone unsubscribe from a topic, but does let them re-subscribe if they stay within that topic (so if they click by mistake, they can unclick immediately) once they leave that topic, then they can’t subscribe, and they can’t subscribe to a topic that they are not subscribed to in the first place.

    @sub0810

    Participant

    Your code works quite well. How simple they are!
    I tried to customize it , but I couldn’t. I couldn’t get strpos code.

    Thank you for your kindness.

    @robin-w

    Moderator

    no problem, glad you ae fixed !

    @robin-w

    Moderator

    I always have hated that PHP doesn’t have a simple ‘contains’, so you have to say if the position of some text does not equal false, then it is true so the string contains the text – very silly !

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar