Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp tags not working in plugins?

  • @peterverkooijen

    Participant

    I’m trying to prefill a field in a plugin form. I get no results with this:

    <input value="<?php bp_user_fullname() ?>">

    This little test did work:

    <input value="<?php echo "test"; ?>">

    bp tags don’t work in plugins? Should I move the plugin to mu-plugins and/or activate it site-wide?

    Is there a way to “associate” the plugin with Buddypress or would that be bad practice?

    Can I get the required data – first name, last name, email – from standard WP tables with standard WP tags? Is there a list of those tags anywhere…?

    Thanks for any pointers!

Viewing 6 replies - 1 through 6 (of 6 total)
  • @jeffsayre

    Participant

    Make sure that in your plugin function you declare the global variable “$bp”:

    global $bp;

    @peterverkooijen

    Participant

    Thanks Jeff Sayre!

    The plugin has a very messy structure. I’ve tried with $bp added to global in several functions in the plugin, both in the main file and the file with the form. Nothing has any effect.

    Are there any downsides to adding $bp if it’s not strictly needed? Can you make any plugin “Buddypress ready” by just adding that $bp to global?

    I did get regular wp data working with help from their forum. I had to add this to the php:

    global $current_user;
    get_currentuserinfo();

    Does Buddypress have something like that? Anything else I can try?

    @johnjamesjacoby

    Keymaster

    BuddyPress has functions to get most of the data that you need without globaizing the $bp. I think different people will give you different answers about globals, but the general idea is that the less you use them is the better off you will be.

    BuddyPress wraps most of the return/echo functions for most content in the -templatetags.php files for each specific component. If you need data that isn’t available, you can always build your own function in bp-custom.php or whatever.

    If you look at the built in BP functions, you’ll see that $bp is globalized a lot in those functions, so the answer to your question comes down to the nuts and bolts of how PHP operates deep within the core of it, and how globals are processed on a per library basis and at what point in the process it occurs.

    Long story short, if it gets you where you need to be safely, it’s probably fine enough unless you notice a slow-down or something.

    @peterverkooijen

    Participant

    Thanks JJJ.

    I can’t get anything to show up with <?php bp_user_fullname() ?> and $bp in global.

    I also noticed that bp_user_email does not exist, so I guess I’ll need custom functions to get data from xprofile.

    The function get_currentuserinfo() is in wp-includes/pluggable.php. Should I try to adapt that code to xprofile? Or is there a better starting point somewhere?

    I can’t code php from scratch, I have to puzzle it together from examples… ;-|

    @jeffsayre

    Participant

    jjj is correct. If you are working on BP theme customizations, you can often find a template tag to grab and output the data. That will always be the best approach.

    But if you are creating your own plugin–as I am assuming based on the title of your thread–then you must make sure that the data you are manipulating in your various functions is made available to a given function’s logic. This can sometimes be done by passing the data via paramaters. But, sometimes the simplest approach is to redeclare a varibable in that function with global.

    I can’t get anything to show up with <?php bp_user_fullname() ?> and $bp in global.

    Try this:

    <?php echo bp_user_fullname() ?>

    @peterverkooijen

    Participant

    I’m not creating a plugin from scratch or doing any complicated manipulations on the data. I’m only trying to pre-populate fields in the RSVP form in this Event Registration plugin.

    Adding the ‘echo’ didn’t fix the problem. It probably is something stupid like that.

    Which code actually pulls the data from xprofile? I couldn’t make much sense of function bp_user_fullname(). The real magic apparently happens somewhere else.

    Getting regular wp data works fine. If I could figure out how to consistently synchronize firstname and last name between xprofile and wp_usermeta, that would solve the problem as well.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘bp tags not working in plugins?’ is closed to new replies.
Skip to toolbar