Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to check user capability to customize fields displayed in member directory


  • newbie999
    Participant

    @newbie999

    Hello. I added the code below in wp-content/plugins/buddypress/bp-themes/bp-default/members/members-loop.php, to display additional profile fields in the member directory and to display the member’s role (either ‘Subscriber’ or ‘Provider’). I only have 2 types of roles – Subscribers cannot edit posts and Providers can edit posts. In the code below, I specifically checked for the user’s role to determine whether I need to display ‘Subscriber’ or ‘Provider’.

    Questions:

    – is there a way to check for the capability instead – i.e., if the user can ‘edit posts’ then I will display ‘Subscriber’, otherwise I will display ‘Provider’? If so, can you please let me know how to do that as I have not been able to figure it out.

    – is there a way to display a newline so that ‘Subscriber’ or ‘Provider’ will display on the next line, below the member’s title and company name. I tried to echo “\n” but it’s not outputting a newline and I have no idea why.

    Thank you for the help.

    <?php

    /***

    * If you want to show specific profile fields here you can,

    * but it’ll add an extra query for each member in the loop

    * (only one regadless of the number of fields you show):

    *

    * bp_member_profile_data( ‘field=the field name’ );

    */

    if( bp_get_member_profile_data ( ‘field=Title’ ) )

    echo bp_member_profile_data( ‘field=Title’ ), ‘ (‘, bp_member_profile_data( ‘field=Company’ ), ‘)’, ‘ – ‘;

    $user = new WP_User( bp_get_member_user_id() );

    if ( $user->roles[0] == ‘subscriber’ )

    echo ‘Subscriber’;

    else

    echo ‘Provider’;

    ?>

  • The topic ‘How to check user capability to customize fields displayed in member directory’ is closed to new replies.
Skip to toolbar