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
Formidable Pro to Buddypress Activity
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 )); } }
March 18, 2015 at 1:49 am
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.
March 18, 2015 at 3:47 am
Great! it could be safer to check if Buddypress Activity is active, as in the code updated above.
March 18, 2015 at 4:13 am
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)
July 11, 2015 at 10:49 am
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?
July 12, 2015 at 4:29 am
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
July 12, 2015 at 8:08 am
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?
July 12, 2015 at 8:48 am
<a href="/members/'.$username.'">'.$username.'</a>
July 12, 2015 at 9:14 am
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
July 12, 2015 at 9:17 am
in that case you change your $username with
$username=$user-> user_login;
it should make it (I didn't try)
July 12, 2015 at 9:20 am
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.