Skip to:
Content
Pages
Categories
Search
Top
Bottom

Remove Separator


  • MaxLiao
    Participant

    @maxliao

    My question is simple, but for the life of me I cannot find the answer.

    I am creating my own theme from scratch. Currently I’m working on bbPress integration. So far everything is going well; however, I would like to remove the | separator that appears between Favorite and Subscribe (Favorite | Subscribe) when viewing a post. I cannot find where this dang separator is located and it needs to be gone.

    Please see the attached image for further clarification. You’ll quickly see how the separator does not belong.

    Bad Separator

    thank you for any assistance.

Viewing 12 replies - 1 through 12 (of 12 total)

  • Robin W
    Moderator

    @robin-w

    quick reply as I’m on my way out, so untested, but put the following in your functions file

    function remove_sep ($args) {
    $args['before' ] = '' ;
    Return $args ;
    }
    
    add_filter ('bbp_before_get_topic_subscription_link_parse_args', 'remove_sep') ;
    

    If it doesn’t work, come back and I’ll do it properly and test it for you !


    Robin W
    Moderator

    @robin-w

    Previous response edited to correct


    MaxLiao
    Participant

    @maxliao

    First of all, thank you for the response. I really appreciate your help.

    Unfortunately, that code did not work; the separator is still there. You indicated that was a possibility, so no worries.

    Since this doesn’t seem like a matter of just finding a | in some code and removing it or adding a display:none; to the CSS to remove it, is there a resource that would better help me understand how this is being accomplished? I would hate to have to ask this same question every time I want to add or remove a separator. My PHP skills exist but they are weak. Anything to help strengthen them in this regard would be fantastic.


    Robin W
    Moderator

    @robin-w

    never write code whilst your other half is waiting to go out !

    ok, this works

    function remove_sep ($args) {
    $args['before'] = '' ;
    return $args ;
    }
    
    add_filter ('bbp_before_get_forum_subscribe_link_parse_args', 'remove_sep') ;
    

    On your larger point, there are a lot of resources, but it takes a lot of practice to get good at PHP, and to understand how any plugin works which is the size that bbpress is.

    Generally it is quicker to ask a question on here, than spend hours delving into bbpress. But if you start wanting to really tailor it, then the step by step guides and other documentation will try and get you into how to go about finding code within bbpress.

    I know nothing of php 18months ago (I’m just a humble bbpress user – I didn’t write any of it!), and now have several plugins for bbpress to add functionality, so it is quire do-able.

    I’ve tried to get much of my learning into the documentation, so have a look round

    Codex


    MaxLiao
    Participant

    @maxliao

    Yep, I just got home from work and confirmed that it worked perfectly. Thank you very much, you have been most helpful!

    In regard to the rest, I think my frustration comes from the fact that I never would have considered a function as a separator. I was looking at the template PHP/HTML and the CSS coding, but it never even crossed my mind that it would be written as a function – nor did any of my searches indicate that. That’s cool though, now that I know I’m hopefully better able to resolve these issues in the future.


    Robin W
    Moderator

    @robin-w

    No problem !


    Gomle
    Participant

    @gomle

    Very, very old topic – but still relevant today. This topic is searchable in google, so I’m not creating another one 😉

    The above code does unfortunately not work anymore.

    Do you have an updated code for removing the pipepline between favorite | subscribe ?

    And if you don’t – how do you actually find what to use. I’m trying to learn, but I don’t know what to look for..


    Robin W
    Moderator

    @robin-w

    function remove_sep ($args) {
    $args['before'] = ' ' ;
    return $args ;
    }
    
    add_filter ('bbp_before_get_topic_subscribe_link_parse_args', 'remove_sep') ;

      is the code for space, so if you want 2 spaces put

    $args['before'] = '  ' ;


    Gomle
    Participant

    @gomle

    Thanks!

    This worked 🙂

    But when I press the Subscribe-button (toggle on / off), the pipeline comes back, and stays there until I reload the page.

    If I toggle it back off, the pipeline returns again, and stays there until I reload the page.

    The sort order for links is favorite | subscribe
    This happens only when I press subscribe. Never when I press favorite.

    I deleted cache from chrome settings. I’ve turned of all server cache, I also tried using Edge.

    Any suggestions?


    Robin W
    Moderator

    @robin-w

    ah, found the function that the ajax call is doing.

    this code works on my test site

    function remove_sep ($args) {
    $args['before'] = '  ' ;
    return $args ;
    }
    
    add_filter ('bbp_before_get_topic_subscribe_link_parse_args', 'remove_sep') ;
    
    remove_action( 'bbp_ajax_subscription', array( 'BBP_Default', 'ajax_subscription' ) );
    
    add_action ( 'bbp_ajax_subscription', 'new_ajax_subscription');
    
    function new_ajax_subscription() {
    
    		// Bail if subscriptions are not active
    		if ( ! bbp_is_subscriptions_active() ) {
    			bbp_ajax_response( false, esc_html__( 'Subscriptions are no longer active.', 'bbpress' ), 300 );
    		}
    
    		// Bail if user is not logged in
    		if ( ! is_user_logged_in() ) {
    			bbp_ajax_response( false, esc_html__( 'Please login to subscribe.', 'bbpress' ), 301 );
    		}
    
    		// Get user and topic data
    		$user_id = bbp_get_current_user_id();
    		$id      = ! empty( $_POST['id']   ) ? intval( $_POST['id'] )         : 0;
    		$type    = ! empty( $_POST['type'] ) ? sanitize_key( $_POST['type'] ) : 'post';
    
    		// Bail if user cannot add favorites for this user
    		if ( ! current_user_can( 'edit_user', $user_id ) ) {
    			bbp_ajax_response( false, esc_html__( 'You do not have permission to do this.', 'bbpress' ), 302 );
    		}
    
    		// Get the object
    		if ( 'post' === $type ) {
    			$object = get_post( $id );
    		}
    
    		// Bail if topic cannot be found
    		if ( empty( $object ) ) {
    			bbp_ajax_response( false, esc_html__( 'Subscription failed.', 'bbpress' ), 303 );
    		}
    
    		// Bail if user did not take this action
    		if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'toggle-subscription_' . $object->ID ) ) {
    			bbp_ajax_response( false, esc_html__( 'Are you sure you meant to do that?', 'bbpress' ), 304 );
    		}
    
    		// Take action
    		$status = bbp_is_user_subscribed( $user_id, $object->ID )
    			? bbp_remove_user_subscription( $user_id, $object->ID )
    			:    bbp_add_user_subscription( $user_id, $object->ID );
    
    		// Bail if action failed
    		if ( empty( $status ) ) {
    			bbp_ajax_response( false, esc_html__( 'The request was unsuccessful. Please try again.', 'bbpress' ), 305 );
    		}
    
    		// Put subscription attributes in convenient array
    		$attrs = array(
    			'object_id'   => $object->ID,
    			'object_type' => $type,
    			'user_id'     => $user_id
    		);
    
    		// Add separator to topic if favorites is active
    		if ( ( 'post' === $type ) && ( bbp_get_topic_post_type() === get_post_type( $object ) ) && bbp_is_favorites_active() ) {
    			$attrs['before'] = '  ';
    		}
    
    		// Action succeeded
    		bbp_ajax_response( true, bbp_get_user_subscribe_link( $attrs, $user_id, false ), 200 );
    }

    Gomle
    Participant

    @gomle

    Wow! That worked like a charm! Thank you very much @robin-w!

    I almost feel bad for asking, when all that is needed. It’s almost like I should have just colored it with css – blending it into my background :p

    But now things look just the way I want them to, in a perfect way.

    Can I ask where do you guys go to find all those filters and actions?
    I feel like I have a long way to go to learn 1/100 of all this.. 😅


    Robin W
    Moderator

    @robin-w

    it’s a lot of code to learn.

    There are hundreds of filters and actions.

    most of it is detective work.

    I have bbpress in a folder on my laptop/

    I use

    https://notepad-plus-plus.org/

    as my main tool, it understands all the file types and displays them in a very readable way.

    It has a ‘search on files’, so in your case I looked for ‘subscribe’ as this was the word that had the | before it.

    that got me to the subscribe link function, which has the ' | ' in it, which got me to the filter

    When you came back with it changing when you click, I then searched for ' | ' and found it in the core function.

    For the ‘before_xx_parse_args’ and other filter stuff see

    Step by step guide to setting up a bbPress forum – part 5

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