Skip to:
Content
Pages
Categories
Search
Top
Bottom

using friends_check_friendship

  • Avatar of Matt082606
    matt082606
    Participant

    @matt082606

    Hello,

    I have added some extra features to wpmu and using the buddy press friend feature I need to verify friendships.

    I do this:

    if ( friends_check_friendship( $current_user->ID, $adm_id )

    where current_user->ID = the loggedin users ID number, and $adm_id = the user ID of the friend I am comparing too.

    my problem is that it always returns false, if I edit the function in bp-friends.php and make it return true then the code works so I know that the error is within that function.

    Is there a reason I wouldn’t be able to call that function? do I need an include in order to properly use it?

    Thanks

    EDIT:

    Also, I have tried to just manually put numbers here of two ID’s I KNOW are friends, still false return.

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • Avatar of Matt082606
    matt082606
    Participant

    @matt082606

    I know it’s only been one day, but here are some updates to what I’ve done to troubleshoot the problem.

    1) I placed an echo within the function friends_check_friendship that tells me what was returned and also tells me what the ID’s are for the two users being compared.

    This verified that I am passing correct data in and I am getting back ‘not_friend’ however when I go to the wire page, the same data goes in and I get back ‘is_friend’ so for some reason when calling this function from the wp-includesquery.php I am not getting back the correct data. I have also tried adding the following:

    require_once (./wp-content/mu-plugins/bp-core.php);

    include_once (./wp-content/mu-plugins/bp-friends/bp-friends-ajax.php); <- and all files in this folder, just like at the top of bp-friends.php

    Does ANYONE have a clue why this isn’t working?

    Avatar of Burt Adsit
    Burt Adsit
    Participant

    @burtadsit

    I’m not sure in what context the function is being called. You are saying this works in bp for you but not outside of bp? The call might be failing because the bp globals might not be fired up. bp’s plugins get loaded but bp relies on the ‘wp’ action to init the $bp global object which has all the table names and other goodies bp needs to operate.

    You are making the fn call from inside query.php inside of a wp theme context? Is this from an ajax context? If it’s ajax then bp doesn’t have any plugins loaded or global vars instantiated.

    Try doing this in an ajax context:

    wp-load.php like you are then

    wp();

    See Andy’s /bp-core/bp-core-ajax-handler.php for how he does this.

    Avatar of Matt082606
    matt082606
    Participant

    @matt082606

    no I am doing this call from within the wp_query class function get_post. if I add wp(); I get server error, from I guess an infinite loop.

    I realize there has to be something missing from the bp, I just don’t know what that is, I’ve included everything I can think of, and I’ve added global $bp.

    In all honesty there is no reason this shouldn’t work but it’s not so there has to be something I am missing and when I find it I am sure it will be something that is so obvious, which makes this all the more painful.

    Just for more info, the function exists in bp-friends.php in the mu-plugins root. it makes the call to the function BP_Friends_Frienship::check_is_friend… now this class and function exists in the bp-friends-classes.php within the bp-friends folder. I also have an include to this. I tried including ALL the files that are included in bp-friends.php, even though that seems redundant.

    I don’t know what to do next, I think I am going to just create my own friend check function to query the db at this point.

    Avatar of Matt082606
    matt082606
    Participant

    @matt082606

    one more thing, this line specifically “$bp” inside of bp-friends-classes is where I feel that this is failing. now there is a global $wpdb, $bp; and again this will pass when being pulled from other pages within the core of bp…

    perhaps that will help, is there something I need to add to make sure that this will work?

    Avatar of Burt Adsit
    Burt Adsit
    Participant

    @burtadsit

    Well, I can’t look at the same code you are running because I’m running RC-1 and the latest trunk. The global var $bp is not an array any more it’s an object now. Take a look at bp-core.php and the <component>_setup_globals() functions to get to know the new layout of this object. It’s got all the same things but we reference them differently now.

    It’s not a very good idea to be modifying the wpmu core code for any reason. That being said, I see where you are calling the fn from now. I still don’t know the context in which you are calling this function. This is within a theme you are building?

    I’m marking this a ‘not a support question’ because this really has nothing to do with bp support.

    Where are you calling this modified wp_query member function? In a theme? I gotta have some idea of the context. The wp_query obj doesn’t have a context all by itself. It can be called from anywhere.

    Avatar of Matt082606
    matt082606
    Participant

    @matt082606

    I guess I should start at the beginning.

    A) I’ve made LOTS of core mods, I have no plans of upgrading, as I am heavily customizing this and removing as many features as I will be adding.

    This particular thing comes from me adding 2 check boxes where you post a blog entry now the user has a choice of “keep private” “friends only” and “logged in members only” so when checking friends, or loggedin I set the post_status to friend, or loggedin respectively. This allows me when any theme calls “THE LOOP” as it were I can look at the post_status and decided if the user matches the credentials.

    As for now what I have working is if user is logged in the loggedin only posts show with all of the standard published posts no problem. if the user is the owner then everything shows, but if the user is a friend the friend check is failing and there-by not showing the friend only posts.

    The place I have injected this is in query.php file. I think I’m going to look through this quite a bit more today on my own… I’ll post the result in case others are trying to use this function from outside the bp-core.

    Avatar of Matt082606
    matt082606
    Participant

    @matt082606

    I fixed this, I decided to come back and post the solution incase others try to use this same function throughout their site.

    I was right about the failure being “$bp”, all I did was finally hardcode the value of that into the db query. it should be wp_bp_friends if you left everything as default, but if for security reasons you used a different table header yours may look different so make sure you get it right or it will stop working for friend wire posting and other friend based features.

    The reason I use this is for a friends only posting feature I added to my site which allows users now to make a post that can only be read by those on the friends list.

    Avatar of Burt Adsit
    Burt Adsit
    Participant

    @burtadsit

    OK. Thanks for getting back to me about the solution. I’m still kinda hazy on the problem. Glad you got it working.

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

You must be logged in to reply to this topic.