Post to Buddypress Actvities

This topic contains 24 reply and 5 voices, and was last updated by Aaron 9 years, 11 months ago
Viewing 15 Posts - 1 through 15 (of 24 total)
Author Posts
April 29, 2013 at 12:45 pm 2982
Aaron Hi, I like to know if can use one form to publish an BP activity instead a post. Thsnks
April 29, 2013 at 6:35 pm 2987
Tareq Hasan Tareq Hasan

Sorry, it can’t be done. Only thing WPUF can do is creating post or custom post type.

June 11, 2013 at 9:02 am 4788
quokka quokka

Hi Tareq,

Thanks for the great plugin!
I used it to create a front end post form to submit to main blog in Buddypress.
Also I created a custom post type ‘imagegalleries’ where users can post photo’s to with WPUF.
Amazingly easy with WPUF!

One concern..
I would like the activity of posting to my custom post type and blog to be recorded in the BP activity stream..

I have been looking on how other plugins do it.
For example the BP Portfolio plugin logs all activity to the stream..

BuddyPress Portfolio

[php]/**
* Record an activity item
*/
function bp_portfolio_record_activity( $args = ” ) {
global $bp;

if ( !function_exists( ‘bp_activity_add’ ) )
return false;

$defaults = array(
‘id’ => false,
‘user_id’ => $bp->loggedin_user->id,
‘action’ => ”,
‘content’ => ”,
‘primary_link’ => ”,
‘component’ => $bp->portfolio->id,
‘type’ => false,
‘item_id’ => false,
‘secondary_item_id’ => false,
‘recorded_time’ => gmdate( "Y-m-d H:i:s" ),
‘hide_sitewide’ => false
);

$r = wp_parse_args( $args, $defaults );
extract( $r );

return bp_activity_add( array( ‘id’ => $id, ‘user_id’ => $user_id, ‘action’ => $action, ‘content’ => $content, ‘primary_link’ => $primary_link, ‘component’ => $component, ‘type’ => $type, ‘item_id’ => $item_id, ‘secondary_item_id’ => $secondary_item_id, ‘recorded_time’ => $recorded_time, ‘hide_sitewide’ => $hide_sitewide ) );
}
<pre><code>

bp-portfolio-activity.php has a function o update the stream and i gets called on every post creation or update.
</code></pre>
// Records an activity
if($result = $portfolio->save()) {

/* Now record the activity item */
$user_link = bp_core_get_userlink( $bp->loggedin_user->id );

$project = new BP_Portfolio_Item( array( ‘id’ => $result ) );
$project->get();

$title = $project->query->post->post_title;
$user_portfolio_link = ‘<a href="’. bp_core_get_user_domain($bp->loggedin_user->id) . BP_PORTFOLIO_SLUG . ‘">portfolio</a>’;

if($id) {
// Edit an existing item
bp_portfolio_record_activity( array(
‘type’ => ‘edit_project’,
‘action’ => apply_filters( ‘bp_edit_portfolio_activity_action’, sprintf( __( ‘%s edited the <strong>%s</strong> project in his %s’, ‘bp-portfolio’ ), $user_link, $title, $user_portfolio_link ), $user_link, $title, $user_portfolio_link ),
‘item_id’ => $bp->loggedin_user->id,
) );
}
else {
// New item, so new activity
$description = $project->query->post->post_content;
$url = get_post_meta($result, ‘bp_portfolio_url’, true);

$attachment = wp_get_attachment_image_src($project->query->post->post_parent, ‘portfolio-thumb’);
if($attachment != 0)
$thumbnail = apply_filters( ‘bp_portfolio_get_item_thumbnail’, $attachment[0]);
else
$thumbnail = apply_filters( ‘bp_portfolio_get_item_thumbnail’, BP_PORTFOLIO_PLUGIN_URL . ‘/templates/’ . BP_PORTFOLIO_TEMPLATE . ‘/img/default.png’);

$activity_content = sprintf(__( ‘<div class="item-project"><div class="item-project-pictures"><img width="250px" height="170px" src="%s"></div><div class="item-project-content"><div class="item-project-title">%s</div><div class="item-project-url"><a href="%s">%s</a></div><div class="item-project-desc">%s</div></div></div></div>’, ‘bp-portfolio’), $thumbnail, $title, $url, $url, $description);

bp_portfolio_record_activity( array(
‘type’ => ‘new_project’,
‘action’ => apply_filters( ‘bp_new_portfolio_activity_action’, sprintf( __( ‘%s created a new project in his %s’, ‘bp-portfolio’ ), $user_link, $user_portfolio_link ), $user_link, $user_portfolio_link ),
‘content’ => $activity_content,
‘item_id’ => $bp->loggedin_user->id,
) );
}

return true;
}[/php]

