Skip to:
Content
Pages
Categories
Search
Top
Bottom

Status


  • Humiges
    Participant

    @humiges

    Hi,
    We would like to have status available only for Administrators to post important stuff and Editors.
    Is there any way we can do that? Sorry, I couldn’t figure out how to do it.
    Thank you

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

  • danbp
    Participant

    @danbp

    To restrict the usage of the What’s New form to only admins and editors…

    Copy post-form.php from (bp-templates/bp-legacy/buddypress/activity/ ) to (/your-child-theme/buddypress/activity/).

    In the copy, add if ( bp_current_user_can( 'editor' ) ) : above the form tab and add endif; right after the closing form tag, at the end of the file and you’re done.
    Note to take care of the existing php tags.


    Humiges
    Participant

    @humiges

    Thank you very much.
    Sorry, I supposed to ask in my first question… if I want to have more profile types access to it, do I just change it to if
    ( bp_current_user_can( ‘editor’ , ‘administrator’ , ‘other’ ) ) :

    Thanks 🙂


    danbp
    Participant

    @danbp

    Hi,

    the function name contains current_user. So it seems you have to check the capability of the current_user, one cap by one, and not for all his capabilities.

    Try if( bp_current_user_can( 'editor' ) || ( bp_current_user_can( 'author') || and so on...) )
    or better bp_current_user_can( 'bp_moderate' ).

    More details about bp_current_user_can are given by @jjj(BP project lead) in this topic.

    To clarify the situation, in the first topic you mention “administrator” and “editor”, which are WP roles.

    In the second topic you speak about profile types. Sorry for this question, but do you mean you’ve created new WP roles or did you created some member types ?
    This is ambigous. Give details please.

    It’s important to know because WP roles and member_types are absolutely not the same thing as they don’t work identical.

    Default WP role of a BuddyPress member is “subscriber”.
    If you create a member type Teacher and asign it to a user, you then have a subscriber with a member type of Teacher.

    At this stage, you can eventually sort your members by type, but they don’t have any additionnal capability outside those allowed for “subscriber”.

    In the same way, you can have users with “author” or “editor” (wp) role and give them a Teacher member type.

    In this case, you have subscribers, authors and editors listed/appearing/or whatever inside BP as Teacher, and for each role, what they can do inside WP.


    Humiges
    Participant

    @humiges

    Thank you very much for your kind answer.
    You are right, I’m creating new profile types as your Teacher example.
    The reason is, that statuses should be accessible to only trusted users… we are not planning to be next Facebook with ‘any status’ – but we would like to give the access to those trusted users which we are sure, wouldn’t abuse it 😉
    Thanks a lot for all of your thoughts
    All the best 🙂


    danbp
    Participant

    @danbp

    To complete this topic, a little tutorial to restrict Updates to a BuddyPress “member_type” (not a WP role).
    Spec: only Teachers are allowed to publish.
    Required: a member_type of “teacher”.

    The Update form used for Site, Members and Group activities is in
    wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/activity/post-form.php
    This form is called by the function bp_get_template_part everywhere BP needs it. In this case, in 3 different component: activities, members and groups.

    What we are going to do is to add a condition before calling the template part. Without altering core or even your theme. Just telling BP to show the form if condition is ok and doing nothing if the condition doesn’t fit.

    Let’s go !

    You need a template overload of 3 files. Copy them into your child theme buddypress directory by respecting the path (ie. child-theme/buddypress/members/single/file

    wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/activity/index.php
    	Line 31: <?php bp_get_template_part( 'activity/post-form' ); ?>
    
    wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/groups/single/activity.php
    	Line 54: <?php bp_get_template_part( 'activity/post-form' ); ?> 
    
    wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/members/single/activity.php
    	Line 48: bp_get_template_part( 'activity/post-form' );

    In each file before bp_get_template_part there is an if statement.

    We’re going to add one more for the member_type of “teacher” by using var $member_type == 'teacher'

    For that, we need a user_id and the member_type of that user. If both fit to the whole if condition, we call the template part. If not, the template is not called. And voila.

    We are adding 2 lines: ($user_id and $member_type) and a condition (&& $member_type == 'teacher') to the existing statement.

    The only thing you have to change is the member_type name (teacher) to fit yours.
    If you do it correctly, here’s how the end result should look alike.

    This snippet goes to /activity/index.php (see line # above)

    <?php 
    $user_id = bp_loggedin_user_id();
    $member_type = bp_get_member_type( $user_id );
    
    if ( is_user_logged_in()  &&  $member_type == 'teacher' ) : ?>
       <?php bp_get_template_part( 'activity/post-form' ); ?>
    <?php endif; ?>

    This one goes to /groups/single/activity.php

    <?php 
    $user_id = bp_loggedin_user_id();
    $member_type = bp_get_member_type( $user_id );
    
    if ( is_user_logged_in() && bp_group_is_member() &&  $member_type == 'teacher' ) : ?>
       <?php bp_get_template_part( 'activity/post-form' ); ?>
    <?php endif; ?>

    And this one is for /members/single/activity.php

    <?php
    $user_id = bp_loggedin_user_id();
    $member_type = bp_get_member_type( $user_id );
    
    if ( is_user_logged_in() && $member_type == 'teacher' && bp_is_my_profile() && ( !bp_current_action() || bp_is_current_action( 'just-me' ) ) )
    	bp_get_template_part( 'activity/post-form' );
    
    /**
     * Fires after the display of the member activity post form.

    In hope it helps.

    Codex Reference


    Humiges
    Participant

    @humiges

    WOW, thank you so much @danbp,
    I’ll test it tomorrow and let you you.
    BTW, you are a STAR 🙂
    Thank you soooo mcuh 🙂

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