Changeset 5309
- Timestamp:
- 03/05/2014 06:41:02 PM (11 years ago)
- Location:
- trunk/src/includes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/core/actions.php
r5156 r5309 248 248 add_action( 'bbp_unspammed_reply', 'bbp_update_reply_walker' ); 249 249 250 // Users topic & reply counts 251 add_action( 'bbp_new_topic', 'bbp_increase_user_topic_count' ); 252 add_action( 'bbp_new_reply', 'bbp_increase_user_reply_count' ); 253 add_action( 'bbp_untrash_topic', 'bbp_increase_user_topic_count' ); 254 add_action( 'bbp_untrash_reply', 'bbp_increase_user_reply_count' ); 255 add_action( 'bbp_unspam_topic', 'bbp_increase_user_topic_count' ); 256 add_action( 'bbp_unspam_reply', 'bbp_increase_user_reply_count' ); 257 add_action( 'bbp_trash_topic', 'bbp_decrease_user_topic_count' ); 258 add_action( 'bbp_trash_reply', 'bbp_decrease_user_reply_count' ); 259 add_action( 'bbp_spam_topic', 'bbp_decrease_user_topic_count' ); 260 add_action( 'bbp_spam_reply', 'bbp_decrease_user_reply_count' ); 261 250 262 // User status 251 263 // @todo make these sub-actions -
trunk/src/includes/users/functions.php
r5187 r5309 156 156 157 157 return apply_filters( 'bbp_current_author_ua', $retval ); 158 }159 160 /** Post Counts ***************************************************************/161 162 /**163 * Return the raw database count of topics by a user164 *165 * @since bbPress (r3633)166 * @global WPDB $wpdb167 * @uses bbp_get_user_id()168 * @uses get_posts_by_author_sql()169 * @uses bbp_get_topic_post_type()170 * @uses apply_filters()171 * @return int Raw DB count of topics172 */173 function bbp_get_user_topic_count_raw( $user_id = 0 ) {174 $user_id = bbp_get_user_id( $user_id );175 if ( empty( $user_id ) )176 return false;177 178 global $wpdb;179 180 $where = get_posts_by_author_sql( bbp_get_topic_post_type(), true, $user_id );181 $count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} {$where}" );182 183 return (int) apply_filters( 'bbp_get_user_topic_count_raw', $count, $user_id );184 }185 186 /**187 * Return the raw database count of replies by a user188 *189 * @since bbPress (r3633)190 * @global WPDB $wpdb191 * @uses bbp_get_user_id()192 * @uses get_posts_by_author_sql()193 * @uses bbp_get_reply_post_type()194 * @uses apply_filters()195 * @return int Raw DB count of replies196 */197 function bbp_get_user_reply_count_raw( $user_id = 0 ) {198 $user_id = bbp_get_user_id( $user_id );199 if ( empty( $user_id ) )200 return false;201 202 global $wpdb;203 204 $where = get_posts_by_author_sql( bbp_get_reply_post_type(), true, $user_id );205 $count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} {$where}" );206 207 return (int) apply_filters( 'bbp_get_user_reply_count_raw', $count, $user_id );208 158 } 209 159 … … 1533 1483 } 1534 1484 1535 /** Premissions ***************************************************************/ 1485 /** Post Counts ***************************************************************/ 1486 1487 /** 1488 * Return the raw database count of topics by a user 1489 * 1490 * @since bbPress (r3633) 1491 * @global WPDB $wpdb 1492 * @uses bbp_get_user_id() 1493 * @uses get_posts_by_author_sql() 1494 * @uses bbp_get_topic_post_type() 1495 * @uses apply_filters() 1496 * @return int Raw DB count of topics 1497 */ 1498 function bbp_get_user_topic_count_raw( $user_id = 0 ) { 1499 $user_id = bbp_get_user_id( $user_id ); 1500 if ( empty( $user_id ) ) { 1501 return false; 1502 } 1503 1504 global $wpdb; 1505 1506 $where = get_posts_by_author_sql( bbp_get_topic_post_type(), true, $user_id ); 1507 $count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} {$where}" ); 1508 1509 return (int) apply_filters( 'bbp_get_user_topic_count_raw', $count, $user_id ); 1510 } 1511 1512 /** 1513 * Return the raw database count of replies by a user 1514 * 1515 * @since bbPress (r3633) 1516 * @global WPDB $wpdb 1517 * @uses bbp_get_user_id() 1518 * @uses get_posts_by_author_sql() 1519 * @uses bbp_get_reply_post_type() 1520 * @uses apply_filters() 1521 * @return int Raw DB count of replies 1522 */ 1523 function bbp_get_user_reply_count_raw( $user_id = 0 ) { 1524 $user_id = bbp_get_user_id( $user_id ); 1525 if ( empty( $user_id ) ) { 1526 return false; 1527 } 1528 1529 global $wpdb; 1530 1531 $where = get_posts_by_author_sql( bbp_get_reply_post_type(), true, $user_id ); 1532 $count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} {$where}" ); 1533 1534 return (int) apply_filters( 'bbp_get_user_reply_count_raw', $count, $user_id ); 1535 } 1536 1537 /** 1538 * Bump the topic count for a user by a certain amount. 1539 * 1540 * @since bbPress (r5309) 1541 * 1542 * @param int $user_id 1543 * @param int $difference 1544 * @uses bbp_get_user_topic_count() To get the users current topic count 1545 * @uses bbp_set_user_topic_count() To set the users new topic count 1546 */ 1547 function bbp_bump_user_topic_count( $user_id = 0, $difference = 1 ) { 1548 1549 // Validate user ID 1550 $user_id = bbp_get_user_id( $user_id ); 1551 if ( empty( $user_id ) ) { 1552 return false; 1553 } 1554 1555 // Check meta for count, or query directly if not found 1556 $count = bbp_get_user_topic_count( $user_id, true ); 1557 if ( empty( $count ) ) { 1558 $count = bbp_get_user_topic_count_raw( $user_id ); 1559 } 1560 1561 // Add them up and filter them 1562 $new_count = apply_filters( 'bbp_bump_user_topic_count', ( (int) $count + (int) $difference ), $user_id, $difference, $count ); 1563 1564 return bbp_update_user_topic_count( $user_id, $new_count ); 1565 } 1566 1567 /** 1568 * Bump the reply count for a user by a certain amount. 1569 * 1570 * @since bbPress (r5309) 1571 * 1572 * @param int $user_id 1573 * @param int $difference 1574 * @uses bbp_get_user_reply_count() To get the users current reply count 1575 * @uses bbp_set_user_reply_count() To set the users new reply count 1576 */ 1577 function bbp_bump_user_reply_count( $user_id = 0, $difference = 1 ) { 1578 1579 // Validate user ID 1580 $user_id = bbp_get_user_id( $user_id ); 1581 if ( empty( $user_id ) ) { 1582 return false; 1583 } 1584 1585 // Check meta for count, or query directly if not found 1586 $count = bbp_get_user_reply_count( $user_id, true ); 1587 if ( empty( $count ) ) { 1588 $count = bbp_get_user_reply_count_raw( $user_id ); 1589 } 1590 1591 // Add them up and filter them 1592 $new_count = apply_filters( 'bbp_bump_user_reply_count', ( (int) $count + (int) $difference ), $user_id, $difference, $count ); 1593 1594 return bbp_update_user_reply_count( $user_id, $new_count ); 1595 } 1596 1597 /** 1598 * Helper function used to increase (by one) the count of topics for a user when 1599 * a topic is published. 1600 * 1601 * @since bbPress (r5309) 1602 * 1603 * @access 1604 * @param $topic_id 1605 * @param $forum_id 1606 * @param $anonymous_data 1607 * @param $topic_author 1608 */ 1609 function bbp_increase_user_topic_count( $topic_id = 0 ) { 1610 $user_id = bbp_get_topic_author_id( $topic_id ); 1611 return bbp_bump_user_topic_count( $user_id, 1 ); 1612 } 1613 1614 /** 1615 * Helper function used to increase (by one) the count of replies for a user when 1616 * a reply is published. 1617 * 1618 * This is a helper function, hooked to `bbp_new_reply` 1619 * 1620 * @since bbPress (r5309) 1621 * 1622 * @param $topic_id 1623 * @param $forum_id 1624 * @param $anonymous_data 1625 * @param $topic_author 1626 */ 1627 function bbp_increase_user_reply_count( $reply_id = 0 ) { 1628 $user_id = bbp_get_reply_author_id( $reply_id ); 1629 return bbp_bump_user_reply_count( $user_id, 1 ); 1630 } 1631 1632 /** 1633 * Helper function used to decrease (by one) the count of topics for a user when 1634 * a topic is unpublished. 1635 * 1636 * @since bbPress (r5309) 1637 * 1638 * @param $topic_id 1639 */ 1640 function bbp_decrease_user_topic_count( $topic_id = 0 ) { 1641 $user_id = bbp_get_topic_author_id( $topic_id ); 1642 return bbp_bump_user_topic_count( $user_id, -1 ); 1643 } 1644 1645 /** 1646 * Helper function used to increase (by one) the count of replies for a user when 1647 * a topic is unpublished. 1648 * 1649 * @since bbPress (r5309) 1650 * 1651 * @param $reply_id 1652 */ 1653 function bbp_decrease_user_reply_count( $reply_id = 0 ) { 1654 $user_id = bbp_get_reply_author_id( $reply_id ); 1655 return bbp_bump_user_reply_count( $user_id, -1 ); 1656 } 1657 1658 /** Permissions ***************************************************************/ 1536 1659 1537 1660 /** -
trunk/src/includes/users/options.php
r4995 r5309 43 43 // Validate user id 44 44 $user_id = bbp_get_user_id( $user_id ); 45 if ( empty( $user_id ) ) 45 if ( empty( $user_id ) ) { 46 46 return; 47 } 47 48 48 49 // Add default options 49 foreach ( bbp_get_default_user_options() as $key => $value ) 50 foreach ( bbp_get_default_user_options() as $key => $value ) { 50 51 update_user_option( $user_id, $key, $value ); 52 } 51 53 52 54 // Allow previously activated plugins to append their own user options. … … 69 71 // Validate user id 70 72 $user_id = bbp_get_user_id( $user_id ); 71 if ( empty( $user_id ) ) 73 if ( empty( $user_id ) ) { 72 74 return; 75 } 73 76 74 77 // Add default options 75 foreach ( array_keys( bbp_get_default_user_options() ) as $key ) 78 foreach ( array_keys( bbp_get_default_user_options() ) as $key ) { 76 79 delete_user_option( $user_id, $key ); 80 } 77 81 78 82 // Allow previously activated plugins to append their own options. … … 92 96 93 97 // Add filters to each bbPress option 94 foreach ( array_keys( bbp_get_default_user_options() ) as $key ) 98 foreach ( array_keys( bbp_get_default_user_options() ) as $key ) { 95 99 add_filter( 'get_user_option_' . $key, 'bbp_filter_get_user_option', 10, 3 ); 100 } 96 101 97 102 // Allow previously activated plugins to append their own options. … … 111 116 112 117 // Check the options global for preset value 113 if ( isset( $user->ID ) && isset( $bbp->user_options[$user->ID] ) && !empty( $bbp->user_options[$user->ID][$option] ) ) 118 if ( isset( $user->ID ) && isset( $bbp->user_options[$user->ID] ) && !empty( $bbp->user_options[$user->ID][$option] ) ) { 114 119 $value = $bbp->user_options[$user->ID][$option]; 120 } 115 121 116 122 // Always return a value, even if false … … 119 125 120 126 /** Post Counts ***************************************************************/ 127 128 /** 129 * Update the topic count for a user 130 * 131 * @since bbPress (r5309) 132 * 133 * @param int $user_id 134 * @param mixed $count 135 * @return boolean 136 */ 137 function bbp_update_user_topic_count( $user_id = 0, $count = false ) { 138 139 // Validate user id 140 $user_id = bbp_get_user_id( $user_id ); 141 if ( empty( $user_id ) ) { 142 return false; 143 } 144 145 // Just in time filtering of the user's topic count 146 $count = apply_filters( 'bbp_update_user_topic_count', $count, $user_id ); 147 148 // Bail if no count was passed 149 if ( false === $count ) { 150 return false; 151 } 152 153 // Return the updated user option 154 return update_user_option( $user_id, '_bbp_topic_count', $count ); 155 } 156 157 /** 158 * Update the reply count for a user 159 * 160 * @since bbPress (r5309) 161 * 162 * @param int $user_id 163 * @param mixed $count 164 * @return boolean 165 */ 166 function bbp_update_user_reply_count( $user_id = 0, $count = false ) { 167 168 // Validate user id 169 $user_id = bbp_get_user_id( $user_id ); 170 if ( empty( $user_id ) ) { 171 return false; 172 } 173 174 // Just in time filtering of the user's reply count 175 $count = apply_filters( 'bbp_update_user_reply_count', $count, $user_id ); 176 177 // Bail if no count was passed 178 if ( false === $count ) { 179 return false; 180 } 181 182 // Return the updated user option 183 return update_user_option( $user_id, '_bbp_reply_count', $count ); 184 } 121 185 122 186 /** … … 146 210 */ 147 211 function bbp_get_user_topic_count( $user_id = 0, $integer = false ) { 148 212 149 213 // Validate user id 150 214 $user_id = bbp_get_user_id( $user_id ); 151 if ( empty( $user_id ) ) 215 if ( empty( $user_id ) ) { 152 216 return false; 217 } 153 218 154 219 $count = (int) get_user_option( '_bbp_topic_count', $user_id ); … … 187 252 // Validate user id 188 253 $user_id = bbp_get_user_id( $user_id ); 189 if ( empty( $user_id ) ) 254 if ( empty( $user_id ) ) { 190 255 return false; 256 } 191 257 192 258 $count = (int) get_user_option( '_bbp_reply_count', $user_id ); 193 $filter = ( true === $integer ) ? 'bbp_get_user_ topic_count_int' : 'bbp_get_user_topic_count';259 $filter = ( true === $integer ) ? 'bbp_get_user_reply_count_int' : 'bbp_get_user_reply_count'; 194 260 195 261 return apply_filters( $filter, $count, $user_id ); … … 225 291 // Validate user id 226 292 $user_id = bbp_get_user_id( $user_id ); 227 if ( empty( $user_id ) ) 293 if ( empty( $user_id ) ) { 228 294 return false; 295 } 229 296 230 297 $topics = bbp_get_user_topic_count( $user_id, true ); … … 250 317 // Validate user id 251 318 $user_id = bbp_get_user_id( $user_id ); 252 if ( empty( $user_id ) ) 253 return false; 319 if ( empty( $user_id ) ) { 320 return false; 321 } 254 322 255 323 // Set time to now if nothing is passed 256 if ( empty( $time ) ) 324 if ( empty( $time ) ) { 257 325 $time = time(); 326 } 258 327 259 328 return update_user_option( $user_id, '_bbp_last_posted', $time ); … … 282 351 // Validate user id 283 352 $user_id = bbp_get_user_id( $user_id ); 284 if ( empty( $user_id ) ) 353 if ( empty( $user_id ) ) { 285 354 return false; 355 } 286 356 287 357 $time = get_user_option( '_bbp_last_posted', $user_id );
Note: See TracChangeset
for help on using the changeset viewer.