Any chance you could build this support into WPUF?
I’m willing to sponsor the development, maybe ggsalas is interested too?

Thanks!
Bas

June 11, 2013 at 5:14 pm 4792
quokka quokka

Looking at WPUF documentation and seems to me like the action hooks wpuf_add_post_after_insert ans wpuf_edit_post_after_update could be used to call a function likke the bp_portfolio_record_activity above that writes to the activity stream, or in’t it that easy?

Thanks,
Bas

June 11, 2013 at 7:02 pm 4795
Tareq Hasan Tareq Hasan

Hey Bas, yes you are right. Using those hooks you add the activities easily.

June 11, 2013 at 7:09 pm 4796
quokka quokka

Hi Tareq,

Thanks…i’m aready fooling around..
Can you tell me what I’m doing wrong please?
I didn’t play with action hooks before and while it looks pretty simple, I even can’t get this working:

<?php
/*
Plugin Name: Do action after insert or update
Plugin URI: http://www.basdebie.com
Description: Testing the action hooks of WPUF
Version: 1.0
Author: Bas Debie
Author URI: http://www.basdebie.com
License: GPL2
*/

function bd_trigger_wpuf_update_insert( $post_id ) {
    //update_post_meta( $post_id, 'artist', $_POST['song_artist'] );
	$to = "my_email_addres@domain.com";
	$subject = "Test mail from plugin";
	$message = "Hello! This is a test mail from plugin";
	$from = "my_email_addres@domain.com";
	$headers = "From:" . $from;
	mail($to,$subject,$message,$headers);
}
add_action( 'wpuf_add_post_after_insert', 'bd_trigger_wpuf_update_insert' );
add_action( 'wpuf_add_post_after_update', 'bd_trigger_wpuf_update_insert' );

?>

Thanks!
Bas

June 11, 2013 at 7:10 pm 4797
quokka quokka

I activated this simple plugin and when I add or update a post with the WPUF forntend form, nothing seems to happen..

Thanks!

June 11, 2013 at 7:15 pm 4799
Tareq Hasan Tareq Hasan

Your code is fine and it should work. May be some problem with the email delivery?

June 11, 2013 at 7:24 pm 4801
quokka quokka

;-D

You are right, seems like php mail() function not working on that domain hosting account. Tried on another domain / WP install and working fine!

Thanks Tareq,
If I manage to get this working I’ll post it here for other Buddypress users..
Bye…
Bas

June 11, 2013 at 8:29 pm 4805
quokka quokka

Hi Tareq (and anybody else that maybe interested)…

I managed to get this little plugin of mine working.

When I create a new post (of custom post type ‘photoalbum’) with WP User Frontend Pro this plugin also writes the activity to the Buddypress Activity Stream.

To use this with your own custom post type just search/replace for ‘photoalbum’ and replace with ‘your_custom_post_type_name’

Grab the code and save it as a WordPress plugin and you should be fine..

Thanks Tareq for pointing me in the right direction, and for making those handy action hooks available in WP User Frontend Pro 😀

Take care!
Bas

The plugin code:


<?php
/*
Plugin Name: Photoalbum CPT 2 Buddypress Activity Stream
Plugin URI: http://www.basdebie.com
Description: This plugin hooks into WP User Frontend and posts to the Buddypress Activity Stream on new photoalbum submission
Version: 1.0
Author: Bas Debie
Author URI: http://www.basdebie.com
License: GPL2
*/
 
 
 /**
 * Record an activity item
 * This code is taken from Nicolas Crocfer's BuddyPress Portfolio Plugin
 */
function bd_custom_bp_record_activity( $args = '' ) {
	if ( !function_exists( 'bp_activity_add' ) )
		return false;

	$defaults = array(
		'id' => false,
		'user_id' => '',
		'action' => '',
		'content' => '',
		'primary_link' => '',
		'component' => 'photoalbum',
		'type' => false,
		'item_id' => false,
		'secondary_item_id' => false,
		'recorded_time' => gmdate( "Y-m-d H:i:s" ),
		'hide_sitewide' => false
	);

	$r = wp_parse_args( $args, $defaults );
	extract( $r );
	return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
}

/**
 * After post photoalbum update the Buddypress Activity Stream
 */
function bd_after_photoalbum_insert( $post_id ) {
	
	global $bp;
	if( get_post_type( $post_id ) == "photoalbum" ) {
	bd_custom_bp_record_activity( array(
				'user_id' => $bp->loggedin_user->id,
				'action' => sprintf(__('%s added the Photoalbum \''.get_the_title($post_id).'\' at %s','bd-photoalbum'), "<a href='".$bp->loggedin_user->domain."/'>".$bp->loggedin_user->fullname."</a>", get_permalink( $post_id ) ),
				'primary_link' => get_permalink( $post_id ),
				'type' => 'new_photoalbum',
				'item_id' => $bp->loggedin_user->id,
			));
	}

}
add_action( 'wpuf_add_post_after_insert', 'bd_after_photoalbum_insert' );

?>
June 11, 2013 at 8:48 pm 4806
Mahi Mahi

Hello @quokka,

Thats great. Would you mind to email this as tutorial to support@wedevs.com with your name , email address and site (as ref) ? If you can include some screenshot images that would be great.

We will post it on our Documentation as tutorial with your ref.

Cheers.

June 11, 2013 at 8:52 pm 4807
quokka quokka

Hi Mahi,

Sure no problem..I will include the custom post type code from my functions-custom.php as well together with some screenshots..

Can take a day or two because I’m very busy playing with you cool WPUF plugin ;-D

Take care and keep up the great work at Wedevs.com!
Bas

July 2, 2013 at 7:47 pm 5502
ggsalas ggsalas

what I need is to insert custom-fields in activity posts and i can’t. This is the code that doesn’t work:

[php]add_filter( ‘bp_blogs_activity_new_post_content’, ‘record_post_activity_content’, 1, 3 );
function record_post_activity_content($activity_content, $post,
$post_permalink ){
if( $post-_post_type == ‘post’ ) {
global $post;
$activity_content = get_post_meta($post->ID, "txt_link", true);
}
return $activity_content;
}[/php]

July 2, 2013 at 8:33 pm 5504
Tareq Hasan Tareq Hasan

Make sure your filter is actually running and you are getting the correct post id. I am not that much experienced in buddypress.

July 2, 2013 at 9:58 pm 5507
ggsalas ggsalas

I found something, when i set to false:

return get_post_meta($post->ID, 'txt_link', false);

I get “array” text in activity content

July 2, 2013 at 10:22 pm 5508
quokka quokka

Hi..
That’s normal…

The true is for returning a single custom field value..
http://codex.wordpress.org/Function_Reference/get_post_meta

Try changing this:
if( $post-_post_type == 'post' ) {

To:

if( $post->post_type == 'post' ) {

Does that fix it?

Regards,
Bas

Viewing 15 Posts - 1 through 15 (of 24 total)