Ticket #5669: 5669.05.patch
File 5669.05.patch, 61.2 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..1a82979 100644
function bp_ajax_get_suggestions() { 766 766 wp_send_json_success( $results ); 767 767 } 768 768 add_action( 'wp_ajax_bp_get_suggestions', 'bp_ajax_get_suggestions' ); 769 770 /** 771 * Detect a change in post type status, and initiate an activity update if necessary. 772 * 773 * @since BuddyPress (2.2.0) 774 * 775 * @todo Support untrashing better 776 * 777 * @param string $new_status New status for the post. 778 * @param string $old_status Old status for the post. 779 * @param object $post Post data. 780 */ 781 function bp_activity_catch_transition_post_type_status( $new_status, $old_status, $post ) { 782 if ( ! post_type_supports( $post->post_type, 'buddypress-activity' ) ) { 783 return; 784 } 785 786 // This is an edit 787 if ( $new_status === $old_status ) { 788 if ( $new_status == 'publish' ) { 789 // Update the post type 790 bp_activity_post_type_update( $post ); 791 return; 792 } 793 } 794 795 // Publishing a previously unpublished post 796 if ( 'publish' === $new_status ) { 797 // Untrashing the post type 798 // Nothing here yet 799 if ( 'trash' == $old_status ) { 800 do_action( 'bp_activity_post_type_untrash_' . $post->post_type, $post ); 801 } else { 802 // Record the post type 803 bp_activity_post_type_publish( $post->ID, $post ); 804 } 805 806 // Unpublishing a previously published post 807 } else if ( 'publish' === $old_status ) { 808 // Some form of pending status 809 // Only remove the activity entry 810 bp_activity_post_type_unpublish( $post->ID, $post ); 811 } 812 } 813 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..4386b28 100644
function bp_activity_admin_get_activity_actions() { 798 798 $actions = array(); 799 799 800 800 // Walk through the registered actions, and build an array of actions/values. 801 foreach ( b uddypress()->activity->actionsas $action ) {801 foreach ( bp_activity_get_actions() as $action ) { 802 802 $action = array_values( (array) $action ); 803 803 804 804 for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) { … … function bp_activity_admin_edit_metabox_type( $item ) { 831 831 $selected = $item->type; 832 832 833 833 // Walk through the registered actions, and build an array of actions/values. 834 foreach ( $bp->activity->actionsas $action ) {834 foreach ( bp_activity_get_actions() as $action ) { 835 835 $action = array_values( (array) $action ); 836 836 837 837 for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) … … class BP_Activity_List_Table extends WP_List_Table { 1365 1365 $selected = ( ! empty( $_REQUEST['activity_type'] ) ) ? $_REQUEST['activity_type'] : ''; 1366 1366 1367 1367 // Get the actions 1368 $activity_actions = b uddypress()->activity->actions; ?>1368 $activity_actions = bp_activity_get_actions(); ?> 1369 1369 1370 1370 <div class="alignleft actions"> 1371 1371 <select name="activity_type"> -
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..d33c2d7 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; 374 375 } 375 376 376 377 /** 378 * Set tracking arguments for a given post type 379 * 380 * @since BuddyPress (2.2.0) 381 * 382 * @global $wp_post_types 383 * @param string $post_type the name of the post type eg: 'post' or 'page' 384 * @param array $args an associative array of tracking args to set 385 * eg : array( 'component_id' => 'blogs' ) 386 */ 387 function bp_activity_set_post_type_tracking_args( $post_type = '', $args = array() ) { 388 global $wp_post_types; 389 $bp = buddypress(); 390 391 if ( empty( $wp_post_types[ $post_type ] ) || ! post_type_supports( $post_type, 'buddypress-activity' ) || ! is_array( $args ) ) { 392 return false; 393 } 394 395 /** 396 * Set the labels 397 */ 398 if ( ! empty( $args['bp_activity_admin_filter'] ) ) { 399 $wp_post_types[ $post_type ]->labels->bp_activity_admin_filter = $args['bp_activity_admin_filter']; 400 unset( $args['bp_activity_admin_filter'] ); 401 } 402 403 if ( ! empty( $args['bp_activity_front_filter'] ) ) { 404 $wp_post_types[ $post_type ]->labels->bp_activity_front_filter = $args['bp_activity_front_filter']; 405 unset( $args['bp_activity_front_filter'] ); 406 } 407 408 if ( ! empty( $args['bp_activity_new_post'] ) ) { 409 $wp_post_types[ $post_type ]->labels->bp_activity_new_post = $args['bp_activity_new_post']; 410 unset( $args['bp_activity_new_post'] ); 411 } 412 413 if ( ! empty( $args['bp_activity_new_post_ms'] ) ) { 414 $wp_post_types[ $post_type ]->labels->bp_activity_new_post_ms = $args['bp_activity_new_post_ms']; 415 unset( $args['bp_activity_new_post_ms'] ); 416 } 417 418 /** 419 * If the array is not empty, put the args in the bp_activity attribute of the post type 420 */ 421 if ( ! empty( $args ) ) { 422 $wp_post_types[ $post_type ]->bp_activity = $args; 423 } 424 } 425 426 /** 427 * Get tracking arguments for a specific post type 428 * 429 * @since BuddyPress (2.2.0) 430 * 431 * @param string $post_type name of the post type 432 * @uses get_post_type_object() to get the labels and the attributes of the post type 433 * @return object the tracking arguments of the post type 434 */ 435 function bp_activity_get_post_type_tracking_args( $post_type = '' ) { 436 if ( ! post_type_supports( $post_type, 'buddypress-activity' ) ) { 437 return false; 438 } 439 440 $post_type_object = get_post_type_object( $post_type ); 441 442 $post_type_activity = array( 443 'component_id' => buddypress()->activity->id, 444 'action_id' => 'new_' . $post_type, 445 'format_callback' => 'bp_activity_format_activity_action_custom_post_type_post', 446 'front_filter' => $post_type_object->labels->name, 447 'contexts' => array( 'activity' ), 448 'position' => 0, 449 'singular' => strtolower( $post_type_object->labels->singular_name ), 450 'activity_commment' => ! post_type_supports( $post_type, 'comments' ), 451 ); 452 453 if ( ! empty( $post_type_object->bp_activity ) ) { 454 $post_type_activity = bp_parse_args( (array) $post_type_object->bp_activity, $post_type_activity, $post_type . '_tracking_args' ); 455 } 456 457 $post_type_activity = (object) $post_type_activity; 458 459 // Try to get the admin filter in the post type labels 460 if ( ! empty( $post_type_object->labels->bp_activity_admin_filter ) ) { 461 $post_type_activity->admin_filter = $post_type_object->labels->bp_activity_admin_filter; 462 463 // Fallback to a generic one 464 } else { 465 $post_type_activity->admin_filter = sprintf( 466 _x( 'New %s published', 'Post Type generic activity post admin filter', 'buddypress' ), 467 strtolower( $post_type_object->labels->singular_name ) 468 ); 469 } 470 471 // Check for the front filter in the post type labels 472 if ( ! empty( $post_type_object->labels->bp_activity_front_filter ) ) { 473 $post_type_activity->front_filter = $post_type_object->labels->bp_activity_front_filter; 474 } 475 476 // Try to get the action for new post type action on regular sites 477 if ( ! empty( $post_type_object->labels->bp_activity_new_post ) ) { 478 $post_type_activity->new_post_type_action = $post_type_object->labels->bp_activity_new_post; 479 } 480 481 // Try to get the action for new post type action on multisites 482 if ( ! empty( $post_type_object->labels->bp_activity_new_post_ms ) ) { 483 $post_type_activity->new_post_type_action_ms = $post_type_object->labels->bp_activity_new_post_ms; 484 } 485 486 return apply_filters( 'bp_activity_get_post_type_tracking_args', $post_type_activity, $post_type ); 487 } 488 489 /** 490 * Get all post types tracking arguments 491 * 492 * @since BuddyPress (2.2.0) 493 * 494 * @uses get_post_types() to fetch the public post types 495 * @uses bp_activity_get_post_type_tracking_args() to get the tracking args for a specific post type 496 * @return array() the list of post types with their tracking arguments 497 */ 498 function bp_activity_get_post_types_tracking_args() { 499 // Fetch all public post types 500 $post_types = get_post_types( array( 'public' => true ), 'names' ); 501 502 $post_types_tracking_args = array(); 503 504 foreach ( $post_types as $post_type ) { 505 $track_post_type = bp_activity_get_post_type_tracking_args( $post_type ); 506 507 if ( ! empty( $track_post_type ) ) { 508 $post_types_tracking_args[ $track_post_type->action_id ] = $track_post_type; 509 } 510 511 } 512 513 return apply_filters( 'bp_activity_get_post_types_tracking_args', $post_types_tracking_args ); 514 } 515 516 /** 517 * Get all components activity actions sorted by their position attribute 518 * 519 * @since BuddyPress (2.2.0) 520 * 521 * @uses bp_activity_get_post_types_tracking_args() to get all post types tracking args 522 * @uses bp_activity_set_action() to set the post types activity actions 523 * @return object actions ordered by their position 524 */ 525 function bp_activity_get_actions() { 526 $bp = buddypress(); 527 528 $post_types = bp_activity_get_post_types_tracking_args(); 529 530 // Create the actions for the post types 531 if ( ! empty( $post_types ) ) { 532 foreach ( $post_types as $post_type ) { 533 bp_activity_set_action( 534 $post_type->component_id, 535 $post_type->action_id, 536 $post_type->admin_filter, 537 $post_type->format_callback, 538 $post_type->front_filter, 539 $post_type->contexts, 540 $post_type->position 541 ); 542 } 543 } 544 545 // Sort the actions by their position inside each component 546 foreach ( $bp->activity->actions as $component => $actions ) { 547 $temp = array(); 548 549 foreach( $actions as $key => $params ) { 550 if ( empty( $temp[ $params['position'] ] ) ) { 551 $temp[ $params['position'] ] = $params; 552 } else { 553 // increase numbers here to fit new items in. 554 do { 555 $params['position']++; 556 } while ( ! empty( $temp[ $params['position'] ] ) ); 557 558 $temp[ $params['position'] ] = $params; 559 } 560 561 unset( $bp->activity->actions->{$component}->{$key} ); 562 ksort( $temp ); 563 } 564 565 // Restore keys 566 foreach ( $temp as $key_ordered ) { 567 $bp->activity->actions->{$component}->{$key_ordered['key']} = $key_ordered; 568 } 569 } 570 571 return $bp->activity->actions; 572 } 573 574 /** 377 575 * Retreive the current action from a component and key. 378 576 * 379 577 * @since BuddyPress (1.1.0) … … function bp_activity_get_action( $component_id, $key ) { 391 589 return false; 392 590 } 393 591 394 $bp = buddypress(); 395 $retval = isset( $bp->activity->actions->{$component_id}->{$key} ) 396 ? $bp->activity->actions->{$component_id}->{$key} 592 $bp = buddypress(); 593 $actions = bp_activity_get_actions(); 594 $retval = isset( $actions->{$component_id}->{$key} ) 595 ? $actions->{$component_id}->{$key} 397 596 : false; 398 597 399 598 /** … … function bp_activity_get_types() { 419 618 $actions = array(); 420 619 421 620 // Walk through the registered actions, and build an array of actions/values. 422 foreach ( b uddypress()->activity->actionsas $action ) {621 foreach ( bp_activity_get_actions() as $action ) { 423 622 $action = array_values( (array) $action ); 424 623 425 624 for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) { … … function bp_activity_format_activity_action_activity_comment( $action, $activity 1130 1329 return apply_filters( 'bp_activity_comment_action', $action, $activity ); 1131 1330 } 1132 1331 1332 /** 1333 * Format custom post type activity post actions. 1334 * 1335 * @since BuddyPress (2.2.0) 1336 * 1337 * @param string $action Static activity action. 1338 * @param object $activity Activity data object. 1339 * @uses bp_activity_get_post_types_tracking_args() to get all post types tracking args 1340 * @return string 1341 */ 1342 function bp_activity_format_activity_action_custom_post_type_post( $action, $activity ) { 1343 $bp = buddypress(); 1344 1345 // Fetch all the tracked post types once 1346 if ( empty( $bp->activity->track ) ) { 1347 $bp->activity->track = bp_activity_get_post_types_tracking_args(); 1348 } 1349 1350 if ( empty( $activity->type ) || empty( $bp->activity->track[ $activity->type ] ) ) { 1351 return $action; 1352 } 1353 1354 $user_link = bp_core_get_userlink( $activity->user_id ); 1355 $blog_url = get_home_url( $activity->item_id ); 1356 1357 if ( empty( $activity->post_url ) ) { 1358 $post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) ); 1359 } else { 1360 $post_url = $activity->post_url; 1361 } 1362 1363 $post_link = '<a href="' . $post_url . '">' . $bp->activity->track[ $activity->type ]->singular . '</a>'; 1364 1365 if ( ! empty( $bp->activity->track[ $activity->type ]->new_post_type_action ) ) { 1366 $action = sprintf( $bp->activity->track[ $activity->type ]->new_post_type_action, $user_link, $post_url ); 1367 } else { 1368 $action = sprintf( _x( '%1$s wrote a new %2$s', 'Activity Custom Post Type post action', 'buddypress' ), $user_link, $post_link ); 1369 } 1370 1371 if ( is_multisite() ) { 1372 $blog_link = '<a href="' . $blog_url . '">' . get_blog_option( $activity->item_id, 'blogname' ) . '</a>'; 1373 1374 if ( ! empty( $bp->activity->track[ $activity->type ]->new_post_type_action_ms ) ) { 1375 $action = sprintf( $bp->activity->track[ $activity->type ]->new_post_type_action_ms, $user_link, $post_url, $blog_link ); 1376 } else { 1377 $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 ); 1378 } 1379 } 1380 1381 /** 1382 * Filters the formatted custom post type activity post action string. 1383 * 1384 * @since BuddyPress (2.2.0) 1385 * 1386 * @param string $action Activity action string value. 1387 * @param BP_Activity_Activity $activity Activity item object. 1388 */ 1389 return apply_filters( 'bp_activity_custom_post_type_post_action', $action, $activity ); 1390 } 1391 1133 1392 /****************************************************************************** 1134 1393 * Business functions are where all the magic happens in BuddyPress. They will 1135 1394 * handle the actual saving or manipulation of information. Usually they will … … function bp_activity_post_update( $args = '' ) { 1513 1772 } 1514 1773 1515 1774 /** 1775 * Publish an activity for the post type. 1776 * 1777 * @since BuddyPress (2.2.0) 1778 * 1779 * @param int $post_id 1780 * @param WP_Post $post 1781 * @param int $user_id 1782 * @uses bp_activity_get_post_type_tracking_args() to get the tracking args for the post type being published 1783 */ 1784 function bp_activity_post_type_publish( $post_id = 0, $post = null, $user_id = 0 ) { 1785 $bp = buddypress(); 1786 1787 if ( ! is_a( $post, 'WP_Post' ) ) { 1788 return; 1789 } 1790 1791 // Get the post type tracking args 1792 $activity_post_object = bp_activity_get_post_type_tracking_args( $post->post_type ); 1793 1794 if ( 'publish' != $post->post_status || ! empty( $post->post_password ) || empty( $activity_post_object->action_id ) ) { 1795 return; 1796 } 1797 1798 if ( empty( $post_id ) ) { 1799 $post_id = $post->ID; 1800 } 1801 1802 $blog_id = get_current_blog_id(); 1803 1804 if ( empty( $user_id ) ) { 1805 $user_id = (int) $post->post_author; 1806 } 1807 1808 $existing = bp_activity_get( array( 1809 'filter' => array( 1810 'action' => $activity_post_object->action_id, 1811 'primary_id' => $blog_id, 1812 'secondary_id' => $post_id, 1813 ) 1814 ) ); 1815 1816 // Leave Components/plugins bail before the activity is posted 1817 if ( ! empty( $existing['activities'] ) || false === apply_filters( "bp_activity_{$post->post_type}_pre_publish", true, $blog_id, $post_id, $user_id ) ) { 1818 return; 1819 } 1820 1821 // Record this in activity streams 1822 $blog_url = get_home_url( $blog_id ); 1823 $post_url = add_query_arg( 1824 'p', 1825 $post_id, 1826 trailingslashit( $blog_url ) 1827 ); 1828 1829 /** 1830 * As the 'post' post type will no more use bp_blogs_record_post(), we need to be sure the filters 1831 * - 'bp_blogs_activity_new_post_content' can be applied on the content. 1832 * - 'bp_blogs_activity_new_post_primary_link' can be applied on the primary_link. 1833 */ 1834 if ( 'blogs' == $activity_post_object->component_id ) { 1835 $activity_content = apply_filters( 'bp_blogs_activity_new_post_content', $post->post_content, $post, $post_url, $post->post_type ); 1836 $activity_primary_link = apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_url, $post_id, $post->post_type ); 1837 } else { 1838 $activity_content = $post->post_content; 1839 $activity_primary_link = $post_url; 1840 } 1841 1842 $activity_args = array( 1843 'user_id' => $user_id, 1844 'content' => $activity_content, 1845 'primary_link' => $activity_primary_link, 1846 'component' => $activity_post_object->component_id, 1847 'type' => $activity_post_object->action_id, 1848 'item_id' => $blog_id, 1849 'secondary_item_id' => $post_id, 1850 'recorded_time' => $post->post_date_gmt, 1851 ); 1852 1853 // Remove large images and replace them with just one image thumbnail 1854 if ( ! empty( $activity_args['content'] ) ) { 1855 $activity_args['content'] = bp_activity_thumbnail_content_images( $activity_args['content'], $activity_args['primary_link'], $activity_args ); 1856 } 1857 1858 if ( ! empty( $activity_args['content'] ) ) { 1859 // Create the excerpt 1860 $activity_excerpt = bp_create_excerpt( $activity_args['content'] ); 1861 1862 /** 1863 * As the 'post' post type will not use bp_blogs_record_activity(), we need to be sure the filter 1864 * 'bp_blogs_record_activity_content' can be applied on the action. 1865 */ 1866 if ( 'blogs' == $activity_post_object->component_id ) { 1867 $activity_args['content'] = apply_filters( 'bp_blogs_record_activity_content', $activity_excerpt, $activity_args['content'], $activity_args, $post->post_type ); 1868 } else { 1869 $activity_args['content'] = $activity_excerpt; 1870 } 1871 } 1872 1873 // Setup the action by using the format functions 1874 $action_args = array_merge( $activity_args, array( 1875 'post_title' => $post->post_title, 1876 'post_url' => $post_url, 1877 ) ); 1878 1879 $activity_args['action'] = call_user_func_array( $activity_post_object->format_callback, array( '', (object) $action_args ) ); 1880 1881 // Make sure the action is set 1882 if ( empty( $activity_args['action'] ) ) { 1883 return; 1884 } else { 1885 /** 1886 * As the 'post' post type will not use bp_blogs_record_activity(), we need to be sure the filter 1887 * 'bp_blogs_record_activity_action' can be applied on the action. 1888 */ 1889 if ( 'blogs' == $activity_post_object->component_id ) { 1890 $activity_args['action'] = apply_filters( 'bp_blogs_record_activity_action', $activity_args['action'] ); 1891 } 1892 } 1893 1894 do_action( 'bp_activity_post_type_published', bp_activity_add( $activity_args ), $post, $action_args ); 1895 } 1896 1897 /** 1898 * Update an activity for the custom post type. 1899 * 1900 * @since BuddyPress (2.2.0) 1901 * 1902 * @param WP_Post $post 1903 * @uses bp_activity_get_post_type_tracking_args() to get the tracking args for the post type being updated 1904 */ 1905 function bp_activity_post_type_update( $post = null ) { 1906 $bp = buddypress(); 1907 1908 if ( ! is_a( $post, 'WP_Post' ) ) { 1909 return; 1910 } 1911 1912 // Get the post type tracking args 1913 $activity_post_object = bp_activity_get_post_type_tracking_args( $post->post_type ); 1914 1915 if ( empty( $activity_post_object->action_id ) ) { 1916 return; 1917 } 1918 1919 $activity_id = bp_activity_get_activity_id( array( 1920 'component' => $activity_post_object->component_id, 1921 'item_id' => get_current_blog_id(), 1922 'secondary_item_id' => $post->ID, 1923 'type' => $activity_post_object->action_id, 1924 ) ); 1925 1926 // activity ID doesn't exist, so stop! 1927 if ( empty( $activity_id ) ) { 1928 return; 1929 } 1930 1931 // Delete the activity if the post was updated with a password 1932 if ( ! empty( $post->post_password ) ) { 1933 bp_activity_delete( array( 'id' => $activity_id ) ); 1934 } 1935 1936 // update the activity entry 1937 $activity = new BP_Activity_Activity( $activity_id ); 1938 1939 if ( ! empty( $post->post_content ) ) { 1940 // Make sure to update the thumbnail image 1941 $post_content = bp_activity_thumbnail_content_images( $post->post_content, $activity->primary_link, (array) $activity ); 1942 1943 // apply the excerpt 1944 $activity_excerpt = bp_create_excerpt( $post_content ); 1945 1946 /** 1947 * As the 'post' post type will no more use bp_blogs_update_post(), we need to be sure the filter 1948 * 'bp_blogs_record_activity_content' can be applied on the action. 1949 */ 1950 if ( 'blogs' == $activity_post_object->component_id ) { 1951 $activity->content = apply_filters( 'bp_blogs_record_activity_content', $activity_excerpt, $post_content, (array) $activity, $post->post_type ); 1952 } else { 1953 $activity->content = $activity_excerpt; 1954 } 1955 } 1956 1957 // Save the updated activity 1958 $activity->save(); 1959 1960 do_action( 'bp_activity_post_type_updated', $post, $activity ); 1961 } 1962 1963 /** 1964 * Unpublish an activity for the custom post type. 1965 * 1966 * @since BuddyPress (2.2.0) 1967 * 1968 * @param int $post_id 1969 * @param WP_Post $post 1970 * @uses bp_activity_get_post_type_tracking_args() to get the tracking args for the post type being unpublished 1971 */ 1972 function bp_activity_post_type_unpublish( $post_id = 0, $post = null ) { 1973 $bp = buddypress(); 1974 1975 if ( ! is_a( $post, 'WP_Post' ) ) { 1976 return; 1977 } 1978 1979 // Get the post type tracking args 1980 $activity_post_object = bp_activity_get_post_type_tracking_args( $post->post_type ); 1981 1982 if ( empty( $activity_post_object->action_id ) ) { 1983 return; 1984 } 1985 1986 if ( empty( $post_id ) ) { 1987 $post_id = $post->ID; 1988 } 1989 1990 $delete_activity_args = array( 1991 'item_id' => get_current_blog_id(), 1992 'secondary_item_id' => $post_id, 1993 'component' => $activity_post_object->component_id, 1994 'type' => $activity_post_object->action_id, 1995 'user_id' => false, 1996 ); 1997 1998 do_action( 'bp_activity_post_type_unpublished', bp_activity_delete_by_item_id( $delete_activity_args ), $delete_activity_args, $post ); 1999 } 2000 2001 /** 1516 2002 * Add an activity comment. 1517 2003 * 1518 2004 * @since BuddyPress (1.2.0) … … function bp_activity_delete_comment( $activity_id, $comment_id ) { 1988 2474 * @return string $link Permalink for the activity item. 1989 2475 */ 1990 2476 function bp_activity_get_permalink( $activity_id, $activity_obj = false ) { 2477 $bp = buddypress(); 1991 2478 1992 2479 if ( empty( $activity_obj ) ) { 1993 2480 $activity_obj = new BP_Activity_Activity( $activity_id ); … … function bp_activity_get_permalink( $activity_id, $activity_obj = false ) { 1997 2484 $activity_obj = $activity_obj->current_comment; 1998 2485 } 1999 2486 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 ) { 2487 $use_primary_links = array( 2488 'new_blog_post', 2489 'new_blog_comment', 2490 'new_forum_topic', 2491 'new_forum_post', 2492 ); 2493 2494 if ( ! empty( $bp->activity->track ) ) { 2495 $use_primary_links = array_merge( $use_primary_links, array_keys( $bp->activity->track ) ); 2496 } 2497 2498 if ( false !== array_search( $activity_obj->type, $use_primary_links ) ) { 2001 2499 $link = $activity_obj->primary_link; 2002 2500 } else { 2003 2501 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..9035a86 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; 3340 3329 } 3341 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 } 3346 } 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 = '' ) { 4367 4375 4368 4376 // Walk through the registered actions, and prepare an the 4369 4377 // select box options. 4370 foreach ( b uddypress()->activity->actionsas $actions ) {4378 foreach ( bp_activity_get_actions() as $actions ) { 4371 4379 foreach ( $actions as $action ) { 4372 4380 if ( ! in_array( $context, (array) $action['context'] ) ) { 4373 4381 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..40e14e9 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_get_post_type_tracking_args', array( $this, 'post_tracking_args' ), 10, 2 ); 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 tracking arguments for the 'post' post type 270 * 271 * @since BuddyPress (2.2.0) 272 */ 273 public function post_tracking_args( $params = array(), $post_type = 0 ) { 274 if ( 'post' != $post_type ) { 275 return $params; 276 } 277 278 // Set specific params for the 'post' post type 279 $params->component_id = $this->id; 280 $params->action_id = 'new_blog_post'; 281 $params->admin_filter = __( 'New post published', 'buddypress' ); 282 $params->format_callback = 'bp_blogs_format_activity_action_new_blog_post'; 283 $params->front_filter = __( 'Posts', 'buddypress' ); 284 $params->contexts = array( 'activity', 'member' ); 285 $params->position = 5; 286 287 return $params; 288 } 249 289 } 250 290 251 291 /** -
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..799a8fe 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_catch_transition_post_type_status 22 * @group activity_tracking 23 */ 24 public function test_bp_activity_catch_transition_post_type_status_publish() { 25 $bp = buddypress(); 26 27 register_post_type( 'foo', array( 28 'label' => 'foo', 29 'public' => true, 30 'supports' => array( 'buddypress-activity' ), 31 ) ); 32 33 $post_id = $this->factory->post->create( array( 34 'post_status' => 'publish', 35 'post_type' => 'foo', 36 ) ); 37 38 $post = get_post( $post_id ); 39 40 // 'new' => 'publish' 41 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 42 43 _unregister_post_type( 'foo' ); 44 45 // Reset globals 46 unset( $bp->activity->actions->activity->new_foo ); 47 $bp->activity->track = array(); 48 } 49 50 /** 51 * @group bp_activity_catch_transition_post_type_status 52 * @group activity_tracking 53 */ 54 public function test_bp_activity_catch_transition_post_type_status_publish_to_publish() { 55 $bp = buddypress(); 56 57 register_post_type( 'foo', array( 58 'label' => 'foo', 59 'public' => true, 60 'supports' => array( 'buddypress-activity' ), 61 ) ); 62 63 $post_id = $this->factory->post->create( array( 64 'post_status' => 'publish', 65 'post_type' => 'foo', 66 ) ); 67 68 $post = get_post( $post_id ); 69 70 // 'new' => 'publish' 71 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 72 73 // Delete the activity 74 bp_activity_post_type_unpublish( $post_id, $post ); 75 76 $post->post_status = 'publish'; 77 $post->post_content .= ' foo'; 78 79 wp_update_post( $post ); 80 81 $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Updating a post type should not create a new activity' ); 82 83 _unregister_post_type( 'foo' ); 84 85 // Reset globals 86 unset( $bp->activity->actions->activity->new_foo ); 87 $bp->activity->track = array(); 88 } 89 90 /** 91 * @group bp_activity_catch_transition_post_type_status 92 * @group activity_tracking 93 */ 94 public function test_bp_activity_catch_transition_post_type_status_publish_password() { 95 $bp = buddypress(); 96 97 register_post_type( 'foo', array( 98 'label' => 'foo', 99 'public' => true, 100 'supports' => array( 'buddypress-activity' ), 101 ) ); 102 103 $post_id = $this->factory->post->create( array( 104 'post_status' => 'publish', 105 'post_type' => 'foo', 106 ) ); 107 108 $post = get_post( $post_id ); 109 110 // 'new' => 'publish' 111 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 112 113 $post->post_status = 'publish'; 114 $post->post_password = 'foo'; 115 116 wp_update_post( $post ); 117 118 // 'publish' => 'publish' (password protected) 119 $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Password protected post type should not have activity' ); 120 121 _unregister_post_type( 'foo' ); 122 123 // Reset globals 124 unset( $bp->activity->actions->activity->new_foo ); 125 $bp->activity->track = array(); 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_trash() { 133 $bp = buddypress(); 134 135 register_post_type( 'foo', array( 136 'label' => 'foo', 137 'public' => true, 138 'supports' => array( 'buddypress-activity' ), 139 ) ); 140 141 $post_id = $this->factory->post->create( array( 142 'post_status' => 'publish', 143 'post_type' => 'foo', 144 ) ); 145 146 $post = get_post( $post_id ); 147 148 // 'new' => 'publish' 149 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 150 151 wp_trash_post( $post->ID ); 152 153 // 'publish' => 'publish' (password protected) 154 $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Unpublished post type should not have activity' ); 155 156 _unregister_post_type( 'foo' ); 157 158 // Reset globals 159 unset( $bp->activity->actions->activity->new_foo ); 160 $bp->activity->track = array(); 161 } 162 163 protected function activity_exists_for_post( $post_id, $action ) { 164 $a = bp_activity_get( array( 165 'action' => $action, 166 'item_id' => get_current_blog_id(), 167 'secondary_item_id' => $post_id, 168 ) ); 169 170 return ! empty( $a['activities'] ); 171 } 172 } -
tests/phpunit/testcases/activity/functions.php
diff --git tests/phpunit/testcases/activity/functions.php tests/phpunit/testcases/activity/functions.php index 6cea6bd..8e8cade 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 // Build the actions to fetch the tracking args 597 bp_activity_get_actions(); 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' => 'activity', 607 'type' => 'new_foo', 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 . '">foo</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 626 // Reset globals 627 unset( $bp->activity->actions->activity->new_foo ); 628 $bp->activity->track = array(); 629 } 630 631 /** 632 * @group activity_action 633 * @group bp_activity_format_activity_action_custom_post_type_post_ms 634 * @group activity_tracking 635 */ 636 public function test_bp_activity_format_activity_action_custom_post_type_post_ms() { 637 if ( ! is_multisite() ) { 638 return; 639 } 640 641 $bp = buddypress(); 642 643 $b = $this->factory->blog->create(); 644 $u = $this->factory->user->create(); 645 646 switch_to_blog( $b ); 647 648 register_post_type( 'foo', array( 649 'label' => 'foo', 650 'public' => true, 651 'supports' => array( 'buddypress-activity' ), 652 ) ); 653 654 // Build the actions to fetch the tracking args 655 bp_activity_get_actions(); 656 657 $p = $this->factory->post->create( array( 658 'post_author' => $u, 659 'post_type' => 'foo', 660 ) ); 661 662 $activity_args = array( 663 'component' => 'activity', 664 'type' => 'new_foo', 665 'user_id' => $u, 666 'item_id' => $b, 667 'secondary_item_id' => $p, 668 ); 669 670 _unregister_post_type( 'foo' ); 671 bp_activity_get_actions(); 672 673 restore_current_blog(); 674 675 $a = $this->factory->activity->create( $activity_args ); 676 677 $a_obj = new BP_Activity_Activity( $a ); 678 679 $user_link = bp_core_get_userlink( $u ); 680 $blog_url = get_blog_option( $a_obj->item_id, 'home' ); 681 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) ); 682 683 $post_link = '<a href="' . $post_url . '">foo</a>'; 684 685 $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>' ); 686 687 $this->assertSame( $expected, $a_obj->action ); 688 689 // Reset globals 690 unset( $bp->activity->actions->activity->new_foo ); 691 $bp->activity->track = array(); 692 } 693 694 /** 695 * @group activity_action 696 * @group bp_activity_format_activity_action_custom_post_type_post 697 * @group activity_tracking_imath 698 */ 699 public function test_bp_activity_format_activity_action_custom_string_post_type_post_nonms() { 700 if ( is_multisite() ) { 701 return; 702 } 703 704 $bp = buddypress(); 705 706 $labels = array( 707 'name' => 'bars', 708 'singular_name' => 'bar', 709 'bp_activity_new_post' => '%1$s shared a new <a href="%2$s">bar</a>', 710 ); 711 712 register_post_type( 'foo', array( 713 'labels' => $labels, 714 'public' => true, 715 'supports' => array( 'buddypress-activity' ), 716 'bp_activity' => array( 717 'action_id' => 'foo_bar', 718 ), 719 ) ); 720 721 // Build the actions to fetch the tracking args 722 bp_activity_get_actions(); 723 724 $u = $this->factory->user->create(); 725 $p = $this->factory->post->create( array( 726 'post_author' => $u, 727 'post_type' => 'foo', 728 ) ); 729 730 $a = $this->factory->activity->create( array( 731 'component' => 'activity', 732 'type' => 'foo_bar', 733 'user_id' => $u, 734 'item_id' => 1, 735 'secondary_item_id' => $p, 736 ) ); 737 738 $a_obj = new BP_Activity_Activity( $a ); 739 740 $user_link = bp_core_get_userlink( $u ); 741 $blog_url = get_home_url(); 742 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) ); 743 744 $expected = sprintf( '%1$s shared a new <a href="%2$s">bar</a>', $user_link, $post_url ); 745 746 $this->assertSame( $expected, $a_obj->action ); 747 748 _unregister_post_type( 'foo' ); 749 750 // Reset globals 751 unset( $bp->activity->actions->activity->foo_bar ); 752 $bp->activity->track = array(); 753 } 754 755 /** 756 * @group activity_action 757 * @group bp_activity_format_activity_action_custom_post_type_post_ms 758 * @group activity_tracking 759 */ 760 public function test_bp_activity_format_activity_action_custom_string_post_type_post_ms() { 761 if ( ! is_multisite() ) { 762 return; 763 } 764 765 $bp = buddypress(); 766 $reset = $bp->activity->actions; 767 768 $b = $this->factory->blog->create(); 769 $u = $this->factory->user->create(); 770 771 switch_to_blog( $b ); 772 773 $labels = array( 774 'name' => 'bars', 775 'singular_name' => 'bar', 776 'bp_activity_new_post_ms' => '%1$s shared a new <a href="%2$s">bar</a>, on the site %3$s', 777 ); 778 779 register_post_type( 'foo', array( 780 'labels' => $labels, 781 'public' => true, 782 'supports' => array( 'buddypress-activity' ), 783 ) ); 784 785 // Build the actions to fetch the tracking args 786 bp_activity_get_actions(); 787 788 $p = $this->factory->post->create( array( 789 'post_author' => $u, 790 'post_type' => 'foo', 791 ) ); 792 793 $activity_args = array( 794 'component' => 'activity', 795 'type' => 'new_foo', 796 'user_id' => $u, 797 'item_id' => $b, 798 'secondary_item_id' => $p, 799 ); 800 801 _unregister_post_type( 'foo' ); 802 803 restore_current_blog(); 804 805 $a = $this->factory->activity->create( $activity_args ); 806 807 $a_obj = new BP_Activity_Activity( $a ); 808 809 $user_link = bp_core_get_userlink( $u ); 810 $blog_url = get_blog_option( $a_obj->item_id, 'home' ); 811 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) ); 812 813 $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>' ); 814 815 $this->assertSame( $expected, $a_obj->action ); 816 817 // Reset globals 818 unset( $bp->activity->actions->activity->new_foo ); 819 $bp->activity->track = array(); 820 } 821 822 /** 823 * @group bp_activity_set_post_type_tracking_args 824 * @group activity_tracking 825 */ 826 public function test_bp_activity_set_post_type_tracking_args() { 827 $bp = buddypress(); 828 829 add_post_type_support( 'page', 'buddypress-activity' ); 830 831 bp_activity_set_post_type_tracking_args( 'page', array( 832 'component_id' => $bp->blogs->id, 833 'dummy' => 'dummy value', 834 ) ); 835 836 // Build the actions to fetch the tracking args 837 bp_activity_get_actions(); 838 839 $u = $this->factory->user->create(); 840 841 $post_id = $this->factory->post->create( array( 842 'post_author' => $u, 843 'post_status' => 'publish', 844 'post_type' => 'page', 845 ) ); 846 847 $a = bp_activity_get( array( 848 'action' => 'new_page', 849 'item_id' => get_current_blog_id(), 850 'secondary_item_id' => $post_id, 851 ) ); 852 853 $this->assertSame( $bp->blogs->id, $a['activities'][0]->component ); 854 855 remove_post_type_support( 'page', 'buddypress-activity' ); 856 857 // Reset globals 858 unset( $bp->activity->actions->blogs->new_page ); 859 $bp->activity->track = array(); 860 } 861 862 /** 579 863 * @group bp_activity_new_comment 580 864 * @group cache 581 865 */ -
tests/phpunit/testcases/blogs/activity.php
diff --git tests/phpunit/testcases/blogs/activity.php tests/phpunit/testcases/blogs/activity.php index cc16b1f..e67adab 100644
2 2 3 3 class BP_Tests_Blogs_Activity extends BP_UnitTestCase { 4 4 /** 5 * @group bp_blogs_register_activity_actions 6 * @group activity_tracking 7 */ 8 public function test_bp_blogs_loader_post_tracking_args_filter() { 9 $bp = buddypress(); 10 11 $expected = array( 'new_blog_post', 'new_blog_comment' ); 12 13 if ( is_multisite() ) { 14 $expected = array_merge( array( 'new_blog' ), $expected ); 15 } 16 17 $actions = bp_activity_get_actions(); 18 $actions = array_keys( (array) $actions->blogs ); 19 20 $this->assertEquals( $expected, $actions ); 21 } 22 23 /** 5 24 * @group activity_action 6 25 * @group bp_blogs_format_activity_action_new_blog 7 26 */ -
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,