Skip to:
Content
Pages
Categories
Search
Top
Bottom

Replace Activity Stream blog excerpt with the_excerpt

Viewing 16 replies - 26 through 41 (of 41 total)
  • @rogercoathup I have another strange issue, I’m using a front end editor so users can create blog posts http://perishablepress.com/user-submitted-posts/ I modified that using some recommended code so that the image attached will be set as a post thumbnail. Which works as it should the image is there with the post when I check the post and it appears everywhere I call for the post thumbnail such as the home page. The only place it doesn’t appear is in the Buddypress activity stream next to the excerpt. Interestingly if I go and edit or update a post that I originally created with the front end editor, the thumbnail suddenly appears in the buddypress activity stream as it should. Any thoughts on what might be going on?


    Roger Coathup
    Participant

    @rogercoathup

    Timing! I suspect the thumbnail is getting created by your plugin after the BuddyPress activity create hook.

    ahhh elementary my dear Roger, I’ll mess around with the code see what I can do. Thanks.

    Have you got any ideas how to fix this weird problem? You’ll probably have better idea than me.

    I can’t believe I’m going through this all because buddypress doesn’t support post thumbnail. An it’s not the only issue I’m having either. Buddypress is great providing you don’t want to change anything expect a few colours.

    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

    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;

    }


    Roger Coathup
    Participant

    @rogercoathup

    @tindell – this is one of several areas where the BuddyPress core API embeds too much markup and presentation, causing a consequent problem for developers.

    If you look at my solution on page 1 of this thread, you have the solution for this problem for thumbnails.

    As for your note:

    Buddypress is great providing you don’t want to change anything expect a few colours

    To a large extent that’s true if you are building child themes from bp-default.

    You can develop true bespoke sites with BuddyPress, but it’s not a trivial development process – the API could be much cleaner.


    Roger Coathup
    Participant

    @rogercoathup

    @thinkluke

    A couple of points:

    1. You are passing the post_id into your my_set_post_thumbnail() function – so don’t know why don’t just use that, rather than doing a get_post with that id, and then trying to use the ID from that post. Similarly, with your thumbnail ID.

    2. Naming your variable $post may be causing some conflict with the global $post – at the very least, it makes your function difficult to read

    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


    Roger Coathup
    Participant

    @rogercoathup

    You need to create / edit the bp activity item for that post directly in your gravity forms filter.. As you are not saving / updating the post, so missing the default bp hook that does the activity admin for you

    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

    Sorry I would search for it myself on buddypress however the search is broken..just returns me to the home page.

    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.

    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.

    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

Viewing 16 replies - 26 through 41 (of 41 total)
  • The topic ‘Replace Activity Stream blog excerpt with the_excerpt’ is closed to new replies.
Skip to toolbar