Ticket #5938: bp-activity-functions-5938.diff
File bp-activity-functions-5938.diff, 20.5 KB (added by , 10 years ago) |
---|
-
src/bp-activity/bp-activity-functions.php
45 45 * @return bool $retval True to enable mentions, false to disable. 46 46 */ 47 47 function bp_activity_do_mentions() { 48 49 /** 50 * Filters whether or not mentions are enabled. 51 * 52 * @since BuddyPress (1.8.0) 53 * 54 * @param bool $enabled The enabled status of mentions. 55 */ 48 56 return (bool) apply_filters( 'bp_activity_do_mentions', true ); 49 57 } 50 58 … … 61 69 bp_is_user_active() && 62 70 ( bp_is_activity_component() || bp_is_blog_page() && is_singular() && comments_open() || is_admin() ); 63 71 72 /** 73 * Filters whether or not BuddyPress should load mentions scripts and assets. 74 * 75 * @since BuddyPress (2.1.0) 76 * 77 * @param bool $retval The status of if scripts and assets should be loaded. 78 */ 64 79 return (bool) apply_filters( 'bp_activity_maybe_load_mentions_scripts', $retval ); 65 80 } 66 81 … … 333 348 $bp->activity->actions->{$component_id} = new stdClass; 334 349 } 335 350 351 /** 352 * Filters the action type being set for the current activity item. 353 * 354 * @since BuddyPress (1.1.0) 355 * 356 * @param array $array Array of arguments for action type being set. 357 * @param string $component_id ID of the current component being set. 358 * @param string $type Action type being set. 359 * @param string $description Action description for action being set. 360 * @param callable $format_callback Callback for formatting the action string. 361 * @param string $label String to describe this action in the activity stream filter dropdown. 362 * @param array $context Activity stream contexts where the filter should appear. 'activity', 'member', 'member_groups', 'group'. 363 */ 336 364 $bp->activity->actions->{$component_id}->{$type} = apply_filters( 'bp_activity_set_action', array( 337 365 'key' => $type, 338 366 'value' => $description, … … 367 395 ? $bp->activity->actions->{$component_id}->{$key} 368 396 : false; 369 397 398 /** 399 * Filters the current action by component and key. 400 * 401 * @since BuddyPress (1.1.0) 402 * 403 * @param string|bool $retval The action key. 404 * @param string $component_id The unique string ID of the component. 405 * @param string $key The action key. 406 */ 370 407 return apply_filters( 'bp_activity_get_action', $retval, $component_id, $key ); 371 408 } 372 409 … … 392 429 // This was a mis-named activity type from before BP 1.6 393 430 unset( $actions['friends_register_activity_action'] ); 394 431 432 /** 433 * Filters the available activity types. 434 * 435 * @since BuddyPress (1.7.0) 436 * 437 * @param array $actions Array of registered activity types. 438 */ 395 439 return apply_filters( 'bp_activity_get_types', $actions ); 396 440 } 397 441 … … 418 462 // Get favorites for user 419 463 $favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true ); 420 464 465 /** 466 * Filters the favorited activity items for a specified user. 467 * 468 * @since BuddyPress (1.2.0) 469 * 470 * @param array $favs Array of user's favorited activity items. 471 */ 421 472 return apply_filters( 'bp_activity_get_user_favorites', $favs ); 422 473 } 423 474 … … 473 524 // Update activity meta counts 474 525 if ( bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count ) ) { 475 526 476 // Execute additional code 527 /** 528 * Fires if bp_activity_update_meta() for favorite_count is successful and before returning a true value for success. 529 * 530 * @since BuddyPress (1.2.1) 531 * 532 * @param int $activity_id ID of the activity item being favorited. 533 * @param int $user_id ID of the user doing the favoriting. 534 */ 477 535 do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id ); 478 536 479 537 // Success … … 481 539 482 540 // Saving meta was unsuccessful for an unknown reason 483 541 } else { 484 // Execute additional code 542 543 /** 544 * Fires if bp_activity_update_meta() for favorite_count is unsuccessful and before returning a false value for failure. 545 * 546 * @since BuddyPress (1.5.0) 547 * 548 * @param int $activity_id ID of the activity item being favorited. 549 * @param int $user_id ID of the user doing the favoriting. 550 */ 485 551 do_action( 'bp_activity_add_user_favorite_fail', $activity_id, $user_id ); 486 552 487 553 return false; … … 538 604 // Update users favorites 539 605 if ( bp_update_user_meta( $user_id, 'bp_favorite_activities', $my_favs ) ) { 540 606 541 // Execute additional code 607 /** 608 * Fires if bp_update_user_meta() is successful and before returning a true value for success. 609 * 610 * @since BuddyPress (1.2.1) 611 * 612 * @param int $activity_id ID of the activity item being unfavorited. 613 * @param int $user_id ID of the user doing the unfavoriting. 614 */ 542 615 do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id ); 543 616 544 617 // Success … … 572 645 * @return int|null The ID of the located activity item. Null if none is found. 573 646 */ 574 647 function bp_activity_check_exists_by_content( $content ) { 648 649 /** 650 * Filters the results of the check for if an activity item exists by specified content. 651 * 652 * @since BuddyPress (1.1.0) 653 * 654 * @param BP_Activity_Activity $content_exists ID of the activity if found, else null. 655 */ 575 656 return apply_filters( 'bp_activity_check_exists_by_content', BP_Activity_Activity::check_exists_by_content( $content ) ); 576 657 } 577 658 … … 586 667 * @return string Date last updated. 587 668 */ 588 669 function bp_activity_get_last_updated() { 670 671 /** 672 * Filters the value for the last updated time for an activity item. 673 * 674 * @since BuddyPress (1.1.0) 675 * 676 * @param BP_Activity_Activity $last_updated Date last updated. 677 */ 589 678 return apply_filters( 'bp_activity_get_last_updated', BP_Activity_Activity::get_last_updated() ); 590 679 } 591 680 … … 676 765 $retval = get_metadata( 'activity', $activity_id, $meta_key, $single ); 677 766 remove_filter( 'query', 'bp_filter_metaid_column_name' ); 678 767 679 // Filter result before returning 768 /** 769 * Filters the metadata for a specified activity item. 770 * 771 * @since BuddyPress (1.5.0) 772 * 773 * @param mixed $retval The meta values for the activity item. 774 * @param int $activity_id ID of the activity item. 775 * @param string $meta_key Meta key for the value being requested. 776 * @param bool $single Whether to return one matched meta key row or all. 777 */ 680 778 return apply_filters( 'bp_activity_get_meta', $retval, $activity_id, $meta_key, $single ); 681 779 } 682 780 … … 757 855 // Execute additional code 758 856 do_action( 'bp_activity_remove_data', $user_id ); // Deprecated! Do not use! 759 857 760 // Use this going forward 858 /** 859 * Fires after the removal of all of a user's activity data. 860 * 861 * @since BuddyPress (1.5.0) 862 * 863 * @param int $user_id ID of the user being deleted. 864 */ 761 865 do_action( 'bp_activity_remove_all_user_data', $user_id ); 762 866 } 763 867 add_action( 'wpmu_delete_user', 'bp_activity_remove_all_user_data' ); … … 820 924 // Mark all of this user's activities as spam 821 925 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 1 WHERE user_id = %d", $user_id ) ); 822 926 823 // Call an action for plugins to use 927 /** 928 * Fires after all activity data from a user has been marked as spam. 929 * 930 * @since BuddyPress (1.6.0) 931 * 932 * @param int $user_id ID of the user whose activity is being marked as spam. 933 * @param array $activities Array of activity items being marked as spam. 934 */ 824 935 do_action( 'bp_activity_spam_all_user_data', $user_id, $activities['activities'] ); 825 936 } 826 937 add_action( 'bp_make_spam_user', 'bp_activity_spam_all_user_data' ); … … 880 991 unset( $activity_obj ); 881 992 } 882 993 883 // Mark all of this user's activities as spam994 // Mark all of this user's activities as not spam 884 995 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 0 WHERE user_id = %d", $user_id ) ); 885 996 886 // Call an action for plugins to use 997 /** 998 * Fires after all activity data from a user has been marked as ham. 999 * 1000 * @since BuddyPress (1.6.0) 1001 * 1002 * @param int $user_id ID of the user whose activity is being marked as ham. 1003 * @param array $activities Array of activity items being marked as ham. 1004 */ 887 1005 do_action( 'bp_activity_ham_all_user_data', $user_id, $activities['activities'] ); 888 1006 } 889 1007 add_action( 'bp_make_ham_user', 'bp_activity_ham_all_user_data' ); … … 913 1031 __( 'Activity Comments', 'buddypress' ) 914 1032 ); 915 1033 1034 /** 1035 * Fires at the end of the activity actions registration. 1036 * 1037 * Allows for plugin authors to add their own activity actions along side the core actions. 1038 * 1039 * @since BuddyPress (1.6.0) 1040 */ 916 1041 do_action( 'bp_activity_register_activity_actions' ); 917 1042 918 1043 // Backpat. Don't use this. … … 942 1067 // We apply the format_callback as a filter 943 1068 add_filter( 'bp_activity_generate_action_string', buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'], 10, 2 ); 944 1069 945 // Generate the action string (run through the filter defined above) 1070 /** 1071 * Filters the string for the activity action being returned. 1072 * 1073 * @since BuddyPress (2.0.0) 1074 * 1075 * @param BP_Activity_Activity $action Action string being requested. 1076 * @param BP_Activity_Activity $activity Activity item object. 1077 */ 946 1078 $action = apply_filters( 'bp_activity_generate_action_string', $activity->action, $activity ); 947 1079 948 1080 // Remove the filter for future activity items … … 962 1094 */ 963 1095 function bp_activity_format_activity_action_activity_update( $action, $activity ) { 964 1096 $action = sprintf( __( '%s posted an update', 'buddypress' ), bp_core_get_userlink( $activity->user_id ) ); 1097 1098 /** 1099 * Filters the formatted activity action update string. 1100 * 1101 * @since BuddyPress (1.2.0) 1102 * 1103 * @param string $action Activity action string value. 1104 * @param BP_Activity_Activity $activity Activity item object. 1105 */ 965 1106 return apply_filters( 'bp_activity_new_update_action', $action, $activity ); 966 1107 } 967 1108 … … 976 1117 */ 977 1118 function bp_activity_format_activity_action_activity_comment( $action, $activity ) { 978 1119 $action = sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_core_get_userlink( $activity->user_id ) ); 1120 1121 /** 1122 * Filters the formatted activity action comment string. 1123 * 1124 * @since BuddyPress (1.2.0) 1125 * 1126 * @param string $action Activity action string value. 1127 * @param BP_Activity_Activity $activity Activity item object. 1128 */ 979 1129 return apply_filters( 'bp_activity_comment_action', $action, $activity ); 980 1130 } 981 1131 … … 1084 1234 ) ); 1085 1235 } 1086 1236 1237 /** 1238 * Filters the requested activity item(s). 1239 * 1240 * @since BuddyPress (1.2.0) 1241 * 1242 * @param BP_Activity_Activity $activity Requested activity object. 1243 * @param array $r Arguments used for the activity query. 1244 */ 1087 1245 return apply_filters_ref_array( 'bp_activity_get', array( &$activity, &$r ) ); 1088 1246 } 1089 1247 … … 1131 1289 'update_meta_cache' => $r['update_meta_cache'], 1132 1290 ); 1133 1291 1292 /** 1293 * Filters the requested specific activity item. 1294 * 1295 * @since BuddyPress (1.2.0) 1296 * 1297 * @param BP_Activity_Activity $activity Requested activity object. 1298 * @param array $args Original passed in arguments. 1299 * @param array $get_args Constructed arguments used with request. 1300 */ 1134 1301 return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get( $get_args ), $args, $get_args ); 1135 1302 } 1136 1303 … … 1233 1400 } 1234 1401 1235 1402 wp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); 1403 1404 /** 1405 * Fires at the end of the execution of adding a new activity item, before the returning of the new activity item ID. 1406 * 1407 * @since BuddyPress (1.1.0) 1408 * 1409 * @param array $r Array of parsed arguments for the activity item being added. 1410 */ 1236 1411 do_action( 'bp_activity_add', $r ); 1237 1412 1238 1413 return $activity->id; … … 1279 1454 $activity_content = $r['content']; 1280 1455 $primary_link = bp_core_get_userlink( $r['user_id'], false, true ); 1281 1456 1457 /** 1458 * Filters the new activity content for current activity item. 1459 * 1460 * @since BuddyPress (1.2.0) 1461 * 1462 * @param string $activity_content Activity content posted by user. 1463 */ 1464 $add_content = apply_filters( 'bp_activity_new_update_content', $activity_content ); 1465 1466 /** 1467 * Filters the activity primary link for current activity item. 1468 * 1469 * @since BuddyPress (1.2.0) 1470 * 1471 * @param string $primary_link Link to the profile for the user who posted the activity. 1472 */ 1473 $add_primary_link = apply_filters( 'bp_activity_new_update_primary_link', $primary_link ); 1474 1282 1475 // Now write the values 1283 1476 $activity_id = bp_activity_add( array( 1284 1477 'user_id' => $r['user_id'], 1285 'content' => apply_filters( 'bp_activity_new_update_content', $activity_content ),1286 'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),1478 'content' => $add_content, 1479 'primary_link' => $add_primary_link, 1287 1480 'component' => buddypress()->activity->id, 1288 1481 'type' => 'activity_update', 1289 1482 ) ); 1290 1483 1484 /** 1485 * Filters the latest update content for the activity item. 1486 * 1487 * @since BuddyPress (1.6.0) 1488 * 1489 * @param string $r Content of the activity update. 1490 * @param string $activity_content Content of the activity update. 1491 */ 1291 1492 $activity_content = apply_filters( 'bp_activity_latest_update_content', $r['content'], $activity_content ); 1292 1493 1293 1494 // Add this update to the "latest update" usermeta so it can be fetched anywhere. … … 1296 1497 'content' => $activity_content 1297 1498 ) ); 1298 1499 1500 /** 1501 * Fires at the end of an activity post update, before the returning of the updated activity item ID. 1502 * 1503 * @since BuddyPress (1.2.0) 1504 * 1505 * @param string $content Content of the activity post update. 1506 * @param int $user_id ID of the user posting the activity update. 1507 * @param int $activity_id ID of the activity item being updated. 1508 */ 1299 1509 do_action( 'bp_activity_posted_update', $r['content'], $r['user_id'], $activity_id ); 1300 1510 1301 1511 return $activity_id; … … 1374 1584 // Check to see if the parent activity is hidden, and if so, hide this comment publically. 1375 1585 $is_hidden = ( (int) $activity->hide_sitewide ) ? 1 : 0; 1376 1586 1587 /** 1588 * Filters the content of a new comment. 1589 * 1590 * @since BuddyPress (1.2.0) 1591 * 1592 * @param string $r Content for the newly posted comment. 1593 */ 1594 $comment_content = apply_filters( 'bp_activity_comment_content', $r['content'] ); 1595 1377 1596 // Insert the activity comment 1378 1597 $comment_id = bp_activity_add( array( 1379 1598 'id' => $r['id'], 1380 'content' => apply_filters( 'bp_activity_comment_content', $r['content'] ),1599 'content' => $comment_content, 1381 1600 'component' => buddypress()->activity->id, 1382 1601 'type' => 'activity_comment', 1383 1602 'user_id' => $r['user_id'], … … 1398 1617 } 1399 1618 wp_cache_delete( $activity_id, 'bp_activity' ); 1400 1619 1620 /** 1621 * Fires near the end of an activity comment posting, before the returning of the comment ID. 1622 * 1623 * @since BuddyPress (1.2.0) 1624 * 1625 * @param int $comment_id ID of the newly posted activity comment. 1626 * @param array $r Array of parsed comment arguments. 1627 * @param int $activity ID of the activity item being commented on. 1628 */ 1401 1629 do_action( 'bp_activity_comment_posted', $comment_id, $r, $activity ); 1402 1630 1403 1631 if ( empty( $comment_id ) ) { … … 1434 1662 'date_recorded' => false, 1435 1663 ) ); 1436 1664 1665 /** 1666 * Filters the activity ID being requested. 1667 * 1668 * @since BuddyPress (1.2.0) 1669 * 1670 * @param BP_Activity_Activity ID returned by BP_Activity_Activity get_id method with provided arguments. 1671 */ 1437 1672 return apply_filters( 'bp_activity_get_activity_id', BP_Activity_Activity::get_id( 1438 1673 $r['user_id'], 1439 1674 $r['component'], … … 1495 1730 'hide_sitewide' => false 1496 1731 ) ); 1497 1732 1733 /** 1734 * Fires before an activity item proceeds to be deleted. 1735 * 1736 * @since BuddyPress (1.5.0) 1737 * 1738 * @param array $args Array of arguments to be used with the activity deletion. 1739 */ 1498 1740 do_action( 'bp_before_activity_delete', $args ); 1499 1741 1500 1742 // Adjust the new mention count of any mentioned member … … 1517 1759 } 1518 1760 } 1519 1761 1762 /** 1763 * Fires after the activity item has been deleted. 1764 * 1765 * @since BuddyPress (1.0.0) 1766 * 1767 * @param array $args Array of arguments used with the activity deletion. 1768 */ 1520 1769 do_action( 'bp_activity_delete', $args ); 1770 1771 /** 1772 * Fires after the activity item has been deleted. 1773 * 1774 * @since BuddyPress (1.2.0) 1775 * 1776 * @param array $activity_ids_deleted Array of affected activity item IDs. 1777 */ 1521 1778 do_action( 'bp_activity_deleted_activities', $activity_ids_deleted ); 1522 1779 1523 1780 wp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); … … 1531 1788 * You should use bp_activity_delete() instead. 1532 1789 * 1533 1790 * @since BuddyPress (1.1.0) 1534 * @deprecated BuddyPress (1.2 )1791 * @deprecated BuddyPress (1.2.0) 1535 1792 * 1536 1793 * @uses wp_parse_args() 1537 1794 * @uses bp_activity_delete() … … 1574 1831 * You should use bp_activity_delete() instead. 1575 1832 * 1576 1833 * @since BuddyPress (1.1.0) 1577 * @deprecated BuddyPress (1.2 )1834 * @deprecated BuddyPress (1.2.0) 1578 1835 * 1579 1836 * @uses bp_activity_delete() 1580 1837 * … … 1599 1856 * You should use bp_activity_delete() instead. 1600 1857 * 1601 1858 * @since BuddyPress (1.1.0) 1602 * @deprecated BuddyPress (1.2 )1859 * @deprecated BuddyPress (1.2.0) 1603 1860 * 1604 1861 * @uses bp_activity_delete() 1605 1862 * … … 1635 1892 * @return bool True on success, false on failure 1636 1893 */ 1637 1894 function bp_activity_delete_comment( $activity_id, $comment_id ) { 1638 /*** 1895 1896 /** 1897 * Filters whether BuddyPress should delete an activity comment or not. 1898 * 1639 1899 * You may want to hook into this filter if you want to override this function and 1640 1900 * handle the deletion of child comments differently. Make sure you return false. 1901 * 1902 * @since BuddyPress (1.2.0) 1903 * 1904 * @param bool $true Whether BuddyPress should continue or not. 1905 * @param int $activity_id ID of the root activity item being deleted. 1906 * @param int $comment_id ID of the comment being deleted. 1641 1907 */ 1642 1908 if ( ! apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) ) { 1643 1909 return false; … … 1657 1923 // Recalculate the comment tree 1658 1924 BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id ); 1659 1925 1926 /** 1927 * Fires at the end of the deletion of an activity comment, before the returning of success. 1928 * 1929 * @since BuddyPress (1.2.0) 1930 * 1931 * @param int $activity_id ID of the activity that has had a comment deleted from. 1932 * @param int $comment_id ID of the comment that was deleted. 1933 */ 1660 1934 do_action( 'bp_activity_delete_comment', $activity_id, $comment_id ); 1661 1935 1662 1936 return true; … … 1733 2007 } 1734 2008 } 1735 2009 2010 /** 2011 * Filters the activity permalink for the specified activity item. 2012 * 2013 * @since BuddyPress (1.2.0) 2014 * 2015 * @param array $array Array holding activity permalink and activity item object. 2016 */ 1736 2017 return apply_filters_ref_array( 'bp_activity_get_permalink', array( $link, &$activity_obj ) ); 1737 2018 } 1738 2019 … … 1812 2093 } 1813 2094 } 1814 2095 2096 /** 2097 * Filters the activity content that had a thumbnail replace images. 2098 * 2099 * @since BuddyPress (1.2.0) 2100 * 2101 * @param string $content Activity content that had images replaced in. 2102 * @param array $matches Array of all image tags found in the posted content. 2103 * @param array $args Arguments passed into function creating the activity update. 2104 */ 1815 2105 return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches, $args ); 1816 2106 } 1817 2107 … … 1823 2113 * @return bool True if user is allowed to mark activity items as spam. 1824 2114 */ 1825 2115 function bp_activity_user_can_mark_spam() { 2116 2117 /** 2118 * Filters if the current user should be able to mark items as spam. 2119 * 2120 * @since BuddyPress (1.6.0) 2121 * 2122 * @param bool $moderate Whether or not the current user has bp_moderate capability. 2123 */ 1826 2124 return apply_filters( 'bp_activity_user_can_mark_spam', bp_current_user_can( 'bp_moderate' ) ); 1827 2125 } 1828 2126 … … 1861 2159 add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_spam_meta' ), 1, 1 ); 1862 2160 } 1863 2161 2162 /** 2163 * Fires at the end of the process to mark an activity item as spam. 2164 * 2165 * @since BuddyPress (1.6.0) 2166 * 2167 * @param BP_Activity_Activity $activity Activity item being marked as spam. 2168 * @param string $source Source of determination of spam status. For example "by_a_person" or "by_akismet". 2169 */ 1864 2170 do_action( 'bp_activity_mark_as_spam', $activity, $source ); 1865 2171 } 1866 2172 … … 1899 2205 add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_ham_meta' ), 1, 1 ); 1900 2206 } 1901 2207 2208 /** 2209 * Fires at the end of the process to mark an activity item as ham. 2210 * 2211 * @since BuddyPress (1.6.0) 2212 * 2213 * @param BP_Activity_Activity $activity Activity item being marked as ham. 2214 * @param string $source Source of determination of ham status. For example "by_a_person" or "by_akismet". 2215 */ 1902 2216 do_action( 'bp_activity_mark_as_ham', $activity, $source ); 1903 2217 } 1904 2218