Skip to:
Content
Pages
Categories
Search
Top
Bottom

inserting field into profile area of topics and replies


  • andrew55
    Participant

    @andrew55

    Is there a function to insert a profile field below the users avatar in topics and replies?

    I have some custom php that will create the value for the field but I can’t figure out how to insert the field in the profile area in topics and replies.

    I found a great plugin: bbp buddypress profile information

    It does a great job of showing BP fields in bbpress forum profiles. But I still can’t figure out how to have our custom php snippet be the source of the value for the field.

    Thanks for any suggestions.

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

  • Robin W
    Moderator

    @robin-w

    glad you like the plugin – I wrote it, and also

    https://wordpress.org/plugins/bbp-profile-information/

    which just does bbpress if you don’t have buddypress, and might be the better one to crib from.

    if you download it and look at

    includes/display.php you’ll see it hooks to an action in bbpress

    add_action (‘bbp_theme_after_reply_author_details’, ‘bbp_profile_information’) ;

    so you just (!) need to create a function that echos the output of your snippet and use that in the hook.

    Not sure of your php knowledge level, so do come back if you need further help


    andrew55
    Participant

    @andrew55

    Thanks – this is a great start. Although, my skill level just isn’t there yet with writing functions for WordPress. Here is the php snippet I have that will create the value I need to have displayed in profile area of topics and replies:

    <?php
    require_once '/home/site/public_html/amember/library/Am/Lite.php';
    if (Am_Lite::getInstance()->haveSubscriptions(2))
    {
    ?>
    <p>custom text 1</p>
    <?php
    }
    else {
    if (Am_Lite::getInstance()->isLoggedIn())
    {
    ?>
    <p>custom text 2</p>
    <?php
    }
    else {
    ?>
    <p>custom text 3</p>
    <?php
    }
    }
    ?>

    If anyone is willing to help, that would be great.


    Robin W
    Moderator

    @robin-w

    ok assuming it works it just needs wrapping into a function, and then adding to the action so :

    <?php
    Function andrew55_insert_field () {
    require_once '/home/site/public_html/amember/library/Am/Lite.php';
    if (Am_Lite::getInstance()->haveSubscriptions(2))
    {
    ?>
    <p>custom text 1</p>
    <?php
    }
    else {
    if (Am_Lite::getInstance()->isLoggedIn())
    {
    ?>
    <p>custom text 2</p>
    <?php
    }
    else {
    ?>
    <p>custom text 3</p>
    <?php
    }
    }
    }
    

    which could be shortened to

    Function andrew55_insert_field () {
    require_once '/home/site/public_html/amember/library/Am/Lite.php';
    if (Am_Lite::getInstance()->haveSubscriptions(2)) echo '<p>custom text 1</p>' ;
    elseif (Am_Lite::getInstance()->isLoggedIn() ) echo '<p>custom text 2</p>' ;
    else echo '<p>custom text 3</p>' ;
    }
    
    add_action (‘bbp_theme_after_reply_author_details’, ‘andrew55_insert_field ’) ;

    that might upset the purists who seem to love have php statements all over their code, but makes it more readable – apologies if you’re in the purist camp 🙂

    You need to put this code into your functions file, so that it is automatically called when the action is executed

    Functions files and child themes – explained !


    andrew55
    Participant

    @andrew55

    Wow – thanks for taking the time to create this. Much appreciated. I’m a realist, not so much of a purist!

    Unfortunately, I am getting this error in the profile area of all topics and replies:

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'andrew55_insert_field ' not found or invalid function name in /home/mysite/wp-includes/plugin.php on line 496

    I tried function with both “bbp buddypress profile information” and “bbp profile information” installed.

    Another idea – instead of pestering for help with advanced php functions, what about just throwing the snippet I have in a template file in my child theme?

    I’ve been looking, but I can’t find the correct template file that controls the “user profile area” for the topics and replies when viewing a single topic. Any suggestions on where I might find this file so I can give it a try? It seems like it would be loop-single-topic.php, but that is for the view for all the topics together.

    I’m still new to bbPress and am finding it tricky to learn my way around the files – but I’m getting there!

    Thanks for any suggestions.


    andrew55
    Participant

    @andrew55

    Got it: loop-single-reply.php


    Robin W
    Moderator

    @robin-w

    great, putting it in the template is equally fine, BUT make sure you put that template into a child theme, else plugin and theme updates will destroy it.

    Functions files and child themes – explained !

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