How to use bp-custom.php properly with BuddyDev snippet?

Okay, so I found this brilliant code snippet by BuddyDev(tinyurl.com/lpxbrwc), but, being a newbie to all of this, I have absolutely no clue how to use it.

I want to use the first code snippet of the article to hide a specific user (with username: wpengine and ID: 1) from my Buddypress Members Directory.

Can somebody post what I would exactly need to enter into bp-custom.php (tags, no placeholders, etc.)? As in, I could just copy and paste this into my bp-custom.php and it should work as is.

This would be really appreciated.

  • signed_up
    • The Crimson Coder

    To clarify, I do want help on the first snippet. I’ll paste it below in case:

    add_action('bp_ajax_querystring','bpdev_exclude_users',20,2);
    function bpdev_exclude_users($qs=false,$object=false){
    //list of users to exclude

    $excluded_user='1,2,3';//comma separated ids of users whom you want to exclude

    if($object!='members')//hide for members only
    return $qs;

    $args=wp_parse_args($qs);

    //check if we are listing friends?, do not exclude in this case
    if(!empty($args['user_id']))
    return $qs;

    if(!empty($args['exclude']))
    $args['exclude']=$args['exclude'].','.$excluded_user;
    else
    $args['exclude']=$excluded_user;

    $qs=build_query($args);

    return $qs;

    }

    Please do read the article though (at least the beginning) to understand what is happening.

  • signed_up
    • The Crimson Coder

    Are there any developers (staff & community) who are willing to help me with this by either posting the code snippet (that I can copy and paste into empty bp-custom.php document) or attaching bp-custom.php file with just this code in it?

    That would really be helpful.

  • signed_up
    • The Crimson Coder

    Oh, sorry about the last post. I was on a non-refreshed page and obviously, there was a delay, so I didn’t see your post, Tom. I did actually mess-up the link, sorry about that.

    Here is the non-shortened url: http://buddydev.com/buddypress/exclude-users-from-members-directory-on-a-buddypress-based-social-network/

    UPDATE: Just found out that you can’t attach .php files, so please just post the code that I can copy and paste directly into empty bp-custom.php. Thank you.

  • Patrick
    • Support Monkey

    @signed_up

    Your question is an easy one. :slight_smile:

    Simply enter the actual user IDs to replace the 1,2,3 in $excluded_user=’1,2,3′. Then be sure to wrap the entire code in php tags like this

    <?php ALL_THE_CODE_HERE ; ?>

    Then save that document as bp-custom.php and upload the file to your wp-content/plugins folder.

  • signed_up
    • The Crimson Coder
    <?php
    add_action('bp_ajax_querystring','bpdev_exclude_users',20,2);
    function bpdev_exclude_users($qs=false,$object=false){
     //list of users to exclude
     
     $excluded_user='10';//comma separated ids of users whom you want to exclude
     
     if($object!='members')//hide for members only
     return $qs;
     
     $args=wp_parse_args($qs);
     
     //check if we are listing friends?, do not exclude in this case
     if(!empty($args['user_id']))
     return $qs;
     
     if(!empty($args['exclude']))
     $args['exclude']=$args['exclude'].','.$excluded_user;
     else
     $args['exclude']=$excluded_user;
     
     $qs=build_query($args);
     
     return $qs;
     
    };
    ?>

    Is that correct?

  • signed_up
    • The Crimson Coder

    When, I paste the above code (that I just posted) into an empty bp-custom.php folder, I get a Server Error and my website is inaccessible. When I delete the contents of bp-custom.php, my site performs perfectly well, but the user is not hidden.

    I want to note that I have used Better WP Security to change the wp-content directory to “anotherdirectoryname” (just an example), so when I go through FTP, I do not have a wp-content folder, but a “anotherdirectoryname” folder.

    So bp-custom.php is placed in anotherdirectoryname/plugins

    Do you think that has anything to do with it?

  • signed_up
    • The Crimson Coder

    Trying that. My “functions.php” is jam-packed with code. Some (maybe all) is from the theme author and some might be from plugins (probably all from theme author).

    Is there a specific location within the functions.php that I need to enter this or right at the beginning?

  • signed_up
    • The Crimson Coder

    I entered the code (without start and end tags) right after the first opening php tag that was already in my functions.php document. I received the same server error. I’m really lost here and have no clue what to do.

    I don’t think it has anything to do with my wp-content directory being renamed, because there is content that my theme author wrote in functions.php (which has to go through “myrenamedwp-contentdirectory” to reach) and my site works perfectly fine.

    All I know is that I need help fast. Not trying to sound rude though, I really do appreciate your help.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.