BuddyDev

Search

[Resolved] Hiding Admin from activity stream, Recently Active Members widget etc

  • Participant
    Level: Enlightened
    Posts: 21
    Edward on #20514

    Hi Brajesh,

    I got this code from your site but need advise on where to place it:

    add_action(“plugins_loaded”,”bpdev_init_sm_mode”);
    function bpdev_init_sm_mode(){
    if(is_super_admin())
    remove_action(“wp_head”,”bp_core_record_activity”);//id SM is on, remove the record activity hook
    }

    Would appreciate your feedback.

    Have a great weekend!

    Best regards
    Edward

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #20518

    Hi Edward,
    The code does not remove admin’s activity from activity stream. It only disables the recording of “last activity time” of a user.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 21
    Edward on #20531

    Hi Brajesh,

    This is the correct code and its worked perfectly when placed in themes functions.php:

    /**
    * Exclude Users from BuddyPress Members List by WordPress role.
    *
    * @param array $args args.
    *
    * @return array
    */
    function buddydev_exclude_users_by_role( $args ) {
    // do not exclude in admin.
    if ( is_admin() && ! defined( ‘DOING_AJAX’ ) ) {
    return $args;
    }

    $excluded = isset( $args[‘exclude’] ) ? $args[‘exclude’] : array();

    if ( ! is_array( $excluded ) ) {
    $excluded = explode( ‘,’, $excluded );
    }

    $role = ‘administrator’;// change to the role to be excluded.
    $user_ids = get_users( array( ‘role’ => $role, ‘fields’ => ‘ID’ ) );

    $excluded = array_merge( $excluded, $user_ids );

    $args[‘exclude’] = $excluded;

    return $args;
    }

    add_filter( ‘bp_after_has_members_parse_args’, ‘buddydev_exclude_users_by_role’ );

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #20544

    Thank you Edward,
    For others looking for the same,
    The code is from the blog post. Please see the post for details.
    https://buddydev.com/hiding-users-on-buddypress-based-site/

    Regards
    Brajesh

The topic ‘ [Resolved] Hiding Admin from activity stream, Recently Active Members widget etc’ is closed to new replies.

This topic is: resolved