Skip to:
Content

BuddyPress.org

Ticket #3460: 3460.04.diff

File 3460.04.diff, 30.5 KB (added by imath, 11 years ago)
  • bp-activity/bp-activity-functions.php

     
    15381538                $activity_obj = $activity_obj->current_comment;
    15391539        }
    15401540
    1541         if ( 'new_blog_post' == $activity_obj->type || 'new_blog_comment' == $activity_obj->type || 'new_forum_topic' == $activity_obj->type || 'new_forum_post' == $activity_obj->type ) {
     1541        $use_primary_link = array( 'new_forum_topic', 'new_forum_post' );
     1542
     1543        if ( bp_is_active( 'blogs' ) ) {
     1544                // Gets all post types activity actions available
     1545                $blogs_post_types        = get_object_vars( buddypress()->activity->actions->blogs );
     1546                // Adds them to the array to check.
     1547                $use_primary_link = array_merge( $use_primary_link, array_keys( $blogs_post_types ) );
     1548        }
     1549
     1550        if ( in_array( $activity_obj->type, $use_primary_link ) ) {
    15421551                $link = $activity_obj->primary_link;
    15431552        } else {
    15441553                if ( 'activity_comment' == $activity_obj->type ) {
  • bp-activity/bp-activity-template.php

     
    26262626        $can_comment = true;
    26272627
    26282628        if ( false === $activities_template->disable_blogforum_replies || (int) $activities_template->disable_blogforum_replies ) {
    2629                 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() )
     2629                // initialize with forum activity types
     2630                $activity_comment_types = array( 'new_forum_topic', 'new_forum_post' );
     2631
     2632                if ( bp_is_active( 'blogs' ) ) {
     2633                        // Gets all post types activity actions available
     2634                        $blogs_post_types        = get_object_vars( buddypress()->activity->actions->blogs );
     2635                        // Adds them to the array to check.
     2636                        $activity_comment_types = array_merge( $activity_comment_types, array_keys( $blogs_post_types ) );
     2637                }
     2638
     2639                if ( in_array( bp_get_activity_action_name(), $activity_comment_types ) )
    26302640                        $can_comment = false;
    26312641        }
    26322642
  • 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        /**
     35         * if post type argument 'bp_tracking' (array) is set and these two labels are set, they will override default values.
     36         * labels are :
     37         *
     38         * - activity_post_type_action_label         // the post type main action label
     39         * - activity_post_type_comment_action_label // the post type comment action label
     40         *
     41         * Plugins developers can set these, by adding a bp_tracking argument when registering their post type
     42         * see how to set a post type argument: http://codex.wordpress.org/Function_Reference/register_post_type#Arguments
     43         */
    3644
     45        foreach( $_wp_post_type_features as $post => $post_type ) {
     46       
     47                // if the admin did not activate the post type, continue..
     48                if ( ! bp_blogs_is_blog_post_type_trackable( $post ) )
     49                        continue;
     50
     51                /** Posts ************************************************/
     52
     53                // Default values
     54                $post_type_activity_action       = 'new_blog_'. $post;
     55                $post_type_activity_action_label = lcfirst( esc_html( $wp_post_types[ $post ]->labels->singular_name ) );
     56
     57                // overridden value provided by the post type when registering
     58                if ( ! empty( $wp_post_types[ $post ]->bp_tracking['activity_post_type_action'] ) ) {
     59                        $post_type_activity_action       = esc_html( $wp_post_types[ $post ]->bp_tracking['activity_post_type_action'] );
     60                }
     61
     62                if ( ! empty( $wp_post_types[ $post ]->bp_tracking['activity_post_type_action_label'] ) ) {
     63                        $post_type_activity_action_label = esc_html( $wp_post_types[ $post ]->bp_tracking['activity_post_type_action_label'] );
     64                }
     65
     66                // Registering the post type activity action
     67                bp_activity_set_action( $bp->blogs->id, $post_type_activity_action, sprintf( __( 'New %s published', 'buddypress' ), $post_type_activity_action_label ) );
     68               
     69
     70                /** Comments ************************************************/
     71
     72                // Checking if post type has comments support else no need to set the activity, as there should never be a comment.
     73                if ( ! post_type_supports( $post, 'comments' ) )
     74                        continue;
     75
     76                // Default values
     77                $comment_prefix = ( 'post' == $post ) ? '' : $post . '_';
     78                $post_type_comment_activity_action       = "new_blog_{$comment_prefix}comment";
     79                $post_type_comment_activity_action_label = lcfirst( esc_html( $wp_post_types[$post]->labels->singular_name ) ) . ' comment';
     80
     81                if ( ! empty( $wp_post_types[ $post ]->bp_tracking['activity_post_type_comment_action'] ) ) {
     82                        $post_type_comment_activity_action       = esc_html( $wp_post_types[ $post ]->bp_tracking['activity_post_type_comment_action'] );
     83                }
     84
     85                if ( ! empty( $wp_post_types[ $post ]->bp_tracking['activity_post_type_comment_action_label'] ) ) {
     86                        $post_type_comment_activity_action_label = esc_html( $wp_post_types[ $post ]->bp_tracking['activity_post_type_comment_action_label'] );
     87                }
     88               
     89                // Registering the post type comment activity action
     90                bp_activity_set_action( $bp->blogs->id, $post_type_comment_activity_action, sprintf( __( 'New %s posted', 'buddypress' ), $post_type_comment_activity_action_label ) );
     91        }
     92
    3793        do_action( 'bp_blogs_register_activity_actions' );
    3894}
    39 add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' );
     95add_action( 'bp_catch_post_types', 'bp_blogs_register_activity_actions' );
    4096
    4197/**
    4298 * Record blog-related activity to the activity stream.
  • bp-blogs/bp-blogs-functions.php

     
    159159}
    160160
    161161/**
     162 * Check whether a given blog post type should be tracked by the Blogs component.
     163 *
     164 * If $blog_id is provided, the developer can restrict a given blog post type from
     165 * being trackable.
     166 *
     167 * @since BuddyPress (?)
     168 *
     169 * @uses bp_trackable_post_types()
     170 * @uses apply_filters()
     171 *
     172 * @param string $post_type the post type being checked.
     173 * @param int $blog_id the blog the post type is registered to.
     174 * @return bool True if the post type is trackable, otherwise false.
     175 */
     176function bp_blogs_is_blog_post_type_trackable( $post_type = '', $blog_id = 0 ) {
     177        /**
     178         * This filter can be used to eventually remove a tracked or add a new post type
     179         * the array bp_trackable_post_types() is listing the post types as keys. Values are 1 or 0. 1 means
     180         * the post type has been activated by the admin
     181         */
     182        $trackable = (array) apply_filters( 'bp_blogs_is_blog_post_type_trackable', bp_trackable_post_types(), $blog_id );
     183
     184        // BackCompat
     185        $legacy_post_type_filter = apply_filters( 'bp_blogs_record_post_post_types', array() );
     186        $legacy_comment_filter   = apply_filters( 'bp_blogs_record_comment_post_types', array() );
     187        $legacy_post_type_filter = array_merge( $legacy_post_type_filter, $legacy_comment_filter );
     188
     189        if ( ! empty( $legacy_post_type_filter ) ) {
     190                $legacy_post_type_filter = array_fill_keys( $legacy_post_type_filter, 1 );
     191
     192                // Merge the two arrays making sure the setting saved for the post type will be the final value
     193                $trackable = array_merge( $legacy_post_type_filter, $trackable );
     194        }
     195
     196        return ! empty( $trackable[ $post_type ] );
     197}
     198
     199/**
    162200 * Make BuddyPress aware of a new site so that it can track its activity.
    163201 *
    164202 * @since BuddyPress (1.0.0)
     
    280318add_action( 'transition_post_status', 'bp_blogs_catch_published_post', 10, 3 );
    281319
    282320/**
     321 * Callback function to build the permalink to the post type
     322 *
     323 * @since  BuddyPress (?)
     324 *
     325 * @param  integer $post_id the post type id
     326 * @param  integer $blog_id the blog id
     327 * @param  WP_Post  $post    Post object.
     328 * @uses   add_query_arg()   To add custom args to the url
     329 * @uses   get_home_url()
     330 * @return string           the post type permalink
     331 */
     332function bp_blogs_activity_post_type_permalink_callback( $post_id = 0, $blog_id = 0, $post = null ) {
     333        $post_permalink = add_query_arg(
     334                'p',
     335                $post_id,
     336                trailingslashit( get_home_url( $blog_id ) )
     337        );
     338
     339        return $post_permalink;
     340}
     341
     342/**
     343 * Callback function to build the action for the post type
     344 *
     345 * @param  array  $args the available arguments
     346 * @uses   bp_core_get_userlink() to build the post author profile link
     347 * @uses   get_blog_option() WordPress function to fetch blog meta.
     348 * @return string the activity action
     349 */
     350function bp_blogs_activity_post_type_action_callback( $args = array() ) {
     351
     352        $r = bp_parse_args( $args, array(
     353                'post_author'             => bp_loggedin_user_id(),
     354                'post_title'              => '',
     355                'singular_post_type_name' => '',
     356                'blog_id'                 => 0,
     357                'post_permalink'          => '',
     358        ), 'blogs_activity_post_type_action_callback' );
     359
     360        extract( $r, EXTR_SKIP );
     361
     362        if ( ! empty( $blog_id ) ) {
     363                $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>' );
     364        } else {
     365                $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>' );
     366        }
     367
     368        return $activity_action;
     369}
     370
     371/**
    283372 * Record a new blog post in the BuddyPress activity stream.
    284373 *
    285374 * @param int $post_id ID of the post being recorded.
     
    313402        if ( (int) $blog_id == $tags_blog_id && apply_filters( 'bp_blogs_block_sitewide_tags_activity', true ) )
    314403                return false;
    315404
    316         // Don't record this if it's not a post
    317         if ( !in_array( $post->post_type, apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) ) ) )
     405        // Don't record this if the post type is not trackable
     406        if ( ! bp_blogs_is_blog_post_type_trackable( $post->post_type, $blog_id ) )
    318407                return false;
    319408
    320409        $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) );
     
    323412                if ( $is_blog_public || !is_multisite() ) {
    324413
    325414                        // Record this in activity streams
    326                         $post_permalink = add_query_arg(
    327                                 'p',
    328                                 $post_id,
    329                                 trailingslashit( get_home_url( $blog_id ) )
     415                        $post_type_object = get_post_type_object( $post->post_type );
     416
     417                        // Initializing the action arguments
     418                        $action_args = array(
     419                                'post_author'              => absint( $post->post_author ),
     420                                'post_title'               => esc_html( $post->post_title ),
     421                                'singular_post_type_name'  => lcfirst( esc_html( $post_type_object->labels->singular_name ) ),
     422                                'blog_id'                  => is_multisite() ? $blog_id : 0,
    330423                        );
    331424
    332                         if ( is_multisite() )
    333                                 $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>' );
    334                         else
    335                                 $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>' );
     425                        if ( ! empty( $post_type_object->bp_tracking ) ) {
     426                                /**
     427                                 * Extracting bp_tracking post type argument will give us the following vars (if set):
     428                                 * - activity_post_type_action                   // the post type main action
     429                                 * - activity_post_type_action_label             // the post type main action label (used in template filter box)
     430                                 * - activity_post_type_permalink_callback       // the post type provided function to build the permalink
     431                                 * - activity_post_type_action_callback          // the post type provided function to build the activity action
     432                                 *
     433                                 * Plugins developers can set these, by adding a bp_tracking argument when registering their post type
     434                                 * see how to set a post type argument: http://codex.wordpress.org/Function_Reference/register_post_type#Arguments
     435                                 */
     436                                extract( $post_type_object->bp_tracking, EXTR_SKIP );
    336437
     438                                // Builds the permalink to the post_type using the callback function provided by the post type
     439                                if ( ! empty( $activity_post_type_permalink_callback ) && is_callable( $activity_post_type_permalink_callback ) )
     440                                        $action_args['post_permalink'] = call_user_func_array( $activity_post_type_permalink_callback, array( $post_id, $blog_id, $post ) );
     441
     442                                // Builds the activity action for the post type
     443                                if ( ! empty( $activity_post_type_action_callback ) && is_callable( $activity_post_type_action_callback ) )
     444                                        $activity_action               = call_user_func_array( $activity_post_type_action_callback, array( $action_args ) );
     445
     446                        }
     447
     448                        if ( empty( $action_args['post_permalink'] ) )
     449                                $action_args['post_permalink'] = bp_blogs_activity_post_type_permalink_callback( $post_id, $blog_id, $post );
     450
     451                        if ( empty( $activity_action ) )
     452                                $activity_action               = bp_blogs_activity_post_type_action_callback( $action_args );
     453
     454                        // if no action "identifier" ( == type field of activity table ) was provided by the post type
     455                        if ( empty( $activity_post_type_action ) ) {
     456                                $activity_post_type_action = 'new_blog_'. $post->post_type;
     457                        }
     458
    337459                        // Make sure there's not an existing entry for this post (prevent bumping)
    338460                        if ( bp_is_active( 'activity' ) ) {
    339461                                $existing = bp_activity_get( array(
    340462                                        'filter' => array(
    341                                                 'action'       => 'new_blog_post',
     463                                                'action'       => $activity_post_type_action,
    342464                                                'primary_id'   => $blog_id,
    343465                                                'secondary_id' => $post_id,
    344466                                        )
    345467                                ) );
    346468
    347                                 if ( !empty( $existing['activities'] ) ) {
     469                                if ( ! empty( $existing['activities'] ) ) {
    348470                                        return;
    349471                                }
    350472                        }
    351473
    352474                        $activity_content = $post->post_content;
     475                        $post_permalink   = $action_args['post_permalink'];
    353476
    354477                        bp_blogs_record_activity( array(
    355478                                'user_id'           => (int) $post->post_author,
    356                                 'action'            => apply_filters( 'bp_blogs_activity_new_post_action',       $activity_action,  $post, $post_permalink ),
    357                                 'content'           => apply_filters( 'bp_blogs_activity_new_post_content',      $activity_content, $post, $post_permalink ),
    358                                 'primary_link'      => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink,   $post_id               ),
    359                                 'type'              => 'new_blog_post',
     479                                'action'            => apply_filters( "bp_blogs_activity_new_{$post->post_type}_action",       $activity_action,  $post, $post_permalink ),
     480                                'content'           => apply_filters( "bp_blogs_activity_new_{$post->post_type}_content",      $activity_content, $post, $post_permalink ),
     481                                'primary_link'      => apply_filters( "bp_blogs_activity_new_{$post->post_type}_primary_link", $post_permalink,   $post_id               ),
     482                                'type'              => $activity_post_type_action,
    360483                                'item_id'           => $blog_id,
    361484                                'secondary_item_id' => $post_id,
    362485                                'recorded_time'     => $post->post_date_gmt,
     
    373496}
    374497
    375498/**
     499 * Callback function to build the action for the comment on the post type
     500 *
     501 * @param  array  $args the available arguments
     502 * @uses   bp_core_get_userlink() to build the post author profile link
     503 * @uses   get_blog_option() WordPress function to fetch blog meta.
     504 * @return string the activity action
     505 */
     506function bp_blogs_activity_post_type_comment_action_callback( $args = array() ) {
     507       
     508        $r = bp_parse_args( $args, array(
     509                'user_id'                 => bp_loggedin_user_id(),
     510                'post_title'              => '',
     511                'singular_post_type_name' => '',
     512                'blog_id'                 => 0,
     513                'post_permalink'          => '',
     514        ), 'blogs_activity_post_type_comment_action_callback' );
     515
     516        extract( $r, EXTR_SKIP );
     517
     518        if ( ! empty( $blog_id ) )
     519                $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>' );
     520        else
     521                $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>' );
     522
     523        return $activity_action;
     524}
     525
     526/**
    376527 * Record a new blog comment in the BuddyPress activity stream.
    377528 *
    378529 * Only posts the item if blog is public and post is not password-protected.
     
    424575        if ( !empty( $recorded_comment->post->post_password ) )
    425576                return false;
    426577
    427         // Don't record activity if the comment's associated post isn't a WordPress Post
    428         if ( !in_array( $recorded_comment->post->post_type, apply_filters( 'bp_blogs_record_comment_post_types', array( 'post' ) ) ) )
     578        // Don't record this if the post type has not been set by administrator to be tracked
     579        if ( ! bp_blogs_is_blog_post_type_trackable( $recorded_comment->post->post_type, $blog_id ) )
    429580                return false;
    430581
    431582        $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) );
     
    433584        // If blog is public allow activity to be posted
    434585        if ( $is_blog_public ) {
    435586
    436                 // Get activity related links
    437                 $post_permalink = get_permalink( $recorded_comment->comment_post_ID );
     587                // Record this in activity streams
     588                $post_type_object = get_post_type_object( $recorded_comment->post->post_type );
     589
     590                // Initializing the action arguments
     591                $action_args = array(
     592                        'user_id'                  => $user_id,
     593                        'post_title'               => $recorded_comment->post->post_title,
     594                        'singular_post_type_name'  => lcfirst( esc_html( $post_type_object->labels->singular_name ) ),
     595                        'blog_id'                  => is_multisite() ? $blog_id : 0,
     596                );
     597               
     598                if( ! empty( $post_type_object->bp_tracking ) ) {
     599                        /**
     600                         * Extracting bp_tracking post type argument will give us the following vars (if set):
     601                         * - activity_post_type_permalink_callback       // the post type provided function to build the permalink
     602                         * - activity_post_type_comment_action           // the post type comment action
     603                         * - activity_post_type_comment_action_label     // the post type comment action label (used in template filter box)
     604                         * - activity_post_type_comment_action_callback  // the post type provided function to build the comment activity action
     605                         *
     606                         * Plugins developers can set these, by adding a bp_tracking argument when registering their post type
     607                         * see how to set a post type argument: http://codex.wordpress.org/Function_Reference/register_post_type#Arguments
     608                         */
     609                        extract( $post_type_object->bp_tracking, EXTR_SKIP );
     610
     611                        // Builds the permalink to the post_type comment
     612                        if ( ! empty( $activity_post_type_permalink_callback ) && is_callable( $activity_post_type_permalink_callback ) )
     613                                $action_args['post_permalink'] = call_user_func_array( $activity_post_type_permalink_callback, array( $recorded_comment->comment_post_ID, $blog_id, $recorded_comment->post ) );
     614
     615                        if( ! empty( $activity_post_type_comment_action_callback ) && is_callable( $activity_post_type_comment_action_callback ) )
     616                                $activity_action               = call_user_func_array( $activity_post_type_comment_action_callback, array( $action_args ) );
     617
     618                }
     619
     620                if ( empty( $action_args['post_permalink'] ) )
     621                        $action_args['post_permalink'] = get_permalink( $recorded_comment->comment_post_ID );
     622
     623                if ( empty( $activity_action ) )
     624                        $activity_action = bp_blogs_activity_post_type_comment_action_callback( $action_args );
     625
     626               
     627                // Get the activity type
     628                $comment_prefix = ( 'post' == $recorded_comment->post->post_type ) ? '' : $recorded_comment->post->post_type . '_';
     629
     630                // if no action "identifier" ( == type field of activity table ) was provided by the post type
     631                if ( empty( $activity_post_type_comment_action ) ) {
     632                        $activity_post_type_comment_action = "new_blog_{$comment_prefix}comment";
     633                }
     634
     635                // Get comment link
    438636                $comment_link   = get_comment_link( $recorded_comment->comment_ID );
    439637
    440                 // Prepare to record in activity streams
    441                 if ( is_multisite() )
    442                         $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>' );
    443                 else
    444                         $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>' );
     638                // Get the comment content
     639                $activity_content = $recorded_comment->comment_content;
    445640
    446                 $activity_content       = $recorded_comment->comment_content;
     641                // to have custom filters by type of post type commented.
     642                $comment_post_type = ( 'post' == $recorded_comment->post->post_type ) ? 'comment' : $recorded_comment->post->post_type . '_comment';
    447643
    448644                // Record in activity streams
    449645                bp_blogs_record_activity( array(
    450646                        'user_id'           => $user_id,
    451                         'action'            => apply_filters_ref_array( 'bp_blogs_activity_new_comment_action',       array( $activity_action,  &$recorded_comment, $comment_link ) ),
    452                         'content'           => apply_filters_ref_array( 'bp_blogs_activity_new_comment_content',      array( $activity_content, &$recorded_comment, $comment_link ) ),
    453                         'primary_link'      => apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link,     &$recorded_comment                ) ),
    454                         'type'              => 'new_blog_comment',
     647                        'action'            => apply_filters_ref_array( "bp_blogs_activity_new_{$comment_post_type}_action",       array( $activity_action,  &$recorded_comment, $comment_link ) ),
     648                        'content'           => apply_filters_ref_array( "bp_blogs_activity_new_{$comment_post_type}_content",      array( $activity_content, &$recorded_comment, $comment_link ) ),
     649                        'primary_link'      => apply_filters_ref_array( "bp_blogs_activity_new_{$comment_post_type}_primary_link", array( $comment_link,     &$recorded_comment                ) ),
     650                        'type'              => $activity_post_type_comment_action,
    455651                        'item_id'           => $blog_id,
    456652                        'secondary_item_id' => $comment_id,
    457653                        'recorded_time'     => $recorded_comment->comment_date_gmt
  • bp-blogs/bp-blogs-template.php

     
    12881288        // Filter and return
    12891289        return apply_filters( 'bp_blogs_get_profile_stats', $r['output'], $r );
    12901290}
     1291
     1292/**
     1293 * Adds the available post types actions to activity filters
     1294 *
     1295 * As in bp-legacy or bp-default templates the regular post type
     1296 * is already added we'll need to remove it from these options.
     1297 * Leaving it this way for backcompat theme purpose. But all
     1298 * post types should be handled there in the future..
     1299 *
     1300 * @return string html output
     1301 */
     1302function bp_blogs_post_types_activity_options() {
     1303
     1304        $blogs_legacy_actions     = array( 'new_blog_post', 'new_blog_comment' );
     1305        $blogs_post_types_actions = buddypress()->activity->actions->blogs;
     1306
     1307        foreach ( $blogs_post_types_actions as $action ) {
     1308                if ( in_array( $action['key'], $blogs_legacy_actions ) )
     1309                        continue;
     1310                ?>
     1311                <option value="<?php echo esc_attr( $action['key'] ) ;?>"><?php echo esc_html( $action['value'] ) ;?></option>
     1312                <?php
     1313        }
     1314}
     1315add_action( 'bp_activity_filter_options',        'bp_blogs_post_types_activity_options' );
     1316add_action( 'bp_member_activity_filter_options', 'bp_blogs_post_types_activity_options' );
  • bp-core/admin/bp-core-settings.php

     
    211211<?php
    212212}
    213213
     214/** Blogs Section *************************************************************/
     215
     216/**
     217 * Displays a message about the trackable post types in case BuddyPress is network activated
     218 *
     219 * @since BuddyPress (?)
     220 * @uses  bp_core_do_network_admin() to check if BuddyPress is network activated
     221 */
     222function bp_admin_setting_callback_blogs_section() {
     223        if ( bp_core_do_network_admin() ) {
     224        ?>
     225                <p class="description"><?php _e( 'Only the networked enabled & the primary blog post types can be tracked in Activity stream.', 'buddypress' );?></p>
     226        <?php
     227        }
     228}
     229
     230/**
     231 * Allow the Admin to define the post types to track in activity stream
     232 *
     233 * @since BuddyPress (?)
     234 *
     235 * @uses  get_post_types() to list the show_in_nav_menus enabled post types
     236 * @uses  checked() To display the checked attribute
     237 * @uses  post_type_supports() to check for bp_tracking support
     238 */
     239function bp_admin_setting_callback_post_types_tracked() {
     240        /**
     241         * Using show_in_nav_menus argument avoids the inclusion of the attachment post type
     242         * if show_in_nav_menus is not defined it defaults to the value of public arguments
     243         */
     244        $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' );
     245
     246        // Building an array to compare with the array saved in bp-enabled-post-types option
     247        $compare    = array_fill_keys( array_keys( $post_types ), 0 );
     248
     249        // Merge the two arrays making sure the setting saved for the post type will be the final value
     250        $db_post_types = array_merge( $compare, bp_trackable_post_types() );
     251
     252        if ( empty( $db_post_types ) )
     253                return;
     254
     255        foreach ( $post_types as $post_type => $arguments ) {
     256                $readonly = ( 'post' == $post_type ) ? 'disabled' : '';
     257                ?>
     258
     259                <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( $db_post_types[ $post_type ] ); ?> <?php echo $readonly;?>/>
     260                <label for="bp-enabled-post-types-<?php echo $post_type;?>"><?php echo $arguments->labels->name ?></label>
     261
     262                <?php
     263        }
     264
     265}
     266
     267/**
     268 * Sanitization for bp-enabled-post-types
     269 *
     270 * @since BuddyPress (?)
     271 */
     272function bp_admin_sanitize_callback_post_types_tracked( $value = array() ) {
     273        // Post is legacy : always tracked.
     274        $tracked = array( 'post' => 1 );
     275
     276        if( is_array( $value ) )
     277                $tracked = array_merge( $tracked, $value );
     278
     279        return array_map( 'absint', $tracked );
     280}
     281
    214282/** Forums Section ************************************************************/
    215283
    216284/**
  • 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-core/bp-core-admin.php

     
    348348                    add_settings_field( 'bp-disable-avatar-uploads', __( 'Avatar Uploads',   'buddypress' ), 'bp_admin_setting_callback_avatar_uploads',   'buddypress', $avatar_setting );
    349349                    register_setting  ( 'buddypress',         'bp-disable-avatar-uploads',   'intval'                                                                                    );
    350350                }
     351
     352                /** Blogs Section **************************************************/
     353
     354                if ( bp_is_active( 'blogs' ) ) {
     355
     356                        // Add the main section
     357                        add_settings_section( 'bp_blogs', __( 'Site Tracking Settings', 'buddypress' ), 'bp_admin_setting_callback_blogs_section', 'buddypress' );
     358
     359                        // Activity commenting on blog and forum posts
     360                        add_settings_field( 'bp-enabled-post-types', __( 'List of post types to track', 'buddypress' ), 'bp_admin_setting_callback_post_types_tracked', 'buddypress', 'bp_blogs' );
     361                        register_setting  ( 'buddypress',           'bp-enabled-post-types',                            'bp_admin_sanitize_callback_post_types_tracked'                          );
     362                }
    351363        }
    352364
    353365        /**
  • bp-core/bp-core-dependency.php

     
    388388        // Use this static action if you don't mind checking the 'action' yourself.
    389389        do_action( 'bp_get_request',   $_GET['action'] );
    390390}
     391
     392/**
     393 * The main action used for catching registered post types
     394 *
     395 * @since BuddyPress (?)
     396 * @uses do_action()
     397 */
     398function bp_catch_post_types() {
     399        do_action( 'bp_catch_post_types' );
     400}
  • bp-core/bp-core-options.php

     
    506506}
    507507
    508508/**
     509 * What are the registered post types trackable in activity streams?
     510 *
     511 * @since BuddyPress (?)
     512 *
     513 * @uses bp_get_option() To get the blog/forum comments option.
     514 *
     515 * @param array $default Optional. Fallback value if not found in the database.
     516 *        Default: array().
     517 * @return bool True if activity comments are disabled for blog and forum
     518 *         items, otherwise false.
     519 */
     520function bp_trackable_post_types( $default = array( 'post' => 1 ) ) {
     521        return (array) apply_filters( 'bp_trackable_post_types', (array) bp_get_option( 'bp-enabled-post-types', $default ) );
     522}
     523
     524/**
    509525 * Is group creation turned off?
    510526 *
    511527 * @since BuddyPress (1.6.0)