The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Formidable Pro to Buddypress Activity

Labels

This Discussion is public

Notifications

As it has been requested before,

with the help of $form_id hook you can post a Buddypress activity when a entry is submitted:

add_action('frm_after_create_entry', 'after_entry_created', 30, 2);
function after_entry_created($entry_id, $form_id) {
if ( ! bp_is_active( 'activity' ) ) {// Check if the Activity component is active before using it.
        return;
    }
if(($form_id == XXX) { // Replace XXX with the ID of your form
 $message=sprintf( __( 'Your Message'));
 bp_activity_add( array(
 'id' => false,
 'user_id' => bp_loggedin_user_id(),
 'item_id' => false,
 'action' => $message,
 'component' => 'profile', //or whatever you want as BP component
 'primary_link' => false, // or link you want
 'type' => 'profile_updated', //or whatever you want as BP component type
 'hide_sitewide' => false,
 'is_spam' => false
 ));
}
}

Thanks for the code!   I'm going to try it out.

Update: it worked, now I just need to customize it. Thanks again, it should come in handy.

Great! it could be safer to check if Buddypress Activity is active, as in the code updated above.

Thanks, I'll add that.  I also added another parameter to show additional content in the BuddyPress activity.    You didn't include the 'content' parameter.   I set mine for the post title but will probably combine several form fields for the content.

'content' => $_POST['item_meta'][85],

BTW There is an extra '(' in this line below that needs to be removed.

if(($form_id == XXX) { // Replace XXX with the ID of your form

should be if($form_id == XXX)

Awesome snippet! Thanks a bunch. :)

Has anyone figured out how to get the BP username in the $message variable (or on that same line) as in other activity items?

You can try something like that :

$user_id= $_POST['item_meta'][XXX]; // where XXX is the field ID of your form's hidden field ID 
$user=get_user_by('id',$user_id);
$username=$user->display_name; 

and you can add $username in the text of your $message

Thanks! That works just fine when added to the action like so:
'action' => $username . $message,
Now, how to link the username to the user profile, lol?


<a href="/members/'.$username.'">'.$username.'</a>

Thanks, that's what I first tried, lol. But that generates a URL with the display name in it, rather than the username. So, instead of this:

example.com/members/Jake Someguy
We would want this:
example.com/members/username

in that case you change your $username with

$username=$user-> user_login;

it should make it (I didn't try)

Yup, just had a flash with the same idea. That works perfectly!

Now on to try & figure out how to get a custom filter on the frontend for this new activity:
https://codex.buddypress.org/plugindev/add-custom-filters-to-loops-and-enjoy-them-within-your-plugin/

Thanks so much for your help!

Discussion closed.