Ticket #5669: 5669.04.patch
File 5669.04.patch, 58.6 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..b33c113 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 $activity_params = 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 'position' => 0, 45 'singular' => strtolower( $object->labels->singular_name ), 46 'plural' => strtolower( $object->labels->name ), 47 'activity_commment' => ! post_type_supports( $key, 'comments' ), 48 ); 49 50 if ( ! empty( $object->labels->bp_activity_new_post ) ) { 51 $activity_params['bp_activity_new_post'] = $object->labels->bp_activity_new_post; 52 } 53 54 if ( ! empty( $object->labels->bp_activity_new_post_ms ) ) { 55 $activity_params['bp_activity_new_post_ms'] = $object->labels->bp_activity_new_post_ms; 56 } 57 58 // Register the post type in tracking global 59 $bp->activity->track[ 'new_' . $key ] = apply_filters( 'bp_activity_tracking_register_' . $key . '_post_type', $activity_params, $object ); 60 61 // Set activity action for the post type 62 call_user_func_array( 'bp_activity_set_action', array_intersect_key( 63 $bp->activity->track[ 'new_' . $key ], 64 array_flip( array( 'component_id', 'action_id', 'admin_filter', 'callback', 'filter', 'contexts', 'position' ) ) 65 ) ); 66 } 67 68 do_action( 'bp_activity_tracking_register_post_types' ); 69 } 70 add_action( 'bp_fully_loaded', 'bp_activity_tracking_register_post_types' ); 71 72 /** 16 73 * Allow core components and dependent plugins to register activity actions. 17 74 * 18 75 * @since BuddyPress (1.2.0) … … function bp_ajax_get_suggestions() { 766 823 wp_send_json_success( $results ); 767 824 } 768 825 add_action( 'wp_ajax_bp_get_suggestions', 'bp_ajax_get_suggestions' ); 826 827 /** 828 * Detect a change in post type status, and initiate an activity update if necessary. 829 * 830 * @since BuddyPress (2.2.0) 831 * 832 * @todo Support untrashing better 833 * 834 * @param string $new_status New status for the post. 835 * @param string $old_status Old status for the post. 836 * @param object $post Post data. 837 */ 838 function bp_activity_catch_transition_post_type_status( $new_status, $old_status, $post ) { 839 $bp = buddypress(); 840 841 // This is an edit 842 if ( $new_status === $old_status ) { 843 if ( $new_status == 'publish' ) { 844 // Update the post type 845 if ( ! empty( $bp->activity->track[ 'new_' . $post->post_type ] ) ) { 846 bp_activity_post_type_update( $post ); 847 } 848 return; 849 } 850 } 851 852 // Publishing a previously unpublished post 853 if ( 'publish' === $new_status ) { 854 // Untrashing the post type 855 // Nothing here yet 856 if ( 'trash' == $old_status ) { 857 do_action( 'bp_activity_post_type_untrash_' . $post->post_type, $post ); 858 } else { 859 // Record the post type 860 if ( ! empty( $bp->activity->track[ 'new_' . $post->post_type ] ) && empty( $post->post_password ) ) { 861 bp_activity_post_type_publish( $post->ID, $post ); 862 } 863 } 864 865 // Unpublishing a previously published post 866 } else if ( 'publish' === $old_status ) { 867 // Some form of pending status 868 // Only remove the activity entry 869 if ( ! empty( $bp->activity->track[ 'new_' . $post->post_type ] ) ) { 870 bp_activity_post_type_unpublish( $post->ID, $post ); 871 } 872 } 873 } 874 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..dee2310 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 484 /** 485 * Set a specific activity attribute of a tracked post type 486 * 487 * @since BuddyPress (2.2.0) 488 * 489 * @param string $post_type the name of the post type eg: 'post' or 'page' 490 * @param array $args an associative array of tracking args to edit 491 * eg : array( 'component_id' => 'blogs' ) 492 */ 493 function bp_activity_set_post_type_tracking_args( $post_type = '', $args = array() ) { 494 $bp = buddypress(); 495 496 $action = 'new_' . $post_type; 497 498 if ( empty( $bp->activity->track ) || empty( $bp->activity->track[ $action ] ) ) { 499 return false; 500 } 501 502 $bp->activity->track[ $action ] = bp_parse_args( (array) $args, $bp->activity->track[ $action ] ); 503 } 504 443 505 /** Favorites ****************************************************************/ 444 506 445 507 /** … … function bp_activity_format_activity_action_activity_comment( $action, $activity 1130 1192 return apply_filters( 'bp_activity_comment_action', $action, $activity ); 1131 1193 } 1132 1194 1195 /** 1196 * Format custom post type activity post actions. 1197 * 1198 * @since BuddyPress (2.2.0) 1199 * 1200 * @param string $action Static activity action. 1201 * @param object $activity Activity data object. 1202 * @return string 1203 */ 1204 function bp_activity_format_activity_action_custom_post_type_post( $action, $activity ) { 1205 $bp = buddypress(); 1206 1207 if ( empty( $activity->type ) || empty( $bp->activity->track[ $activity->type ] ) ) { 1208 return $action; 1209 } 1210 1211 $user_link = bp_core_get_userlink( $activity->user_id ); 1212 $blog_url = get_home_url( $activity->item_id ); 1213 1214 if ( empty( $activity->post_url ) ) { 1215 $post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) ); 1216 } else { 1217 $post_url = $activity->post_url; 1218 } 1219 1220 $post_link = '<a href="' . $post_url . '">' . $bp->activity->track[ $activity->type ]['singular'] . '</a>'; 1221 1222 if ( ! empty( $bp->activity->track[ $activity->type ]['bp_activity_new_post'] ) ) { 1223 $action = sprintf( $bp->activity->track[ $activity->type ]['bp_activity_new_post'], $user_link, $post_url ); 1224 } else { 1225 $action = sprintf( _x( '%1$s wrote a new %2$s', 'Activity Custom Post Type post action', 'buddypress' ), $user_link, $post_link ); 1226 } 1227 1228 if ( is_multisite() ) { 1229 $blog_link = '<a href="' . $blog_url . '">' . get_blog_option( $activity->item_id, 'blogname' ) . '</a>'; 1230 1231 if ( ! empty( $bp->activity->track[ $activity->type ]['bp_activity_new_post_ms'] ) ) { 1232 $action = sprintf( $bp->activity->track[ $activity->type ]['bp_activity_new_post_ms'], $user_link, $post_url, $blog_link ); 1233 } else { 1234 $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 ); 1235 } 1236 } 1237 1238 /** 1239 * Filters the formatted custom post type activity post action string. 1240 * 1241 * @since BuddyPress (2.2.0) 1242 * 1243 * @param string $action Activity action string value. 1244 * @param BP_Activity_Activity $activity Activity item object. 1245 */ 1246 return apply_filters( 'bp_activity_custom_post_type_post_action', $action, $activity ); 1247 } 1248 1133 1249 /****************************************************************************** 1134 1250 * Business functions are where all the magic happens in BuddyPress. They will 1135 1251 * handle the actual saving or manipulation of information. Usually they will … … function bp_activity_post_update( $args = '' ) { 1513 1629 } 1514 1630 1515 1631 /** 1632 * Publish an activity for the custom post type. 1633 * 1634 * @since BuddyPress (2.2.0) 1635 * 1636 * @param int $post_id 1637 * @param WP_Post $post 1638 * @param int $user_id 1639 */ 1640 function bp_activity_post_type_publish( $post_id = 0, $post = null, $user_id = 0 ) { 1641 $bp = buddypress(); 1642 1643 if ( ! is_a( $post, 'WP_Post' ) ) { 1644 return; 1645 } 1646 1647 if ( 'publish' != $post->post_status || ! empty( $post->post_password ) || empty( $bp->activity->track[ 'new_' . $post->post_type ] ) ) { 1648 return; 1649 } 1650 1651 if ( empty( $post_id ) ) { 1652 $post_id = $post->ID; 1653 } 1654 1655 $blog_id = get_current_blog_id(); 1656 1657 if ( empty( $user_id ) ) { 1658 $user_id = (int) $post->post_author; 1659 } 1660 1661 $activity_post_object = (object) $bp->activity->track[ 'new_' . $post->post_type ]; 1662 1663 $existing = bp_activity_get( array( 1664 'filter' => array( 1665 'action' => $activity_post_object->action_id, 1666 'primary_id' => $blog_id, 1667 'secondary_id' => $post_id, 1668 ) 1669 ) ); 1670 1671 // Leave Components/plugins bail before the activity is posted 1672 if ( ! empty( $existing['activities'] ) || false === apply_filters( "bp_activity_{$post->post_type}_pre_publish", true, $blog_id, $post_id, $user_id ) ) { 1673 return; 1674 } 1675 1676 // Record this in activity streams 1677 $blog_url = get_home_url( $blog_id ); 1678 $post_url = add_query_arg( 1679 'p', 1680 $post_id, 1681 trailingslashit( $blog_url ) 1682 ); 1683 1684 /** 1685 * As the 'post' post type will no more use bp_blogs_record_post(), we need to be sure the filters 1686 * - 'bp_blogs_activity_new_post_content' can be applied on the content. 1687 * - 'bp_blogs_activity_new_post_primary_link' can be applied on the primary_link. 1688 */ 1689 $activity_args = array( 1690 'user_id' => $user_id, 1691 'content' => apply_filters( "bp_{$activity_post_object->component_id}_activity_new_post_content", $post->post_content, $post, $post_url, $post->post_type ), 1692 'primary_link' => apply_filters( "bp_{$activity_post_object->component_id}_activity_new_post_primary_link", $post_url, $post_id, $post->post_type ), 1693 'component' => $activity_post_object->component_id, 1694 'type' => $activity_post_object->action_id, 1695 'item_id' => $blog_id, 1696 'secondary_item_id' => $post_id, 1697 'recorded_time' => $post->post_date_gmt, 1698 'hide_sitewide' => apply_filters( 'bp_activity_post_type_publish_primary_link', false, $post ), 1699 ); 1700 1701 // Remove large images and replace them with just one image thumbnail 1702 if ( ! empty( $activity_args['content'] ) ) { 1703 $activity_args['content'] = bp_activity_thumbnail_content_images( $activity_args['content'], $activity_args['primary_link'], $activity_args ); 1704 } 1705 1706 if ( ! empty( $activity_args['content'] ) ) { 1707 /** 1708 * As the 'post' post type will not use bp_blogs_record_activity(), we need to be sure the filter 1709 * 'bp_blogs_record_activity_content' can be applied on the action. 1710 */ 1711 $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 ); 1712 } 1713 1714 // Setup the action by using the format functions 1715 $action_args = array_merge( $activity_args, array( 1716 'post_title' => $post->post_title, 1717 'post_url' => $post_url, 1718 ) ); 1719 1720 $activity_args['action'] = call_user_func_array( $activity_post_object->callback, array( '', (object) $action_args ) ); 1721 1722 // Make sure the action is set 1723 if ( empty( $activity_args['action'] ) ) { 1724 return; 1725 } else { 1726 /** 1727 * As the 'post' post type will not use bp_blogs_record_activity(), we need to be sure the filter 1728 * 'bp_blogs_record_activity_action' can be applied on the action. 1729 */ 1730 $activity_args['action'] = apply_filters( "bp_{$activity_post_object->component_id}_record_activity_action", $activity_args['action'] ); 1731 } 1732 1733 do_action( 'bp_activity_post_type_published', bp_activity_add( $activity_args ), $post, $action_args ); 1734 } 1735 1736 /** 1737 * Update an activity for the custom post type. 1738 * 1739 * @since BuddyPress (2.2.0) 1740 * 1741 * @param WP_Post $post 1742 */ 1743 function bp_activity_post_type_update( $post = null ) { 1744 $bp = buddypress(); 1745 1746 if ( ! is_a( $post, 'WP_Post' ) ) { 1747 return; 1748 } 1749 1750 if ( empty( $bp->activity->track[ 'new_' . $post->post_type ] ) ) { 1751 return; 1752 } 1753 1754 $activity_post_object = (object) $bp->activity->track[ 'new_' . $post->post_type ]; 1755 1756 $activity_id = bp_activity_get_activity_id( array( 1757 'component' => $activity_post_object->component_id, 1758 'item_id' => get_current_blog_id(), 1759 'secondary_item_id' => $post->ID, 1760 'type' => $activity_post_object->action_id, 1761 ) ); 1762 1763 // activity ID doesn't exist, so stop! 1764 if ( empty( $activity_id ) ) { 1765 return; 1766 } 1767 1768 // Delete the activity if the post was updated with a password 1769 if ( ! empty( $post->post_password ) ) { 1770 bp_activity_delete( array( 'id' => $activity_id ) ); 1771 } 1772 1773 // update the activity entry 1774 $activity = new BP_Activity_Activity( $activity_id ); 1775 1776 if ( ! empty( $post->post_content ) ) { 1777 // Make sure to update the thumbnail image 1778 $post_content = bp_activity_thumbnail_content_images( $post->post_content, $activity->primary_link, (array) $activity ); 1779 1780 /** 1781 * Make sure to apply the excerpt 1782 * 1783 * As the 'post' post type will no more use bp_blogs_update_post(), we need to be sure the filter 1784 * 'bp_blogs_record_activity_content' can be applied on the action. 1785 */ 1786 $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 ); 1787 } 1788 1789 // Save the updated activity 1790 $activity->save(); 1791 1792 do_action( 'bp_activity_post_type_updated', $post, $activity ); 1793 } 1794 1795 /** 1796 * Unpublish an activity for the custom post type. 1797 * 1798 * @since BuddyPress (2.2.0) 1799 * 1800 * @param int $post_id 1801 * @param WP_Post $post 1802 */ 1803 function bp_activity_post_type_unpublish( $post_id = 0, $post = null ) { 1804 $bp = buddypress(); 1805 1806 if ( ! is_a( $post, 'WP_Post' ) ) { 1807 return; 1808 } 1809 1810 if ( empty( $bp->activity->track[ 'new_' . $post->post_type ] ) ) { 1811 return; 1812 } 1813 1814 if ( empty( $post_id ) ) { 1815 $post_id = $post->ID; 1816 } 1817 1818 $activity_post_object = (object) $bp->activity->track[ 'new_' . $post->post_type ]; 1819 1820 $delete_activity_args = array( 1821 'item_id' => get_current_blog_id(), 1822 'secondary_item_id' => $post_id, 1823 'component' => $activity_post_object->component_id, 1824 'type' => $activity_post_object->action_id, 1825 'user_id' => false, 1826 ); 1827 1828 do_action( 'bp_activity_post_type_unpublished', bp_activity_delete_by_item_id( $delete_activity_args ), $delete_activity_args, $post ); 1829 } 1830 1831 /** 1516 1832 * Add an activity comment. 1517 1833 * 1518 1834 * @since BuddyPress (1.2.0) … … function bp_activity_delete_comment( $activity_id, $comment_id ) { 1988 2304 * @return string $link Permalink for the activity item. 1989 2305 */ 1990 2306 function bp_activity_get_permalink( $activity_id, $activity_obj = false ) { 2307 $bp = buddypress(); 1991 2308 1992 2309 if ( empty( $activity_obj ) ) { 1993 2310 $activity_obj = new BP_Activity_Activity( $activity_id ); … … function bp_activity_get_permalink( $activity_id, $activity_obj = false ) { 1997 2314 $activity_obj = $activity_obj->current_comment; 1998 2315 } 1999 2316 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 ) { 2317 $use_primary_links = array( 2318 'new_blog_post', 2319 'new_blog_comment', 2320 'new_forum_topic', 2321 'new_forum_post', 2322 ); 2323 2324 if ( ! empty( $bp->activity->track ) ) { 2325 $use_primary_links = array_merge( $use_primary_links, array_keys( $bp->activity->track ) ); 2326 } 2327 2328 if ( false !== array_search( $activity_obj->type, $use_primary_links ) ) { 2001 2329 $link = $activity_obj->primary_link; 2002 2330 } else { 2003 2331 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..3a1af31 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 'position' => 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..9ce637d 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 $bp = buddypress(); 26 $reset = $bp->activity->track; 27 28 add_post_type_support( 'page', 'buddypress-activity' ); 29 remove_post_type_support( 'post', 'buddypress-activity' ); 30 31 register_post_type( 'foo', array( 32 'label' => 'foo', 33 'public' => true, 34 'supports' => array( 'buddypress-activity' ), 35 ) ); 36 37 register_post_type( 'bar', array( 38 'label' => 'bar', 39 'public' => false, 40 'supports' => array( 'buddypress-activity' ), 41 ) ); 42 43 $expected = array( 'new_page', 'new_foo' ); 44 45 bp_activity_tracking_register_post_types(); 46 47 $this->assertEquals( $expected, array_keys( buddypress()->activity->track ) ); 48 49 // reset 50 add_post_type_support( 'post', 'buddypress-activity' ); 51 remove_post_type_support( 'page', 'buddypress-activity' ); 52 _unregister_post_type( 'foo' ); 53 _unregister_post_type( 'bar' ); 54 55 $bp->activity->track = $reset; 56 } 57 58 /** 59 * @group bp_activity_catch_transition_post_type_status 60 * @group activity_tracking 61 */ 62 public function test_bp_activity_catch_transition_post_type_status_publish() { 63 $bp = buddypress(); 64 $reset = $bp->activity->track; 65 66 register_post_type( 'foo', array( 67 'label' => 'foo', 68 'public' => true, 69 'supports' => array( 'buddypress-activity' ), 70 ) ); 71 72 bp_activity_tracking_register_post_types(); 73 74 $post_id = $this->factory->post->create( array( 75 'post_status' => 'publish', 76 'post_type' => 'foo', 77 ) ); 78 79 $post = get_post( $post_id ); 80 81 // 'new' => 'publish' 82 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 83 84 _unregister_post_type( 'foo' ); 85 $bp->activity->track = $reset; 86 } 87 88 /** 89 * @group bp_activity_catch_transition_post_type_status 90 * @group activity_tracking 91 */ 92 public function test_bp_activity_catch_transition_post_type_status_publish_to_publish() { 93 $bp = buddypress(); 94 $reset = $bp->activity->track; 95 96 register_post_type( 'foo', array( 97 'label' => 'foo', 98 'public' => true, 99 'supports' => array( 'buddypress-activity' ), 100 ) ); 101 102 bp_activity_tracking_register_post_types(); 103 104 $post_id = $this->factory->post->create( array( 105 'post_status' => 'publish', 106 'post_type' => 'foo', 107 ) ); 108 109 $post = get_post( $post_id ); 110 111 // 'new' => 'publish' 112 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 113 114 // Delete the activity 115 bp_activity_post_type_unpublish( $post_id, $post ); 116 117 $post->post_status = 'publish'; 118 $post->post_content .= ' foo'; 119 120 wp_update_post( $post ); 121 122 $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Updating a post type should not create a new activity' ); 123 124 _unregister_post_type( 'foo' ); 125 $bp->activity->track = $reset; 126 } 127 128 /** 129 * @group bp_activity_catch_transition_post_type_status 130 * @group activity_tracking 131 */ 132 public function test_bp_activity_catch_transition_post_type_status_publish_password() { 133 $bp = buddypress(); 134 $reset = $bp->activity->track; 135 136 register_post_type( 'foo', array( 137 'label' => 'foo', 138 'public' => true, 139 'supports' => array( 'buddypress-activity' ), 140 ) ); 141 142 bp_activity_tracking_register_post_types(); 143 144 $post_id = $this->factory->post->create( array( 145 'post_status' => 'publish', 146 'post_type' => 'foo', 147 ) ); 148 149 $post = get_post( $post_id ); 150 151 // 'new' => 'publish' 152 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 153 154 $post->post_status = 'publish'; 155 $post->post_password = 'foo'; 156 157 wp_update_post( $post ); 158 159 // 'publish' => 'publish' (password protected) 160 $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Password protected post type should not have activity' ); 161 162 _unregister_post_type( 'foo' ); 163 $bp->activity->track = $reset; 164 } 165 166 /** 167 * @group bp_activity_catch_transition_post_type_status 168 * @group activity_tracking 169 */ 170 public function test_bp_activity_catch_transition_post_type_status_publish_trash() { 171 $bp = buddypress(); 172 $reset = $bp->activity->track; 173 174 register_post_type( 'foo', array( 175 'label' => 'foo', 176 'public' => true, 177 'supports' => array( 'buddypress-activity' ), 178 ) ); 179 180 bp_activity_tracking_register_post_types(); 181 182 $post_id = $this->factory->post->create( array( 183 'post_status' => 'publish', 184 'post_type' => 'foo', 185 ) ); 186 187 $post = get_post( $post_id ); 188 189 // 'new' => 'publish' 190 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 191 192 wp_trash_post( $post->ID ); 193 194 // 'publish' => 'publish' (password protected) 195 $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Unpublished post type should not have activity' ); 196 197 _unregister_post_type( 'foo' ); 198 $bp->activity->track = $reset; 199 } 200 201 protected function activity_exists_for_post( $post_id, $action ) { 202 $a = bp_activity_get( array( 203 'action' => $action, 204 'item_id' => get_current_blog_id(), 205 'secondary_item_id' => $post_id, 206 ) ); 207 208 return ! empty( $a['activities'] ); 209 } 210 } -
tests/phpunit/testcases/activity/functions.php
diff --git tests/phpunit/testcases/activity/functions.php tests/phpunit/testcases/activity/functions.php index 6cea6bd..868a305 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 $reset = $bp->activity->track; 590 591 register_post_type( 'foo', array( 592 'label' => 'foo', 593 'public' => true, 594 'supports' => array( 'buddypress-activity' ), 595 ) ); 596 597 bp_activity_tracking_register_post_types(); 598 599 $u = $this->factory->user->create(); 600 $p = $this->factory->post->create( array( 601 'post_author' => $u, 602 'post_type' => 'foo', 603 ) ); 604 605 $a = $this->factory->activity->create( array( 606 'component' => $bp->activity->track['new_foo']['component_id'], 607 'type' => $bp->activity->track['new_foo']['action_id'], 608 'user_id' => $u, 609 'item_id' => 1, 610 'secondary_item_id' => $p, 611 ) ); 612 613 $a_obj = new BP_Activity_Activity( $a ); 614 615 $user_link = bp_core_get_userlink( $u ); 616 $blog_url = get_home_url(); 617 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) ); 618 $post_link = '<a href="' . $post_url . '">' . $bp->activity->track['new_foo']['singular'] . '</a>'; 619 620 $expected = sprintf( '%s wrote a new %s', $user_link, $post_link ); 621 622 $this->assertSame( $expected, $a_obj->action ); 623 624 _unregister_post_type( 'foo' ); 625 $bp->activity->track = $reset; 626 } 627 628 /** 629 * @group activity_action 630 * @group bp_activity_format_activity_action_custom_post_type_post_ms 631 * @group activity_tracking 632 */ 633 public function test_bp_activity_format_activity_action_custom_post_type_post_ms() { 634 if ( ! is_multisite() ) { 635 return; 636 } 637 638 $bp = buddypress(); 639 $reset = $bp->activity->track; 640 641 $b = $this->factory->blog->create(); 642 $u = $this->factory->user->create(); 643 644 switch_to_blog( $b ); 645 646 register_post_type( 'foo', array( 647 'label' => 'foo', 648 'public' => true, 649 'supports' => array( 'buddypress-activity' ), 650 ) ); 651 652 bp_activity_tracking_register_post_types(); 653 654 $p = $this->factory->post->create( array( 655 'post_author' => $u, 656 'post_type' => 'foo', 657 ) ); 658 659 $activity_args = array( 660 'component' => $bp->activity->track['new_foo']['component_id'], 661 'type' => $bp->activity->track['new_foo']['action_id'], 662 'user_id' => $u, 663 'item_id' => $b, 664 'secondary_item_id' => $p, 665 ); 666 667 $post_type_label = $bp->activity->track['new_foo']['singular']; 668 669 _unregister_post_type( 'foo' ); 670 671 restore_current_blog(); 672 673 $a = $this->factory->activity->create( $activity_args ); 674 675 $a_obj = new BP_Activity_Activity( $a ); 676 677 $user_link = bp_core_get_userlink( $u ); 678 $blog_url = get_blog_option( $a_obj->item_id, 'home' ); 679 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) ); 680 681 $post_link = '<a href="' . $post_url . '">' . $post_type_label . '</a>'; 682 683 $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>' ); 684 685 $this->assertSame( $expected, $a_obj->action ); 686 $bp->activity->track = $reset; 687 } 688 689 /** 690 * @group activity_action 691 * @group bp_activity_format_activity_action_custom_post_type_post 692 * @group activity_tracking 693 */ 694 public function test_bp_activity_format_activity_action_custom_string_post_type_post_nonms() { 695 if ( is_multisite() ) { 696 return; 697 } 698 699 $bp = buddypress(); 700 $reset = $bp->activity->track; 701 702 $labels = array( 703 'name' => 'bars', 704 'singular_name' => 'bar', 705 'bp_activity_new_post' => '%1$s shared a new <a href="%2$s">bar</a>', 706 ); 707 708 register_post_type( 'foo', array( 709 'labels' => $labels, 710 'public' => true, 711 'supports' => array( 'buddypress-activity' ), 712 ) ); 713 714 bp_activity_tracking_register_post_types(); 715 716 $u = $this->factory->user->create(); 717 $p = $this->factory->post->create( array( 718 'post_author' => $u, 719 'post_type' => 'foo', 720 ) ); 721 722 $a = $this->factory->activity->create( array( 723 'component' => $bp->activity->track['new_foo']['component_id'], 724 'type' => $bp->activity->track['new_foo']['action_id'], 725 'user_id' => $u, 726 'item_id' => 1, 727 'secondary_item_id' => $p, 728 ) ); 729 730 $a_obj = new BP_Activity_Activity( $a ); 731 732 $user_link = bp_core_get_userlink( $u ); 733 $blog_url = get_home_url(); 734 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) ); 735 736 $expected = sprintf( '%1$s shared a new <a href="%2$s">bar</a>', $user_link, $post_url ); 737 738 $this->assertSame( $expected, $a_obj->action ); 739 740 _unregister_post_type( 'foo' ); 741 $bp->activity->track = $reset; 742 } 743 744 /** 745 * @group activity_action 746 * @group bp_activity_format_activity_action_custom_post_type_post_ms 747 * @group activity_tracking 748 */ 749 public function test_bp_activity_format_activity_action_custom_string_post_type_post_ms() { 750 if ( ! is_multisite() ) { 751 return; 752 } 753 754 $bp = buddypress(); 755 $reset = $bp->activity->track; 756 757 $b = $this->factory->blog->create(); 758 $u = $this->factory->user->create(); 759 760 switch_to_blog( $b ); 761 762 $labels = array( 763 'name' => 'bars', 764 'singular_name' => 'bar', 765 'bp_activity_new_post_ms' => '%1$s shared a new <a href="%2$s">bar</a>, on the site %3$s', 766 ); 767 768 register_post_type( 'foo', array( 769 'labels' => $labels, 770 'public' => true, 771 'supports' => array( 'buddypress-activity' ), 772 ) ); 773 774 bp_activity_tracking_register_post_types(); 775 776 $p = $this->factory->post->create( array( 777 'post_author' => $u, 778 'post_type' => 'foo', 779 ) ); 780 781 $activity_args = array( 782 'component' => $bp->activity->track['new_foo']['component_id'], 783 'type' => $bp->activity->track['new_foo']['action_id'], 784 'user_id' => $u, 785 'item_id' => $b, 786 'secondary_item_id' => $p, 787 ); 788 789 $post_type_label = $bp->activity->track['new_foo']['singular']; 790 791 _unregister_post_type( 'foo' ); 792 793 restore_current_blog(); 794 795 $a = $this->factory->activity->create( $activity_args ); 796 797 $a_obj = new BP_Activity_Activity( $a ); 798 799 $user_link = bp_core_get_userlink( $u ); 800 $blog_url = get_blog_option( $a_obj->item_id, 'home' ); 801 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) ); 802 803 $expected = sprintf( '%1$s shared a new <a href="%2$s">bar</a>, on the site %3$s', $user_link, $post_url, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' ); 804 805 $this->assertSame( $expected, $a_obj->action ); 806 $bp->activity->track = $reset; 807 } 808 809 /** 810 * @group bp_activity_set_post_type_tracking_args 811 * @group activity_tracking 812 */ 813 public function test_bp_activity_set_post_type_tracking_args() { 814 $bp = buddypress(); 815 $reset = $bp->activity->track; 816 817 add_post_type_support( 'page', 'buddypress-activity' ); 818 819 bp_activity_tracking_register_post_types(); 820 bp_activity_set_post_type_tracking_args( 'page', array( 821 'component_id' => $bp->blogs->id, 822 'dummy' => 'dummy value', 823 ) ); 824 825 $u = $this->factory->user->create(); 826 827 $post_id = $this->factory->post->create( array( 828 'post_author' => $u, 829 'post_status' => 'publish', 830 'post_type' => 'page', 831 ) ); 832 833 $a = bp_activity_get( array( 834 'action' => 'new_page', 835 'item_id' => get_current_blog_id(), 836 'secondary_item_id' => $post_id, 837 ) ); 838 839 $this->assertSame( $bp->blogs->id, $a['activities'][0]->component ); 840 841 remove_post_type_support( 'page', 'buddypress-activity' ); 842 $bp->activity->track = $reset; 843 } 844 845 /** 579 846 * @group bp_activity_new_comment 580 847 * @group cache 581 848 */ -
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,