Skip to:
Content
Pages
Categories
Search
Top
Bottom

Make ADMIN everyones FRIEND?


  • coolhunt
    Participant

    @coolhunt

    Hey Guys,

    I imported my users and Id like to add ADMIN as everyones friend. I found this snippet…
    (But it doesnt work)

    function create_global_buddypress_friend($user_ID) {    
    global $wpdb;
    $now = date('Y-m-d H:i:s');
    $wpdb->insert($wpdb->prefix . "bp_is_friends", array('initiator_user_id' => $user_ID,'friend_user_id' => '1','is_confirmed' => '1','date_created' => $now));
    }
    add_action('user_register', 'create_global_buddypress_friend');

    Any ideas?

Viewing 1 replies (of 1 total)

  • Henry Wright
    Moderator

    @henrywright

    Try this:

    add_action( 'user_register', function( $user_id ) {
        $admin_id = 1;
        $friendship_status = BP_Friends_Friendship::check_is_friend( $user_id, $admin_id );
        if ( 'not_friends' === $friendship_status ) {
            if ( ! friends_add_friend( $user_id, $admin_id ) ) {
                // There was a problem submitting the friend request. Do something here.
            } else {
                // Friend request sent successfully. Do something here.
            }
        }
    } );

    Be sure to change $admin_id to the ID of your admin user.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar