Forum Replies Created
-
thanks for you help Roger Dodger. couldn’t get the peice of shit to work, not enough documentation in the buddypress… wiki… function list? not sure what it is, but its not helpful. Anyways i used drupal to achieve the same thing in 20mins
Roger, This is the code I have thus far….
add_filter(“gform_post_submission_1”, “set_post_thumbnail_as”, 10, 2);
function set_post_thumbnail_as($entry, $form){//getting first image associated with the post
$post_id = $entry[“post_id”];
$attachments = get_posts(array(‘numberposts’ => ‘1’, ‘post_parent’ => $post_id, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘order’ => ‘ASC’));
if(sizeof($attachments) == 0)
return; //no images attached to the post//setting first image as the thumbnail for this post
update_post_meta( $post_id, ‘_thumbnail_id’, $attachments[0]->ID);// update bp activty stream content.
$activity_id = bp_activity_add( array( ‘id’ => $post_id, ‘content’ => ‘$attachments’ ));
}I understand the activity post id is different from the wordpress post id? How can I get this activity post id. Also is it okay I am using the post-submission gf filter? Is it just this simple with the correct activity add code?
Can you please help me? I’m really stuck and almost thinking of scrapping the project just because I suck at buddypress and PHP.
Is this on the right track?
bp_activity_add(array( ‘id’ => $post_id, ‘action’ => ‘I did something awesome’, ‘content’ => ‘more content here’, ‘component’ => ‘your component’, ‘type’ => ‘activity_thing’ ));
Just not sure how to add the correct data.
Sorry I would search for it myself on buddypress however the search is broken..just returns me to the home page.
The form gets saved by the gravity forms, however this happens before the thumbnail gets set. Could you possibly help me out with some code I can add to my post submission filter? The documentation for buddypress really sucks… Thanks Roger
Hi Roger, I jumped to a solution then, when in fact it does not work correctly, sorry…
I have used your code from page 1 to display featured image on the bp activity stream. However I have a gravity form that lets user upload posts from their, I have used this simple snipet of code to make the upload image a featured image.
add_filter(“gform_post_submission”, “set_post_thumbnail_as”, 10, 2);
function set_post_thumbnail_as($entry, $form){
//getting first image associated with the post
$post_id = $entry[“post_id”];
$attachments = get_posts(array(‘numberposts’ => ‘1’, ‘post_parent’ => $post_id, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘order’ => ‘ASC’));
if(sizeof($attachments) == 0)
return; //no images attached to the post
//setting first image as the thumbnail for this post
update_post_meta( $post_id, ‘_thumbnail_id’, $attachments[0]->ID);
}This works perfectly for wordpress and displays the featured image correctly. However the featured image does not appear in the buddypress activity stream until I manually go to that post and hit update in the backend… really defeats the purpose of publishing the post… pulled my hair out for days on this.. Do you have any suggestions? I believe it is something to do with the way bp saves posts… Maybe bp_activity_post_update would work
I have found a solution if you are using gravity forms… I just need to know who to add the post id into the form submission function because atm it just uploads the image to the actually form page
add_action(“gform_pre_submission_2”, “gform_registration”);
function gform_registration( $form_meta ){
// $post_id gets set here by some code I have removed for clarity
// If there is a logo, attach that file and make it the post featured image
if($_FILES) {
//WordPress Administration API required for the media_handle_upload() function
require_once(ABSPATH . ‘wp-admin/includes/file.php’);
require_once(ABSPATH . ‘wp-admin/includes/image.php’);
require_once(ABSPATH . ‘wp-admin/includes/media.php’);
$media_id = media_handle_upload(‘input_3’, $post_id);
my_set_post_thumbnail( $post_id, $media_id);
}
}
// This function will be obsolete once WP 3.1 is release since that includes
// an identical function name set_post_thumbnail
function my_set_post_thumbnail( $post, $thumbnail_id ) {
$post = get_post( $post );
$thumbnail_id = absint( $thumbnail_id );
if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) {
$thumbnail_html = wp_get_attachment_image( $thumbnail_id, ‘thumbnail’ );
if ( ! empty( $thumbnail_html ) ) {
update_post_meta( $post->ID, ‘_thumbnail_id’, $thumbnail_id );
return true;
}
}
return false;
}
I got the exact same issue here @tindell … featured image will not display in buddypress activty until I update it in the backend of wordpress manually Has anyone come up with a solution? This is really frustrating!!!! Ah buddypress