Ticket #5669: 5669.02.patch
File 5669.02.patch, 19.4 KB (added by , 10 years ago) |
---|
-
src/bp-activity/bp-activity-actions.php
diff --git src/bp-activity/bp-activity-actions.php src/bp-activity/bp-activity-actions.php index 576628f..8219a50 100644
13 13 if ( !defined( 'ABSPATH' ) ) exit; 14 14 15 15 /** 16 * Allow post types to register to the tracking feature 17 * 18 * @since BuddyPress (2.2.0) 19 * 20 * @uses buddypress() 21 * @uses get_post_types() 22 * @uses post_type_supports() 23 */ 24 function bp_activity_tracking_register_post_types() { 25 $bp = buddypress(); 26 $bp->activity->track = array(); 27 28 // Fetch public post types 29 $post_types = get_post_types( array( 'public' => true ), 'objects' ); 30 31 foreach ( $post_types as $key => $object ) { 32 // Check if they support BuddyPress activity tracking feature 33 if ( ! post_type_supports( $key, 'buddypress-activity' ) ) { 34 continue; 35 } 36 37 $bp->activity->track[ 'new_' . $key ] = apply_filters( 'bp_activity_tracking_register_' . $key . '_post', array( 38 'component_id' => $bp->activity->id, 39 'action_id' => 'new_' . $key, 40 'admin_filter' => sprintf( _x( 'New %s published', 'Custom Post Type generic activity post admin filter label', 'buddypress' ), strtolower( $object->labels->singular_name ) ), 41 'callback' => 'bp_activity_format_activity_action_custom_post_type_post', 42 'filter' => $object->labels->name, 43 'contexts' => array( 'activity' ), 44 'singular' => strtolower( $object->labels->singular_name ), 45 'plural' => strtolower( $object->labels->name ), 46 'activity_commment' => ! post_type_supports( $key, 'comments' ), 47 ), $object ); 48 } 49 } 50 add_action( 'bp_init', 'bp_activity_tracking_register_post_types', 7 ); 51 52 /** 16 53 * Allow core components and dependent plugins to register activity actions. 17 54 * 18 55 * @since BuddyPress (1.2.0) … … function bp_ajax_get_suggestions() { 766 803 wp_send_json_success( $results ); 767 804 } 768 805 add_action( 'wp_ajax_bp_get_suggestions', 'bp_ajax_get_suggestions' ); 806 807 /** 808 * Detect a change in post type status, and initiate an activity update if necessary. 809 * 810 * @since BuddyPress (?) 811 * 812 * @todo Support untrashing better 813 * 814 * @param string $new_status New status for the post. 815 * @param string $old_status Old status for the post. 816 * @param object $post Post data. 817 */ 818 function bp_activity_catch_transition_post_type_status( $new_status, $old_status, $post ) { 819 $bp = buddypress(); 820 821 // This is an edit 822 if ( $new_status === $old_status ) { 823 if ( $new_status == 'publish' ) { 824 // Update the post type 825 if ( ! empty( $bp->activity->track[ 'new_' . $post->post_type ] ) ) { 826 bp_activity_custom_post_type_update( $post ); 827 } else { 828 do_action( 'bp_activity_post_type_update_' . $post->post_type, $post ); 829 } 830 return; 831 } 832 } 833 834 // Publishing a previously unpublished post 835 if ( 'publish' === $new_status ) { 836 // Untrashing the post type 837 // Nothing here yet 838 if ( 'trash' == $old_status ) { 839 do_action( 'bp_activity_post_type_untrash_' . $post->post_type, $post ); 840 } else { 841 // Record the post type 842 if ( ! empty( $bp->activity->track[ 'new_' . $post->post_type ] ) ) { 843 bp_activity_custom_post_type_publish( $post->ID, $post ); 844 } else { 845 do_action( 'bp_activity_post_type_publish_' . $post->post_type, $post->ID, $post ); 846 } 847 } 848 849 // Unpublishing a previously published post 850 } else if ( 'publish' === $old_status ) { 851 // Some form of pending status 852 // Only remove the activity entry 853 if ( ! empty( $bp->activity->track[ 'new_' . $post->post_type ] ) ) { 854 bp_activity_custom_post_type_unpublish( $post->ID, $post ); 855 } else { 856 do_action( 'bp_activity_post_type_unpublish_' . $post->post_type, $post->id ); 857 } 858 } 859 } 860 add_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 ); -
src/bp-activity/bp-activity-functions.php
diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php index fcbbc07..a4a2ef4 100644
function bp_activity_register_activity_actions() { 1043 1043 1044 1044 // Backpat. Don't use this. 1045 1045 do_action( 'updates_register_activity_actions' ); 1046 1047 /** 1048 * Set activity actions for post types supporting activity tracking 1049 */ 1050 if ( ! empty( $bp->activity->track ) ) { 1051 foreach ( $bp->activity->track as $post_type ) { 1052 bp_activity_set_action( 1053 $post_type['component_id'], 1054 $post_type['action_id'], 1055 $post_type['admin_filter'], 1056 $post_type['callback'], 1057 $post_type['filter'], 1058 $post_type['contexts'] 1059 ); 1060 } 1061 } 1046 1062 } 1047 1063 add_action( 'bp_register_activity_actions', 'bp_activity_register_activity_actions' ); 1048 1064 … … function bp_activity_format_activity_action_activity_comment( $action, $activity 1130 1146 return apply_filters( 'bp_activity_comment_action', $action, $activity ); 1131 1147 } 1132 1148 1149 /** 1150 * Format custom post type activity post actions. 1151 * 1152 * @since BuddyPress (2.2.0) 1153 * 1154 * @param string $action Static activity action. 1155 * @param object $activity Activity data object. 1156 * @return string 1157 */ 1158 function bp_activity_format_activity_action_custom_post_type_post( $action, $activity ) { 1159 $bp = buddypress(); 1160 1161 if ( empty( $activity->type ) || empty( $bp->activity->track[ $activity->type ] ) ) { 1162 return $action; 1163 } 1164 1165 $user_link = bp_core_get_userlink( $activity->user_id ); 1166 $blog_url = get_home_url( $activity->item_id ); 1167 $post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) ); 1168 $post_link = '<a href="' . $post_url . '">' . $bp->activity->track[ $activity->type ]['singular'] . '</a>'; 1169 1170 $action = sprintf( _x( '%1$s wrote a new %2$s', 'Activity Custom Post Type post action', 'buddypress' ), $user_link, $post_link ); 1171 1172 if ( is_multisite() ) { 1173 $blog_link = '<a href="' . $blog_url . '">' . get_blog_option( $activity->item_id, 'blogname' ) . '</a>'; 1174 $action = sprintf( _x( '%1$s wrote a new %2$s, on the site %3$s', 'Activity Custom Post Type post action', 'buddypress' ), $user_link, $post_link, $blog_link ); 1175 } 1176 1177 /** 1178 * Filters the formatted custom post type activity post action string. 1179 * 1180 * @since BuddyPress (2.2.0) 1181 * 1182 * @param string $action Activity action string value. 1183 * @param BP_Activity_Activity $activity Activity item object. 1184 */ 1185 return apply_filters( 'bp_activity_custom_post_type_post_action', $action, $activity ); 1186 } 1187 1133 1188 /****************************************************************************** 1134 1189 * Business functions are where all the magic happens in BuddyPress. They will 1135 1190 * handle the actual saving or manipulation of information. Usually they will … … function bp_activity_post_update( $args = '' ) { 1513 1568 } 1514 1569 1515 1570 /** 1571 * Publish an activity for the custom post type. 1572 * 1573 * @since BuddyPress (2.2.0) 1574 * 1575 * @param int $post_id 1576 * @param WP_Post $post 1577 * @param int $user_id 1578 */ 1579 function bp_activity_custom_post_type_publish( $post_id = 0, $post = null, $user_id = 0 ) { 1580 $bp = buddypress(); 1581 1582 if ( ! is_a( $post, 'WP_Post' ) ) { 1583 return; 1584 } 1585 1586 if ( 'publish' != $post->post_status || ! empty( $post->post_password ) || empty( $bp->activity->track[ 'new_' . $post->post_type ] ) ) { 1587 return; 1588 } 1589 1590 if ( empty( $post_id ) ) { 1591 $post_id = $post->ID; 1592 } 1593 1594 $blog_id = get_current_blog_id(); 1595 1596 if ( empty( $user_id ) ) { 1597 $user_id = (int) $post->post_author; 1598 } 1599 1600 // Record this in activity streams 1601 $blog_url = get_home_url( $blog_id ); 1602 $post_url = add_query_arg( 1603 'p', 1604 $post_id, 1605 trailingslashit( $blog_url ) 1606 ); 1607 $activity_post_object = (object) $bp->activity->track[ 'new_' . $post->post_type ]; 1608 $post_link = '<a href="' . $post_url . '">' . $activity_post_object->singular . '</a>'; 1609 $user_link = bp_core_get_userlink( $user_id); 1610 1611 $action = sprintf( _x( '%1$s wrote a new %2$s', 'Activity Custom Post Type post action', 'buddypress' ), $user_link, $post_link ); 1612 1613 if ( is_multisite() ) { 1614 $blog_link = '<a href="' . $blog_url . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>'; 1615 $action = sprintf( _x( '%1$s wrote a new %2$s, on the site %3$s', 'Activity Custom Post Type post action', 'buddypress' ), $user_link, $post_link, $blog_link ); 1616 } 1617 1618 $existing = bp_activity_get( array( 1619 'filter' => array( 1620 'action' => $activity_post_object->action_id, 1621 'primary_id' => $blog_id, 1622 'secondary_id' => $post_id, 1623 ) 1624 ) ); 1625 1626 if ( ! empty( $existing['activities'] ) ) { 1627 return; 1628 } 1629 1630 $activity_args = array( 1631 'user_id' => $user_id, 1632 'content' => apply_filters( 'bp_activity_custom_post_type_publish_pre_content', $post->post_content, $post, $post_link ), 1633 'primary_link' => apply_filters( 'bp_activity_custom_post_type_publish_primary_link', $post_link, $post_id ), 1634 'component' => $activity_post_object->component_id, 1635 'type' => $activity_post_object->action_id, 1636 'item_id' => $blog_id, 1637 'secondary_item_id' => $post_id, 1638 'primary_link' => $post_url, 1639 'recorded_time' => $post->post_date_gmt, 1640 'hide_sitewide' => apply_filters( 'bp_activity_custom_post_type_publish_primary_link', false, $post ), 1641 ); 1642 1643 // Remove large images and replace them with just one image thumbnail 1644 if ( ! empty( $activity_args['content'] ) ) { 1645 $activity_args['content'] = bp_activity_thumbnail_content_images( $activity_args['content'], $activity_args['primary_link'], $activity_args ); 1646 } 1647 1648 if ( ! empty( $activity_args['content'] ) ) { 1649 $activity_args['content'] = apply_filters( 'bp_activity_custom_post_type_publish_content', bp_create_excerpt( $activity_args['content'] ), $activity_args['content'], $activity_args ); 1650 } 1651 1652 do_action( 'bp_activity_custom_post_type_published', bp_activity_add( $activity_args ), $activity_args, $post ); 1653 } 1654 1655 /** 1656 * Update an activity for the custom post type. 1657 * 1658 * @since BuddyPress (2.2.0) 1659 * 1660 * @param WP_Post $post 1661 */ 1662 function bp_activity_custom_post_type_update( $post = null ) { 1663 $bp = buddypress(); 1664 1665 if ( ! is_a( $post, 'WP_Post' ) ) { 1666 return; 1667 } 1668 1669 if ( empty( $bp->activity->track[ 'new_' . $post->post_type ] ) ) { 1670 return; 1671 } 1672 1673 $activity_post_object = (object) $bp->activity->track[ 'new_' . $post->post_type ]; 1674 1675 $activity_id = bp_activity_get_activity_id( array( 1676 'component' => $activity_post_object->component_id, 1677 'item_id' => get_current_blog_id(), 1678 'secondary_item_id' => $post->ID, 1679 'type' => $activity_post_object->action_id, 1680 ) ); 1681 1682 // activity ID doesn't exist, so stop! 1683 if ( empty( $activity_id ) ) { 1684 return; 1685 } 1686 1687 // update the activity entry 1688 $activity = new BP_Activity_Activity( $activity_id ); 1689 1690 if ( ! empty( $post->post_content ) ) { 1691 // Make sure to update the thumbnail image 1692 $post_content = bp_activity_thumbnail_content_images( $post->post_content, $activity->primary_link, (array) $activity ); 1693 1694 // Make sure to apply the excerpt 1695 $activity->content = apply_filters( 'bp_activity_custom_post_type_update_content', bp_create_excerpt( $post_content ), $post_content, (array) $activity ); 1696 } 1697 1698 // Save the updated activity 1699 $activity->save(); 1700 1701 do_action( 'bp_activity_custom_post_type_update_updated', $activity, $post ); 1702 } 1703 1704 /** 1705 * Unpublish an activity for the custom post type. 1706 * 1707 * @since BuddyPress (2.2.0) 1708 * 1709 * @param int $post_id 1710 * @param WP_Post $post 1711 */ 1712 function bp_activity_custom_post_type_unpublish( $post_id = 0, $post = null ) { 1713 $bp = buddypress(); 1714 1715 if ( ! is_a( $post, 'WP_Post' ) ) { 1716 return; 1717 } 1718 1719 if ( empty( $bp->activity->track[ 'new_' . $post->post_type ] ) ) { 1720 return; 1721 } 1722 1723 if ( empty( $post_id ) ) { 1724 $post_id = $post->ID; 1725 } 1726 1727 $activity_post_object = (object) $bp->activity->track[ 'new_' . $post->post_type ]; 1728 1729 $delete_activity_args = array( 1730 'item_id' => get_current_blog_id(), 1731 'secondary_item_id' => $post_id, 1732 'component' => $activity_post_object->component_id, 1733 'type' => $activity_post_object->action_id 1734 ); 1735 1736 do_action( 'bp_activity_custom_post_type_unpublished', bp_blogs_delete_activity( $delete_activity_args ), $delete_activity_args, $post ); 1737 } 1738 1739 /** 1516 1740 * Add an activity comment. 1517 1741 * 1518 1742 * @since BuddyPress (1.2.0) … … function bp_activity_delete_comment( $activity_id, $comment_id ) { 1988 2212 * @return string $link Permalink for the activity item. 1989 2213 */ 1990 2214 function bp_activity_get_permalink( $activity_id, $activity_obj = false ) { 2215 $bp = buddypress(); 1991 2216 1992 2217 if ( empty( $activity_obj ) ) { 1993 2218 $activity_obj = new BP_Activity_Activity( $activity_id ); … … function bp_activity_get_permalink( $activity_id, $activity_obj = false ) { 1997 2222 $activity_obj = $activity_obj->current_comment; 1998 2223 } 1999 2224 2000 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 ) { 2225 $use_primary_links = array( 2226 'new_blog_post', 2227 'new_blog_comment', 2228 'new_forum_topic', 2229 'new_forum_post', 2230 ); 2231 2232 if ( ! empty( $bp->activity->track ) ) { 2233 $use_primary_links = array_merge( $use_primary_links, array_keys( $bp->activity->track ) ); 2234 } 2235 2236 if ( false !== array_search( $activity_obj->type, $use_primary_links ) ) { 2001 2237 $link = $activity_obj->primary_link; 2002 2238 } else { 2003 2239 if ( 'activity_comment' == $activity_obj->type ) { -
src/bp-activity/bp-activity-template.php
diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php index 0318b4e..1ac682b 100644
function bp_activity_filter_links( $args = false ) { 3308 3308 */ 3309 3309 function bp_activity_can_comment() { 3310 3310 global $activities_template; 3311 $bp = buddypress(); 3311 3312 3312 3313 // Assume activity can be commented on 3313 3314 $can_comment = true; 3314 3315 3315 3316 // Determine ability to comment based on activity action name 3316 3317 $activity_action = bp_get_activity_action_name(); 3317 switch ( $activity_action ) {3318 3319 // Maybe turn off for blog and forum updates3320 case 'new_blog_post' :3321 case 'new_blog_comment' :3322 case 'new_forum_topic' :3323 case 'new_forum_post' :3324 if ( ! empty( $activities_template->disable_blogforum_replies ) ) {3325 $can_comment = false;3326 }3327 break;3328 3318 3329 // Turn off for activity comments 3330 case 'activity_comment' : 3331 $can_comment = false; 3332 break; 3319 $turn_off = 0; 3320 if ( ! empty( $activities_template->disable_blogforum_replies ) ) { 3321 $turn_off = 1; 3333 3322 } 3334 3323 3324 $maybe_turn_off = array_fill_keys( array( 3325 'new_blog_post', 3326 'new_blog_comment', 3327 'new_forum_topic', 3328 'new_forum_post', 3329 ), $turn_off ); 3330 3331 $maybe_turn_off['activity_comment'] = 1; 3332 3333 if ( ! empty( $bp->activity->track ) ) { 3334 foreach ( array_keys( $bp->activity->track ) as $action ) { 3335 if ( empty( $bp->activity->track[ $action ]['activity_commment'] ) ) { 3336 $maybe_turn_off[ $action ] = $turn_off; 3337 } 3338 } 3339 } 3340 3341 $can_comment = empty( $maybe_turn_off[ $activity_action ] ); 3342 3335 3343 /** 3336 3344 * Filters whether a comment can be made on an activity item. 3337 3345 * -
src/bp-blogs/bp-blogs-functions.php
diff --git src/bp-blogs/bp-blogs-functions.php src/bp-blogs/bp-blogs-functions.php index 41f62f6..4e7f663 100644
function bp_blogs_update_option_thread_comments_depth( $oldvalue, $newvalue ) { 402 402 add_action( 'update_option_thread_comments_depth', 'bp_blogs_update_option_thread_comments_depth', 10, 2 ); 403 403 404 404 /** 405 * Detect a change in post status, and initiate an activity update if necessary.406 *407 * Posts get new activity updates when (a) they are being published, and (b)408 * they have not already been published. This enables proper posting for409 * regular posts as well as scheduled posts, while preventing post bumping.410 *411 * See #4090, #3746, #2546 for background.412 *413 * @since BuddyPress (2.0.0)414 *415 * @todo Support untrashing better416 *417 * @param string $new_status New status for the post.418 * @param string $old_status Old status for the post.419 * @param object $post Post data.420 */421 function bp_blogs_catch_transition_post_status( $new_status, $old_status, $post ) {422 423 // This is an edit424 if ( $new_status === $old_status ) {425 if ( $new_status == 'publish' ) {426 bp_blogs_update_post( $post );427 return;428 }429 }430 431 // Publishing a previously unpublished post432 if ( 'publish' === $new_status ) {433 // Untrashing the post434 // Nothing here yet435 if ( 'trash' == $old_status ) {}436 437 // Record the post438 bp_blogs_record_post( $post->ID, $post );439 440 // Unpublishing a previously published post441 } else if ( 'publish' === $old_status ) {442 // Some form of pending status443 // Only remove the activity entry444 bp_blogs_delete_activity( array(445 'item_id' => get_current_blog_id(),446 'secondary_item_id' => $post->ID,447 'component' => buddypress()->blogs->id,448 'type' => 'new_blog_post'449 ) );450 }451 }452 add_action( 'transition_post_status', 'bp_blogs_catch_transition_post_status', 10, 3 );453 454 /**455 405 * Record a new blog post in the BuddyPress activity stream. 456 406 * 457 407 * @param int $post_id ID of the post being recorded. … … function bp_blogs_record_post( $post_id, $post, $user_id = 0 ) { 548 498 549 499 do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id ); 550 500 } 501 add_action( 'bp_activity_post_type_publish_post', 'bp_blogs_record_post', 10, 2 ); 551 502 552 503 /** 553 504 * Updates a blog post's corresponding activity entry during a post edit. … … function bp_blogs_update_post( $post ) { 655 606 bp_activity_delete_meta( $activity_id, 'post_comment_status' ); 656 607 } 657 608 } 609 add_action( 'bp_activity_post_type_update_post', 'bp_blogs_update_post', 10, 1 ); 610 611 /** 612 * Delete a blog post activity 613 * 614 * Used if the post has been unpublished (draft, private, trash) 615 * 616 * @since BuddyPress (2.2.0) 617 * 618 * @param int $blog_id 619 * @param int $post_id 620 * @uses bp_blogs_delete_activity() to delete the new blog post activity 621 */ 622 function bp_blogs_unpublish_post( $post_id = 0 ) { 623 bp_blogs_delete_activity( array( 624 'item_id' => get_current_blog_id(), 625 'secondary_item_id' => $post_id, 626 'component' => buddypress()->blogs->id, 627 'type' => 'new_blog_post' 628 ) ); 629 } 630 add_action( 'bp_activity_post_type_unpublish_post', 'bp_blogs_unpublish_post', 10, 2 ); 658 631 659 632 /** 660 633 * Record a new blog comment in the BuddyPress activity stream. -
src/bp-core/deprecated/2.2.php
diff --git src/bp-core/deprecated/2.2.php src/bp-core/deprecated/2.2.php index e69de29..d4473b7 100644
1 <?php 2 /** 3 * Deprecated functions 4 * 5 * @package BuddyPress 6 * @subpackage Core 7 * @deprecated 2.2.0 8 */ 9 10 // Exit if accessed directly 11 if ( ! defined( 'ABSPATH' ) ) exit; 12 13 /** 14 * Detect a change in post status, and initiate an activity update if necessary. 15 * 16 * Posts get new activity updates when (a) they are being published, and (b) 17 * they have not already been published. This enables proper posting for 18 * regular posts as well as scheduled posts, while preventing post bumping. 19 * 20 * See #4090, #3746, #2546 for background. 21 * 22 * @since BuddyPress (2.0.0) 23 * @deprecated BuddyPress (2.2.0) 24 * 25 * @todo Support untrashing better 26 * 27 * @param string $new_status New status for the post. 28 * @param string $old_status Old status for the post. 29 * @param object $post Post data. 30 */ 31 function bp_blogs_catch_transition_post_status( $new_status, $old_status, $post ) { 32 _deprecated_function( __FUNCTION__, '2.2', 'bp_activity_catch_transition_post_type_status()' ); 33 bp_activity_catch_transition_post_type_status( $new_status, $old_status, $post ); 34 }