Skip to:
Content

BuddyPress.org

Ticket #3460: 3460.3.diff

File 3460.3.diff, 25.2 KB (added by imath, 6 years ago)
  • bp-core/admin/bp-core-settings.php

     
    103103<?php
    104104}
    105105
     106/** Blogs *******************************************************************/
     107
    106108/**
     109 * Post type Site Tracking settings section description for the settings page
     110 *
     111 * @since BuddyPress (?)
     112 */
     113function bp_admin_setting_callback_blogs_section() {
     114        if( bp_core_do_network_admin() ) {
     115        ?>
     116                <p class="description"><?php _e( 'Only the networked enabled & the primary blog post types can be tracked in Activity stream.', 'buddypress' );?></p>
     117        <?php
     118        }
     119}
     120
     121/**
     122 * Allow Post type tracking setting field
     123 *
     124 * @since BuddyPress (?)
     125 *
     126 * @uses  get_post_types() to list the show_in_nav_menus enabled post types
     127 * @uses  checked() To display the checked attribute
     128 * @uses  post_type_supports() to check for bp_tracking support
     129 */
     130function bp_admin_setting_callback_post_types_tracked() {
     131        /*
     132        Using show_in_nav_menus avoids the inclusion of attachment post type
     133        if show_in_nav_menus is not defined it defaults to the value of public arguments
     134        */
     135        $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' );
     136
     137        foreach( $post_types as $post_type => $arguments ) {
     138                $readonly = ( 'post' == $post_type ) ? 'disabled' : '';
     139                ?>
     140
     141                <input id="bp-enabled-post-types-<?php echo $post_type;?>" name="bp-enabled-post-types[<?php echo $post_type;?>]" type="checkbox" value="1" <?php checked( post_type_supports( $post_type, 'bp_tracking' ) ); ?> <?php echo $readonly;?>/>
     142                <label for="bp-enabled-post-types-<?php echo $post_type;?>"><?php echo $arguments->labels->name ?></label>
     143
     144                <?php
     145        }
     146
     147}
     148
     149/**
     150 * Sanitization for bp-enabled-post-types
     151 *
     152 *
     153 * @since BuddyPress (?)
     154 * @access Private
     155 */
     156function bp_admin_sanitize_callback_post_types_tracked( $value = false ) {
     157        $value = !is_array( $value ) ? array() : array_map( 'absint', $value );
     158        return $value;
     159}
     160
     161/**
    107162 * Sanitization for _bp_force_buddyvar
    108163 *
    109164 * If upgraded to 1.6 and you chose to keep the BuddyBar, a checkbox asks if you want to switch to
  • bp-core/bp-core-dependency.php

     
    9292}
    9393
    9494/**
     95 * Fire the 'bp_catch_post_types' action, BuddyPress's way to get all registered post types.
     96 */
     97function bp_catch_post_types() {
     98        do_action( 'bp_catch_post_types' );
     99}
     100
     101/**
    95102 * Fire the 'bp_loaded' action, which fires after BP's core plugin files have been loaded.
    96103 *
    97104 * Attached to 'plugins_loaded'.
  • bp-core/bp-core-admin.php

     
    332332                                register_setting  ( 'buddypress',         '_bp_enable_akismet',   'intval'                                                                                  );
    333333                        }
    334334                }
     335
     336                /** Blogs Section **************************************************/
     337
     338                if ( bp_is_active( 'blogs' ) ) {
     339
     340                        // Add the main section
     341                        add_settings_section( 'bp_blogs',      __( 'Site Tracking Settings', 'buddypress' ), 'bp_admin_setting_callback_blogs_section', 'buddypress'                );
     342
     343                        // Activity commenting on blog and forum posts
     344                        add_settings_field( 'bp-enabled-post-types', __( 'List of post types to track', 'buddypress' ), 'bp_admin_setting_callback_post_types_tracked', 'buddypress', 'bp_blogs' );
     345                        register_setting( 'buddypress', 'bp-enabled-post-types', 'bp_admin_sanitize_callback_post_types_tracked' );
     346
     347                }
     348
    335349        }
    336350
    337351        /**
  • bp-core/bp-core-actions.php

     
    3333  */
    3434add_action( 'plugins_loaded',          'bp_loaded',                 10    );
    3535add_action( 'init',                    'bp_init',                   10    );
     36add_action( 'init',                                'bp_catch_post_types',       100   ); // late to catch post types
    3637add_action( 'parse_query',             'bp_parse_query',            2     ); // Early for overrides
    3738add_action( 'wp',                      'bp_ready',                  10    );
    3839add_action( 'set_current_user',        'bp_setup_current_user',     10    );
  • bp-activity/bp-activity-template.php

     
    25822582        $can_comment = true;
    25832583
    25842584        if ( false === $activities_template->disable_blogforum_replies || (int) $activities_template->disable_blogforum_replies ) {
    2585                 if ( 'new_blog_post' == bp_get_activity_action_name() || 'new_blog_comment' == bp_get_activity_action_name() || 'new_forum_topic' == bp_get_activity_action_name() || 'new_forum_post' == bp_get_activity_action_name() )
     2585
     2586                $comment_objects = array( 'new_forum_topic', 'new_forum_post' );
     2587
     2588                if( bp_is_active( 'blogs' ) ) {
     2589                        $available_post_types = get_object_vars( buddypress()->activity->actions->blogs );
     2590                        $comment_objects = array_merge( $comment_objects, array_keys( $available_post_types ) );
     2591                }
     2592
     2593                if ( in_array( bp_get_activity_action_name(), $comment_objects ) )
    25862594                        $can_comment = false;
    25872595        }
    25882596
     
    32693277<?php
    32703278}
    32713279add_action( 'bp_head', 'bp_activity_sitewide_feed' );
     3280
     3281
     3282
     3283/** Activity type for post types **/
     3284function bp_activity_post_type_filter_options() {
     3285        echo bp_get_activity_post_type_filter_options();
     3286}
     3287
     3288        function bp_get_activity_post_type_filter_options() {
     3289                $output = '';
     3290
     3291                if( !bp_is_active( 'blogs' ) )
     3292                        return $output;
     3293
     3294                $available_types = buddypress()->activity->actions->blogs;
     3295
     3296                foreach( $available_types as $post_type ) {
     3297                        $output .= '<option value="' . $post_type['key'] . '">' . $post_type['value'] . '</option>' ."\n";
     3298                }
     3299
     3300                return apply_filters( 'bp_get_activity_post_type_filter_options', $output );
     3301        }
     3302
     3303
  • bp-templates/bp-legacy/buddypress/members/single/activity.php

     
    2222
    2323                                <?php
    2424                                if ( !bp_is_current_action( 'groups' ) ) :
    25                                         if ( bp_is_active( 'blogs' ) ) : ?>
     25                                        bp_activity_post_type_filter_options();
    2626
    27                                                 <option value="new_blog_post"><?php _e( 'Posts', 'buddypress' ); ?></option>
    28                                                 <option value="new_blog_comment"><?php _e( 'Comments', 'buddypress' ); ?></option>
    29 
    30                                         <?php
    31                                         endif;
    32 
    3327                                        if ( bp_is_active( 'friends' ) ) : ?>
    3428
    3529                                                <option value="friendship_accepted,friendship_created"><?php _e( 'Friendships', 'buddypress' ); ?></option>
  • bp-templates/bp-legacy/buddypress/activity/index.php

     
    7878                                        <option value="-1"><?php _e( 'Everything', 'buddypress' ); ?></option>
    7979                                        <option value="activity_update"><?php _e( 'Updates', 'buddypress' ); ?></option>
    8080
    81                                         <?php if ( bp_is_active( 'blogs' ) ) : ?>
     81                                        <?php bp_activity_post_type_filter_options();?>
    8282
    83                                                 <option value="new_blog_post"><?php _e( 'Posts', 'buddypress' ); ?></option>
    84                                                 <option value="new_blog_comment"><?php _e( 'Comments', 'buddypress' ); ?></option>
    85 
    86                                         <?php endif; ?>
    87 
    8883                                        <?php if ( bp_is_active( 'forums' ) ) : ?>
    8984
    9085                                                <option value="new_forum_topic"><?php _e( 'Forum Topics', 'buddypress' ); ?></option>
  • bp-blogs/bp-blogs-functions.php

     
    156156        return $trackable_globally;
    157157}
    158158
     159
    159160/**
     161 * Check whether a given post type should be tracked by the Blogs component.
     162 *
     163 * If $user_id is provided, the developer can restrict site from
     164 * being trackable only to particular users.
     165 *
     166 * @since BuddyPress (?)
     167 *
     168 * @uses bp_get_option()
     169 * @uses apply_filters()
     170 *
     171 * @param string $post_type the post type being checked.
     172 * @return bool True if blog is trackable, otherwise false.
     173 */
     174function bp_blogs_is_post_type_trackable( $post_type = 'post', $blog_id = 0 ) {
     175        // This filter can be used by a child blog to eventually remove a tracked post type
     176        $optional_post_types = apply_filters( 'bp_blogs_post_type_trackable', bp_get_option( 'bp-enabled-post-types', array() ), $blog_id );
     177
     178        $trackable = array_merge( array( 'post' ), array_keys( $optional_post_types ) );
     179
     180        return in_array( $post_type, $trackable );
     181}
     182
     183/**
    160184 * Make BuddyPress aware of a new site so that it can track its activity.
    161185 *
    162186 * @since BuddyPress (1.0.0)
     
    278302add_action( 'transition_post_status', 'bp_blogs_catch_published_post', 10, 3 );
    279303
    280304/**
     305 * Callback function to build the permalink to the post type
     306 *
     307 * @param  integer $post_id the post type id
     308 * @param  integer $blog_id the blog id
     309 * @param  WP_Post  $post    Post object.
     310 * @uses   add_query_arg()   To add custom args to the url
     311 * @uses   get_home_url()
     312 * @return string           the post type permalink
     313 */
     314function bp_blogs_activity_permalink_post_callback( $post_id = 0, $blog_id = 0, $post = null ) {
     315        $post_permalink = add_query_arg(
     316                'p',
     317                $post_id,
     318                trailingslashit( get_home_url( $blog_id ) )
     319        );
     320
     321        return $post_permalink;
     322}
     323
     324/**
     325 * Callback function to build the action for the post type
     326 *
     327 * @param  array  $args the available arguments
     328 * @uses   bp_core_get_userlink() to build the post author profile link
     329 * @uses   get_blog_option() WordPress function to fetch blog meta.
     330 * @return string the activity action
     331 */
     332function bp_blogs_activity_action_post_callback( $args = array() ) {
     333        extract( $args, EXTR_SKIP );
     334
     335        if ( !empty( $blog_id ) )
     336                $activity_action  = sprintf( __( '%1$s wrote a new %2$s, %3$s, on the site %4$s', 'buddypress' ), bp_core_get_userlink( (int) $post_author ), $singular_post_type_name, '<a href="' . $post_permalink . '">' . $post_title . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' );
     337        else
     338                $activity_action  = sprintf( __( '%1$s wrote a new %2$s, %3$s', 'buddypress' ), bp_core_get_userlink( (int) $post_author ), $singular_post_type_name, '<a href="' . $post_permalink . '">' . $post_title . '</a>' );
     339
     340        return $activity_action;
     341}
     342
     343/**
    281344 * Record a new blog post in the BuddyPress activity stream.
    282345 *
    283346 * @param int $post_id ID of the post being recorded.
     
    311374        if ( (int) $blog_id == $tags_blog_id && apply_filters( 'bp_blogs_block_sitewide_tags_activity', true ) )
    312375                return false;
    313376
    314         // Don't record this if it's not a post
    315         if ( !in_array( $post->post_type, apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) ) ) )
     377        // Don't record this if the post type has not been set by administrator to be tracked
     378        if ( ! bp_blogs_is_post_type_trackable( $post->post_type, $blog_id ) )
    316379                return false;
    317380
    318381        $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) );
     
    320383        if ( 'publish' == $post->post_status && empty( $post->post_password ) ) {
    321384                if ( $is_blog_public || !is_multisite() ) {
    322385
    323                         // Record this in activity streams
    324                         $post_permalink = add_query_arg(
    325                                 'p',
    326                                 $post_id,
    327                                 trailingslashit( get_home_url( $blog_id ) )
     386                        $post_type_object = get_post_type_object( $post->post_type );
     387
     388                        if( !empty( $post_type_object->bp_tracking ) )
     389                                extract( $post_type_object->bp_tracking, EXTR_SKIP );
     390
     391                        // Builds the permalink to the post_type
     392                        if ( !empty( $activity_permalink_post_callback ) && is_callable( $activity_permalink_post_callback ) )
     393                                $post_permalink = call_user_func_array( $activity_permalink_post_callback, array( $post_id, $blog_id, $post ) );
     394                        else
     395                                $post_permalink = bp_blogs_activity_permalink_post_callback( $post_id, $blog_id, $post );
     396
     397                        $action_args = array(
     398                                'post_author'              => $post->post_author,
     399                                'post_permalink'           => $post_permalink,
     400                                'post_title'               => $post->post_title,
     401                                'singular_post_type_name'  => lcfirst( esc_html( $post_type_object->labels->singular_name ) )
    328402                        );
    329403
    330                         if ( is_multisite() )
    331                                 $activity_action  = sprintf( __( '%1$s wrote a new post, %2$s, on the site %3$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' );
     404                        if( is_multisite() )
     405                                $action_args['blog_id'] = $blog_id;
     406
     407                        // Builds the activity action for the post type
     408                        if( !empty( $activity_action_post_callback ) && is_callable( $activity_action_post_callback ) )
     409                                $activity_action = call_user_func_array( $activity_action_post_callback, array( $action_args ) );
    332410                        else
    333                                 $activity_action  = sprintf( __( '%1$s wrote a new post, %2$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
     411                                $activity_action = bp_blogs_activity_action_post_callback( $action_args );
    334412
     413                        $type_post = !empty( $type_post ) ? $type_post : 'new_blog_'. $post->post_type ;
     414
    335415                        // Make sure there's not an existing entry for this post (prevent bumping)
    336416                        if ( bp_is_active( 'activity' ) ) {
    337417                                $existing = bp_activity_get( array(
    338418                                        'filter' => array(
    339                                                 'action'       => 'new_blog_post',
     419                                                'action'       => $type_post,
    340420                                                'primary_id'   => $blog_id,
    341421                                                'secondary_id' => $post_id,
    342422                                        )
     
    351431
    352432                        bp_blogs_record_activity( array(
    353433                                'user_id'           => (int) $post->post_author,
    354                                 'action'            => apply_filters( 'bp_blogs_activity_new_post_action',       $activity_action,  $post, $post_permalink ),
    355                                 'content'           => apply_filters( 'bp_blogs_activity_new_post_content',      $activity_content, $post, $post_permalink ),
    356                                 'primary_link'      => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink,   $post_id               ),
    357                                 'type'              => 'new_blog_post',
     434                                'action'            => apply_filters( "bp_blogs_activity_new_{$post->post_type}_action",       $activity_action,  $post, $post_permalink ),
     435                                'content'           => apply_filters( "bp_blogs_activity_new_{$post->post_type}_content",      $activity_content, $post, $post_permalink ),
     436                                'primary_link'      => apply_filters( "bp_blogs_activity_new_{$post->post_type}_primary_link", $post_permalink,   $post_id               ),
     437                                'type'              => $type_post,
    358438                                'item_id'           => $blog_id,
    359439                                'secondary_item_id' => $post_id,
    360440                                'recorded_time'     => $post->post_date_gmt,
     
    371451}
    372452
    373453/**
     454 * Callback function to build the action for the comment on the post type
     455 *
     456 * @param  array  $args the available arguments
     457 * @uses   bp_core_get_userlink() to build the post author profile link
     458 * @uses   get_blog_option() WordPress function to fetch blog meta.
     459 * @return string the activity action
     460 */
     461function bp_blogs_activity_action_comment_callback( $args = array() ) {
     462        extract( $args, EXTR_SKIP );
     463
     464        if ( !empty( $blog_id ) )
     465                $activity_action = sprintf( __( '%1$s commented on the %2$s, %3$s, on the site %4$s', 'buddypress' ), bp_core_get_userlink( $user_id ), $singular_post_type_name, '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $post_title ) . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' );
     466        else
     467                $activity_action = sprintf( __( '%1$s commented on the %2$s, %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ), $singular_post_type_name, '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $post_title ) . '</a>' );
     468
     469        return $activity_action;
     470}
     471
     472/**
    374473 * Record a new blog comment in the BuddyPress activity stream.
    375474 *
    376475 * Only posts the item if blog is public and post is not password-protected.
     
    422521        if ( !empty( $recorded_comment->post->post_password ) )
    423522                return false;
    424523
    425         // Don't record activity if the comment's associated post isn't a WordPress Post
    426         if ( !in_array( $recorded_comment->post->post_type, apply_filters( 'bp_blogs_record_comment_post_types', array( 'post' ) ) ) )
     524        // Don't record this if the post type has not been set by administrator to be tracked
     525        if ( ! bp_blogs_is_post_type_trackable( $recorded_comment->post->post_type, $blog_id ) )
    427526                return false;
    428527
    429528        $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) );
     
    431530        // If blog is public allow activity to be posted
    432531        if ( $is_blog_public ) {
    433532
    434                 // Get activity related links
    435                 $post_permalink = get_permalink( $recorded_comment->comment_post_ID );
    436                 $comment_link   = get_comment_link( $recorded_comment->comment_ID );
     533                $post_type_object = get_post_type_object( $recorded_comment->post->post_type );
     534               
     535                if( !empty( $post_type_object->bp_tracking ) )
     536                        extract( $post_type_object->bp_tracking, EXTR_SKIP );
    437537
    438                 // Prepare to record in activity streams
    439                 if ( is_multisite() )
    440                         $activity_action = sprintf( __( '%1$s commented on the post, %2$s, on the site %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' );
     538                // Builds the permalink to the post_type
     539                if ( !empty( $activity_permalink_post_callback ) && is_callable( $activity_permalink_post_callback ) )
     540                        $post_permalink = call_user_func_array( $activity_permalink_post_callback, array( $recorded_comment->comment_post_ID, $blog_id, $recorded_comment->post ) );
    441541                else
    442                         $activity_action = sprintf( __( '%1$s commented on the post, %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' );
     542                        $post_permalink = get_permalink( $recorded_comment->comment_post_ID );
    443543
     544                $action_args = array(
     545                        'user_id'                  => $user_id,
     546                        'post_permalink'           => $post_permalink,
     547                        'post_title'               => $recorded_comment->post->post_title,
     548                        'singular_post_type_name'  => lcfirst( esc_html( $post_type_object->labels->singular_name ) )
     549                );
     550
     551                if( is_multisite() )
     552                        $action_args['blog_id'] = $blog_id;
     553
     554                // Builds the activity action for the post type
     555                if( !empty( $activity_action_comment_callback ) && is_callable( $activity_action_comment_callback ) )
     556                        $activity_action = call_user_func_array( $activity_action_comment_callback, array( $action_args ) );
     557                else
     558                        $activity_action = bp_blogs_activity_action_comment_callback( $action_args );
     559
     560                // Get the activity type
     561                $comment_prefix = ( 'post' == $recorded_comment->post->post_type ) ? '' : $recorded_comment->post->post_type . '_';
     562                $type_comment = !empty( $type_comment ) ? $type_comment : "new_blog_{$comment_prefix}comment";
     563
     564                // Get comment link
     565                $comment_link   = get_comment_link( $recorded_comment->comment_ID );
     566                       
     567                // Get the comment content
    444568                $activity_content       = $recorded_comment->comment_content;
    445569
     570                $comment_post_type = ( 'post' == $recorded_comment->post->post_type ) ? 'comment' : $recorded_comment->post->post_type . '_comment';
     571
    446572                // Record in activity streams
    447573                bp_blogs_record_activity( array(
    448574                        'user_id'           => $user_id,
    449                         'action'            => apply_filters_ref_array( 'bp_blogs_activity_new_comment_action',       array( $activity_action,  &$recorded_comment, $comment_link ) ),
    450                         'content'           => apply_filters_ref_array( 'bp_blogs_activity_new_comment_content',      array( $activity_content, &$recorded_comment, $comment_link ) ),
    451                         'primary_link'      => apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link,     &$recorded_comment                ) ),
    452                         'type'              => 'new_blog_comment',
     575                        'action'            => apply_filters_ref_array( "bp_blogs_activity_new_{$comment_post_type}_action",       array( $activity_action,  &$recorded_comment, $comment_link ) ),
     576                        'content'           => apply_filters_ref_array( "bp_blogs_activity_new_{$comment_post_type}_content",      array( $activity_content, &$recorded_comment, $comment_link ) ),
     577                        'primary_link'      => apply_filters_ref_array( "bp_blogs_activity_new_{$comment_post_type}_primary_link", array( $comment_link,     &$recorded_comment                ) ),
     578                        'type'              => $type_comment,
    453579                        'item_id'           => $blog_id,
    454580                        'secondary_item_id' => $comment_id,
    455581                        'recorded_time'     => $recorded_comment->comment_date_gmt
  • bp-blogs/bp-blogs-activity.php

     
    2020 * @return bool|null Returns false if activity component is not active.
    2121 */
    2222function bp_blogs_register_activity_actions() {
    23         global $bp;
     23        global $bp, $_wp_post_type_features, $wp_post_types;
    2424
    2525        // Bail if activity is not active
    2626        if ( ! bp_is_active( 'activity' ) ) {
     
    3131                bp_activity_set_action( $bp->blogs->id, 'new_blog', __( 'New site created',        'buddypress' ) );
    3232        }
    3333
    34         bp_activity_set_action( $bp->blogs->id, 'new_blog_post',    __( 'New post published',      'buddypress' ) );
    35         bp_activity_set_action( $bp->blogs->id, 'new_blog_comment', __( 'New post comment posted', 'buddypress' ) );
     34        foreach( $_wp_post_type_features as $key_post => $post_type ) {
    3635
     36                if( ! bp_blogs_is_post_type_trackable( $key_post ) )
     37                        continue;
     38
     39                $type_activity_post = !empty( $wp_post_types[$key_post]->bp_tracking['type_post'] ) ? $wp_post_types[$key_post]->bp_tracking['type_post'] : 'new_blog_'. $key_post ;
     40
     41                // Registering the 'post' activity
     42                bp_activity_set_action( $bp->blogs->id, $type_activity_post,    sprintf( __( 'New %s published',      'buddypress' ), lcfirst( esc_html( $wp_post_types[$key_post]->labels->singular_name ) ) ) );
     43               
     44                // Checking if post type has comments support else no need to set the activity, as there should never be a comment !
     45                if( ! post_type_supports( $key_post, 'comments') )
     46                        continue;
     47
     48                $comment_prefix = ( 'post' == $key_post ) ? '' : $key_post . '_';
     49                $type_activity_comment = !empty( $wp_post_types[$key_post]->bp_tracking['comment'] ) ? $wp_post_types[$key_post]->bp_tracking['comment'] : "new_blog_{$comment_prefix}comment";
     50               
     51                bp_activity_set_action( $bp->blogs->id, $type_activity_comment, sprintf( __( 'New %s comment posted', 'buddypress' ), lcfirst( esc_html( $wp_post_types[$key_post]->labels->singular_name ) ) ) );
     52        }
     53
    3754        do_action( 'bp_blogs_register_activity_actions' );
    3855}
    39 add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' );
     56add_action( 'bp_catch_post_types', 'bp_blogs_register_activity_actions' );
    4057
    4158/**
    4259 * Record blog-related activity to the activity stream.
  • bp-blogs/bp-blogs-actions.php

     
    3232        }
    3333}
    3434add_action( 'bp_actions', 'bp_blogs_redirect_to_random_blog' );
     35
     36/**
     37 * Early hooks bp_catch_post_types to extend the post post type arguments and add to it the "bp_tracking" support
     38 * Then it checks for BuddyPress Site Tracking settings to eventually add support for bp_tracking to other post types
     39 *
     40 * @global $wp_post_types the different registered post types
     41 *
     42 * @uses  add_post_type_support() to add the "bp_tracking" support to the post post type
     43 * @uses  bp_get_option() to get the post type the Community administratar enabled in BuddyPress settings
     44 * @uses  post_type_exists() to check the post type exists
     45 * @uses  post_type_supports() to check if it's necessary to add bp_tracking support
     46 */
     47function bp_blogs_extend_initial_post_types() {
     48        global $wp_post_types;
     49
     50        // Default post type
     51        $wp_post_types['post']->bp_tracking = array(
     52                'type_post'                           => 'new_blog_post',
     53                'activity_permalink_post_callback'    => 'bp_blogs_activity_permalink_post_callback',
     54                'activity_action_post_callback'       => 'bp_blogs_activity_action_post_callback',
     55                'type_comment'                        => 'new_blog_comment',
     56                'activity_action_comment_callback'    => 'bp_blogs_activity_action_comment_callback',
     57        );
     58
     59        add_post_type_support( 'post', 'bp_tracking' );
     60
     61        // Optional post types
     62        $optional_post_types = bp_get_option( 'bp-enabled-post-types', array() );
     63
     64        if( empty( $optional_post_types ) )
     65                return;
     66
     67        foreach( array_keys( $optional_post_types ) as $post_type ) {
     68                if( post_type_exists( $post_type ) && ! post_type_supports( $post_type, 'bp_tracking' ) )
     69                        add_post_type_support( $post_type, 'bp_tracking' );
     70        }
     71
     72}
     73
     74add_action( 'bp_catch_post_types', 'bp_blogs_extend_initial_post_types', 0 );