Ticket #5938: bp-activity-classes-5938.diff
File bp-activity-classes-5938.diff, 12.1 KB (added by , 10 years ago) |
---|
-
src/bp-activity/bp-activity-classes.php
201 201 $this->mptt_right = apply_filters_ref_array( 'bp_activity_mptt_right_before_save', array( $this->mptt_right, &$this ) ); 202 202 $this->is_spam = apply_filters_ref_array( 'bp_activity_is_spam_before_save', array( $this->is_spam, &$this ) ); 203 203 204 // Use this, not the filters above 204 /** 205 * Fires before the current activity item gets saved. 206 * 207 * Please use this hook to filter the properties above. Each part will be passed in. 208 * 209 * @since BuddyPress (1.0.0) 210 * 211 * @param BP_Activity_Activity Current instance of the activity item being saved. 212 */ 205 213 do_action_ref_array( 'bp_activity_before_save', array( &$this ) ); 206 214 207 215 if ( !$this->component || !$this->type ) … … 227 235 else 228 236 add_filter( 'bp_activity_at_name_do_notifications', '__return_false' ); 229 237 238 /** 239 * Fires after an activity item has been saved to the database. 240 * 241 * @since BuddyPress (1.0.0) 242 * 243 * @param BP_Activity_Activity Reference to current instance of activity being saved. 244 */ 230 245 do_action_ref_array( 'bp_activity_after_save', array( &$this ) ); 231 246 232 247 return true; … … 414 429 $where_conditions['excluded_types'] = "a.type NOT IN ({$not_in})"; 415 430 } 416 431 417 // Filter the where conditions 432 /** 433 * Filters the MySQL WHERE conditions for the Activity items get method. 434 * 435 * @since BuddyPress (1.9.0) 436 * 437 * @param array $where_conditions Current conditions for MySQL WHERE statement. 438 * @param array $r Parsed arguments passed into method. 439 * @param string $select_sql Current SELECT MySQL statement at point of execution. 440 * @param string $from_sql Current FROM MySQL statement at point of execution. 441 * @param string $join_sql Current INNER JOIN MySQL statement at point of execution. 442 */ 418 443 $where_conditions = apply_filters( 'bp_activity_get_where_conditions', $where_conditions, $r, $select_sql, $from_sql, $join_sql ); 419 444 420 445 // Join the where conditions together 421 446 $where_sql = 'WHERE ' . join( ' AND ', $where_conditions ); 422 447 423 // Define the preferred order for indexes 448 /** 449 * Filters the preferred order of indexes for activity item. 450 * 451 * @since Buddypress (1.6.0) 452 * 453 * @param array Array of indexes in preferred order. 454 */ 424 455 $indexes = apply_filters( 'bp_activity_preferred_index_order', array( 'user_id', 'item_id', 'secondary_item_id', 'date_recorded', 'component', 'type', 'hide_sitewide', 'is_spam' ) ); 425 456 426 457 foreach( $indexes as $key => $index ) { … … 446 477 'has_more_items' => null, 447 478 ); 448 479 449 // Filter and return true to use the legacy query structure (not recommended) 480 /** 481 * Filters if BuddyPress should use legacy query structure over current structure for version 2.0+. 482 * 483 * It is not recommended to use the legacy structure, but allowed to if needed. 484 * 485 * @since BuddyPress (2.0.0) 486 * 487 * @param bool Whether to use legacy structure or not. 488 * @param BP_Activity_Activity Current method being called. 489 * @param array $r Parsed arguments pased into method. 490 */ 450 491 if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $r ) ) { 451 492 452 493 // Legacy queries joined against the user table … … 455 496 456 497 if ( ! empty( $page ) && ! empty( $per_page ) ) { 457 498 $pag_sql = $wpdb->prepare( "LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page ); 499 500 /** this filter is documented in bp-activity/bp-activity-classes.php */ 458 501 $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}", $select_sql, $from_sql, $where_sql, $sort, $pag_sql ) ); 459 502 } else { 460 503 $pag_sql = ''; 504 505 /** 506 * Filters the legacy MySQL query statement so plugins can alter before results are fetched. 507 * 508 * @since BuddyPress (1.5.0) 509 * 510 * @param string Concatenated MySQL statement pieces to be query results with for legacy query. 511 * @param string $select_sql Final SELECT MySQL statement portion for legacy query. 512 * @param string $from_sql Final FROM MySQL statement portion for legacy query. 513 * @param string $where_sql Final WHERE MySQL statement portion for legacy query. 514 * @param string $sort Final sort direction for legacy query. 515 */ 461 516 $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}", $select_sql, $from_sql, $where_sql, $sort, $pag_sql ) ); 462 517 } 463 518 … … 472 527 $activity_ids_sql .= $wpdb->prepare( " LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page + 1 ); 473 528 } 474 529 530 /** 531 * Filters the paged activities MySQL statement. 532 * 533 * @since BuddyPress (2.0.0) 534 * 535 * @param string $activity_ids_sql MySQL statement used to query for Activity IDs. 536 * @param array $r Array of arguments passed into method. 537 */ 475 538 $activity_ids_sql = apply_filters( 'bp_activity_paged_activities_sql', $activity_ids_sql, $r ); 476 539 477 540 $activity_ids = $wpdb->get_col( $activity_ids_sql ); … … 514 577 // If $max is set, only return up to the max results 515 578 if ( ! empty( $r['count_total'] ) ) { 516 579 580 /** 581 * Filters the total activities MySQL statement. 582 * 583 * @since BuddyPress (1.5.0) 584 * 585 * @param string MySQL statement used to query for total activities. 586 * @param string $where_sql MySQL WHERE statement portion. 587 * @param string $sort sort direction for query. 588 */ 517 589 $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', "SELECT count(DISTINCT a.id) FROM {$bp->activity->table_name} a {$join_sql} {$where_sql}", $where_sql, $sort ); 518 590 $total_activities = $wpdb->get_var( $total_activities_sql ); 519 591 … … 640 712 * @param array $activities Array of activities. 641 713 */ 642 714 protected static function prefetch_object_data( $activities ) { 715 716 /** 717 * Filters inside prefetch_object_data method to aid in pre-fetching object data associated with activity item. 718 * 719 * @since BuddyPress (2.0.0) 720 * 721 * @param array $activities Array of activities. 722 */ 643 723 return apply_filters( 'bp_activity_prefetch_object_data', $activities ); 644 724 } 645 725 … … 1054 1134 1055 1135 // Legacy query - not recommended 1056 1136 $func_args = func_get_args(); 1137 1138 /** 1139 * Filters if BuddyPress should use the legacy activity query. 1140 * 1141 * @since BuddyPress (2.0.0) 1142 * 1143 * @param bool Whether or not to use the legacy query. 1144 * @param BP_Activity_Activity Magic method referring to currently called method. 1145 * @param array $func_args Array of the method's argument list. 1146 */ 1057 1147 if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $func_args ) ) { 1148 1149 /** 1150 * Filters the MySQL prepared statement for the legacy activity query. 1151 * 1152 * @since BuddyPress (1.5.0) 1153 * 1154 * @param string Prepared statement for the activity query. 1155 * @param int $activity_id Activity ID to fetch comments for. 1156 * @param int $left Left-most node boundary. 1157 * @param int $right Right-most node boundary. 1158 * @param string $spam_sql SQL Statement portion to differentiate between ham or spam. 1159 */ 1058 1160 $sql = apply_filters( 'bp_activity_comments_user_join_filter', $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' {$spam_sql} AND a.item_id = %d AND a.mptt_left > %d AND a.mptt_left < %d ORDER BY a.date_recorded ASC", $top_level_parent_id, $left, $right ), $activity_id, $left, $right, $spam_sql ); 1059 1161 1060 1162 $descendants = $wpdb->get_results( $sql ); … … 1450 1552 * @param array $args Optional 1451 1553 */ 1452 1554 public function __construct( $args = array() ) { 1453 // If feeds are disabled, stop now! 1555 1556 /** 1557 * Filters if BuddyPress should consider feeds enabled. If disabled, it will return early. 1558 * 1559 * @since BuddyPress (1.8.0) 1560 * 1561 * @param bool true Default true aka feeds are enabled. 1562 */ 1454 1563 if ( false === (bool) apply_filters( 'bp_activity_enable_feeds', true ) ) { 1455 1564 global $wp_query; 1456 1565 … … 1496 1605 'activity_args' => array() 1497 1606 ) ); 1498 1607 1499 // Plugins can use this filter to modify the feed before it is setup 1608 /** 1609 * Fires before the feed is setup so plugins can modify. 1610 * 1611 * @since BuddyPress (1.8.0) 1612 * 1613 * @param BP_Activity_Feed Reference to current instance of activity feed. 1614 */ 1500 1615 do_action_ref_array( 'bp_activity_feed_prefetch', array( &$this ) ); 1501 1616 1502 1617 // Setup class properties … … 1508 1623 return false; 1509 1624 } 1510 1625 1511 // Plugins can use this filter to modify the feed after it's setup 1626 /** 1627 * Fires after the feed is setup so plugins can modify. 1628 * 1629 * @since BuddyPress (1.8.0) 1630 * 1631 * @param BP_Activity_Feed Reference to current instance of activity feed. 1632 */ 1512 1633 do_action_ref_array( 'bp_activity_feed_postfetch', array( &$this ) ); 1513 1634 1514 1635 // Setup feed hooks … … 1565 1686 * Fire a hook to ensure backward compatibility for RSS attributes. 1566 1687 */ 1567 1688 public function backpat_rss_attributes() { 1689 1690 /** 1691 * Fires inside backpat_rss_attributes method for backwards compatibility related to RSS attributes. 1692 * 1693 * This hook was originally separated out for individual components but has since been abstracted into the BP_Activity_Feed class. 1694 * 1695 * @since BuddyPress (1.0.0) 1696 */ 1568 1697 do_action( 'bp_activity_' . $this->id . '_feed' ); 1569 1698 } 1570 1699 … … 1572 1701 * Fire a hook to ensure backward compatibility for channel elements. 1573 1702 */ 1574 1703 public function backpat_channel_elements() { 1704 1705 /** 1706 * Fires inside backpat_channel_elements method for backwards compatibility related to RSS channel elements. 1707 * 1708 * This hook was originally separated out for individual components but has since been abstracted into the BP_Activity_Feed class. 1709 * 1710 * @since BuddyPress (1.0.0) 1711 */ 1575 1712 do_action( 'bp_activity_' . $this->id . '_feed_head' ); 1576 1713 } 1577 1714 … … 1594 1731 break; 1595 1732 } 1596 1733 1734 /** 1735 * Fires inside backpat_item_elements method for backwards compatibility related to RSS item elements. 1736 * 1737 * This hook was originally separated out for individual components but has since been abstracted into the BP_Activity_Feed class. 1738 * 1739 * @since BuddyPress (1.0.0) 1740 */ 1597 1741 do_action( 'bp_activity_' . $id . '_feed_item' ); 1598 1742 } 1599 1743 … … 1719 1863 xmlns:atom="http://www.w3.org/2005/Atom" 1720 1864 xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" 1721 1865 xmlns:slash="http://purl.org/rss/1.0/modules/slash/" 1722 <?php do_action( 'bp_activity_feed_rss_attributes' ); ?> 1866 <?php 1867 1868 /** 1869 * Fires at the end of the opening RSS tag for feed output so plugins can add extra attributes. 1870 * 1871 * @since BuddyPress (1.8.0) 1872 */ 1873 do_action( 'bp_activity_feed_rss_attributes' ); ?> 1723 1874 > 1724 1875 1725 1876 <channel> … … 1733 1884 <ttl><?php echo $this->ttl; ?></ttl> 1734 1885 <sy:updatePeriod><?php echo $this->update_period; ?></sy:updatePeriod> 1735 1886 <sy:updateFrequency><?php echo $this->update_frequency; ?></sy:updateFrequency> 1736 <?php do_action( 'bp_activity_feed_channel_elements' ); ?>1887 <?php 1737 1888 1889 /** 1890 * Fires at the end of channel elements list in RSS feed so plugins can add extra channel elements. 1891 * 1892 * @since BuddyPress (1.8.0) 1893 */ 1894 do_action( 'bp_activity_feed_channel_elements' ); ?> 1895 1738 1896 <?php if ( bp_has_activities( $this->activity_args ) ) : ?> 1739 1897 <?php while ( bp_activities() ) : bp_the_activity(); ?> 1740 1898 <item> … … 1751 1909 <slash:comments><?php bp_activity_comment_count(); ?></slash:comments> 1752 1910 <?php endif; ?> 1753 1911 1754 <?php do_action( 'bp_activity_feed_item_elements' ); ?> 1912 <?php 1913 1914 /** 1915 * Fires at the end of the individual RSS Item list in RSS feed so plugins can add extra item elements. 1916 * 1917 * @since BuddyPress (1.8.0) 1918 */ 1919 do_action( 'bp_activity_feed_item_elements' ); ?> 1755 1920 </item> 1756 1921 <?php endwhile; ?> 1757 1922