Ticket #3460: 3460.3.diff
File 3460.3.diff, 25.2 KB (added by , 11 years ago) |
---|
-
bp-core/admin/bp-core-settings.php
103 103 <?php 104 104 } 105 105 106 /** Blogs *******************************************************************/ 107 106 108 /** 109 * Post type Site Tracking settings section description for the settings page 110 * 111 * @since BuddyPress (?) 112 */ 113 function 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 */ 130 function 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 */ 156 function 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 /** 107 162 * Sanitization for _bp_force_buddyvar 108 163 * 109 164 * 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
92 92 } 93 93 94 94 /** 95 * Fire the 'bp_catch_post_types' action, BuddyPress's way to get all registered post types. 96 */ 97 function bp_catch_post_types() { 98 do_action( 'bp_catch_post_types' ); 99 } 100 101 /** 95 102 * Fire the 'bp_loaded' action, which fires after BP's core plugin files have been loaded. 96 103 * 97 104 * Attached to 'plugins_loaded'. -
bp-core/bp-core-admin.php
332 332 register_setting ( 'buddypress', '_bp_enable_akismet', 'intval' ); 333 333 } 334 334 } 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 335 349 } 336 350 337 351 /** -
bp-core/bp-core-actions.php
33 33 */ 34 34 add_action( 'plugins_loaded', 'bp_loaded', 10 ); 35 35 add_action( 'init', 'bp_init', 10 ); 36 add_action( 'init', 'bp_catch_post_types', 100 ); // late to catch post types 36 37 add_action( 'parse_query', 'bp_parse_query', 2 ); // Early for overrides 37 38 add_action( 'wp', 'bp_ready', 10 ); 38 39 add_action( 'set_current_user', 'bp_setup_current_user', 10 ); -
bp-activity/bp-activity-template.php
2582 2582 $can_comment = true; 2583 2583 2584 2584 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 ) ) 2586 2594 $can_comment = false; 2587 2595 } 2588 2596 … … 3269 3277 <?php 3270 3278 } 3271 3279 add_action( 'bp_head', 'bp_activity_sitewide_feed' ); 3280 3281 3282 3283 /** Activity type for post types **/ 3284 function 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
22 22 23 23 <?php 24 24 if ( !bp_is_current_action( 'groups' ) ) : 25 if ( bp_is_active( 'blogs' ) ) : ?>25 bp_activity_post_type_filter_options(); 26 26 27 <option value="new_blog_post"><?php _e( 'Posts', 'buddypress' ); ?></option>28 <option value="new_blog_comment"><?php _e( 'Comments', 'buddypress' ); ?></option>29 30 <?php31 endif;32 33 27 if ( bp_is_active( 'friends' ) ) : ?> 34 28 35 29 <option value="friendship_accepted,friendship_created"><?php _e( 'Friendships', 'buddypress' ); ?></option> -
bp-templates/bp-legacy/buddypress/activity/index.php
78 78 <option value="-1"><?php _e( 'Everything', 'buddypress' ); ?></option> 79 79 <option value="activity_update"><?php _e( 'Updates', 'buddypress' ); ?></option> 80 80 81 <?php if ( bp_is_active( 'blogs' ) ) :?>81 <?php bp_activity_post_type_filter_options();?> 82 82 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 88 83 <?php if ( bp_is_active( 'forums' ) ) : ?> 89 84 90 85 <option value="new_forum_topic"><?php _e( 'Forum Topics', 'buddypress' ); ?></option> -
bp-blogs/bp-blogs-functions.php
156 156 return $trackable_globally; 157 157 } 158 158 159 159 160 /** 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 */ 174 function 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 /** 160 184 * Make BuddyPress aware of a new site so that it can track its activity. 161 185 * 162 186 * @since BuddyPress (1.0.0) … … 278 302 add_action( 'transition_post_status', 'bp_blogs_catch_published_post', 10, 3 ); 279 303 280 304 /** 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 */ 314 function 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 */ 332 function 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 /** 281 344 * Record a new blog post in the BuddyPress activity stream. 282 345 * 283 346 * @param int $post_id ID of the post being recorded. … … 311 374 if ( (int) $blog_id == $tags_blog_id && apply_filters( 'bp_blogs_block_sitewide_tags_activity', true ) ) 312 375 return false; 313 376 314 // Don't record this if it's not a post315 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 ) ) 316 379 return false; 317 380 318 381 $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) ); … … 320 383 if ( 'publish' == $post->post_status && empty( $post->post_password ) ) { 321 384 if ( $is_blog_public || !is_multisite() ) { 322 385 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 ) ) 328 402 ); 329 403 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 ) ); 332 410 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 ); 334 412 413 $type_post = !empty( $type_post ) ? $type_post : 'new_blog_'. $post->post_type ; 414 335 415 // Make sure there's not an existing entry for this post (prevent bumping) 336 416 if ( bp_is_active( 'activity' ) ) { 337 417 $existing = bp_activity_get( array( 338 418 'filter' => array( 339 'action' => 'new_blog_post',419 'action' => $type_post, 340 420 'primary_id' => $blog_id, 341 421 'secondary_id' => $post_id, 342 422 ) … … 351 431 352 432 bp_blogs_record_activity( array( 353 433 '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, 358 438 'item_id' => $blog_id, 359 439 'secondary_item_id' => $post_id, 360 440 'recorded_time' => $post->post_date_gmt, … … 371 451 } 372 452 373 453 /** 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 */ 461 function 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 /** 374 473 * Record a new blog comment in the BuddyPress activity stream. 375 474 * 376 475 * Only posts the item if blog is public and post is not password-protected. … … 422 521 if ( !empty( $recorded_comment->post->post_password ) ) 423 522 return false; 424 523 425 // Don't record activity if the comment's associated post isn't a WordPress Post426 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 ) ) 427 526 return false; 428 527 429 528 $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) ); … … 431 530 // If blog is public allow activity to be posted 432 531 if ( $is_blog_public ) { 433 532 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 ); 437 537 438 // Prepare to record in activity streams439 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 ) ); 441 541 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 ); 443 543 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 444 568 $activity_content = $recorded_comment->comment_content; 445 569 570 $comment_post_type = ( 'post' == $recorded_comment->post->post_type ) ? 'comment' : $recorded_comment->post->post_type . '_comment'; 571 446 572 // Record in activity streams 447 573 bp_blogs_record_activity( array( 448 574 '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, 453 579 'item_id' => $blog_id, 454 580 'secondary_item_id' => $comment_id, 455 581 'recorded_time' => $recorded_comment->comment_date_gmt -
bp-blogs/bp-blogs-activity.php
20 20 * @return bool|null Returns false if activity component is not active. 21 21 */ 22 22 function bp_blogs_register_activity_actions() { 23 global $bp ;23 global $bp, $_wp_post_type_features, $wp_post_types; 24 24 25 25 // Bail if activity is not active 26 26 if ( ! bp_is_active( 'activity' ) ) { … … 31 31 bp_activity_set_action( $bp->blogs->id, 'new_blog', __( 'New site created', 'buddypress' ) ); 32 32 } 33 33 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 ) { 36 35 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 37 54 do_action( 'bp_blogs_register_activity_actions' ); 38 55 } 39 add_action( 'bp_ register_activity_actions', 'bp_blogs_register_activity_actions' );56 add_action( 'bp_catch_post_types', 'bp_blogs_register_activity_actions' ); 40 57 41 58 /** 42 59 * Record blog-related activity to the activity stream. -
bp-blogs/bp-blogs-actions.php
32 32 } 33 33 } 34 34 add_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 */ 47 function 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 74 add_action( 'bp_catch_post_types', 'bp_blogs_extend_initial_post_types', 0 );