BuddyDev

Search

[Resolved] Block Users plugin


  • Participant
    Level: Guru
    Posts: 617
    calu on #30014

    Hi Brajesh, congratulations, and thanks for the new, and much needed Block Users plugin.

    The features are good, the only option missing, is to hide the Block button in Members Directory and Recent Visitors list.

    One issue, the plugin seems to overrule this code snippet, for excluding admins in user list, as the admin are displayed with the plugin activated.

    
    /**
     * Exclude logged and admin users from BuddyPress users list.
     * https://buddydev.com/support/forums/topic/hide-current-logged-in-user-and-admin/#post-14503
     *
     * @param array $args member loop args.
     *
     * @return array
     */
    function buddydev_exclude_logged_and_admin_users( $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 );
    
    	if ( is_user_logged_in() ) {
    		array_push( $excluded, get_current_user_id() );
    	}
    
    	$args['exclude'] = $excluded;
    
    	return $args;
    }
    
    add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_logged_and_admin_users' );
    

    I want to move the block option from the header to another position under profile content, can you provide me with the function for the block button I should use?

    Regards
    Carsten


  • Keymaster
    (BuddyDev Team)
    Posts: 14737
    Brajesh Singh on #30020

    Hi Carsten,
    Thank you for using the plugin.

    Please upgrade to 1.0.1.

    It will fix the exclude issue. Does not override it anymore.

    To dosable the button, you can out this code in your fnctions.php(of theme) or in bp-custom.php

    
    
    add_filter( 'bublock_show_button_in_profile_header', '__return_false' );
    

    You cal put the button anywhere by using this code

    
    
    if ( function_exists( 'bublock_get_button' ) ) {
    	echo bublock_get_button( $user_id );
    }
    
    

    Where $user_id is the user’s id.

    Regards
    Brajesh


  • Participant
    Level: Guru
    Posts: 617
    calu on #30021

    Hi Brajesh, thanks for adding a solution for disabling the button.

    About the wish for disabling the Block option in Members Directory, should I use CSS for that, or will there be a solution to this?

    It might makes sense to me, to have the block button in the Recent Visitors list, but not in the Members Directory.

    Apparently the class is the same for both Members Directory, and Recent Visitors list, should I use page id to hide the relevant button on the relevant page?

    Regards
    Carsten


  • Keymaster
    (BuddyDev Team)
    Posts: 14737
    Brajesh Singh on #30022

    Hi Carsten,
    Thank you.

    You can use the following to disable it in the members list

    
    add_filter( 'bublock_show_button_in_members_directory', '__return_false' );
    

    The plugin does not differentiate between various members list though.

    Regards
    Brajesh


  • Participant
    Level: Guru
    Posts: 617
    calu on #30023

    Thanks Brajesh


  • Keymaster
    (BuddyDev Team)
    Posts: 14737
    Brajesh Singh on #30024

    You are welcome.

    PS:- I will be adding option to turn it off/on from admin as well in the upcoming releases.

    Regards
    Brajesh


  • Participant
    Level: Guru
    Posts: 617
    calu on #30025

    Hi Brajesh, sounds great, options for both Recent Visitors and Members Directory would be much appreciated, thank you!

    Regards
    Carsten


  • Keymaster
    (BuddyDev Team)
    Posts: 14737
    Brajesh Singh on #30029

    Thank you.


  • Participant
    Level: Guru
    Posts: 617
    calu on #30057

    Hi Brajesh, if I use this code as it is, the Block button is displayed on own profile as well, so I need some kind of denial to the statement, like the opposite to if ( bp_is_my_profile() ) {}?

    
    if ( function_exists( 'bublock_get_button' ) ) {
    	echo bublock_get_button( $user_id );
    }
    

    2.

    Notice: Undefined variable: user_id in /home/domain/public_html/wp-content/plugins/gp-premium/elements/class-hooks.php(180) : eval()’d code on line 4

    I get this error because of the undefined $user_id, but to my understanding this a variable that should not be defined, would you please clarify about this?

    This is how I added the code to the element:

    <?php
    
    if ( function_exists( 'bublock_get_button' ) ) {
    	echo bublock_get_button( $user_id );
    }
    
    ?>

    Regards
    Carsten


  • Keymaster
    (BuddyDev Team)
    Posts: 14737
    Brajesh Singh on #30062

    Hi Carsten,
    In my code above, you need to pass the actual user id.

    For example, if you want to show it on profile, You can use bp_displayed_user_id() for that.

    Here is the updated example.

    
    
    if ( is_user_logged_in() && function_exists( 'bublock_get_button' ) && bp_is_user() && ! bp_is_my_profile() ) {
    	echo bublock_get_button(bp_displayed_user_id() );
    }
    

    This code will only show button on other user’s profile.

The topic ‘ [Resolved] Block Users plugin’ is closed to new replies.

This topic is: resolved
Subscribe