Skip to:
Content
Pages
Categories
Search
Top
Bottom

How do you add something to bp_group_header_actions ?

  • @macpresss

    Participant
    
    <?php do_action( 'bp_group_header_actions' ); ?>
    

    This action calls a div but i can’t find where it’s created or generated.
    The only thing i can find is this line inside the functions.. But this doesn’t tell me anything, i wanna now where the div and url is made.

    
    add_action( 'bp_group_header_actions', 'bp_group_join_button', 5 );
    

    I would like to change the HTML inside that action.

Viewing 9 replies - 1 through 9 (of 9 total)
  • @macpresss

    Participant

    I found this video the best I’ve seen this far, because it keeps it very easy to understand.

    It starts with a very basic understanding of what Actions and what Filters do because they maybe sound very overwhelming? when you bump onto them for the first time.
    You don’t wanna know how many bbPress or BuddyPress projects I have deleted because I couldn’t understand what actions are, I knew they where spot that you can Hook into but making it happen and writing some code that finally gets Hooked into an action is a different story.

    Actions DO stuff.
    Filters CHANGE stuff.

    I’ve tried to make my own custom add_action for the first time just to see if I was able to Hook into that ‘ bp_group_header_actions ‘ and it worked.
    Something as simple as this added an empty span tag above the ‘ bp_group_header_actions ‘ code but the only question that still remains how to I get inside the HTML of this action.

    
    add_action ( 'bp_group_header_actions', 'my_stuff', 1 );
    
    function my_stuff() {
    	echo '<span></span>';
    }
    
    

    This empty span tag has to go inside that div before the a href tag.
    actions and filters

    @henrywright-1

    Member

    Looks like you’re on the right track. The do_action will execute a particular function. However, the statements inside that function build a button. It is these statements you’d need to change if you want to modify the button.

    Filters CHANGE stuff.

    So are you trying to change the new topic button or the group join button? These buttons are filterable using:

    bp_get_group_join_button

    and

    bp_get_group_new_topic_button

    Does this put help put you on the right track?

    @mgrmn

    Participant

    Its made in wp-content/plugins/buddypress/bp-groups/bp-groups-template.php starting from line 1766

    Line 1027 /wp-content/plugins/buddypress/bp-groups/bp-groups-screens.php
    Line 21 /wp-content/plugins/buddypress/bp-themes/bp-default/groups/index.php

    @macpresss

    Participant

    Well i’m trying to add an icon to the Join + Leave group button – just before the text ‘Join Group’ and ‘Leave Group’ inside the A tag, that way the icon is still part of the link when you Hover over it.

    Now i’m a bit further and I’ve found the $button + bp_get_button tag which creates the HTML + button.
    The only problem is I can’t ADD to that HTML but only replace it.

    Here is what I did:

    First I’ve found this line of code:

    
    // Filter and return the HTML button
    return bp_get_button( apply_filters( 'bp_get_group_join_button', $button ) );
    

    The bp_get_button tells me thats the action or Tag that creates the button and the apply_filter -> bp_get_group_join_button will add the ‘ Group text or content to it.

    So I was thinking I need to add my Filter to that bp_get_button tag to get inside the HTML A tag.

    Searching for bp_get_button + bp_button got me looking inside the bp_core_template file and thats where i’ve found this.

    By looking at this code I assume I have to add my custom code to that $args but the only problem is how do I add to it and not replace it.

    
    function bp_button( $args = '' ) {
    	echo bp_get_button( $args );
    }
    // wall of text 
    	function bp_get_button( $args = '' ) {
    		$button = new BP_Button( $args );
    		return apply_filters( 'bp_get_button', $button->contents, $args, $button );
    	}
    

    I’ve added this to my functions:
    I use return instead of echo for filters (video says so)

    
    add_filter( 'bp_get_button', 'my_stuff' );
    
    function my_stuff($args) {
    	$args = '<span>icon</span>';
    	return $args;
    }
    

    This line of code doesn’t crash my website but it only replace to code i’m working on.

    I’ve made some screenshots for better understanding.

    This is before what it should look like – only I want my span (icon) tag inside the html A tag.

    View post on imgur.com

    This is what I get – it replaced the button instead of adding towards it.

    View post on imgur.com

    Sorry I’ve never been a very smart person and slow learning. 🙁

    @henrywright-1

    Member

    If you add this to your theme’s functions.php it will basically filter the entire button. You’ll then be free to modify whatever you need:

    //filter group button
    function bp_change_group_button( $button ) {
    
    global $groups_template;
    
    		if ( empty( $group ) )
    			$group =& $groups_template->group;
    
    		if ( !is_user_logged_in() || bp_group_is_user_banned( $group ) )
    			return false;
    
    		// Group creation was not completed or status is unknown
    		if ( !$group->status )
    			return false;
    
    		// Already a member
    		if ( isset( $group->is_member ) && $group->is_member ) {
    
    			// Stop sole admins from abandoning their group
    	 		$group_admins = groups_get_group_admins( $group->id );
    		 	if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == bp_loggedin_user_id() )
    				return false;
    
    			$button = array(
    				'id'                => 'leave_group',
    				'component'         => 'groups',
    				'must_be_logged_in' => true,
    				'block_self'        => false,
    				'wrapper_class'     => 'group-button ' . $group->status,
    				'wrapper_id'        => 'groupbutton-' . $group->id,
    				'link_href'         => wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ),
    				'link_text'         => __( 'Leave Group', 'buddypress' ),
    				'link_title'        => __( 'Leave Group', 'buddypress' ),
    				'link_class'        => 'group-button leave-group',
    			);
    
    		// Not a member
    		} else {
    
    			// Show different buttons based on group status
    			switch ( $group->status ) {
    				case 'hidden' :
    					return false;
    					break;
    
    				case 'public':
    					$button = array(
    						'id'                => 'join_group',
    						'component'         => 'groups',
    						'must_be_logged_in' => true,
    						'block_self'        => false,
    						'wrapper_class'     => 'group-button ' . $group->status,
    						'wrapper_id'        => 'groupbutton-' . $group->id,
    						'link_href'         => wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ),
    						'link_text'         => __( 'Join Group', 'buddypress' ),
    						'link_title'        => __( 'Join Group', 'buddypress' ),
    						'link_class'        => 'group-button join-group',
    					);
    					break;
    
    				case 'private' :
    
    					// Member has not requested membership yet
    					if ( !bp_group_has_requested_membership( $group ) ) {
    						$button = array(
    							'id'                => 'request_membership',
    							'component'         => 'groups',
    							'must_be_logged_in' => true,
    							'block_self'        => false,
    							'wrapper_class'     => 'group-button ' . $group->status,
    							'wrapper_id'        => 'groupbutton-' . $group->id,
    							'link_href'         => wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_request_membership' ),
    							'link_text'         => __( 'Request Membership', 'buddypress' ),
    							'link_title'        => __( 'Request Membership', 'buddypress' ),
    							'link_class'        => 'group-button request-membership',
    						);
    
    					// Member has requested membership already
    					} else {
    						$button = array(
    							'id'                => 'membership_requested',
    							'component'         => 'groups',
    							'must_be_logged_in' => true,
    							'block_self'        => false,
    							'wrapper_class'     => 'group-button pending ' . $group->status,
    							'wrapper_id'        => 'groupbutton-' . $group->id,
    							'link_href'         => bp_get_group_permalink( $group ),
    							'link_text'         => __( 'Request Sent', 'buddypress' ),
    							'link_title'        => __( 'Request Sent', 'buddypress' ),
    							'link_class'        => 'group-button pending membership-requested',
    						);
    					}
    
    					break;
    			}
    		}
    
    		return $button;
    
    }
    add_filter( 'bp_get_group_join_button', 'bp_change_group_button' );

    @macpresss

    Participant

    Thank you for the help.

    I’ve added my span tag to the array ‘link_text’ of the button.

    Not judging anybody but I believe this should be done with a more Ease of Use and less code.

    Example:
    Array’s like ‘before’ => ‘<span>’, and ‘after’ => ‘</span>’ those features are far more easy to understand for people with less skills and are very very powerful to add custom stuff to some tags-/functions.

    Thanks again.

    @shanebp

    Moderator
    function tweak_button ( $button ) { 
    
    	$button[link_text] = 'my icon ' . $button[link_text]; 
    	return $button;
    
    }
    add_filter( 'bp_get_group_join_button', 'tweak_button', 1, 1 );

    @henrywright-1

    Member

    @shanebp nice approach targeting the array item, didn’t think of that!

    @macpresss

    Participant

    @shanebpdev

    Thats great yes!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How do you add something to bp_group_header_actions ?’ is closed to new replies.
Skip to toolbar