Skip to:
Content
Pages
Categories
Search
Top
Bottom

Get XProfile Field outside of BuddyPress!


  • Buddy Quaid
    Participant

    @buddyq

    For the life of me, I cannot seem to fetch an xprofile field that I need to put into a custom email inside my custom plugin.

    I have scoured these forums all day and tried everything but nothing seems to work.

    – Custom plugin.
    I want to custom field “Name” that the person is required to fill out when registering for the site.

    function aa_activated_user_email( $msg, $user){
      global $bp;
      $users_name = bp_get_member_profile_data( 'field=Name&user_id=' . $user->ID );
      $msg  = "<h1>A User has been activated!</h1>";
      $msg .= "<p>Name: <strong>$users_name</strong><br>";
    }

    This just throws an error:
    PHP Fatal error: Call to undefined function bp_get_member_profile_data()

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

  • Buddy Quaid
    Participant

    @buddyq

    UPDATE:

    I got things ALMOST working now. Looks like this code MUST be in a function in order to operate properly for some reason.

    Here is the code:

    $user_id = $user->ID;
    write_log('$user_id: '. $user_id); // This output the user ID correctly in my log!
    $users_name = xprofile_get_field_data( 'Name', $user_id );

    This does NOT work. It’s blank. For some reason it will not fetch the user id.

    The following code DOES work:

     $user_id = $user->ID;
      write_log('$user_id: '. $user_id);
      $users_name = xprofile_get_field_data( 'Name', 3 );

    Just hard coding the user_id actually gives me a result.
    Why is it not taking the $user_id which does output a real value?


    leog371
    Participant

    @leog371

    Wrap that in a BuddyPress Loop on whatever template your using it on.

    https://codex.buddypress.org/type/loop/

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