Skip to:
Content
Pages
Categories
Search
Top
Bottom

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


  • 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 25 replies - 1 through 25 (of 26 total)

  • Prometheus Fire
    Participant

    @prometheus-fire

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


    modemlooper
    Moderator

    @modemlooper

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


    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


    Prometheus Fire
    Participant

    @prometheus-fire

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


    Warren Harrison
    Member

    @hungrymedia

    @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.


    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


    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.


    aces
    Participant

    @aces


    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 :(


    Hugo Ashmore
    Keymaster

    @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.


    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?


    modemlooper
    Moderator

    @modemlooper

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


    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?)


    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?


    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;
    }`


    johnnymestizo
    Participant

    @johnnymestizo

    Does this work with 1.7 ?


    @prometheus-fire

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

    Cheers,

    Johnny


    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


    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.


    lannagung
    Participant

    @lannagung

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


    neo-tronic
    Participant

    @neo-tronic

    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

    I’ve added this to my bp-custom.php file and get an error on the following Sektion. Can anyone help please? ( @prometheus-fire ? )

    			bp_blogs_record_activity( array(
    				'user_id' => (int)$post->post_author,
    				'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
    				'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
    				'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
    				'type' => 'new_blog_post',
    				'item_id' => $blog_id,
    				'secondary_item_id' => $post_id,
    				'recorded_time' => $post->post_modified_gmt

    Here the error message: Fatal error: Call-time pass-by-reference has been removed; If you would like to pass argument by reference, modify the declaration of apply_filters(). in /homepages/39/d415915588/htdocs/wp-content/plugins/bp-custom.php on line 35


    Prometheus Fire
    Participant

    @prometheus-fire

    @neo-tronic not sure where that error is coming from. I’m still using that snippet to support CPTs without issue. You can narrow it down be checking which one of the above is line 35 and edit it as needed.

    Also, keep in mind, the BP crew is hard at work getting CPTs officially supported. I think it has been bumped to version 1.9, but they’ve been working on the open ticket related to this. Once CPTs get official support, it becomes a game changer for BP.


    jetlej
    Participant

    @jetlej

    @prometheus-fire – I placed the code into my bp-custom.php file and made the edits you specified, but am not seeing CPT’s show up in my activity. No errors, no changes, nothing.

    Any ideas? Thank you for your posts about this across the web! You’re the only one with a serious solution.


    neo-tronic
    Participant

    @neo-tronic

    Hi @prometheus-fire ,

    Thanks for your reply. But i don’t get this to work with my site. My php-skills are btw not very good…

    But: i find a Solution. For blog-posts i use this:

      function bbg_record_my_custom_post_type_posts( $post_types ) {
          $post_types = array ('it_movies', 'it_video_games', 'it_preisalarm', 'post'); // Hier die Slugs der Custom Post Types eintragen, bei denen Erwähnungen im Beitrag selbst berücksichtigt werden
          return $post_types;
      }
      add_filter( 'bp_blogs_record_post_post_types', 'bbg_record_my_custom_post_type_posts' );

    And for comments i use this:

      function bbg_record_my_custom_post_type_comments( $post_types ) {
          $post_types = array ('it_movies', 'it_video_games', 'it_preisalarm', 'post');  // Hier die Slugs der Custom Post Types eintragen, bei denen Erwähnungen in den Kommentaren berücksichtigt werden
          return $post_types;
      }
      add_filter( 'bp_blogs_record_comment_post_types', 'bbg_record_my_custom_post_type_comments' );

    And it works, but without custom messages. Anyway – now it works and for the Future, i wait for the buddypress-update. 😉


    mcpeanut
    Participant

    @mcpeanut

    Hi THERE, @prometheus-fire sorry for pulling you back to this thread but i am trying to implement the code snippet you posted thats working for you, now i understand exactly what to do until i get to this part…

    – Line 62 to reflect the name of the function you created for your CPT

    im not sure what the function is called for my custom post types, the custom post types i am trying to get to show in the activity stream was created by a plugin, now looking through the php files of this plugin it has lots of functions, how would i know which function it is i am meant to add on line 62?

    i may be overlooking something simple?


    mcpeanut
    Participant

    @mcpeanut

    hmm nevermind the above post after re-reading it i have realised that line 62 is to reflect the name i give the function, but i still cant get it to work, i will explain what steps ive taken please tell me if im doing it wrong…

    i have renamed this bit at the top

    // begin record products to BP activity stream
    function product_record_activity( $post_id, $post, $user_id = false ) {

    renamed it from…. function product_record_activity …. to this…… function test_test_test

    am i right so far?

    next i have renamed this on line 19…

    /* Don’t record this if it’s a regular post */
    if ( $post->post_type != ‘product’ ) return false;

    and where it says ‘product’ i added my custom post type name…… am i still right?

    then on line 28 this bit…

    $activity_action = sprintf( __( ‘%1$s added or updated the product %2$s, in the store:

    i change the added or updated the product and in the store to whatever text i want……. am i still doing it right?

    then the last step at the bottom i change line 62 to the name i made earlier which was function test_test_test

    so am i still right?

    then i upload the buddypress custom php to my plugins folder via my ft p….. i then go and check my site and post something in my custom post and guess what? nothing happens!

    now i dont understand what im doing wrong and if this code still works or not? if it doesnt could you please give us your current solution please prometheus? or if im doing something wrong will someone please tell me? because i can get the code @neo-tronic pasted above to work perfectly and show custom post types fine in the activity stream when posting in my custom posts…but the thing is with that code is it does’nt let users comment on the post from the activity stream?

    can someone please help me out here ….ty 🙂

Viewing 25 replies - 1 through 25 (of 26 total)
  • The topic ‘[Resolved] Adding custom post types in the activity stream – need php help’ is closed to new replies.
Skip to toolbar