Ticket #5669: 5669.03.patch
File 5669.03.patch, 51.7 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..e355e48 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 // Register the post type in tracking global 38 $bp->activity->track[ 'new_' . $key ] = apply_filters( 'bp_activity_tracking_register_' . $key . '_post_type', array( 39 'component_id' => $bp->activity->id, 40 'action_id' => 'new_' . $key, 41 'admin_filter' => sprintf( _x( 'New %s published', 'Custom Post Type generic activity post admin filter label', 'buddypress' ), strtolower( $object->labels->singular_name ) ), 42 'callback' => 'bp_activity_format_activity_action_custom_post_type_post', 43 'filter' => $object->labels->name, 44 'contexts' => array( 'activity' ), 45 'singular' => strtolower( $object->labels->singular_name ), 46 'plural' => strtolower( $object->labels->name ), 47 'activity_commment' => ! post_type_supports( $key, 'comments' ), 48 ), $object ); 49 50 // Set activity action for the post type 51 call_user_func_array( 'bp_activity_set_action', array_diff_key( 52 $bp->activity->track[ 'new_' . $key ], 53 array_flip( array( 'singular', 'plural', 'activity_commment' ) ) 54 ) ); 55 } 56 } 57 add_action( 'bp_fully_loaded', 'bp_activity_tracking_register_post_types' ); 58 59 /** 16 60 * Allow core components and dependent plugins to register activity actions. 17 61 * 18 62 * @since BuddyPress (1.2.0) … … function bp_ajax_get_suggestions() { 766 810 wp_send_json_success( $results ); 767 811 } 768 812 add_action( 'wp_ajax_bp_get_suggestions', 'bp_ajax_get_suggestions' ); 813 814 /** 815 * Detect a change in post type status, and initiate an activity update if necessary. 816 * 817 * @since BuddyPress (2.2.0) 818 * 819 * @todo Support untrashing better 820 * 821 * @param string $new_status New status for the post. 822 * @param string $old_status Old status for the post. 823 * @param object $post Post data. 824 */ 825 function bp_activity_catch_transition_post_type_status( $new_status, $old_status, $post ) { 826 $bp = buddypress(); 827 828 // This is an edit 829 if ( $new_status === $old_status ) { 830 if ( $new_status == 'publish' ) { 831 // Update the post type 832 if ( ! empty( $bp->activity->track[ 'new_' . $post->post_type ] ) ) { 833 bp_activity_post_type_update( $post ); 834 } 835 return; 836 } 837 } 838 839 // Publishing a previously unpublished post 840 if ( 'publish' === $new_status ) { 841 // Untrashing the post type 842 // Nothing here yet 843 if ( 'trash' == $old_status ) { 844 do_action( 'bp_activity_post_type_untrash_' . $post->post_type, $post ); 845 } else { 846 // Record the post type 847 if ( ! empty( $bp->activity->track[ 'new_' . $post->post_type ] ) && empty( $post->post_password ) ) { 848 bp_activity_post_type_publish( $post->ID, $post ); 849 } 850 } 851 852 // Unpublishing a previously published post 853 } else if ( 'publish' === $old_status ) { 854 // Some form of pending status 855 // Only remove the activity entry 856 if ( ! empty( $bp->activity->track[ 'new_' . $post->post_type ] ) ) { 857 bp_activity_post_type_unpublish( $post->ID, $post ); 858 } 859 } 860 } 861 add_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 ); -
src/bp-activity/bp-activity-admin.php
diff --git src/bp-activity/bp-activity-admin.php src/bp-activity/bp-activity-admin.php index 5eb6c48..2883efa 100644
class BP_Activity_List_Table extends WP_List_Table { 1371 1371 <select name="activity_type"> 1372 1372 <option value="" <?php selected( ! $selected ); ?>><?php _e( 'View all actions', 'buddypress' ); ?></option> 1373 1373 1374 <?php foreach ( $activity_actions as $component => $actions ) : ?> 1374 <?php foreach ( $activity_actions as $component => $actions ) : 1375 // Sort actions by their position attribute 1376 $actions = bp_activity_sort_component_actions( $actions ); 1377 ?> 1375 1378 1376 1379 <optgroup label="<?php echo ucfirst( $component ); ?>"> 1377 1380 -
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..e83a675 100644
function bp_activity_get_userid_from_mentionname( $mentionname ) { 326 326 * 'activity', 'member', 'member_groups', 'group' 327 327 * @return bool False if any param is empty, otherwise true. 328 328 */ 329 function bp_activity_set_action( $component_id, $type, $description, $format_callback = false, $label = false, $context = array() ) {329 function bp_activity_set_action( $component_id, $type, $description, $format_callback = false, $label = false, $context = array(), $position = 0 ) { 330 330 $bp = buddypress(); 331 331 332 332 // Return false if any of the above values are not set … … function bp_activity_set_action( $component_id, $type, $description, $format_cal 368 368 'format_callback' => $format_callback, 369 369 'label' => $label, 370 370 'context' => $context, 371 'position' => $position, 371 372 ), $component_id, $type, $description, $format_callback, $label, $context ); 372 373 373 374 return true; … … function bp_activity_get_types() { 440 441 return apply_filters( 'bp_activity_get_types', $actions ); 441 442 } 442 443 444 /** 445 * Sort actions of a component by their position attribute 446 * 447 * @since BuddyPress (2.2.0) 448 * 449 * @param object $actions component's activity actions 450 * @return object actions ordered by their position 451 */ 452 function bp_activity_sort_component_actions( $actions = null ) { 453 if ( empty( $actions ) ) { 454 return false; 455 } 456 457 $temp = array(); 458 459 foreach ( $actions as $key => $params ) { 460 if ( empty( $temp[$params['position']]) ) { 461 $temp[$params['position']] = $params; 462 } else { 463 // increase numbers here to fit new items in. 464 do { 465 $params['position']++; 466 } while ( !empty( $temp[$params['position']] ) ); 467 468 $temp[$params['position']] = $params; 469 } 470 471 unset( $actions->{$key} ); 472 } 473 474 ksort( $temp ); 475 476 // Restore keys 477 foreach ( $temp as $key_ordered ) { 478 $actions->{$key_ordered['key']} = $key_ordered; 479 } 480 481 return $actions; 482 } 483 443 484 /** Favorites ****************************************************************/ 444 485 445 486 /** … … function bp_activity_format_activity_action_activity_comment( $action, $activity 1130 1171 return apply_filters( 'bp_activity_comment_action', $action, $activity ); 1131 1172 } 1132 1173 1174 /** 1175 * Format custom post type activity post actions. 1176 * 1177 * @since BuddyPress (2.2.0) 1178 * 1179 * @param string $action Static activity action. 1180 * @param object $activity Activity data object. 1181 * @return string 1182 */ 1183 function bp_activity_format_activity_action_custom_post_type_post( $action, $activity ) { 1184 $bp = buddypress(); 1185 1186 if ( empty( $activity->type ) || empty( $bp->activity->track[ $activity->type ] ) ) { 1187 return $action; 1188 } 1189 1190 $user_link = bp_core_get_userlink( $activity->user_id ); 1191 $blog_url = get_home_url( $activity->item_id ); 1192 1193 if ( empty( $activity->post_url ) ) { 1194 $post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) ); 1195 } else { 1196 $post_url = $activity->post_url; 1197 } 1198 1199 $post_link = '<a href="' . $post_url . '">' . $bp->activity->track[ $activity->type ]['singular'] . '</a>'; 1200 1201 $action = sprintf( _x( '%1$s wrote a new %2$s', 'Activity Custom Post Type post action', 'buddypress' ), $user_link, $post_link ); 1202 1203 if ( is_multisite() ) { 1204 $blog_link = '<a href="' . $blog_url . '">' . get_blog_option( $activity->item_id, 'blogname' ) . '</a>'; 1205 $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 ); 1206 } 1207 1208 /** 1209 * Filters the formatted custom post type activity post action string. 1210 * 1211 * @since BuddyPress (2.2.0) 1212 * 1213 * @param string $action Activity action string value. 1214 * @param BP_Activity_Activity $activity Activity item object. 1215 */ 1216 return apply_filters( 'bp_activity_custom_post_type_post_action', $action, $activity ); 1217 } 1218 1133 1219 /****************************************************************************** 1134 1220 * Business functions are where all the magic happens in BuddyPress. They will 1135 1221 * handle the actual saving or manipulation of information. Usually they will … … function bp_activity_post_update( $args = '' ) { 1513 1599 } 1514 1600 1515 1601 /** 1602 * Publish an activity for the custom post type. 1603 * 1604 * @since BuddyPress (2.2.0) 1605 * 1606 * @param int $post_id 1607 * @param WP_Post $post 1608 * @param int $user_id 1609 */ 1610 function bp_activity_post_type_publish( $post_id = 0, $post = null, $user_id = 0 ) { 1611 $bp = buddypress(); 1612 1613 if ( ! is_a( $post, 'WP_Post' ) ) { 1614 return; 1615 } 1616 1617 if ( 'publish' != $post->post_status || ! empty( $post->post_password ) || empty( $bp->activity->track[ 'new_' . $post->post_type ] ) ) { 1618 return; 1619 } 1620 1621 if ( empty( $post_id ) ) { 1622 $post_id = $post->ID; 1623 } 1624 1625 $blog_id = get_current_blog_id(); 1626 1627 if ( empty( $user_id ) ) { 1628 $user_id = (int) $post->post_author; 1629 } 1630 1631 $activity_post_object = (object) $bp->activity->track[ 'new_' . $post->post_type ]; 1632 1633 $existing = bp_activity_get( array( 1634 'filter' => array( 1635 'action' => $activity_post_object->action_id, 1636 'primary_id' => $blog_id, 1637 'secondary_id' => $post_id, 1638 ) 1639 ) ); 1640 1641 // Leave Components/plugins bail before the activity is posted 1642 if ( ! empty( $existing['activities'] ) || false === apply_filters( "bp_activity_{$post->post_type}_pre_publish", true, $blog_id, $post_id, $user_id ) ) { 1643 return; 1644 } 1645 1646 // Record this in activity streams 1647 $blog_url = get_home_url( $blog_id ); 1648 $post_url = add_query_arg( 1649 'p', 1650 $post_id, 1651 trailingslashit( $blog_url ) 1652 ); 1653 1654 /** 1655 * As the 'post' post type will no more use bp_blogs_record_post(), we need to be sure the filters 1656 * - 'bp_blogs_activity_new_post_content' can be applied on the content. 1657 * - 'bp_blogs_activity_new_post_primary_link' can be applied on the primary_link. 1658 */ 1659 $activity_args = array( 1660 'user_id' => $user_id, 1661 'content' => apply_filters( "bp_{$activity_post_object->component_id}_activity_new_post_content", $post->post_content, $post, $post_url, $post->post_type ), 1662 'primary_link' => apply_filters( "bp_{$activity_post_object->component_id}_activity_new_post_primary_link", $post_url, $post_id, $post->post_type ), 1663 'component' => $activity_post_object->component_id, 1664 'type' => $activity_post_object->action_id, 1665 'item_id' => $blog_id, 1666 'secondary_item_id' => $post_id, 1667 'recorded_time' => $post->post_date_gmt, 1668 'hide_sitewide' => apply_filters( 'bp_activity_post_type_publish_primary_link', false, $post ), 1669 ); 1670 1671 // Remove large images and replace them with just one image thumbnail 1672 if ( ! empty( $activity_args['content'] ) ) { 1673 $activity_args['content'] = bp_activity_thumbnail_content_images( $activity_args['content'], $activity_args['primary_link'], $activity_args ); 1674 } 1675 1676 if ( ! empty( $activity_args['content'] ) ) { 1677 /** 1678 * As the 'post' post type will not use bp_blogs_record_activity(), we need to be sure the filter 1679 * 'bp_blogs_record_activity_content' can be applied on the action. 1680 */ 1681 $activity_args['content'] = apply_filters( "bp_{$activity_post_object->component_id}_record_activity_content", bp_create_excerpt( $activity_args['content'] ), $activity_args['content'], $activity_args, $post->post_type ); 1682 } 1683 1684 // Setup the action by using the format functions 1685 $action_args = array_merge( $activity_args, array( 1686 'post_title' => $post->post_title, 1687 'post_url' => $post_url, 1688 ) ); 1689 1690 $activity_args['action'] = call_user_func_array( $activity_post_object->callback, array( '', (object) $action_args ) ); 1691 1692 // Make sure the action is set 1693 if ( empty( $activity_args['action'] ) ) { 1694 return; 1695 } else { 1696 /** 1697 * As the 'post' post type will not use bp_blogs_record_activity(), we need to be sure the filter 1698 * 'bp_blogs_record_activity_action' can be applied on the action. 1699 */ 1700 $activity_args['action'] = apply_filters( "bp_{$activity_post_object->component_id}_record_activity_action", $activity_args['action'] ); 1701 } 1702 1703 do_action( 'bp_activity_post_type_published', bp_activity_add( $activity_args ), $post, $action_args ); 1704 } 1705 1706 /** 1707 * Update an activity for the custom post type. 1708 * 1709 * @since BuddyPress (2.2.0) 1710 * 1711 * @param WP_Post $post 1712 */ 1713 function bp_activity_post_type_update( $post = null ) { 1714 $bp = buddypress(); 1715 1716 if ( ! is_a( $post, 'WP_Post' ) ) { 1717 return; 1718 } 1719 1720 if ( empty( $bp->activity->track[ 'new_' . $post->post_type ] ) ) { 1721 return; 1722 } 1723 1724 $activity_post_object = (object) $bp->activity->track[ 'new_' . $post->post_type ]; 1725 1726 $activity_id = bp_activity_get_activity_id( array( 1727 'component' => $activity_post_object->component_id, 1728 'item_id' => get_current_blog_id(), 1729 'secondary_item_id' => $post->ID, 1730 'type' => $activity_post_object->action_id, 1731 ) ); 1732 1733 // activity ID doesn't exist, so stop! 1734 if ( empty( $activity_id ) ) { 1735 return; 1736 } 1737 1738 // Delete the activity if the post was updated with a password 1739 if ( ! empty( $post->post_password ) ) { 1740 bp_activity_delete( array( 'id' => $activity_id ) ); 1741 } 1742 1743 // update the activity entry 1744 $activity = new BP_Activity_Activity( $activity_id ); 1745 1746 if ( ! empty( $post->post_content ) ) { 1747 // Make sure to update the thumbnail image 1748 $post_content = bp_activity_thumbnail_content_images( $post->post_content, $activity->primary_link, (array) $activity ); 1749 1750 /** 1751 * Make sure to apply the excerpt 1752 * 1753 * As the 'post' post type will no more use bp_blogs_update_post(), we need to be sure the filter 1754 * 'bp_blogs_record_activity_content' can be applied on the action. 1755 */ 1756 $activity->content = apply_filters( "bp_{$activity_post_object->component_id}_record_activity_content", bp_create_excerpt( $post_content ), $post_content, (array) $activity, $post->post_type ); 1757 } 1758 1759 // Save the updated activity 1760 $activity->save(); 1761 1762 do_action( 'bp_activity_post_type_updated', $post, $activity ); 1763 } 1764 1765 /** 1766 * Unpublish an activity for the custom post type. 1767 * 1768 * @since BuddyPress (2.2.0) 1769 * 1770 * @param int $post_id 1771 * @param WP_Post $post 1772 */ 1773 function bp_activity_post_type_unpublish( $post_id = 0, $post = null ) { 1774 $bp = buddypress(); 1775 1776 if ( ! is_a( $post, 'WP_Post' ) ) { 1777 return; 1778 } 1779 1780 if ( empty( $bp->activity->track[ 'new_' . $post->post_type ] ) ) { 1781 return; 1782 } 1783 1784 if ( empty( $post_id ) ) { 1785 $post_id = $post->ID; 1786 } 1787 1788 $activity_post_object = (object) $bp->activity->track[ 'new_' . $post->post_type ]; 1789 1790 $delete_activity_args = array( 1791 'item_id' => get_current_blog_id(), 1792 'secondary_item_id' => $post_id, 1793 'component' => $activity_post_object->component_id, 1794 'type' => $activity_post_object->action_id, 1795 'user_id' => false, 1796 ); 1797 1798 do_action( 'bp_activity_post_type_unpublished', bp_activity_delete_by_item_id( $delete_activity_args ), $delete_activity_args, $post ); 1799 } 1800 1801 /** 1516 1802 * Add an activity comment. 1517 1803 * 1518 1804 * @since BuddyPress (1.2.0) … … function bp_activity_delete_comment( $activity_id, $comment_id ) { 1988 2274 * @return string $link Permalink for the activity item. 1989 2275 */ 1990 2276 function bp_activity_get_permalink( $activity_id, $activity_obj = false ) { 2277 $bp = buddypress(); 1991 2278 1992 2279 if ( empty( $activity_obj ) ) { 1993 2280 $activity_obj = new BP_Activity_Activity( $activity_id ); … … function bp_activity_get_permalink( $activity_id, $activity_obj = false ) { 1997 2284 $activity_obj = $activity_obj->current_comment; 1998 2285 } 1999 2286 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 ) { 2287 $use_primary_links = array( 2288 'new_blog_post', 2289 'new_blog_comment', 2290 'new_forum_topic', 2291 'new_forum_post', 2292 ); 2293 2294 if ( ! empty( $bp->activity->track ) ) { 2295 $use_primary_links = array_merge( $use_primary_links, array_keys( $bp->activity->track ) ); 2296 } 2297 2298 if ( false !== array_search( $activity_obj->type, $use_primary_links ) ) { 2001 2299 $link = $activity_obj->primary_link; 2002 2300 } else { 2003 2301 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 d51c2f3..2892656 100644
function bp_activity_filter_links( $args = false ) { 3315 3315 */ 3316 3316 function bp_activity_can_comment() { 3317 3317 global $activities_template; 3318 $bp = buddypress(); 3318 3319 3319 3320 // Assume activity can be commented on 3320 3321 $can_comment = true; 3321 3322 3322 3323 // Determine ability to comment based on activity action name 3323 3324 $activity_action = bp_get_activity_action_name(); 3324 switch ( $activity_action ) {3325 3326 // Maybe turn off for blog and forum updates3327 case 'new_blog_post' :3328 case 'new_blog_comment' :3329 case 'new_forum_topic' :3330 case 'new_forum_post' :3331 if ( ! empty( $activities_template->disable_blogforum_replies ) ) {3332 $can_comment = false;3333 }3334 break;3335 3325 3336 // Turn off for activity comments 3337 case 'activity_comment' : 3338 $can_comment = false; 3339 break; 3326 $turn_off = 0; 3327 if ( ! empty( $activities_template->disable_blogforum_replies ) ) { 3328 $turn_off = 1; 3329 } 3330 3331 $maybe_turn_off = array_fill_keys( array( 3332 'new_blog_post', 3333 'new_blog_comment', 3334 'new_forum_topic', 3335 'new_forum_post', 3336 ), $turn_off ); 3337 3338 $maybe_turn_off['activity_comment'] = 1; 3339 3340 if ( ! empty( $bp->activity->track ) ) { 3341 foreach ( array_keys( $bp->activity->track ) as $action ) { 3342 if ( empty( $bp->activity->track[ $action ]['activity_commment'] ) ) { 3343 $maybe_turn_off[ $action ] = $turn_off; 3344 } 3345 } 3340 3346 } 3341 3347 3348 $can_comment = empty( $maybe_turn_off[ $activity_action ] ); 3349 3342 3350 /** 3343 3351 * Filters whether a comment can be made on an activity item. 3344 3352 * … … function bp_activity_show_filters( $context = '' ) { 4368 4376 // Walk through the registered actions, and prepare an the 4369 4377 // select box options. 4370 4378 foreach ( buddypress()->activity->actions as $actions ) { 4379 // Sort actions by their position attribute 4380 $actions = bp_activity_sort_component_actions($actions ); 4381 4371 4382 foreach ( $actions as $action ) { 4372 4383 if ( ! in_array( $context, (array) $action['context'] ) ) { 4373 4384 continue; -
src/bp-blogs/bp-blogs-activity.php
diff --git src/bp-blogs/bp-blogs-activity.php src/bp-blogs/bp-blogs-activity.php index 8b67a16..0a43935 100644
function bp_blogs_register_activity_actions() { 33 33 'new_blog', 34 34 __( 'New site created', 'buddypress' ), 35 35 'bp_blogs_format_activity_action_new_blog', 36 __( 'New Sites', 'buddypress' ) 36 __( 'New Sites', 'buddypress' ), 37 0 37 38 ); 38 39 } 39 40 40 bp_activity_set_action( 41 $bp->blogs->id, 42 'new_blog_post', 43 __( 'New post published', 'buddypress' ), 44 'bp_blogs_format_activity_action_new_blog_post', 45 __( 'Posts', 'buddypress' ), 46 array( 'activity', 'member' ) 47 ); 48 49 bp_activity_set_action( 50 $bp->blogs->id, 51 'new_blog_comment', 52 __( 'New post comment posted', 'buddypress' ), 53 'bp_blogs_format_activity_action_new_blog_comment', 54 __( 'Comments', 'buddypress' ), 55 array( 'activity', 'member' ) 56 ); 41 // Only add the comment type if the 'post' post type is trackable 42 if ( post_type_supports( 'post', 'buddypress-activity' ) ) { 43 bp_activity_set_action( 44 $bp->blogs->id, 45 'new_blog_comment', 46 __( 'New post comment posted', 'buddypress' ), 47 'bp_blogs_format_activity_action_new_blog_comment', 48 __( 'Comments', 'buddypress' ), 49 array( 'activity', 'member' ), 50 10 51 ); 52 } 57 53 58 54 do_action( 'bp_blogs_register_activity_actions' ); 59 55 } … … function bp_blogs_format_activity_action_new_blog_post( $action, $activity ) { 108 104 bp_blogs_update_blogmeta( $activity->item_id, 'name', $blog_name ); 109 105 } 110 106 111 $post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) ); 107 if ( empty( $activity->post_url ) ) { 108 $post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) ); 109 } else { 110 $post_url = $activity->post_url; 111 } 112 112 113 $post_title = bp_activity_get_meta( $activity->id, 'post_title' ); 113 if ( empty( $activity->post_title ) ) { 114 $post_title = bp_activity_get_meta( $activity->id, 'post_title' ); 115 } else { 116 $post_title = $activity->post_title; 117 } 114 118 115 119 // Should only be empty at the time of post creation 116 120 if ( empty( $post_title ) ) { -
src/bp-blogs/bp-blogs-filters.php
diff --git src/bp-blogs/bp-blogs-filters.php src/bp-blogs/bp-blogs-filters.php index 9cf0c92..b0e09dd 100644
add_filter( 'wp_signup_location', 'bp_blogs_creation_location' ); 42 42 * 43 43 * @since BuddyPress (2.1.0) 44 44 * 45 * @see bp_blogs_update_post ()45 * @see bp_blogs_update_post_activity_meta() 46 46 * 47 47 * @param array Current SQL clauses in array format 48 48 * @return array 49 49 */ 50 50 function bp_blogs_comments_clauses_select_by_id( $retval ) { 51 51 $retval['fields'] = 'comment_ID'; 52 52 53 53 return $retval; 54 } 55 No newline at end of file 54 } 55 56 /** 57 * Check if the post can be published 58 * 59 * In deprecated bp_blogs_record_post(), this part was checking whether a post 60 * should be published or not. 61 * 62 * @since BuddyPress (2.2.0) 63 * 64 * @param bool $return by default true 65 * @param int $blog_id 66 * @param int $post_id 67 * @param int $user_id 68 * @return bool true to authorize the post to be published, false otherwise 69 */ 70 function bp_blogs_post_pre_publish( $return = true, $blog_id = 0, $post_id = 0, $user_id = 0 ) { 71 $bp = buddypress(); 72 73 // If blog is not trackable, do not record the activity. 74 if ( ! bp_blogs_is_blog_trackable( $blog_id, $user_id ) ) { 75 return false; 76 } 77 78 // Stop infinite loops with WordPress MU Sitewide Tags. 79 // That plugin changed the way its settings were stored at some point. Thus the dual check. 80 if ( ! empty( $bp->site_options['sitewide_tags_blog'] ) ) { 81 $st_options = maybe_unserialize( $bp->site_options['sitewide_tags_blog'] ); 82 $tags_blog_id = isset( $st_options['tags_blog_id'] ) ? $st_options['tags_blog_id'] : 0; 83 } else { 84 $tags_blog_id = isset( $bp->site_options['tags_blog_id'] ) ? $bp->site_options['tags_blog_id'] : 0; 85 } 86 87 if ( (int) $blog_id == $tags_blog_id && apply_filters( 'bp_blogs_block_sitewide_tags_activity', true ) ) { 88 return false; 89 } 90 91 $is_blog_public = apply_filters( 'bp_is_blog_public', (int) get_blog_option( $blog_id, 'blog_public' ) ); 92 93 if ( 0 === $is_blog_public && is_multisite() ) { 94 return false; 95 } 96 97 return $return; 98 } 99 add_filter( 'bp_activity_post_pre_publish', 'bp_blogs_post_pre_publish', 10, 4 ); -
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..83f719c 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.405 * Record additional metas when a post is published. 406 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 for 409 * regular posts as well as scheduled posts, while preventing post bumping. 407 * @since BuddyPress (2.2.0) 410 408 * 411 * See #4090, #3746, #2546 for background. 412 * 413 * @since BuddyPress (2.0.0) 414 * 415 * @todo Support untrashing better 416 * 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. 409 * @param int $activity_id 410 * @param WP_Post $post 420 411 */ 421 function bp_blogs_catch_transition_post_status( $new_status, $old_status, $post ) { 422 423 // This is an edit 424 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 post 432 if ( 'publish' === $new_status ) { 433 // Untrashing the post 434 // Nothing here yet 435 if ( 'trash' == $old_status ) {} 436 437 // Record the post 438 bp_blogs_record_post( $post->ID, $post ); 439 440 // Unpublishing a previously published post 441 } else if ( 'publish' === $old_status ) { 442 // Some form of pending status 443 // Only remove the activity entry 444 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 ) ); 412 function bp_blogs_publish_post_activity_meta( $activity_id, $post, $args ) { 413 if ( empty( $activity_id ) || 'post' != $post->post_type ) { 414 return; 450 415 } 451 }452 add_action( 'transition_post_status', 'bp_blogs_catch_transition_post_status', 10, 3 );453 454 /**455 * Record a new blog post in the BuddyPress activity stream.456 *457 * @param int $post_id ID of the post being recorded.458 * @param object $post The WP post object passed to the 'save_post' action.459 * @param int $user_id Optional. The user to whom the activity item will be460 * associated. Defaults to the post_author.461 * @return bool|null Returns false on failure.462 */463 function bp_blogs_record_post( $post_id, $post, $user_id = 0 ) {464 global $bp, $wpdb;465 466 $post_id = (int) $post_id;467 $blog_id = (int) $wpdb->blogid;468 469 // If blog is not trackable, do not record the activity.470 if ( ! bp_blogs_is_blog_trackable( $blog_id, $user_id ) )471 return false;472 416 473 if ( !$user_id ) 474 $user_id = (int) $post->post_author; 417 bp_activity_update_meta( $activity_id, 'post_title', $post->post_title ); 475 418 476 // Stop infinite loops with WordPress MU Sitewide Tags. 477 // That plugin changed the way its settings were stored at some point. Thus the dual check. 478 if ( !empty( $bp->site_options['sitewide_tags_blog'] ) ) { 479 $st_options = maybe_unserialize( $bp->site_options['sitewide_tags_blog'] ); 480 $tags_blog_id = isset( $st_options['tags_blog_id'] ) ? $st_options['tags_blog_id'] : 0; 419 if ( ! empty( $args['post_url'] ) ) { 420 $post_permalink = $args['post_url']; 481 421 } else { 482 $ tags_blog_id = isset( $bp->site_options['tags_blog_id'] ) ? $bp->site_options['tags_blog_id'] : 0;422 $post_permalink = $post->guid; 483 423 } 484 424 485 if ( (int) $blog_id == $tags_blog_id && apply_filters( 'bp_blogs_block_sitewide_tags_activity', true ) ) 486 return false; 487 488 // Don't record this if it's not a post 489 if ( !in_array( $post->post_type, apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) ) ) ) 490 return false; 491 492 $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) ); 493 494 if ( 'publish' == $post->post_status && empty( $post->post_password ) ) { 495 if ( $is_blog_public || !is_multisite() ) { 425 bp_activity_update_meta( $activity_id, 'post_url', $post_permalink ); 496 426 497 // Record this in activity streams 498 $post_permalink = add_query_arg( 499 'p', 500 $post_id, 501 trailingslashit( get_home_url( $blog_id ) ) 502 ); 503 504 if ( is_multisite() ) 505 $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>' ); 506 else 507 $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>' ); 508 509 // Make sure there's not an existing entry for this post (prevent bumping) 510 if ( bp_is_active( 'activity' ) ) { 511 $existing = bp_activity_get( array( 512 'filter' => array( 513 'action' => 'new_blog_post', 514 'primary_id' => $blog_id, 515 'secondary_id' => $post_id, 516 ) 517 ) ); 518 519 if ( !empty( $existing['activities'] ) ) { 520 return; 521 } 522 } 523 524 $activity_content = $post->post_content; 525 526 $activity_id = bp_blogs_record_activity( array( 527 'user_id' => (int) $post->post_author, 528 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, $post, $post_permalink ), 529 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ), 530 'type' => 'new_blog_post', 531 'item_id' => $blog_id, 532 'secondary_item_id' => $post_id, 533 'recorded_time' => $post->post_date_gmt, 534 ) ); 535 536 // save post title in activity meta 537 if ( bp_is_active( 'activity' ) ) { 538 bp_activity_update_meta( $activity_id, 'post_title', $post->post_title ); 539 bp_activity_update_meta( $activity_id, 'post_url', $post_permalink ); 540 } 541 } 542 543 // Update the blogs last activity 544 bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() ); 545 } else { 546 bp_blogs_remove_post( $post_id, $blog_id, $user_id ); 547 } 427 // Update the blogs last activity 428 bp_blogs_update_blogmeta( $args['item_id'], 'last_activity', bp_core_current_time() ); 548 429 549 do_action( 'bp_blogs_new_blog_post', $post _id, $post, $user_id);430 do_action( 'bp_blogs_new_blog_post', $post->ID, $post, $args['user_id'] ); 550 431 } 432 add_action( 'bp_activity_post_type_published', 'bp_blogs_publish_post_activity_meta', 10, 3 ); 551 433 552 434 /** 553 * Updates a blog post's corresponding activityentry during a post edit.435 * Updates a blog post's activity meta entry during a post edit. 554 436 * 555 * @since BuddyPress (2.0.0) 556 * 557 * @see bp_blogs_catch_transition_post_status() 437 * @since BuddyPress (2.2.0) 558 438 * 559 * @param WP_Post $post 439 * @param WP_Post $post 440 * @param BP_Actitivy_Activity $activity 560 441 */ 561 function bp_blogs_update_post( $post ) { 562 if ( ! bp_is_active( 'activity' ) ) { 563 return; 564 } 565 566 $activity_id = bp_activity_get_activity_id( array( 567 'component' => buddypress()->blogs->id, 568 'item_id' => get_current_blog_id(), 569 'secondary_item_id' => $post->ID, 570 'type' => 'new_blog_post', 571 ) ); 572 573 // activity ID doesn't exist, so stop! 574 if ( empty( $activity_id ) ) { 442 function bp_blogs_update_post_activity_meta( $post, $activity ) { 443 if ( empty( $activity->id ) || 'post' != $post->post_type ) { 575 444 return; 576 445 } 577 446 578 // update the activity entry579 $activity = new BP_Activity_Activity( $activity_id );580 581 if ( ! empty( $post->post_content ) ) {582 // Make sure to update the thumbnail image583 $post_content = bp_activity_thumbnail_content_images( $post->post_content, $activity->primary_link, (array) $activity );584 585 // Make sure to apply the blop post excerpt586 $activity->content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $post_content ), $post_content, (array) $activity );587 }588 589 // Save the updated activity590 $activity->save();591 592 447 // update post title in activity meta 593 $existing_title = bp_activity_get_meta( $activity _id, 'post_title' );448 $existing_title = bp_activity_get_meta( $activity->id, 'post_title' ); 594 449 if ( $post->post_title !== $existing_title ) { 595 bp_activity_update_meta( $activity _id, 'post_title', $post->post_title );450 bp_activity_update_meta( $activity->id, 'post_title', $post->post_title ); 596 451 597 452 // now update activity meta for post comments... sigh 598 453 add_filter( 'comments_clauses', 'bp_blogs_comments_clauses_select_by_id' ); … … function bp_blogs_update_post( $post ) { 650 505 651 506 // add post comment status to activity meta if closed 652 507 if( 'closed' == $post->comment_status ) { 653 bp_activity_update_meta( $activity _id, 'post_comment_status', $post->comment_status );508 bp_activity_update_meta( $activity->id, 'post_comment_status', $post->comment_status ); 654 509 } else { 655 bp_activity_delete_meta( $activity _id, 'post_comment_status' );510 bp_activity_delete_meta( $activity->id, 'post_comment_status' ); 656 511 } 657 512 } 513 add_action( 'bp_activity_post_type_updated', 'bp_blogs_update_post_activity_meta', 10, 2 ); 658 514 659 515 /** 660 516 * Record a new blog comment in the BuddyPress activity stream. -
src/bp-blogs/bp-blogs-loader.php
diff --git src/bp-blogs/bp-blogs-loader.php src/bp-blogs/bp-blogs-loader.php index 112cc80..2d6b294 100644
class BP_Blogs_Component extends BP_Component { 75 75 76 76 // Setup the globals 77 77 parent::setup_globals( $args ); 78 79 /** 80 * Setup the post post type to track 81 * 82 * In case the config is not multisite, the blog_public option 83 * is ignored. 84 */ 85 if ( 0 !== (int) get_option( 'blog_public' ) || ! is_multisite() ) { 86 // Get all posts to track 87 $post_types = apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) ); 88 89 foreach ( $post_types as $post_type ) { 90 add_post_type_support( $post_type, 'buddypress-activity' ); 91 } 92 } 93 94 // Filter the generic track parameters for the 'post' post type 95 add_filter( 'bp_activity_tracking_register_post_post_type', array( $this, 'track_parameter' ), 10, 1 ); 78 96 } 79 97 80 98 /** … … class BP_Blogs_Component extends BP_Component { 246 264 247 265 parent::setup_title(); 248 266 } 267 268 /** 269 * Set up the track parameters for the 'post' post type 270 * 271 * @since BuddyPress (2.2.0) 272 */ 273 public function track_parameter( $params = array() ) { 274 return array_merge( $params, array( 275 'component_id' => $this->id, 276 'action_id' => 'new_blog_post', 277 'admin_filter' => __( 'New post published', 'buddypress' ), 278 'callback' => 'bp_blogs_format_activity_action_new_blog_post', 279 'filter' => __( 'Posts', 'buddypress' ), 280 'contexts' => array( 'activity', 'member' ), 281 'order' => 5, 282 ) ); 283 } 249 284 } 250 285 251 286 /** -
src/bp-core/bp-core-actions.php
diff --git src/bp-core/bp-core-actions.php src/bp-core/bp-core-actions.php index 2bb2334..32d9e71 100644
if ( !defined( 'ABSPATH' ) ) exit; 33 33 */ 34 34 add_action( 'plugins_loaded', 'bp_loaded', 10 ); 35 35 add_action( 'init', 'bp_init', 10 ); 36 add_action( 'wp_loaded', 'bp_fully_loaded', 10 ); 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 ); -
src/bp-core/bp-core-dependency.php
diff --git src/bp-core/bp-core-dependency.php src/bp-core/bp-core-dependency.php index 8ce93a7..f1c6f28 100644
function bp_loaded() { 108 108 } 109 109 110 110 /** 111 * Fire the 'bp_fully_loaded' action, which fires after WordPress, plugins and themes have been loaded. 112 * 113 * Attached to 'wp_loaded'. 114 * 115 * @since BuddyPress (2.2.0) 116 */ 117 function bp_fully_loaded() { 118 do_action( 'bp_fully_loaded' ); 119 } 120 121 /** 111 122 * Fire the 'bp_ready' action, which runs after BP is set up and the page is about to render. 112 123 * 113 124 * Attached to 'wp'. -
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..acfd25e 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 } 35 36 /** 37 * Record a new blog post in the BuddyPress activity stream. 38 * 39 * @deprecated BuddyPress (2.2.0) 40 * 41 * @param int $post_id ID of the post being recorded. 42 * @param object $post The WP post object passed to the 'save_post' action. 43 * @param int $user_id Optional. The user to whom the activity item will be 44 * associated. Defaults to the post_author. 45 * @return bool|null Returns false on failure. 46 */ 47 function bp_blogs_record_post( $post_id, $post, $user_id = 0 ) { 48 _deprecated_function( __FUNCTION__, '2.2', 'bp_activity_post_type_publish()' ); 49 bp_activity_post_type_publish( $post_id, $post, $user_id ); 50 } 51 52 /** 53 * Updates a blog post's corresponding activity entry during a post edit. 54 * 55 * @since BuddyPress (2.0.0) 56 * @deprecated BuddyPress (2.2.0) 57 * 58 * @see bp_blogs_catch_transition_post_status() 59 * 60 * @param WP_Post $post 61 */ 62 function bp_blogs_update_post( $post ) { 63 _deprecated_function( __FUNCTION__, '2.2', 'bp_activity_post_type_update()' ); 64 bp_activity_post_type_update( $post ); 65 } -
tests/phpunit/testcases/activity/actions.php
diff --git tests/phpunit/testcases/activity/actions.php tests/phpunit/testcases/activity/actions.php index e69de29..a6d9350 100644
1 <?php 2 /** 3 * @group activity 4 */ 5 class BP_Tests_Activity_Actions extends BP_UnitTestCase { 6 protected $old_current_user = 0; 7 8 public function setUp() { 9 parent::setUp(); 10 11 $this->old_current_user = get_current_user_id(); 12 $this->set_current_user( $this->factory->user->create( array( 'role' => 'subscriber' ) ) ); 13 } 14 15 public function tearDown() { 16 parent::tearDown(); 17 $this->set_current_user( $this->old_current_user ); 18 } 19 20 /** 21 * @group bp_activity_tracking_register_post_types 22 * @group activity_tracking 23 */ 24 public function test_bp_activity_tracking_register_post_types() { 25 add_post_type_support( 'page', 'buddypress-activity' ); 26 remove_post_type_support( 'post', 'buddypress-activity' ); 27 28 register_post_type( 'foo', array( 29 'label' => 'foo', 30 'public' => true, 31 'supports' => array( 'buddypress-activity' ), 32 ) ); 33 34 register_post_type( 'bar', array( 35 'label' => 'bar', 36 'public' => false, 37 'supports' => array( 'buddypress-activity' ), 38 ) ); 39 40 $expected = array( 'new_page', 'new_foo' ); 41 42 bp_activity_tracking_register_post_types(); 43 44 $this->assertEquals( $expected, array_keys( buddypress()->activity->track ) ); 45 46 // reset 47 add_post_type_support( 'post', 'buddypress-activity' ); 48 remove_post_type_support( 'page', 'buddypress-activity' ); 49 _unregister_post_type( 'foo' ); 50 _unregister_post_type( 'bar' ); 51 } 52 53 /** 54 * @group bp_activity_catch_transition_post_type_status 55 * @group activity_tracking 56 */ 57 public function test_bp_activity_catch_transition_post_type_status_publish() { 58 register_post_type( 'foo', array( 59 'label' => 'foo', 60 'public' => true, 61 'supports' => array( 'buddypress-activity' ), 62 ) ); 63 64 $post_id = $this->factory->post->create( array( 65 'post_status' => 'publish', 66 'post_type' => 'foo', 67 ) ); 68 69 $post = get_post( $post_id ); 70 71 // 'new' => 'publish' 72 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 73 74 _unregister_post_type( 'foo' ); 75 } 76 77 /** 78 * @group bp_activity_catch_transition_post_type_status 79 * @group activity_tracking 80 */ 81 public function test_bp_activity_catch_transition_post_type_status_publish_to_publish() { 82 register_post_type( 'foo', array( 83 'label' => 'foo', 84 'public' => true, 85 'supports' => array( 'buddypress-activity' ), 86 ) ); 87 88 $post_id = $this->factory->post->create( array( 89 'post_status' => 'publish', 90 'post_type' => 'foo', 91 ) ); 92 93 $post = get_post( $post_id ); 94 95 // 'new' => 'publish' 96 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 97 98 $post->post_status = 'publish'; 99 $post->post_content .= ' foo'; 100 101 wp_update_post( $post ); 102 103 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity (no change)' ); 104 105 _unregister_post_type( 'foo' ); 106 } 107 108 /** 109 * @group bp_activity_catch_transition_post_type_status 110 * @group activity_tracking 111 */ 112 public function test_bp_activity_catch_transition_post_type_status_publish_password() { 113 register_post_type( 'foo', array( 114 'label' => 'foo', 115 'public' => true, 116 'supports' => array( 'buddypress-activity' ), 117 ) ); 118 119 $post_id = $this->factory->post->create( array( 120 'post_status' => 'publish', 121 'post_type' => 'foo', 122 ) ); 123 124 $post = get_post( $post_id ); 125 126 // 'new' => 'publish' 127 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 128 129 $post->post_status = 'publish'; 130 $post->post_password = 'foo'; 131 132 wp_update_post( $post ); 133 134 // 'publish' => 'publish' (password protected) 135 $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Password protected post type should not have activity' ); 136 137 _unregister_post_type( 'foo' ); 138 } 139 140 /** 141 * @group bp_activity_catch_transition_post_type_status 142 * @group activity_tracking 143 */ 144 public function test_bp_activity_catch_transition_post_type_status_publish_trash() { 145 register_post_type( 'foo', array( 146 'label' => 'foo', 147 'public' => true, 148 'supports' => array( 'buddypress-activity' ), 149 ) ); 150 151 $post_id = $this->factory->post->create( array( 152 'post_status' => 'publish', 153 'post_type' => 'foo', 154 ) ); 155 156 $post = get_post( $post_id ); 157 158 // 'new' => 'publish' 159 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 160 161 wp_trash_post( $post->ID ); 162 163 // 'publish' => 'publish' (password protected) 164 $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Unpublished post type should not have activity' ); 165 166 _unregister_post_type( 'foo' ); 167 } 168 169 protected function activity_exists_for_post( $post_id, $action ) { 170 $a = bp_activity_get( array( 171 'action' => $action, 172 'item_id' => get_current_blog_id(), 173 'secondary_item_id' => $post_id, 174 ) ); 175 176 return ! empty( $a['activities'] ); 177 } 178 } -
tests/phpunit/testcases/activity/functions.php
diff --git tests/phpunit/testcases/activity/functions.php tests/phpunit/testcases/activity/functions.php index 6cea6bd..35693eb 100644
Bar!'; 576 576 } 577 577 578 578 /** 579 * @group activity_action 580 * @group bp_activity_format_activity_action_custom_post_type_post 581 * @group activity_tracking 582 */ 583 public function test_bp_activity_format_activity_action_custom_post_type_post_nonms() { 584 if ( is_multisite() ) { 585 return; 586 } 587 588 $bp = buddypress(); 589 590 register_post_type( 'foo', array( 591 'label' => 'foo', 592 'public' => true, 593 'supports' => array( 'buddypress-activity' ), 594 ) ); 595 596 bp_activity_tracking_register_post_types(); 597 598 $u = $this->factory->user->create(); 599 $p = $this->factory->post->create( array( 600 'post_author' => $u, 601 'post_type' => 'foo', 602 ) ); 603 604 $a = $this->factory->activity->create( array( 605 'component' => $bp->activity->track['new_foo']['component_id'], 606 'type' => $bp->activity->track['new_foo']['action_id'], 607 'user_id' => $u, 608 'item_id' => 1, 609 'secondary_item_id' => $p, 610 ) ); 611 612 $a_obj = new BP_Activity_Activity( $a ); 613 614 $user_link = bp_core_get_userlink( $u ); 615 $blog_url = get_home_url(); 616 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) ); 617 $post_link = '<a href="' . $post_url . '">' . $bp->activity->track['new_foo']['singular'] . '</a>'; 618 619 $expected = sprintf( '%s wrote a new %s', $user_link, $post_link ); 620 621 $this->assertSame( $expected, $a_obj->action ); 622 623 _unregister_post_type( 'foo' ); 624 } 625 626 /** 627 * @group activity_action 628 * @group bp_activity_format_activity_action_custom_post_type_post_ms 629 * @group activity_tracking 630 */ 631 public function test_bp_activity_format_activity_action_custom_post_type_post_ms() { 632 if ( ! is_multisite() ) { 633 return; 634 } 635 636 $bp = buddypress(); 637 638 $b = $this->factory->blog->create(); 639 $u = $this->factory->user->create(); 640 641 switch_to_blog( $b ); 642 643 register_post_type( 'foo', array( 644 'label' => 'foo', 645 'public' => true, 646 'supports' => array( 'buddypress-activity' ), 647 ) ); 648 649 bp_activity_tracking_register_post_types(); 650 651 $p = $this->factory->post->create( array( 652 'post_author' => $u, 653 'post_type' => 'foo', 654 ) ); 655 656 $activity_args = array( 657 'component' => $bp->activity->track['new_foo']['component_id'], 658 'type' => $bp->activity->track['new_foo']['action_id'], 659 'user_id' => $u, 660 'item_id' => $b, 661 'secondary_item_id' => $p, 662 ); 663 664 $post_type_label = $bp->activity->track['new_foo']['singular']; 665 666 _unregister_post_type( 'foo' ); 667 668 restore_current_blog(); 669 670 $a = $this->factory->activity->create( $activity_args ); 671 672 $a_obj = new BP_Activity_Activity( $a ); 673 674 $user_link = bp_core_get_userlink( $u ); 675 $blog_url = get_blog_option( $a_obj->item_id, 'home' ); 676 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) ); 677 678 $post_link = '<a href="' . $post_url . '">' . $post_type_label . '</a>'; 679 680 $expected = sprintf( '%s wrote a new %s, on the site %s', $user_link, $post_link, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' ); 681 682 $this->assertSame( $expected, $a_obj->action ); 683 } 684 685 /** 579 686 * @group bp_activity_new_comment 580 687 * @group cache 581 688 */ -
tests/phpunit/testcases/blogs/activity.php
diff --git tests/phpunit/testcases/blogs/activity.php tests/phpunit/testcases/blogs/activity.php index cc16b1f..3db3e8f 100644
2 2 3 3 class BP_Tests_Blogs_Activity extends BP_UnitTestCase { 4 4 /** 5 * @group bp_blogs_register_activity_actions 6 */ 7 public function test_bp_blogs_register_activity_actions() { 8 $bp = buddypress(); 9 10 $expected = array( 'new_blog_post', 'new_blog_comment' ); 11 12 if ( is_multisite() ) { 13 $expected = array_merge( array( 'new_blog' ), $expected ); 14 } 15 16 $actions = array_keys( (array) bp_activity_sort_component_actions( $bp->activity->actions->blogs ) ); 17 18 $this->assertEquals( $expected, $actions ); 19 } 20 21 /** 5 22 * @group activity_action 6 23 * @group bp_blogs_format_activity_action_new_blog 7 24 */ -
tests/phpunit/testcases/blogs/functions.php
diff --git tests/phpunit/testcases/blogs/functions.php tests/phpunit/testcases/blogs/functions.php index 6e03d5c..b2ee4eb 100644
class BP_Tests_Blogs_Functions extends BP_UnitTestCase { 303 303 /** 304 304 * @group bp_blogs_catch_transition_post_status 305 305 */ 306 public function test_transition_post_status_password_publish() { 307 $post_id = $this->factory->post->create( array( 308 'post_status' => 'publish', 309 'post_type' => 'post', 310 'post_password' => 'pass', 311 ) ); 312 $post = get_post( $post_id ); 313 314 // 'new' => 'publish with password' 315 $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Published with password post should not have activity' ); 316 } 317 318 /** 319 * @group bp_blogs_catch_transition_post_status 320 */ 321 public function test_transition_post_status_publish_update_password() { 322 $post_id = $this->factory->post->create( array( 323 'post_status' => 'publish', 324 'post_type' => 'post', 325 ) ); 326 $post = get_post( $post_id ); 327 328 // 'publish' => 'publish' 329 $this->assertTrue( $this->activity_exists_for_post( $post_id ), 'Published post should have activity' ); 330 331 $post->post_content .= ' foo'; 332 $post->post_password = 'pass'; 333 334 wp_update_post( $post ); 335 336 $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Updated with password post should not have activity' ); 337 } 338 339 /** 340 * @group bp_blogs_catch_transition_post_status 341 */ 342 public function test_transition_post_status_private_publish() { 343 $post_id = $this->factory->post->create( array( 344 'post_status' => 'private', 345 'post_type' => 'post', 346 ) ); 347 $post = get_post( $post_id ); 348 349 // 'new' => 'private' 350 $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Private post should not have activity' ); 351 352 $post->post_status = 'publish'; 353 354 wp_update_post( $post ); 355 356 // 'private' => 'publish' 357 $this->assertTrue( $this->activity_exists_for_post( $post_id ), 'Published post should have activity' ); 358 } 359 360 /** 361 * @group bp_blogs_catch_transition_post_status 362 */ 363 public function test_transition_post_status_publish_private() { 364 $post_id = $this->factory->post->create( array( 365 'post_status' => 'publish', 366 'post_type' => 'post', 367 ) ); 368 $post = get_post( $post_id ); 369 370 // 'new' => 'publish' 371 $this->assertTrue( $this->activity_exists_for_post( $post_id ), 'Published post should have activity' ); 372 373 $post->post_status = 'private'; 374 375 wp_update_post( $post ); 376 377 // 'publish' => 'private' 378 $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Private post should not have activity' ); 379 } 380 381 /** 382 * @group bp_blogs_catch_transition_post_status 383 */ 306 384 public function test_transition_post_status_draft_to_draft() { 307 385 $post_id = $this->factory->post->create( array( 308 386 'post_status' => 'draft', … … class BP_Tests_Blogs_Functions extends BP_UnitTestCase { 477 555 $this->set_current_user( $old_user ); 478 556 } 479 557 558 /** 559 * @group bp_blogs_catch_transition_post_status 560 */ 561 public function test_bp_blogs_is_blog_trackable_false_publish_post() { 562 add_filter( 'bp_blogs_is_blog_trackable', '__return_false' ); 563 564 $post_id = $this->factory->post->create( array( 565 'post_status' => 'publish', 566 'post_type' => 'post', 567 ) ); 568 $post = get_post( $post_id ); 569 570 // 'new' => 'publish' 571 $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Not trackable blog post should not have activity' ); 572 573 $post->post_content .= ' foo'; 574 575 wp_update_post( $post ); 576 577 // 'publish' => 'publish' 578 $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Not trackable blog post should not have activity' ); 579 580 remove_filter( 'bp_blogs_is_blog_trackable', '__return_false' ); 581 } 582 583 /** 584 * @group bp_blogs_catch_transition_post_status 585 */ 586 public function test_bp_is_blog_public_zero_publish_post() { 587 if ( ! is_multisite() ) { 588 return; 589 } 590 591 add_filter( 'bp_is_blog_public', '__return_zero' ); 592 593 $post_id = $this->factory->post->create( array( 594 'post_status' => 'publish', 595 'post_type' => 'post', 596 ) ); 597 $post = get_post( $post_id ); 598 599 // 'new' => 'publish' 600 $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Not public blog post should not have activity' ); 601 602 $post->post_content .= ' foo'; 603 604 wp_update_post( $post ); 605 606 // 'publish' => 'publish' 607 $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Not public blog post should not have activity' ); 608 609 remove_filter( 'bp_is_blog_public', '__return_zero' ); 610 } 611 480 612 protected function activity_exists_for_post( $post_id ) { 481 613 $a = bp_activity_get( array( 482 614 'component' => buddypress()->blogs->id,