Changeset 6302
- Timestamp:
- 02/23/2017 11:24:29 PM (8 years ago)
- Location:
- trunk/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bbpress.php
r6254 r6302 390 390 'setup_current_user', // Setup currently logged in user 391 391 'roles_init', // User roles init 392 'register_meta', // Register meta (forum|topic|reply|user) 392 393 'register_post_types', // Register post types (forum|topic|reply) 393 394 'register_post_statuses', // Register post statuses (closed|spam|orphan|hidden) … … 750 751 751 752 /** 753 * Register bbPress meta-data 754 * 755 * Counts added in 2.6.0 to avoid negative values 756 * 757 * @since 2.6.0 bbPress (r6300) 758 */ 759 public function register_meta() { 760 761 // Define "count" meta-type array 762 $count = array( 763 'type' => 'integer', 764 'description' => esc_html__( 'bbPress Item Count', 'bbpress' ), 765 'single' => true, 766 'sanitize_callback' => 'bbp_number_not_negative', 767 'show_in_rest' => true 768 ); 769 770 /** Post **************************************************************/ 771 772 // Counts 773 register_meta( 'post', '_bbp_topic_count', $count ); 774 register_meta( 'post', '_bbp_reply_count', $count ); 775 register_meta( 'post', '_bbp_total_topic_count', $count ); 776 register_meta( 'post', '_bbp_total_reply_count', $count ); 777 register_meta( 'post', '_bbp_voice_count', $count ); 778 register_meta( 'post', '_bbp_anonymous_reply_count', $count ); 779 register_meta( 'post', '_bbp_topic_count_hidden', $count ); 780 register_meta( 'post', '_bbp_reply_count_hidden', $count ); 781 register_meta( 'post', '_bbp_forum_subforum_count', $count ); 782 783 /* User ***************************************************************/ 784 785 // Counts 786 register_meta( 'user', '_bbp_topic_count', $count ); 787 register_meta( 'user', '_bbp_reply_count', $count ); 788 } 789 790 /** 752 791 * Setup the currently logged-in user 753 792 * -
trunk/src/includes/common/formatting.php
r6298 r6302 463 463 464 464 /** 465 * Never let a numeric value be less than zero. 466 * 467 * @since 2.6.0 bbPress (r6300) 468 * 469 * @param int $number 470 */ 471 function bbp_number_not_negative( $number = 0 ) { 472 473 // Protect against formatted strings 474 if ( is_string( $number ) ) { 475 $number = strip_tags( $number ); // No HTML 476 $number = preg_replace( '/[^0-9-]/', '', $number ); // No number-format 477 478 // Protect against objects, arrays, scalars, etc... 479 } elseif ( ! is_numeric( $number ) ) { 480 $number = 0; 481 } 482 483 // Make the number an integer 484 $int = intval( $number ); 485 486 // Pick the maximum value, never less than zero 487 $not_less_than_zero = max( 0, $int ); 488 489 // Filter & return 490 return apply_filters( 'bbp_number_not_negative', $not_less_than_zero, $int, $number ); 491 } 492 493 /** 465 494 * A bbPress specific method of formatting numeric values 466 495 * -
trunk/src/includes/core/actions.php
r6118 r6302 113 113 add_action( 'bbp_register', 'bbp_register_views', 8 ); 114 114 add_action( 'bbp_register', 'bbp_register_shortcodes', 10 ); 115 add_action( 'bbp_register', 'bbp_register_meta', 12 ); 115 116 116 117 // Autoembeds -
trunk/src/includes/core/filters.php
r6301 r6302 207 207 add_filter( 'bbp_get_topic_reply_count_hidden', 'bbp_number_format', 10 ); 208 208 209 // Add intval filter to functions expecting absolute values210 add_filter( 'bbp_get_user_topic_count_int', ' intval', 10 );211 add_filter( 'bbp_get_user_reply_count_int', ' intval', 10 );212 add_filter( 'bbp_get_user_post_count_int', ' intval', 10 );213 add_filter( 'bbp_get_forum_subforum_count_int', ' intval', 10 );214 add_filter( 'bbp_get_forum_topic_count_int', ' intval', 10 );215 add_filter( 'bbp_get_forum_reply_count_int', ' intval', 10 );216 add_filter( 'bbp_get_forum_post_count_int', ' intval', 10 );217 add_filter( 'bbp_get_topic_voice_count_int', ' intval', 10 );218 add_filter( 'bbp_get_topic_reply_count_int', ' intval', 10 );219 add_filter( 'bbp_get_topic_post_count_int', ' intval', 10 );220 add_filter( 'bbp_get_forum_topic_count_hidden_int', ' intval', 10 );221 add_filter( 'bbp_get_topic_reply_count_hidden_int', ' intval', 10 );222 add_filter( 'bbp_get_topic_revision_count_int', ' intval', 10 );223 add_filter( 'bbp_get_reply_revision_count_int', ' intval', 10 );209 // Add number-not-negative filter to values that can never be negative numbers 210 add_filter( 'bbp_get_user_topic_count_int', 'bbp_number_not_negative', 10 ); 211 add_filter( 'bbp_get_user_reply_count_int', 'bbp_number_not_negative', 10 ); 212 add_filter( 'bbp_get_user_post_count_int', 'bbp_number_not_negative', 10 ); 213 add_filter( 'bbp_get_forum_subforum_count_int', 'bbp_number_not_negative', 10 ); 214 add_filter( 'bbp_get_forum_topic_count_int', 'bbp_number_not_negative', 10 ); 215 add_filter( 'bbp_get_forum_reply_count_int', 'bbp_number_not_negative', 10 ); 216 add_filter( 'bbp_get_forum_post_count_int', 'bbp_number_not_negative', 10 ); 217 add_filter( 'bbp_get_topic_voice_count_int', 'bbp_number_not_negative', 10 ); 218 add_filter( 'bbp_get_topic_reply_count_int', 'bbp_number_not_negative', 10 ); 219 add_filter( 'bbp_get_topic_post_count_int', 'bbp_number_not_negative', 10 ); 220 add_filter( 'bbp_get_forum_topic_count_hidden_int', 'bbp_number_not_negative', 10 ); 221 add_filter( 'bbp_get_topic_reply_count_hidden_int', 'bbp_number_not_negative', 10 ); 222 add_filter( 'bbp_get_topic_revision_count_int', 'bbp_number_not_negative', 10 ); 223 add_filter( 'bbp_get_reply_revision_count_int', 'bbp_number_not_negative', 10 ); 224 224 225 225 // Sanitize displayed user data -
trunk/src/includes/core/sub-actions.php
r6106 r6302 240 240 function bbp_register_shortcodes() { 241 241 do_action( 'bbp_register_shortcodes' ); 242 } 243 244 /** 245 * Register the default bbPress meta-data 246 * 247 * @since 2.6.0 bbPress (r46300) 248 * 249 * @uses do_action() Calls 'bbp_register_meta' 250 */ 251 function bbp_register_meta() { 252 do_action( 'bbp_register_meta' ); 242 253 } 243 254 -
trunk/src/includes/forums/template.php
r6296 r6302 1326 1326 function bbp_get_forum_subforum_count( $forum_id = 0, $integer = false ) { 1327 1327 $forum_id = bbp_get_forum_id( $forum_id ); 1328 $forum_count = (int) get_post_meta( $forum_id, '_bbp_forum_subforum_count', true ); 1329 $filter = ( true === $integer ) ? 'bbp_get_forum_subforum_count_int' : 'bbp_get_forum_subforum_count'; 1328 $forum_count = bbp_number_not_negative( get_post_meta( $forum_id, '_bbp_forum_subforum_count', true ) ); 1329 $filter = ( true === $integer ) 1330 ? 'bbp_get_forum_subforum_count_int' 1331 : 'bbp_get_forum_subforum_count'; 1330 1332 1331 1333 return apply_filters( $filter, $forum_count, $forum_id ); … … 1363 1365 $forum_id = bbp_get_forum_id( $forum_id ); 1364 1366 $meta_key = empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count'; 1365 $topics = (int) get_post_meta( $forum_id, $meta_key, true ); 1366 $filter = ( true === $integer ) ? 'bbp_get_forum_topic_count_int' : 'bbp_get_forum_topic_count'; 1367 $topics = bbp_number_not_negative( get_post_meta( $forum_id, $meta_key, true ) ); 1368 $filter = ( true === $integer ) 1369 ? 'bbp_get_forum_topic_count_int' 1370 : 'bbp_get_forum_topic_count'; 1367 1371 1368 1372 return apply_filters( $filter, $topics, $forum_id ); … … 1400 1404 $forum_id = bbp_get_forum_id( $forum_id ); 1401 1405 $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count'; 1402 $replies = (int) get_post_meta( $forum_id, $meta_key, true ); 1403 $filter = ( true === $integer ) ? 'bbp_get_forum_reply_count_int' : 'bbp_get_forum_reply_count'; 1406 $replies = bbp_number_not_negative( get_post_meta( $forum_id, $meta_key, true ) ); 1407 $filter = ( true === $integer ) 1408 ? 'bbp_get_forum_reply_count_int' 1409 : 'bbp_get_forum_reply_count'; 1404 1410 1405 1411 return apply_filters( $filter, $replies, $forum_id ); … … 1439 1445 $topics = bbp_get_forum_topic_count( $forum_id, $total_count, true ); 1440 1446 $replies = bbp_get_forum_reply_count( $forum_id, $total_count, true ); 1441 $retval = $replies + $topics;1447 $retval = bbp_number_not_negative( $replies + $topics ); 1442 1448 $filter = ( true === $integer ) 1443 1449 ? 'bbp_get_forum_post_count_int' … … 1476 1482 function bbp_get_forum_topic_count_hidden( $forum_id = 0, $integer = false ) { 1477 1483 $forum_id = bbp_get_forum_id( $forum_id ); 1478 $topics = (int) get_post_meta( $forum_id, '_bbp_topic_count_hidden', true ); 1479 $filter = ( true === $integer ) ? 'bbp_get_forum_topic_count_hidden_int' : 'bbp_get_forum_topic_count_hidden'; 1484 $topics = bbp_number_not_negative( get_post_meta( $forum_id, '_bbp_topic_count_hidden', true ) ); 1485 $filter = ( true === $integer ) 1486 ? 'bbp_get_forum_topic_count_hidden_int' 1487 : 'bbp_get_forum_topic_count_hidden'; 1480 1488 1481 1489 return apply_filters( $filter, $topics, $forum_id ); -
trunk/src/includes/replies/template.php
r6300 r6302 878 878 */ 879 879 function bbp_get_reply_revision_count( $reply_id = 0, $integer = false ) { 880 $count = (int) count( bbp_get_reply_revisions( $reply_id ) ); 881 $filter = ( true === $integer ) ? 'bbp_get_reply_revision_count_int' : 'bbp_get_reply_revision_count'; 880 $reply_id = bbp_get_reply_id( $reply_id ); 881 $count = bbp_number_not_negative( count( bbp_get_reply_revisions( $reply_id ) ) ); 882 $filter = ( true === $integer ) 883 ? 'bbp_get_reply_revision_count_int' 884 : 'bbp_get_reply_revision_count'; 882 885 883 886 return apply_filters( $filter, $count, $reply_id ); … … 922 925 */ 923 926 function bbp_is_reply_published( $reply_id = 0 ) { 924 $reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ) === bbp_get_public_status_id(); 927 $reply_id = bbp_get_reply_id( $reply_id ); 928 $status = bbp_get_public_status_id(); 929 $reply_status = bbp_get_reply_status( $reply_id ) === $status; 930 925 931 return (bool) apply_filters( 'bbp_is_reply_published', (bool) $reply_status, $reply_id ); 926 932 } … … 937 943 */ 938 944 function bbp_is_reply_spam( $reply_id = 0 ) { 939 $reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ) === bbp_get_spam_status_id(); 945 $reply_id = bbp_get_reply_id( $reply_id ); 946 $status = bbp_get_spam_status_id(); 947 $reply_status = bbp_get_reply_status( $reply_id ) === $status; 948 940 949 return (bool) apply_filters( 'bbp_is_reply_spam', (bool) $reply_status, $reply_id ); 941 950 } … … 952 961 */ 953 962 function bbp_is_reply_trash( $reply_id = 0 ) { 954 $reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ) === bbp_get_trash_status_id(); 963 $reply_id = bbp_get_reply_id( $reply_id ); 964 $status = bbp_get_trash_status_id(); 965 $reply_status = bbp_get_reply_status( $reply_id ) === $status; 966 955 967 return (bool) apply_filters( 'bbp_is_reply_trash', (bool) $reply_status, $reply_id ); 956 968 } … … 968 980 */ 969 981 function bbp_is_reply_pending( $reply_id = 0 ) { 970 $reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ) === bbp_get_pending_status_id(); 982 $reply_id = bbp_get_reply_id( $reply_id ); 983 $status = bbp_get_pending_status_id(); 984 $reply_status = bbp_get_reply_status( $reply_id ) === $status; 985 971 986 return (bool) apply_filters( 'bbp_is_reply_pending', (bool) $reply_status, $reply_id ); 972 987 } … … 984 999 */ 985 1000 function bbp_is_reply_private( $reply_id = 0 ) { 986 $reply_status = bbp_get_reply_status( bbp_get_reply_id( $reply_id ) ) === bbp_get_private_status_id(); 1001 $reply_id = bbp_get_reply_id( $reply_id ); 1002 $status = bbp_get_private_status_id(); 1003 $reply_status = bbp_get_reply_status( $reply_id ) === $status; 1004 987 1005 return (bool) apply_filters( 'bbp_is_reply_private', (bool) $reply_status, $reply_id ); 988 1006 } -
trunk/src/includes/topics/template.php
r6291 r6302 1070 1070 */ 1071 1071 function bbp_get_topic_revision_count( $topic_id = 0, $integer = false ) { 1072 $count = (int) count( bbp_get_topic_revisions( $topic_id ) ); 1073 $filter = ( true === $integer ) ? 'bbp_get_topic_revision_count_int' : 'bbp_get_topic_revision_count'; 1072 $topic_id = bbp_get_topic_id( $topic_id ); 1073 $count = bbp_number_not_negative( count( bbp_get_topic_revisions( $topic_id ) ) ); 1074 $filter = ( true === $integer ) 1075 ? 'bbp_get_topic_revision_count_int' 1076 : 'bbp_get_topic_revision_count'; 1074 1077 1075 1078 return apply_filters( $filter, $count, $topic_id ); … … 2258 2261 function bbp_get_topic_reply_count( $topic_id = 0, $integer = false ) { 2259 2262 $topic_id = bbp_get_topic_id( $topic_id ); 2260 $replies = (int) get_post_meta( $topic_id, '_bbp_reply_count', true ); 2261 $filter = ( true === $integer ) ? 'bbp_get_topic_reply_count_int' : 'bbp_get_topic_reply_count'; 2263 $replies = bbp_number_not_negative( get_post_meta( $topic_id, '_bbp_reply_count', true ) ); 2264 $filter = ( true === $integer ) 2265 ? 'bbp_get_topic_reply_count_int' 2266 : 'bbp_get_topic_reply_count'; 2262 2267 2263 2268 return apply_filters( $filter, $replies, $topic_id ); … … 2291 2296 function bbp_get_topic_post_count( $topic_id = 0, $integer = false ) { 2292 2297 $topic_id = bbp_get_topic_id( $topic_id ); 2293 $replies = (int) get_post_meta( $topic_id, '_bbp_reply_count', true ) + 1; 2294 $filter = ( true === $integer ) ? 'bbp_get_topic_post_count_int' : 'bbp_get_topic_post_count'; 2298 $replies = bbp_number_not_negative( get_post_meta( $topic_id, '_bbp_reply_count', true ) + 1 ); 2299 $filter = ( true === $integer ) 2300 ? 'bbp_get_topic_post_count_int' 2301 : 'bbp_get_topic_post_count'; 2295 2302 2296 2303 return apply_filters( $filter, $replies, $topic_id ); … … 2326 2333 function bbp_get_topic_reply_count_hidden( $topic_id = 0, $integer = false ) { 2327 2334 $topic_id = bbp_get_topic_id( $topic_id ); 2328 $replies = (int) get_post_meta( $topic_id, '_bbp_reply_count_hidden', true ); 2329 $filter = ( true === $integer ) ? 'bbp_get_topic_reply_count_hidden_int' : 'bbp_get_topic_reply_count_hidden'; 2335 $replies = bbp_number_not_negative( get_post_meta( $topic_id, '_bbp_reply_count_hidden', true ) ); 2336 $filter = ( true === $integer ) 2337 ? 'bbp_get_topic_reply_count_hidden_int' 2338 : 'bbp_get_topic_reply_count_hidden'; 2330 2339 2331 2340 return apply_filters( $filter, $replies, $topic_id ); … … 2357 2366 function bbp_get_topic_voice_count( $topic_id = 0, $integer = false ) { 2358 2367 $topic_id = bbp_get_topic_id( $topic_id ); 2359 $voices = (int) get_post_meta( $topic_id, '_bbp_voice_count', true ); 2360 $filter = ( true === $integer ) ? 'bbp_get_topic_voice_count_int' : 'bbp_get_topic_voice_count'; 2368 $voices = bbp_number_not_negative( get_post_meta( $topic_id, '_bbp_voice_count', true ) ); 2369 $filter = ( true === $integer ) 2370 ? 'bbp_get_topic_voice_count_int' 2371 : 'bbp_get_topic_voice_count'; 2361 2372 2362 2373 return apply_filters( $filter, $voices, $topic_id ); -
trunk/src/includes/users/options.php
r5951 r6302 215 215 */ 216 216 function bbp_get_user_topic_count( $user_id = 0, $integer = false ) { 217 217 218 218 // Validate user id 219 219 $user_id = bbp_get_user_id( $user_id ); … … 222 222 } 223 223 224 $count = (int) get_user_option( '_bbp_topic_count', $user_id ); 225 $filter = ( true === $integer ) ? 'bbp_get_user_topic_count_int' : 'bbp_get_user_topic_count'; 224 $count = bbp_number_not_negative( get_user_option( '_bbp_topic_count', $user_id ) ); 225 $filter = ( true === $integer ) 226 ? 'bbp_get_user_topic_count_int' 227 : 'bbp_get_user_topic_count'; 226 228 227 229 return apply_filters( $filter, $count, $user_id ); … … 261 263 } 262 264 263 $count = (int) get_user_option( '_bbp_reply_count', $user_id ); 264 $filter = ( true === $integer ) ? 'bbp_get_user_reply_count_int' : 'bbp_get_user_reply_count'; 265 $count = bbp_number_not_negative( get_user_option( '_bbp_reply_count', $user_id ) ); 266 $filter = ( true === $integer ) 267 ? 'bbp_get_user_reply_count_int' 268 : 'bbp_get_user_reply_count'; 265 269 266 270 return apply_filters( $filter, $count, $user_id ); … … 302 306 $topics = bbp_get_user_topic_count( $user_id, true ); 303 307 $replies = bbp_get_user_reply_count( $user_id, true ); 304 $count = (int) $topics + $replies; 305 $filter = ( true === $integer ) ? 'bbp_get_user_post_count_int' : 'bbp_get_user_post_count'; 308 $count = bbp_number_not_negative( $topics + $replies ); 309 $filter = ( true === $integer ) 310 ? 'bbp_get_user_post_count_int' 311 : 'bbp_get_user_post_count'; 306 312 307 313 return apply_filters( $filter, $count, $user_id );
Note: See TracChangeset
for help on using the changeset viewer.