Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Adding custom post types in the activity stream – need php help

  • Avatar of Prometheus Fire
    Prometheus Fire
    Participant

    @prometheus-fire

    I’ve been working to get custom post types working in the BuddyPress activity stream. I found this post by Boone on the Dev blog and it is a pretty elegant solution to adding custom post types to the activity stream http://bpdevel.wordpress.com/2011/08/12/custom-post-types-comments-and-the-activity-stream-in-bp-1-5/

    As such, I’m working with wikis and products across multisite (from the Wiki plugin and MarketPress from WPMU DEV), though what the plugins isn’t important to this request, its more about getting custom post types in activity stream, with a customized $activity_action line (see below for specifics about what I want to edit/filter)

    To get the Wikis to record to activity I created this and added it to bp-custom.php:

    // add wiki post types to the activity stream
    function activity_publish_wiki_posts($wikiposts) {
    $wikiposts[] = 'incsub_wiki';
    return $wikiposts;
    }
    add_filter ( 'bp_blogs_record_post_post_types', 'activity_publish_wiki_posts' );

    For Products, I have this:

    // add product post types to the activity stream
    function activity_publish_product_posts($productposts) {
    $productposts[] = 'product';
    return $productposts;
    }
    add_filter ( 'bp_blogs_record_post_post_types', 'activity_publish_product_posts' );

    Instead of using two separate snippets you can also streamline the code by putting both post types into the array, like this:

    // add product post types to the activity stream
    function activity_publish_custom_post_types($cpts) {
    $cpts[] = 'product';
    $cpts[] = 'incsub_wiki';
    return $cpts;
    }
    add_filter ( 'bp_blogs_record_post_post_types', 'activity_publish_custom_post_types' );

    These are very efficient ways to add custom post types to the activity stream. I tested this several times and it works great. It also ensures that when a post is updated, the activity record gets updated. I see this as essential behavior, especially with the Wikis.

    Help Needed

    Now, I separated them into two different snippets because I need to get some customization built into them. I want the activity record to read “John updated a wiki article, Cool Stuff, on the site, My Wiki” for the Wikis, and “John added a new product, My Cool Car, to the site, John’s Cars

    I’ve gone through various bits of code, including some older code that predates the 1.5 fix (http://pastebin.com/qrfjCat8 based off of http://pastebin.com/kNqTrRzc) and tried adding a filter to the snippets I post above that would filter $activity_action from BuddyPress core in bp-blogs-function.php. I just can’t seem to get that in there and working properly.

    Can someone help me modify those snippets to get the correct line of text in the activity update?

Viewing 19 replies - 1 through 19 (of 19 total)
  • Avatar of Prometheus Fire
    Prometheus Fire
    Participant

    @prometheus-fire

    @hnla @mercime do either of you have any input on this? Could use some help.

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    Looks like the code above is missing some code. You need an action saved.

    Avatar of Prometheus Fire
    Prometheus Fire
    Participant

    @prometheus-fire

    Thanks for stopping by @modemlooper but not sure what that means, I don’t know php (which is why I’m asking for help).

    The snippets above work, but they use the default text for new blog posts in the activity when the custom post types are added.

    I have tried adding an the action and type parameters into the array, but that didn’t work – it didn’t record the update to the cpt, but I think I’m writing array wrong.

    Here’s a link to the snippet I tried for that, (unfortunately, BP.org isn’t letting me post code into this thread anymore for some reason, keeps returning an error, so you’ll have to go to the other thread where I’m asking for help): http://premium.wpmudev.org/forums/topic/need-some-php-help-custom-post-types-and-buddypress#post-191533

    Avatar of Prometheus Fire
    Prometheus Fire
    Participant

    @prometheus-fire

    @boonebgorges since this patch was implemented by you, could you take a minute to help me out with this?

    @prometheus-fire I’m a long-time WP guy, but brand new to BP. I did find an example of adding a custom activity message at http://bp-tricks.com/snippets/adding-a-new-activity-stream-entry-when-a-user-changes-his-avatar/

    Hope that helps.

    Avatar of dude
    dude
    Member

    @pinhit

    for some reason i cant create a fresh topic?

    can anyone help me with this problem..

    my site has a problem with someone using around 3 googlemail email addresses to keep registering on my buddypress powered website to the point where their details have remained enscribed on my sites registry form..

    is there a way to get rid of this please..?

    many thanks in advance

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    @dude this keeps happening to people and i’m thinking its because sites have been hacked. Nobody has ever come up with a solution. I cant replicate it to find one. It’s probably a hacked site, if it’s not the browser saving info.

    Might be a malicious plugin.

    Avatar of aces
    aces
    Participant

    @aces

    Avatar of dude
    dude
    Member

    @pinhit

    thanks for the reply guys! chances are i been hacked then coz the admin on my site was changed too plus this user has registered with dozens of fake accounts even though verifcation hasnt been approved :(

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    ‘Admin changed’ that should have really caused instant alarm bells my friend, you need to immediately change all your account/hosting access , FTP, DB, passwords and WP user passwords, then start looking for the exploit point if it exists.

    The form filling isn’t due to hacking as aces pointed out it’s discussed and I have also had discussions with other developers who run into this issue – not sure but feel it’s WP/BP not doing something properly here as it should not hold data from process / connection and pass it back to a completely different connection. But as Modemlooper says I haven’t been able to replicate this or run across it personally.

    Avatar of dude
    dude
    Member

    @pinhit

    to be honest, i really cant be doing with all this constant upgrading, changing this and checking that, its all becoming a headache. still.. you get what you pay for i suppose so its swings and roundabouts as they say. Annoys me that you put something cool together for people to connect and all they wanna do is critisize it and tear it apart. some people eh?

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    Did you by chance install WordPress through a one click host install?

    Avatar of BOW
    BOW
    Participant

    @bofw

    I don’t mean to be a pain but this is a shocking example of a thread being hijacked. Where are the moderators on this? Some of the responses are from long time members who should know better too. The forums here are bad enough as it is without allowing threads to go off topic like this.

    Anyway to get this back ‘on topic’…

    There do not seem to be any clean and current examples for custom post types generating a custom message.

    Seeing as CPT’s are so popular these days this would seem like a very cool piece of code to have.

    A single snippet that would allow you to…

    1) turn on activity stream messages from a custom post type
    2) turn on the commenting for that custom post type to appear in the activity stream (BTW: this doesn’t seem to work in the current release at all)
    3) set the custom activity stream message template for that post type

    4) be able to do it for more than one post type elegantly

    Has anyone got the guts of a function pulled together for the above? (1&2 are simple enough – I have posted a code snippet in another thread – but like I said above commenting doesn’t seem to work can anyone else confirm this and I’ll raise a ticket?)

    Avatar of Quint
    Quint
    Participant

    @qrahaman

    @prometheus-fire

    Did you get to a satisfactory solution that you are willing to share?

    Also, since you brought up the WIki example, have you been able to upload images and video on the front end with that plugin?

    Avatar of zudie
    zudie
    Participant

    @zudie

    I think I got the right direction for you:

    In bp-custom.php add:

    `/Change wording in Activity Stream and use post_type iso of ‘post’
    add_filter( ‘bp_blogs_activity_new_post_action’, ‘im_activity_content’, 2, 10 );

    function im_activity_content($activity_content, $post, $post_permalink){

    $activity_content = sprintf( __( ‘%s submitted a new ‘.$post->post_type.’: %s’, ‘buddypress’ ), bp_core_get_userlink( (int)$post->post_author ), ‘‘ . $post->post_title . ‘‘ );
    $activity_content .= bp_create_excerpt( $post->post_content, 25 );

    return $activity_content;
    }`

    Avatar of johnnymestizo
    johnnymestizo
    Participant

    @johnnymestizo

    Does this work with 1.7 ?

    @prometheus-fire

    U got a solid bit of code to make ‘product’ work?

    Cheers,

    Johnny

    Avatar of Prometheus Fire
    Prometheus Fire
    Participant

    @prometheus-fire

    I should have updated this thread ages ago. Yes, I have long had custom post types showing up in my activity stream and it is pretty rock solid.

    I use this snippet (which I found someplace but don’t know where) and add it to bp-custom.php, which is a file you create in your plugins folder.

    http://pastebin.com/SEc32sPf

    The snippet is currently written for MarketPress products, however, you can use it to support any custom post type. Edit the four things below to modify for your custom post type.

    - Edit the function name to whatever you want, it just needs to be unique,
    - Line 19 to be the the custom post type you want to use;
    - Line 28 to reflect the activity record text you want,
    - Line 62 to reflect the name of the function you created for your CPT

    I’m currently using about 7 different edits of it to support that many different CPTs in the activity stream and it works great. Yes, it works in BP 1.7

    Avatar of Prometheus Fire
    Prometheus Fire
    Participant

    @prometheus-fire

    I’ll add that the code resaves the activity record everytime the CPT is updated, even after it has already been published. So everytime an edit is made and saved to the CPT, the corresponding activity stream record gets bumped.

    Avatar of lannagung
    lannagung
    Participant

    @lannagung

    @prometheus-fire can activity stream integrated with tweet and facebook feed and how to do that ?

Viewing 19 replies - 1 through 19 (of 19 total)

You must be logged in to reply to this topic.