Skip to:
Content
Pages
Categories
Search
Top
Bottom

Access to BP functions in external code via wp-load


  • johnmontfx
    Participant

    @johnmontfx

    I’m tying to utilize some of the BuddyPress Extended profile field information on a custom area of my site, but it seems as though certain values aren’t being initialized before I try to access them. More specifically:

    On my custom php page, I load WordPress with the following:

    require_once( WORDPRESS_DIR . '/wp-load.php');

    Lots of WordPress functions work great (even BuddyPress functions). But a bit after this require I’m trying to use the following function:

    xprofile_get_field_data( $field,$user_id );

    The function is accessible, but regrettably it appears as though $bp->profile->table_name_fields is empty…so it can’t search the database for the appropriate field. I end up getting blank results.

    What do I need to do in order to have BuddyPress (and even bbPress) load more fully?

    Thanks — and Merry Christmas!

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

  • johnmontfx
    Participant

    @johnmontfx

    Grr…the subject should have been:

    “Access to BuddyPress functions in external code via wp-load?”


    danbp
    Moderator

    @danbp

    I guess you do it wrong.

    If you need an extra page, the usual method is to copy the page.php file of your theme into your child-theme and make your modification in that file.

    See WP and BP codex for this.

    To show an xprofile value somewhere, and specially outside of the profile loop, you just write a function for that and add it to your child-theme functions.php

    This forum is full of examples of how you can do this.

    As example, here’s a snippet to fetch a profile field with the ID 42

    function bpfr_field( $custom_field ) {
    	global $bp;
    	
    	// is xprofile component active ?
    	if ( bp_is_active( 'xprofile' ) )
    	
    	// fetch the user_id. Mandatory.
    	$current_user = wp_get_current_user();
    	$current_user_id = $current_user->ID;
    	
    	// fetch the data
    	$custom_field = xprofile_get_field_data('42', $current_user_id); // 42 is a field ID
    	
    	// show the data
    	echo '<div class="authorinfo">'. $custom_field .'</div>';
    	
    }
    add_action( 'myfield', 'bpfr_field', 1 );
    

    And at the appropriate place on your template, you add an action hook

    <?php do_action( 'myfield'); ?>

    No need to reinvent the wheel or to call wp twice. 😉


    johnmontfx
    Participant

    @johnmontfx

    Thanks so much Dan — I really appreciate the response. Eventually I will be doing things the way you suggest, but I have a custom architecture for a learning site that I’m transitioning to WordPress over the next six months. There are dozens of pages and interdependencies which I’m cleaning up, so I’ve decided to do the integration in stages since it will take time.

    I can write some custom db code to grab the information from the appropriate xprofile table, but I was hoping to not fully reinvent the wheel as you suggested. At this point, I’ve probably spent more time trying to use the bbpress functions than it would have take to write my own db function 🙂

    I think the issue is that bp-xprofile-loader.php hasn’t been called yet, which is where those values get defined. So it seems that bbpress gets loaded but not fully initialized until somewhere later in the code. Maybe when the templates load or wp() is called.

    Thanks again…really appreciate your time and the sensible response.


    johnmontfx
    Participant

    @johnmontfx

    By the way, so bar bbpress has been a good experience. I’m transitioning over from vbulletin and have done quite a bit of customization to the importer to bring over all our old user data intact.

    It seems like a good community…I’m missing some vb features, but so far am pleased with the move…


    danbp
    Moderator

    @danbp

    You’re welcome !
    bbPress and BuddyPress are TWO separate plugin, and you’re here on the BuddyPress support. 😉

    If you have questions related to bbP, please visit their support for better chance to get the right answer.

    As it is a bit unclear what you’re doing with buddypress for the moment, see here about vbulletin import into bbPress.


    johnmontfx
    Participant

    @johnmontfx

    Thanks Dan — while they are separate plugins I’m sure you’ll agree that they are very much joined at the hip (as bbPress even includes BuddyPress functions). What was really nice was the ability to bring in extended Vbulletin profile information over to to BuddyPress extended profiles at the same time as importing to bbPress. Took some custom coding, but the code in both plugins made it fairly clear about how to accomplish it. Makes it easy to use in both plugins.

    As far as what I’m trying to do with BuddyPress, it’s basically the issue in the first post. I’ve traced the code a bit more and my main issue right now is simply figuring out if I could get access to the xprofile_get_field_data function. wp-load.php doesn’t seem to call the bp-xprofile-loader.php, so $bp->profile->table_name_fields is empty.

    In the meantime, I’ve just issued some mysql db calls to grab the info…but I’d love to use the built in functions if I could.


    danbp
    Moderator

    @danbp

    FYI
    http://ottopress.com/2010/dont-include-wp-load-please/

    Read also the comments in /bp-core/bp-core-actions.php

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Access to BP functions in external code via wp-load’ is closed to new replies.
Skip to toolbar