Changeset 4258
- Timestamp:
- 10/19/2012 07:42:49 AM (12 years ago)
- Location:
- trunk/bbp-includes
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bbp-includes/core/widgets.php
r4249 r4258 521 521 * time 522 522 * @uses bbp_get_topic_id() To get the topic id 523 * @uses bbp_get_topic_reply_count() To get the topic reply count524 523 */ 525 524 public function widget( $args, $instance ) { -
trunk/bbp-includes/forums/functions.php
r4249 r4258 955 955 // Get some counts 956 956 $forum_id = bbp_get_forum_id( $forum_id ); 957 $topic_count = bbp_get_forum_topic_count( $forum_id, false );958 $total_topic_count = bbp_get_forum_topic_count( $forum_id, true 957 $topic_count = bbp_get_forum_topic_count( $forum_id, false, false ); 958 $total_topic_count = bbp_get_forum_topic_count( $forum_id, true, false ); 959 959 960 960 // Update this forum id … … 974 974 975 975 // Get forum counts 976 $parent_topic_count = bbp_get_forum_topic_count( $parent_forum_id, false );977 $parent_total_topic_count = bbp_get_forum_topic_count( $parent_forum_id, true 976 $parent_topic_count = bbp_get_forum_topic_count( $parent_forum_id, false, false ); 977 $parent_total_topic_count = bbp_get_forum_topic_count( $parent_forum_id, true, false ); 978 978 979 979 // Update counts -
trunk/bbp-includes/forums/template-tags.php
r4249 r4258 694 694 695 695 // Bail if there are no subforums 696 if ( !bbp_get_forum_subforum_count( $forum_id ) )696 if ( !bbp_get_forum_subforum_count( $forum_id, false ) ) 697 697 return; 698 698 … … 1117 1117 */ 1118 1118 function bbp_get_forum_topics_link( $forum_id = 0 ) { 1119 1120 1119 $forum = bbp_get_forum( $forum_id ); 1121 1120 $forum_id = $forum->ID; 1122 $topics = bbp_get_forum_topic_count( $forum_id ); 1123 $topics = sprintf( _n( '%s topic', '%s topics', $topics, 'bbpress' ), $topics ); 1121 $topics = sprintf( _n( '%s topic', '%s topics', bbp_get_forum_topic_count( $forum_id, true, false ), 'bbpress' ), bbp_get_forum_topic_count( $forum_id ) ); 1124 1122 $retval = ''; 1125 1123 … … 1157 1155 * @since bbPress (r2464) 1158 1156 * 1157 * @param int $forum_id Optional. Forum id to check 1158 * @param boolean $integer Optional. Whether or not to format the result 1159 1159 * @uses bbp_get_forum_subforum_count() To get the forum's subforum count 1160 * @param int $forum_id Optional. Forum id to check 1161 */ 1162 function bbp_forum_subforum_count( $forum_id = 0 ) { 1163 echo bbp_get_forum_subforum_count( $forum_id ); 1160 */ 1161 function bbp_forum_subforum_count( $forum_id = 0, $integer = false ) { 1162 echo bbp_get_forum_subforum_count( $forum_id, $integer ); 1164 1163 } 1165 1164 /** … … 1169 1168 * 1170 1169 * @param int $forum_id Optional. Forum id 1170 * @param boolean $integer Optional. Whether or not to format the result 1171 1171 * @uses bbp_get_forum_id() To get the forum id 1172 1172 * @uses get_post_meta() To get the subforum count … … 1175 1175 * @return int Forum's subforum count 1176 1176 */ 1177 function bbp_get_forum_subforum_count( $forum_id = 0 ) {1177 function bbp_get_forum_subforum_count( $forum_id = 0, $integer = false ) { 1178 1178 $forum_id = bbp_get_forum_id( $forum_id ); 1179 $forum_count = get_post_meta( $forum_id, '_bbp_forum_subforum_count', true ); 1180 1181 return apply_filters( 'bbp_get_forum_subforum_count', (int) $forum_count, $forum_id ); 1179 $forum_count = absint( get_post_meta( $forum_id, '_bbp_forum_subforum_count', true ) ); 1180 $filter = ( true === $integer ) ? 'bbp_get_forum_subforum_count_int' : 'bbp_get_forum_subforum_count'; 1181 1182 return apply_filters( $filter, $forum_count, $forum_id ); 1182 1183 } 1183 1184 … … 1189 1190 * @param int $forum_id Optional. Forum id 1190 1191 * @param bool $total_count Optional. To get the total count or normal count? 1192 * @param boolean $integer Optional. Whether or not to format the result 1191 1193 * @uses bbp_get_forum_topic_count() To get the forum topic count 1192 1194 */ 1193 function bbp_forum_topic_count( $forum_id = 0, $total_count = true ) {1194 echo bbp_get_forum_topic_count( $forum_id, $total_count );1195 function bbp_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) { 1196 echo bbp_get_forum_topic_count( $forum_id, $total_count, $integer ); 1195 1197 } 1196 1198 /** … … 1202 1204 * @param bool $total_count Optional. To get the total count or normal 1203 1205 * count? Defaults to total. 1206 * @param boolean $integer Optional. Whether or not to format the result 1204 1207 * @uses bbp_get_forum_id() To get the forum id 1205 1208 * @uses get_post_meta() To get the forum topic count … … 1208 1211 * @return int Forum topic count 1209 1212 */ 1210 function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true ) {1213 function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) { 1211 1214 $forum_id = bbp_get_forum_id( $forum_id ); 1212 $topics = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count', true ); 1213 1214 return apply_filters( 'bbp_get_forum_topic_count', (int) $topics, $forum_id ); 1215 $meta_key = empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count'; 1216 $topics = absint( get_post_meta( $forum_id, $meta_key, true ) ); 1217 $filter = ( true === $integer ) ? 'bbp_get_forum_topic_count_int' : 'bbp_get_forum_topic_count'; 1218 1219 return apply_filters( $filter, $topics, $forum_id ); 1215 1220 } 1216 1221 … … 1222 1227 * @param int $forum_id Optional. Forum id 1223 1228 * @param bool $total_count Optional. To get the total count or normal count? 1229 * @param boolean $integer Optional. Whether or not to format the result 1224 1230 * @uses bbp_get_forum_reply_count() To get the forum reply count 1225 1231 */ 1226 function bbp_forum_reply_count( $forum_id = 0, $total_count = true ) {1227 echo bbp_get_forum_reply_count( $forum_id, $total_count );1232 function bbp_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) { 1233 echo bbp_get_forum_reply_count( $forum_id, $total_count, $integer ); 1228 1234 } 1229 1235 /** … … 1235 1241 * @param bool $total_count Optional. To get the total count or normal 1236 1242 * count? 1243 * @param boolean $integer Optional. Whether or not to format the result 1237 1244 * @uses bbp_get_forum_id() To get the forum id 1238 1245 * @uses get_post_meta() To get the forum reply count … … 1241 1248 * @return int Forum reply count 1242 1249 */ 1243 function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true ) {1250 function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) { 1244 1251 $forum_id = bbp_get_forum_id( $forum_id ); 1245 $replies = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count', true ); 1246 1247 return apply_filters( 'bbp_get_forum_reply_count', (int) $replies, $forum_id ); 1252 $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count'; 1253 $replies = absint( get_post_meta( $forum_id, $meta_key, true ) ); 1254 $filter = ( true === $integer ) ? 'bbp_get_forum_reply_count_int' : 'bbp_get_forum_reply_count'; 1255 1256 return apply_filters( $filter, $replies, $forum_id ); 1248 1257 } 1249 1258 … … 1255 1264 * @param int $forum_id Optional. Forum id 1256 1265 * @param bool $total_count Optional. To get the total count or normal count? 1266 * @param boolean $integer Optional. Whether or not to format the result 1257 1267 * @uses bbp_get_forum_post_count() To get the forum post count 1258 1268 */ 1259 function bbp_forum_post_count( $forum_id = 0, $total_count = true ) {1260 echo bbp_get_forum_post_count( $forum_id, $total_count );1269 function bbp_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) { 1270 echo bbp_get_forum_post_count( $forum_id, $total_count, $integer ); 1261 1271 } 1262 1272 /** … … 1268 1278 * @param bool $total_count Optional. To get the total count or normal 1269 1279 * count? 1280 * @param boolean $integer Optional. Whether or not to format the result 1270 1281 * @uses bbp_get_forum_id() To get the forum id 1271 1282 * @uses get_post_meta() To get the forum post count … … 1274 1285 * @return int Forum post count 1275 1286 */ 1276 function bbp_get_forum_post_count( $forum_id = 0, $total_count = true ) {1287 function bbp_get_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) { 1277 1288 $forum_id = bbp_get_forum_id( $forum_id ); 1278 $topics = bbp_get_forum_topic_count( $forum_id, $total_count ); 1279 $replies = get_post_meta( $forum_id, empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count', true ); 1280 1281 return apply_filters( 'bbp_get_forum_post_count', (int) $replies + (int) $topics, $forum_id ); 1289 $topics = bbp_get_forum_topic_count( $forum_id, $total_count, true ); 1290 $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count'; 1291 $replies = absint( get_post_meta( $forum_id, $meta_key, true ) ); 1292 $retval = $replies + $topics; 1293 $filter = ( true === $integer ) ? 'bbp_get_forum_post_count_int' : 'bbp_get_forum_post_count'; 1294 1295 return apply_filters( $filter, $retval, $forum_id ); 1282 1296 } 1283 1297 … … 1289 1303 * 1290 1304 * @param int $forum_id Optional. Topic id 1305 * @param boolean $integer Optional. Whether or not to format the result 1291 1306 * @uses bbp_get_forum_topic_count_hidden() To get the forum hidden topic count 1292 1307 */ 1293 function bbp_forum_topic_count_hidden( $forum_id = 0 ) {1294 echo bbp_get_forum_topic_count_hidden( $forum_id );1308 function bbp_forum_topic_count_hidden( $forum_id = 0, $integer = false ) { 1309 echo bbp_get_forum_topic_count_hidden( $forum_id, $integer ); 1295 1310 } 1296 1311 /** … … 1301 1316 * 1302 1317 * @param int $forum_id Optional. Topic id 1318 * @param boolean $integer Optional. Whether or not to format the result 1303 1319 * @uses bbp_get_forum_id() To get the forum id 1304 1320 * @uses get_post_meta() To get the hidden topic count … … 1307 1323 * @return int Topic hidden topic count 1308 1324 */ 1309 function bbp_get_forum_topic_count_hidden( $forum_id = 0 ) {1325 function bbp_get_forum_topic_count_hidden( $forum_id = 0, $integer = false ) { 1310 1326 $forum_id = bbp_get_forum_id( $forum_id ); 1311 $topics = get_post_meta( $forum_id, '_bbp_topic_count_hidden', true ); 1312 1313 return (int) apply_filters( 'bbp_get_forum_topic_count_hidden', (int) $topics, $forum_id ); 1327 $topics = absint( get_post_meta( $forum_id, '_bbp_topic_count_hidden', true ) ); 1328 $filter = ( true === $integer ) ? 'bbp_get_forum_topic_count_hidden_int' : 'bbp_get_forum_topic_count_hidden'; 1329 1330 return apply_filters( $filter, $topics, $forum_id ); 1314 1331 } 1315 1332 … … 1822 1839 1823 1840 // Get some forum data 1841 $tc_int = bbp_get_forum_topic_count( $forum_id, false ); 1842 $rc_int = bbp_get_forum_reply_count( $forum_id, false ); 1824 1843 $topic_count = bbp_get_forum_topic_count( $forum_id ); 1825 1844 $reply_count = bbp_get_forum_reply_count( $forum_id ); … … 1828 1847 // Has replies 1829 1848 if ( !empty( $reply_count ) ) { 1830 $reply_text = sprintf( _n( '%s reply', '%s replies', $r eply_count, 'bbpress' ), $reply_count );1849 $reply_text = sprintf( _n( '%s reply', '%s replies', $rc_int, 'bbpress' ), $reply_count ); 1831 1850 } 1832 1851 … … 1839 1858 // Forum has no last active data 1840 1859 } else { 1841 $topic_text = sprintf( _n( '%s topic', '%s topics', $t opic_count, 'bbpress' ), $topic_count );1860 $topic_text = sprintf( _n( '%s topic', '%s topics', $tc_int, 'bbpress' ), $topic_count ); 1842 1861 } 1843 1862 -
trunk/bbp-includes/replies/functions.php
r4255 r4258 262 262 'post_type' => bbp_get_reply_post_type(), 263 263 'comment_status' => 'closed', 264 'menu_order' => (int) ( bbp_get_topic_reply_count( $topic_id ) + 1 )264 'menu_order' => bbp_get_topic_reply_count( $topic_id, false ) + 1 265 265 ) ); 266 266 … … 1342 1342 * @since bbPress (r3540) 1343 1343 * 1344 * @param int $default Default replies per page (15) 1344 1345 * @uses get_option() To get the setting 1345 1346 * @uses apply_filters() To allow the return value to be manipulated 1346 1347 * @return int 1347 1348 */ 1348 function bbp_get_replies_per_page() { 1349 1350 // The default per setting 1351 $default = 15; 1349 function bbp_get_replies_per_page( $default = 15 ) { 1352 1350 1353 1351 // Get database option and cast as integer 1354 $ per = $retval = (int)get_option( '_bbp_replies_per_page', $default );1352 $retval = get_option( '_bbp_replies_per_page', $default ); 1355 1353 1356 1354 // If return val is empty, set it to default … … 1359 1357 1360 1358 // Filter and return 1361 return (int) apply_filters( 'bbp_get_replies_per_page', $retval, $per);1359 return absint( apply_filters( 'bbp_get_replies_per_page', $retval, $default ) ); 1362 1360 } 1363 1361 … … 1367 1365 * @since bbPress (r3540) 1368 1366 * 1367 * @param int $default Default replies per page (25) 1369 1368 * @uses get_option() To get the setting 1370 1369 * @uses apply_filters() To allow the return value to be manipulated 1371 1370 * @return int 1372 1371 */ 1373 function bbp_get_replies_per_rss_page() { 1374 1375 // The default per setting 1376 $default = 25; 1372 function bbp_get_replies_per_rss_page( $default = 25 ) { 1377 1373 1378 1374 // Get database option and cast as integer 1379 $ per = $retval = (int)get_option( '_bbp_replies_per_rss_page', $default );1375 $retval = get_option( '_bbp_replies_per_rss_page', $default ); 1380 1376 1381 1377 // If return val is empty, set it to default … … 1384 1380 1385 1381 // Filter and return 1386 return (int) apply_filters( 'bbp_get_replies_per_rss_page', $retval, $per);1382 return absint( apply_filters( 'bbp_get_replies_per_rss_page', $retval, $default ) ); 1387 1383 } 1388 1384 … … 1670 1666 1671 1667 // Make sure the topic has replies before running another query 1672 $reply_count = bbp_get_topic_reply_count( $topic_id );1668 $reply_count = bbp_get_topic_reply_count( $topic_id, false ); 1673 1669 if ( !empty( $reply_count ) ) { 1674 1670 -
trunk/bbp-includes/replies/template-tags.php
r4255 r4258 253 253 } 254 254 255 return (int) apply_filters( 'bbp_get_reply_id', (int)$bbp_reply_id, $reply_id );255 return (int) apply_filters( 'bbp_get_reply_id', $bbp_reply_id, $reply_id ); 256 256 } 257 257 … … 691 691 * 692 692 * @param int $reply_id Optional. Reply id 693 * @param boolean $integer Optional. Whether or not to format the result 693 694 * @uses bbp_get_reply_revisions() To get the reply revisions 694 695 * @uses apply_filters() Calls 'bbp_get_reply_revision_count' … … 696 697 * @return string reply revision count 697 698 */ 698 function bbp_get_reply_revision_count( $reply_id = 0 ) { 699 return apply_filters( 'bbp_get_reply_revisions', count( bbp_get_reply_revisions( $reply_id ) ), $reply_id ); 699 function bbp_get_reply_revision_count( $reply_id = 0, $integer = false ) { 700 $count = absint( count( bbp_get_reply_revisions( $reply_id ) ) ); 701 $filter = ( true === $integer ) ? 'bbp_get_reply_revision_count_int' : 'bbp_get_reply_revision_count'; 702 703 return apply_filters( $filter, $count, $reply_id ); 700 704 } 701 705 … … 863 867 $author_id = get_post_field( 'post_author', $reply_id ); 864 868 865 return (int) apply_filters( 'bbp_get_reply_author_id', (int)$author_id, $reply_id );869 return (int) apply_filters( 'bbp_get_reply_author_id', $author_id, $reply_id ); 866 870 } 867 871 … … 1267 1271 $topic_id = bbp_get_topic_id( $topic_id ); 1268 1272 1269 return apply_filters( 'bbp_get_reply_topic_id', (int)$topic_id, $reply_id );1273 return (int) apply_filters( 'bbp_get_reply_topic_id', $topic_id, $reply_id ); 1270 1274 } 1271 1275 … … 1307 1311 $forum_id = bbp_get_forum_id( $forum_id ); 1308 1312 1309 return apply_filters( 'bbp_get_reply_forum_id', (int)$forum_id, $reply_id );1313 return (int) apply_filters( 'bbp_get_reply_forum_id', $forum_id, $reply_id ); 1310 1314 } 1311 1315 … … 1370 1374 $reply_position++; 1371 1375 1372 return (int) apply_filters( 'bbp_get_reply_position', (int)$reply_position, $reply_id, $topic_id );1376 return (int) apply_filters( 'bbp_get_reply_position', $reply_position, $reply_id, $topic_id ); 1373 1377 } 1374 1378 -
trunk/bbp-includes/topics/functions.php
r4255 r4258 3049 3049 * @since bbPress (r3540) 3050 3050 * 3051 * @param int $default Default replies per page (15) 3051 3052 * @uses get_option() To get the setting 3052 3053 * @uses apply_filters() To allow the return value to be manipulated 3053 3054 * @return int 3054 3055 */ 3055 function bbp_get_topics_per_page() { 3056 3057 // The default per setting 3058 $default = 15; 3056 function bbp_get_topics_per_page( $default = 15 ) { 3059 3057 3060 3058 // Get database option and cast as integer 3061 $ per = $retval = (int)get_option( '_bbp_topics_per_page', $default );3059 $retval = get_option( '_bbp_topics_per_page', $default ); 3062 3060 3063 3061 // If return val is empty, set it to default … … 3066 3064 3067 3065 // Filter and return 3068 return (int) apply_filters( 'bbp_get_topics_per_page', $retval, $per);3066 return absint( apply_filters( 'bbp_get_topics_per_page', $retval, $default ) ); 3069 3067 } 3070 3068 … … 3074 3072 * @since bbPress (r3540) 3075 3073 * 3074 * @param int $default Default replies per page (25) 3076 3075 * @uses get_option() To get the setting 3077 3076 * @uses apply_filters() To allow the return value to be manipulated 3078 3077 * @return int 3079 3078 */ 3080 function bbp_get_topics_per_rss_page() { 3081 3082 // The default per setting 3083 $default = 25; 3079 function bbp_get_topics_per_rss_page( $default = 25 ) { 3084 3080 3085 3081 // Get database option and cast as integer 3086 $ per = $retval = (int)get_option( '_bbp_topics_per_rss_page', $default );3082 $retval = get_option( '_bbp_topics_per_rss_page', $default ); 3087 3083 3088 3084 // If return val is empty, set it to default … … 3091 3087 3092 3088 // Filter and return 3093 return (int) apply_filters( 'bbp_get_topics_per_rss_page', $retval, $per);3089 return absint( apply_filters( 'bbp_get_topics_per_rss_page', $retval, $default ) ); 3094 3090 } 3095 3091 -
trunk/bbp-includes/topics/template-tags.php
r4255 r4258 737 737 738 738 // Get total and add 1 if topic is included in the reply loop 739 $total = bbp_get_topic_reply_count( $topic_id );739 $total = bbp_get_topic_reply_count( $topic_id, true ); 740 740 741 741 // Bump if topic is in loop … … 918 918 * @return string Topic revision count 919 919 */ 920 function bbp_get_topic_revision_count( $topic_id = 0 ) { 921 return apply_filters( 'bbp_get_topic_revisions', count( bbp_get_topic_revisions( $topic_id ) ), $topic_id ); 920 function bbp_get_topic_revision_count( $topic_id = 0, $integer = false ) { 921 $count = absint( count( bbp_get_topic_revisions( $topic_id ) ) ); 922 $filter = ( true === $integer ) ? 'bbp_get_topic_revision_count_int' : 'bbp_get_topic_revision_count'; 923 924 return apply_filters( $filter, $count, $topic_id ); 922 925 } 923 926 … … 1855 1858 $topic = bbp_get_topic( bbp_get_topic_id( (int) $topic_id ) ); 1856 1859 $topic_id = $topic->ID; 1857 $replies = bbp_get_topic_reply_count( $topic_id ); 1858 $replies = sprintf( _n( '%s reply', '%s replies', $replies, 'bbpress' ), $replies ); 1860 $replies = sprintf( _n( '%s reply', '%s replies', bbp_get_topic_reply_count( $topic_id, true ), 'bbpress' ), bbp_get_topic_reply_count( $topic_id ) ); 1859 1861 $retval = ''; 1860 1862 … … 1893 1895 * 1894 1896 * @param int $topic_id Optional. Topic id 1897 * @param boolean $integer Optional. Whether or not to format the result 1895 1898 * @uses bbp_get_topic_reply_count() To get the topic reply count 1896 1899 */ 1897 function bbp_topic_reply_count( $topic_id = 0 ) {1898 echo bbp_get_topic_reply_count( $topic_id );1900 function bbp_topic_reply_count( $topic_id = 0, $integer = false ) { 1901 echo bbp_get_topic_reply_count( $topic_id, $integer ); 1899 1902 } 1900 1903 /** … … 1904 1907 * 1905 1908 * @param int $topic_id Optional. Topic id 1909 * @param boolean $integer Optional. Whether or not to format the result 1906 1910 * @uses bbp_get_topic_id() To get the topic id 1907 1911 * @uses get_post_meta() To get the topic reply count meta … … 1910 1914 * @return int Reply count 1911 1915 */ 1912 function bbp_get_topic_reply_count( $topic_id = 0 ) {1916 function bbp_get_topic_reply_count( $topic_id = 0, $integer = false ) { 1913 1917 $topic_id = bbp_get_topic_id( $topic_id ); 1914 $replies = get_post_meta( $topic_id, '_bbp_reply_count', true ); 1915 1916 return apply_filters( 'bbp_get_topic_reply_count', (int) $replies, $topic_id ); 1918 $replies = absint( get_post_meta( $topic_id, '_bbp_reply_count', true ) ); 1919 $filter = ( true === $integer ) ? 'bbp_get_topic_reply_count_int' : 'bbp_get_topic_reply_count'; 1920 1921 return apply_filters( $filter, $replies, $topic_id ); 1917 1922 } 1918 1923 … … 1923 1928 * 1924 1929 * @param int $topic_id Optional. Topic id 1930 * @param boolean $integer Optional. Whether or not to format the result 1925 1931 * @uses bbp_get_topic_post_count() To get the topic post count 1926 1932 */ 1927 function bbp_topic_post_count( $topic_id = 0 ) {1928 echo bbp_get_topic_post_count( $topic_id );1933 function bbp_topic_post_count( $topic_id = 0, $integer = false ) { 1934 echo bbp_get_topic_post_count( $topic_id, $integer ); 1929 1935 } 1930 1936 /** … … 1934 1940 * 1935 1941 * @param int $topic_id Optional. Topic id 1942 * @param boolean $integer Optional. Whether or not to format the result 1936 1943 * @uses bbp_get_topic_id() To get the topic id 1937 1944 * @uses get_post_meta() To get the topic post count meta … … 1940 1947 * @return int Post count 1941 1948 */ 1942 function bbp_get_topic_post_count( $topic_id = 0 ) {1949 function bbp_get_topic_post_count( $topic_id = 0, $integer = false ) { 1943 1950 $topic_id = bbp_get_topic_id( $topic_id ); 1944 $replies = get_post_meta( $topic_id, '_bbp_reply_count', true ); 1945 1946 return apply_filters( 'bbp_get_topic_post_count', (int) $replies + 1, $topic_id ); 1951 $replies = absint( get_post_meta( $topic_id, '_bbp_reply_count', true ) ) + 1; 1952 $filter = ( true === $integer ) ? 'bbp_get_topic_post_count_int' : 'bbp_get_topic_post_count'; 1953 1954 return apply_filters( $filter, $replies, $topic_id ); 1947 1955 } 1948 1956 … … 1954 1962 * 1955 1963 * @param int $topic_id Optional. Topic id 1964 * @param boolean $integer Optional. Whether or not to format the result 1956 1965 * @uses bbp_get_topic_reply_count_hidden() To get the topic hidden reply count 1957 1966 */ 1958 function bbp_topic_reply_count_hidden( $topic_id = 0 ) {1959 echo bbp_get_topic_reply_count_hidden( $topic_id );1967 function bbp_topic_reply_count_hidden( $topic_id = 0, $integer = false ) { 1968 echo bbp_get_topic_reply_count_hidden( $topic_id, $integer ); 1960 1969 } 1961 1970 /** … … 1966 1975 * 1967 1976 * @param int $topic_id Optional. Topic id 1977 * @param boolean $integer Optional. Whether or not to format the result 1968 1978 * @uses bbp_get_topic_id() To get the topic id 1969 1979 * @uses get_post_meta() To get the hidden reply count … … 1972 1982 * @return int Topic hidden reply count 1973 1983 */ 1974 function bbp_get_topic_reply_count_hidden( $topic_id = 0 ) {1984 function bbp_get_topic_reply_count_hidden( $topic_id = 0, $integer = false ) { 1975 1985 $topic_id = bbp_get_topic_id( $topic_id ); 1976 $replies = get_post_meta( $topic_id, '_bbp_reply_count_hidden', true ); 1977 1978 return (int) apply_filters( 'bbp_get_topic_reply_count_hidden', (int) $replies, $topic_id ); 1986 $replies = absint( get_post_meta( $topic_id, '_bbp_reply_count_hidden', true ) ); 1987 $filter = ( true === $integer ) ? 'bbp_get_topic_reply_count_hidden_int' : 'bbp_get_topic_reply_count_hidden'; 1988 1989 return apply_filters( $filter, $replies, $topic_id ); 1979 1990 } 1980 1991 … … 1987 1998 * @uses bbp_get_topic_voice_count() To get the topic voice count 1988 1999 */ 1989 function bbp_topic_voice_count( $topic_id = 0 ) {1990 echo bbp_get_topic_voice_count( $topic_id );2000 function bbp_topic_voice_count( $topic_id = 0, $integer = false ) { 2001 echo bbp_get_topic_voice_count( $topic_id, $integer ); 1991 2002 } 1992 2003 /** … … 2002 2013 * @return int Voice count of the topic 2003 2014 */ 2004 function bbp_get_topic_voice_count( $topic_id = 0 ) {2015 function bbp_get_topic_voice_count( $topic_id = 0, $integer = false ) { 2005 2016 $topic_id = bbp_get_topic_id( $topic_id ); 2006 $voices = get_post_meta( $topic_id, '_bbp_voice_count', true ); 2007 2008 return apply_filters( 'bbp_get_topic_voice_count', (int) $voices, $topic_id ); 2017 $voices = absint( get_post_meta( $topic_id, '_bbp_voice_count', true ) ); 2018 $filter = ( true === $integer ) ? 'bbp_get_topic_voice_count_int' : 'bbp_get_topic_voice_count'; 2019 2020 return apply_filters( $filter, $voices, $topic_id ); 2009 2021 } 2010 2022 -
trunk/bbp-includes/users/options.php
r4249 r4258 126 126 * 127 127 * @param int $user_id 128 * @param boolean $integer Optional. Whether or not to format the result 128 129 * @uses bbp_get_user_topic_count() 129 130 * @return string 130 131 */ 131 function bbp_user_topic_count( $user_id = 0 ) {132 echo bbp_get_user_topic_count( $user_id );132 function bbp_user_topic_count( $user_id = 0, $integer = false ) { 133 echo bbp_get_user_topic_count( $user_id, $integer ); 133 134 } 134 135 /** … … 138 139 * 139 140 * @param int $user_id 141 * @param boolean $integer Optional. Whether or not to format the result 140 142 * @uses bbp_get_user_id() 141 143 * @uses get_user_option() … … 143 145 * @return string 144 146 */ 145 function bbp_get_user_topic_count( $user_id = 0 ) { 146 147 // Validate user id 148 $user_id = bbp_get_user_id( $user_id ); 149 if ( empty( $user_id ) ) 150 return false; 151 152 $count = get_user_option( '_bbp_topic_count', $user_id ); 153 154 return apply_filters( 'bbp_get_user_topic_count', (int) $count, $user_id ); 147 function bbp_get_user_topic_count( $user_id = 0, $integer = false ) { 148 149 // Validate user id 150 $user_id = bbp_get_user_id( $user_id ); 151 if ( empty( $user_id ) ) 152 return false; 153 154 $count = absint( get_user_option( '_bbp_topic_count', $user_id ) ); 155 $filter = ( false == $integer ) ? 'bbp_get_user_topic_count_int' : 'bbp_get_user_topic_count'; 156 157 return apply_filters( $filter, $count, $user_id ); 155 158 } 156 159 … … 161 164 * 162 165 * @param int $user_id 166 * @param boolean $integer Optional. Whether or not to format the result 163 167 * @uses bbp_get_user_reply_count() 164 168 * @return string 165 169 */ 166 function bbp_user_reply_count( $user_id = 0 ) {167 echo bbp_get_user_reply_count( $user_id );170 function bbp_user_reply_count( $user_id = 0, $integer = false ) { 171 echo bbp_get_user_reply_count( $user_id, $integer ); 168 172 } 169 173 /** … … 173 177 * 174 178 * @param int $user_id 179 * @param boolean $integer Optional. Whether or not to format the result 175 180 * @uses bbp_get_user_id() 176 181 * @uses get_user_option() … … 178 183 * @return string 179 184 */ 180 function bbp_get_user_reply_count( $user_id = 0 ) { 181 182 // Validate user id 183 $user_id = bbp_get_user_id( $user_id ); 184 if ( empty( $user_id ) ) 185 return false; 186 187 $count = get_user_option( '_bbp_reply_count', $user_id ); 188 189 return apply_filters( 'bbp_get_user_reply_count', (int) $count, $user_id ); 185 function bbp_get_user_reply_count( $user_id = 0, $integer = false ) { 186 187 // Validate user id 188 $user_id = bbp_get_user_id( $user_id ); 189 if ( empty( $user_id ) ) 190 return false; 191 192 $count = absint( get_user_option( '_bbp_reply_count', $user_id ) ); 193 $filter = ( true == $integer ) ? 'bbp_get_user_topic_count_int' : 'bbp_get_user_topic_count'; 194 195 return apply_filters( $filter, $count, $user_id ); 190 196 } 191 197 … … 196 202 * 197 203 * @param int $user_id 204 * @param boolean $integer Optional. Whether or not to format the result 198 205 * @uses bbp_get_user_post_count() 199 206 * @return string 200 207 */ 201 function bbp_user_post_count( $user_id = 0 ) {202 echo bbp_get_user_post_count( $user_id );208 function bbp_user_post_count( $user_id = 0, $integer = false ) { 209 echo bbp_get_user_post_count( $user_id, $integer ); 203 210 } 204 211 /** … … 208 215 * 209 216 * @param int $user_id 217 * @param boolean $integer Optional. Whether or not to format the result 210 218 * @uses bbp_get_user_id() 211 219 * @uses get_user_option() … … 213 221 * @return string 214 222 */ 215 function bbp_get_user_post_count( $user_id = 0 ) { 216 217 // Validate user id 218 $user_id = bbp_get_user_id( $user_id ); 219 if ( empty( $user_id ) ) 220 return false; 221 222 $topics = bbp_get_user_topic_count( $user_id ); 223 $replies = bbp_get_user_reply_count( $user_id ); 224 $count = (int) $topics + (int) $replies; 225 226 return apply_filters( 'bbp_get_user_post_count', (int) $count, $user_id ); 223 function bbp_get_user_post_count( $user_id = 0, $integer = false ) { 224 225 // Validate user id 226 $user_id = bbp_get_user_id( $user_id ); 227 if ( empty( $user_id ) ) 228 return false; 229 230 $topics = bbp_get_user_topic_count( $user_id, true ); 231 $replies = bbp_get_user_reply_count( $user_id, true ); 232 $count = absint( $topics + $replies ); 233 $filter = ( true == $integer ) ? 'bbp_get_user_post_count_int' : 'bbp_get_user_post_count'; 234 235 return apply_filters( $filter, $count, $user_id ); 227 236 } 228 237
Note: See TracChangeset
for help on using the changeset viewer.