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 26 replies (of 26 total)
  • Avatar of Prometheus Fire
    Prometheus Fire
    Participant

    @prometheus-fire

    @mcpeanut It sounds like you are doing everything right if I’m reading your posts correctly. There are only 4 edits to the snippet that need to be done.

    One thing you need to check is to make sure is that you are not blocking search engines on the site. This may not work if the site isn’t being tracked. Also, if this is the first time you’ve started using bp-custom.php make sure you’ve got the file formatted correctly with the opening and closing php tags.

    I am still using this code, and it still works (I tested it again before posting this comment to be sure), it is as solid as ever.

    Keep in mind that there is a push to keep some native support for this kind of thing into BP core. You can read more about it here: https://buddypress.trac.wordpress.org/ticket/3460

    There is no timeline for when it will be ready.

Viewing 26 replies (of 26 total)

You must be logged in to reply to this topic.