Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] How to have "Edit" before Profile Group Tab in editing


  • dzung
    Participant

    @bluesharp

    I want to have a “Edit” text before the name of profile groups when users editing their profiles.
    Such as: Edit Base | Edit GroupProfile
    I see, it’s rendered here <li %1$s><a href="%2$s">%3$s</a></li> in the bp_profile_group_tabs() function in bp-xprofile-template.php.

    I want to make it from

    <li %1$s><a href="%2$s">%3$s</a></li>

    To

    <li %1$s><a href="%2$s">Edit %3$s</a></li>

    But I don’t know how to override this function, I have tried copying the function content and paste into theme’s functions.php and rename the function to custom_bp_profile_group_tabs and in the edit.php file I set it to call to the new function:

    <ul class="button-nav">
    	<?php custom_bp_profile_group_tabs(); ?>
    </ul> 

    but it didn’t work. Is there a way to override this function or another way to have the word “Edit” before the Profile Group Tab. Thanks anyone for help!

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

  • shanebp
    Moderator

    @shanebp

    In bp_profile_group_tabs, there is a filter hook:

    $tabs = apply_filters( 'xprofile_filter_profile_group_tabs', $tabs, $groups, $group_name );

    Write a filter function and do a string search & replace for each tab.
    ex. Search for ‘Base’ and replace it with ‘Edit Base’.


    dzung
    Participant

    @bluesharp

    Thanks for your guide – I wrote my code and it works. Can you please have a look to see if it’s okay to do like that?

    PS: I don’t know why If I copy all the function content then I can’t submit this reply it says “ERROR: Your reply cannot be created at this time. ” So I have to remove some line in the function and it ok!

    function custom_bp_profile_group_tabs() {
    ...same content with the original function ....
    $tabs[] = sprintf( '<li %1$s><a href="%2$s">Edit %3$s</a></li>', $selected, $link, esc_html( $groups[$i]->name ) );
    		}
    	}
    	//$tabs = apply_filters( 'xprofile_filter_profile_group_tabs', $tabs, $groups, $group_name );
    	foreach ( (array) $tabs as $tab )
    		echo $tab;
    
    	do_action( 'xprofile_profile_group_tabs' );
    }
    add_filter('xprofile_filter_profile_group_tabs','custom_bp_profile_group_tabs');

    shanebp
    Moderator

    @shanebp

    I’m surprised your code works.
    Filter should always return something.

    This is unfinished but outlines another approach, probably more ‘correct’:

    function custom_bp_profile_group_tabs( $tabs, $groups, $group_name ) {
    
    	tab_names = array('Base', 'GroupProfile' ); // add to as necessary
    	
    	foreach ( (array) $tabs as $tab ) {
    	   // loop thru tab_names using something like strpos() to check for matches
               // if you find a match, use str_replace to add 'Edit '
    		
    	}
    	
    	return $tabs;
    }
    add_filter('xprofile_filter_profile_group_tabs','custom_bp_profile_group_tabs', 1, 3);

    dzung
    Participant

    @bluesharp

    In the original function, there’s no return statement only echo. So I think echo $tab; is the return you mentioned!

    tab_names = array(‘Base’, ‘GroupProfile’ ); // add to as necessary

    The Profile Group name is not fixed and Admin can rename/or add more Profile Groups, so I think shouldn’t use hard-coded like above!


    shanebp
    Moderator

    @shanebp

    >In the original function, there’s no return statement only echo.

    The original function is not a filter hooked function.
    echo $tab; is not a return.
    Read up on WordPress functions, actions and filters.


    dzung
    Participant

    @bluesharp

    I first tested my function like this:

    function custom_bp_profile_group_tabs() {
    echo ‘bacon’;
    }
    add_filter(‘xprofile_filter_profile_group_tabs’,’custom_bp_profile_group_tabs’);

    It worked and returned “bacon” in the area of “Base” and “GroupProfile” menu.

    So if echo is not a return then, I think the Filter doesn’t require return!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] How to have "Edit" before Profile Group Tab in editing’ is closed to new replies.
Skip to toolbar