Skip to:
Content
Pages
Categories
Search
Top
Bottom

Can't seem to get BP 2.2's Post Types Activities working


  • Peter Hardy-vanDoorn
    Participant

    @petervandoorn

    I’ve read the relevant codex page https://codex.buddypress.org/plugindev/post-types-activities/ and have copied the code given there, but it doesn’t seem to want to work for me.

    My custom post type is “music”, and I want it on the activity stream, so I amended the code to:

    add_post_type_support( 'music', 'buddypress-activity' );
     
    function customize_page_tracking_args() {
        if ( ! bp_is_active( 'activity' ) ) return;
     
        bp_activity_set_post_type_tracking_args( 'music', array(
        	'component_id' => buddypress()->activity->id,
    	'action_id' => 'new_music',
            'bp_activity_admin_filter' => __( 'Added a new Music Resource', 'custom-domain' ),
            'bp_activity_front_filter' => __( 'Music', 'custom-domain' ),
            'contexts' => array( 'activity', 'member' ),
            'activity_comment' => true,
            'bp_activity_new_post' => __( '%1$s added a new <a href="%2$s">music resource</a>', 'custom-textdomain' ),
            'bp_activity_new_post_ms' => __( '%1$s added a new <a href="%2$s">music resource</a>, on the site %3$s', 'custom-textdomain' ),
            'position' => 100,
        ) );
    }
    add_action( 'bp_init', 'customize_page_tracking_args' );

    But all I get in the activity stream is the generic Site Admin wrote a new item 10 seconds ago and Music does not appear in the Show drop-down menu.

    What am I missing?

    Cheers

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

  • tstrickland415
    Participant

    @tstrickland415

    I noticed this with mine as well. Your new code may not be affecting the posts previously handled by your old code. Try making a new Music post with the above code in place and see if it works instead of looking for it to update posts already made.


    Peter Hardy-vanDoorn
    Participant

    @petervandoorn

    Hi tstrickland415, thanks for the input, but I am only talking about creating new posts. I wouldn’t expect it to effect old posts as they are already stored in the database!


    Peter Hardy-vanDoorn
    Participant

    @petervandoorn

    *bump* I can’ believe no-one else has this problem!

    I sort of encountered the same issue but sadly can’t say what I did to correct whatever went awry.
    You appear to have followed the codex example correctly, but maybe try the other approach and update your register_post_type() $args; ensure your definitely using the correct custom post type name, text domains etc and your template show filter is current i.e uses ‘bp_activity_show_filters()’


    danbp
    Participant

    @danbp

    Please read here, it’s better explained.

    The example given on Codex is related to ‘page’, and you want to show something on ‘activity’.

    Instead of 'component_id' => buddypress()->activity->id,
    use 'component_id' => 'activity',
    and instead of
    add_action( 'bp_init', 'customize_page_tracking_args' );
    use init with a very late priority
    add_action( 'init', 'customize_page_tracking_args', 999 );

    Pfuiiiiii, taked me a while to find this.

    Here a working example of a CPT called Music and how to get it in the SWA

    // allow tracking of our CPT
    add_post_type_support( 'music', 'buddypress-activity' );
    
    // creating the dropdown filter on activity and members page
    function customize_page_tracking_args() {
        // Check if the Activity component is active before using it.
        if ( ! bp_is_active( 'activity' ) ) {
            return;
        }
     
        bp_activity_set_post_type_tracking_args( 'music', array(
            'component_id'             => 'activity', // unique ID
            'action_id'                => 'new_music', // new_$post_type where new_ is mandatory
            'bp_activity_admin_filter' => __( 'Published a new music', 'text-domain' ),
            'bp_activity_front_filter' => __( 'Music', 'text-domain' ),
    			'contexts'                 => array( 'activity', 'member' ), // swa & member activity page
    			'activity_comment'         => true,
    			'bp_activity_new_post'     => __( '%1$s posted a new <a href="%2$s">Music</a>', 'text-domain' ),
    			'bp_activity_new_post_ms'  => __( '%1$s posted a new <a href="%2$s">Music</a>, on the site %3$s', 'text-domain' ),
    			'position'                 => 100,
        ) );
    }
    add_action( 'init', 'customize_page_tracking_args', 999 );
    
    // creating the CPT
    function bpfr_create_post_type() {
      register_post_type( 'music',
        array(
          'labels' => array(
            'name' => __( 'Music', 'text-domain' ),
            'singular_name' => __( 'Music', 'text-domain' )
          ),
          'public' => true,
          'has_archive' => true,
        )
      );
    }
    add_action( 'init', 'bpfr_create_post_type' );
    

    FYI, i added the mentionned topic to the Codex page. Would probably help more than one. πŸ˜‰

    @danbp Thanks for adding the link, there’s a fair bit of detail in that topic on support which really ought to be in the codex, almost a case where the post topic is better detailed than the codex entry which aint a good thing!

    Not sure here why the split between the register cpt function and BP one, if there’s access to the cpt register args why not simply add the BP args to that, although if BP wasn’t activated it would be harder to check for that especially if the CPT was required regardless of whether BP active or not.


    danbp
    Participant

    @danbp

    Hi @hnla,

    it’s not easy for us frenchies to write Codex articles. @imath write very good tutorials in french, guess it’s more difficult for him to be as good in english. Same for me.
    And after writing php a long time, i suppose it can be difficult to find a more literary style. πŸ˜‰

    > it’s not easy for us frenchies to write Codex articles.

    πŸ™‚ Oh you don’t do too bad a job, the two of you, for frenchies that is πŸ˜›

    Actually I wasn’t commenting on the standard of article/s at all just on the separation of information.


    danbp
    Participant

    @danbp

    πŸ˜€


    Peter Hardy-vanDoorn
    Participant

    @petervandoorn

    Thanks all for this. I can confirm that it has solved the problem.

    I had already worked out that 'component_id' => buddypress()->activity->id was wrong and should be 'component_id' => 'activity', but it’s interesting to find that the source of the problem was that the codex example was (and still is, btw) hooking into the wrong action.

    Now, on a related note, does anyone know if it’s possible to insert the name of the post into the 'bp_activity_new_post' parameter?

    Cheers


    Peter Hardy-vanDoorn
    Participant

    @petervandoorn

    Hmm… just come across some other problems.

    1. The codex example still isn’t inserting the entry into the Show drop-down menu.

    2. I have a post type called “document” and that isn’t working at all, although my others are.

    Finally, and this is just an observation, but I wonder why all of this is necessary. The WordPress function register_post_type() already allows you to set singlular and plural labels for post types – surely it would be better for the bp_activity_set_post_type_tracking_args() function that we’re modifying here to use these labels by default?

    >I had already worked out that ‘component_id’ => buddypress()->activity->id was wrong

    No it’s not wrong, buddypress()->activity->id == ‘activity’, in replacing it with a hardcoded string you could possibly cause issues if activities id did change, where it will cause issues is if BP isn’t loaded then buddypress() will fail, a hardcoded value is safer in that respect.

    >but it’s interesting to find that the source of the problem was that the codex example was (and still is, btw) hooking into the wrong action.

    Again it’s not necessarily hooking into wrong action ‘bp_init’ does work, I used it recently on a register_post_type where issues arose on BP update as init ran before bp had re-activated, although that later priority may have solved that one.

    So the reference to codex entry still being wrong is debatable, possibly it ought to be updated, and on that score the codex like the rest of the BP project is all volunteer work and any member has the ability to add, update codex pages if they see somethings wrong


    Peter Hardy-vanDoorn
    Participant

    @petervandoorn

    Sorry, @hnla, didn’t mean to offend! In my experience, if something doesn’t work and then you’re advised to change it to something else that does work, it usually means the original was wrong!

    Don’t suppose you have any insights into why it’s still not adding the entry to the Show menu?

    Cheers!

    @petervandoorn NP there was no offence taken πŸ™‚ more a concern in stating something was wrong, which can be a little black or white, and where it wasn’t necessarily wrong but different things work or are needed in different circumstances.

    I wish I could remember what corrected the issue when I encountered the no show in the filter, just in case permalinks do figure in things – they do where registering CPT’s are concerned – visit your permalink page to ensure cache is updated?


    Peter Hardy-vanDoorn
    Participant

    @petervandoorn

    πŸ™‚

    Nope, not permalinks.

    Not sure how that would effect the routine that adds the entry to the menu though!

    Cheers

    Did you check this aspect I mentioned a while back?

    >and your template show filter is current i.e uses β€˜bp_activity_show_filters()’


    Peter Hardy-vanDoorn
    Participant

    @petervandoorn

    I’m using a child of the bp-default theme, and I haven’t overridden the activity template.

    A search of the files in the buddypress/bp-themes/bp-default folder turns up nothing, so I’m guessing not.

    Please let me know if you found a solution because I can’t get filtering to work in the front-end either. :/

    bp_init also didn’t work for me. I had to hook into init.

Viewing 18 replies - 1 through 18 (of 18 total)
  • The topic ‘Can't seem to get BP 2.2's Post Types Activities working’ is closed to new replies.
Skip to toolbar