| @@ -7,9 +7,9 @@ | ||
| 7 | 7 | * @subpackage Functions |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | // Exit if accessed directly |
| 11 | -if ( !defined( 'ABSPATH' ) ) exit; | |
| 11 | +defined( 'ABSPATH' ) || exit; | |
| 12 | 12 | |
| 13 | 13 | /** Versions ******************************************************************/ |
| 14 | 14 | |
| 15 | 15 | /** |
| @@ -14,10 +14,9 @@ | ||
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * Output the bbPress version |
| 17 | 17 | * |
| 18 | - * @since bbPress (r3468) | |
| 19 | - * @uses bbp_get_version() To get the bbPress version | |
| 18 | + * @since 2.0.0 bbPress (r3468) | |
| 20 | 19 | */ |
| 21 | 20 | function bbp_version() { |
| 22 | 21 | echo bbp_get_version(); |
| 23 | 22 | } |
| @@ -23,9 +22,10 @@ | ||
| 23 | 22 | } |
| 24 | 23 | /** |
| 25 | 24 | * Return the bbPress version |
| 26 | 25 | * |
| 27 | - * @since bbPress (r3468) | |
| 26 | + * @since 2.0.0 bbPress (r3468) | |
| 27 | + * | |
| 28 | 28 | * @retrun string The bbPress version |
| 29 | 29 | */ |
| 30 | 30 | function bbp_get_version() { |
| 31 | 31 | return bbpress()->version; |
| @@ -31,12 +31,32 @@ | ||
| 31 | 31 | return bbpress()->version; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | + * Output the bbPress asset version | |
| 36 | + * | |
| 37 | + * @since 2.6.7 bbPress (r7188) | |
| 38 | + */ | |
| 39 | +function bbp_asset_version() { | |
| 40 | + echo bbp_get_asset_version(); | |
| 41 | +} | |
| 42 | + /** | |
| 43 | + * Return the bbPress asset version | |
| 44 | + * | |
| 45 | + * @since 2.6.7 bbPress (r7188) | |
| 46 | + * | |
| 47 | + * @retrun string The bbPress asset version | |
| 48 | + */ | |
| 49 | + function bbp_get_asset_version() { | |
| 50 | + return bbp_doing_script_debug() | |
| 51 | + ? (string) time() | |
| 52 | + : bbp_get_version(); | |
| 53 | + } | |
| 54 | + | |
| 55 | +/** | |
| 35 | 56 | * Output the bbPress database version |
| 36 | 57 | * |
| 37 | - * @since bbPress (r3468) | |
| 38 | - * @uses bbp_get_version() To get the bbPress version | |
| 58 | + * @since 2.0.0 bbPress (r3468) | |
| 39 | 59 | */ |
| 40 | 60 | function bbp_db_version() { |
| 41 | 61 | echo bbp_get_db_version(); |
| 42 | 62 | } |
| @@ -42,9 +62,10 @@ | ||
| 42 | 62 | } |
| 43 | 63 | /** |
| 44 | 64 | * Return the bbPress database version |
| 45 | 65 | * |
| 46 | - * @since bbPress (r3468) | |
| 66 | + * @since 2.0.0 bbPress (r3468) | |
| 67 | + * | |
| 47 | 68 | * @retrun string The bbPress version |
| 48 | 69 | */ |
| 49 | 70 | function bbp_get_db_version() { |
| 50 | 71 | return bbpress()->db_version; |
| @@ -52,10 +73,9 @@ | ||
| 52 | 73 | |
| 53 | 74 | /** |
| 54 | 75 | * Output the bbPress database version directly from the database |
| 55 | 76 | * |
| 56 | - * @since bbPress (r3468) | |
| 57 | - * @uses bbp_get_version() To get the current bbPress version | |
| 77 | + * @since 2.0.0 bbPress (r3468) | |
| 58 | 78 | */ |
| 59 | 79 | function bbp_db_version_raw() { |
| 60 | 80 | echo bbp_get_db_version_raw(); |
| 61 | 81 | } |
| @@ -61,9 +81,10 @@ | ||
| 61 | 81 | } |
| 62 | 82 | /** |
| 63 | 83 | * Return the bbPress database version directly from the database |
| 64 | 84 | * |
| 65 | - * @since bbPress (r3468) | |
| 85 | + * @since 2.0.0 bbPress (r3468) | |
| 86 | + * | |
| 66 | 87 | * @retrun string The current bbPress version |
| 67 | 88 | */ |
| 68 | 89 | function bbp_get_db_version_raw() { |
| 69 | 90 | return get_option( '_bbp_db_version', '' ); |
| @@ -71,58 +92,83 @@ | ||
| 71 | 92 | |
| 72 | 93 | /** Post Meta *****************************************************************/ |
| 73 | 94 | |
| 74 | 95 | /** |
| 75 | - * Update a posts forum meta ID | |
| 96 | + * Update the forum meta ID of a post | |
| 76 | 97 | * |
| 77 | - * @since bbPress (r3181) | |
| 98 | + * @since 2.0.0 bbPress (r3181) | |
| 78 | 99 | * |
| 79 | - * @param int $post_id The post to update | |
| 100 | + * @param int $post_id The post to update | |
| 80 | 101 | * @param int $forum_id The forum |
| 81 | 102 | */ |
| 82 | -function bbp_update_forum_id( $post_id, $forum_id ) { | |
| 103 | +function bbp_update_forum_id( $post_id = 0, $forum_id = 0 ) { | |
| 83 | 104 | |
| 84 | 105 | // Allow the forum ID to be updated 'just in time' before save |
| 85 | - $forum_id = apply_filters( 'bbp_update_forum_id', $forum_id, $post_id ); | |
| 106 | + $forum_id = (int) apply_filters( 'bbp_update_forum_id', $forum_id, $post_id ); | |
| 86 | 107 | |
| 87 | 108 | // Update the post meta forum ID |
| 88 | - update_post_meta( $post_id, '_bbp_forum_id', (int) $forum_id ); | |
| 109 | + update_post_meta( $post_id, '_bbp_forum_id', $forum_id ); | |
| 110 | + | |
| 111 | + return $forum_id; | |
| 89 | 112 | } |
| 90 | 113 | |
| 91 | 114 | /** |
| 92 | - * Update a posts topic meta ID | |
| 115 | + * Update the topic meta ID of a post | |
| 93 | 116 | * |
| 94 | - * @since bbPress (r3181) | |
| 117 | + * @since 2.0.0 bbPress (r3181) | |
| 95 | 118 | * |
| 96 | - * @param int $post_id The post to update | |
| 97 | - * @param int $forum_id The forum | |
| 119 | + * @param int $post_id The post to update | |
| 120 | + * @param int $topic_id The topic | |
| 98 | 121 | */ |
| 99 | -function bbp_update_topic_id( $post_id, $topic_id ) { | |
| 122 | +function bbp_update_topic_id( $post_id = 0, $topic_id = 0 ) { | |
| 100 | 123 | |
| 101 | 124 | // Allow the topic ID to be updated 'just in time' before save |
| 102 | - $topic_id = apply_filters( 'bbp_update_topic_id', $topic_id, $post_id ); | |
| 125 | + $topic_id = (int) apply_filters( 'bbp_update_topic_id', $topic_id, $post_id ); | |
| 103 | 126 | |
| 104 | 127 | // Update the post meta topic ID |
| 105 | - update_post_meta( $post_id, '_bbp_topic_id', (int) $topic_id ); | |
| 128 | + update_post_meta( $post_id, '_bbp_topic_id', $topic_id ); | |
| 129 | + | |
| 130 | + return $topic_id; | |
| 106 | 131 | } |
| 107 | 132 | |
| 108 | 133 | /** |
| 109 | - * Update a posts reply meta ID | |
| 134 | + * Update the reply meta ID of a post | |
| 110 | 135 | * |
| 111 | - * @since bbPress (r3181) | |
| 136 | + * @since 2.0.0 bbPress (r3181) | |
| 112 | 137 | * |
| 113 | - * @param int $post_id The post to update | |
| 114 | - * @param int $forum_id The forum | |
| 138 | + * @param int $post_id The post to update | |
| 139 | + * @param int $reply_id The reply | |
| 115 | 140 | */ |
| 116 | -function bbp_update_reply_id( $post_id, $reply_id ) { | |
| 141 | +function bbp_update_reply_id( $post_id = 0, $reply_id = 0 ) { | |
| 117 | 142 | |
| 118 | 143 | // Allow the reply ID to be updated 'just in time' before save |
| 119 | - $reply_id = apply_filters( 'bbp_update_reply_id', $reply_id, $post_id ); | |
| 144 | + $reply_id = (int) apply_filters( 'bbp_update_reply_id', $reply_id, $post_id ); | |
| 120 | 145 | |
| 121 | 146 | // Update the post meta reply ID |
| 122 | - update_post_meta( $post_id, '_bbp_reply_id',(int) $reply_id ); | |
| 147 | + update_post_meta( $post_id, '_bbp_reply_id', $reply_id ); | |
| 148 | + | |
| 149 | + return $reply_id; | |
| 123 | 150 | } |
| 124 | 151 | |
| 152 | +/** | |
| 153 | + * Update the reply-to meta ID of a post | |
| 154 | + * | |
| 155 | + * @since 2.6.0 bbPress (r5735) | |
| 156 | + * | |
| 157 | + * @param int $post_id The post to update | |
| 158 | + * @param int $reply_id The reply ID | |
| 159 | + */ | |
| 160 | +function bbp_update_reply_to_id( $post_id = 0, $reply_id = 0 ) { | |
| 161 | + | |
| 162 | + // Allow the reply ID to be updated 'just in time' before save | |
| 163 | + $reply_id = (int) apply_filters( 'bbp_update_reply_to_id', $reply_id, $post_id ); | |
| 164 | + | |
| 165 | + // Update the post meta reply ID | |
| 166 | + update_post_meta( $post_id, '_bbp_reply_to', $reply_id ); | |
| 167 | + | |
| 168 | + return $reply_id; | |
| 169 | +} | |
| 170 | + | |
| 125 | 171 | /** Views *********************************************************************/ |
| 126 | 172 | |
| 127 | 173 | /** |
| 128 | 174 | * Get the registered views |
| @@ -128,9 +174,9 @@ | ||
| 128 | 174 | * Get the registered views |
| 129 | 175 | * |
| 130 | 176 | * Does nothing much other than return the {@link $bbp->views} variable |
| 131 | 177 | * |
| 132 | - * @since bbPress (r2789) | |
| 178 | + * @since 2.0.0 bbPress (r2789) | |
| 133 | 179 | * |
| 134 | 180 | * @return array Views |
| 135 | 181 | */ |
| 136 | 182 | function bbp_get_views() { |
| @@ -139,56 +185,55 @@ | ||
| 139 | 185 | |
| 140 | 186 | /** |
| 141 | 187 | * Register a bbPress view |
| 142 | 188 | * |
| 143 | - * @todo Implement feeds - See {@link http://trac.bbpress.org/ticket/1422} | |
| 189 | + * @since 2.0.0 bbPress (r2789) | |
| 144 | 190 | * |
| 145 | - * @since bbPress (r2789) | |
| 146 | - * | |
| 147 | 191 | * @param string $view View name |
| 148 | 192 | * @param string $title View title |
| 149 | 193 | * @param mixed $query_args {@link bbp_has_topics()} arguments. |
| 150 | - * @param bool $feed Have a feed for the view? Defaults to true. NOT IMPLEMENTED | |
| 194 | + * @param bool $feed Have a feed for the view? Defaults to true. | |
| 151 | 195 | * @param string $capability Capability that the current user must have |
| 152 | - * @uses sanitize_title() To sanitize the view name | |
| 153 | - * @uses esc_html() To sanitize the view title | |
| 196 | + * | |
| 154 | 197 | * @return array The just registered (but processed) view |
| 155 | 198 | */ |
| 156 | 199 | function bbp_register_view( $view, $title, $query_args = '', $feed = true, $capability = '' ) { |
| 157 | 200 | |
| 158 | 201 | // Bail if user does not have capability |
| 159 | - if ( ! empty( $capability ) && ! current_user_can( $capability ) ) | |
| 202 | + if ( ! empty( $capability ) && ! current_user_can( $capability ) ) { | |
| 160 | 203 | return false; |
| 204 | + } | |
| 161 | 205 | |
| 162 | 206 | $bbp = bbpress(); |
| 163 | 207 | $view = sanitize_title( $view ); |
| 164 | 208 | $title = esc_html( $title ); |
| 165 | 209 | |
| 166 | - if ( empty( $view ) || empty( $title ) ) | |
| 210 | + if ( empty( $view ) || empty( $title ) ) { | |
| 167 | 211 | return false; |
| 212 | + } | |
| 168 | 213 | |
| 169 | 214 | $query_args = bbp_parse_args( $query_args, '', 'register_view' ); |
| 170 | 215 | |
| 171 | 216 | // Set show_stickies to false if it wasn't supplied |
| 172 | - if ( !isset( $query_args['show_stickies'] ) ) | |
| 217 | + if ( ! isset( $query_args['show_stickies'] ) ) { | |
| 173 | 218 | $query_args['show_stickies'] = false; |
| 219 | + } | |
| 174 | 220 | |
| 175 | - $bbp->views[$view] = array( | |
| 221 | + $bbp->views[ $view ] = array( | |
| 176 | 222 | 'title' => $title, |
| 177 | 223 | 'query' => $query_args, |
| 178 | 224 | 'feed' => $feed |
| 179 | 225 | ); |
| 180 | 226 | |
| 181 | - return $bbp->views[$view]; | |
| 227 | + return $bbp->views[ $view ]; | |
| 182 | 228 | } |
| 183 | 229 | |
| 184 | 230 | /** |
| 185 | 231 | * Deregister a bbPress view |
| 186 | 232 | * |
| 187 | - * @since bbPress (r2789) | |
| 233 | + * @since 2.0.0 bbPress (r2789) | |
| 188 | 234 | * |
| 189 | 235 | * @param string $view View name |
| 190 | - * @uses sanitize_title() To sanitize the view name | |
| 191 | 236 | * @return bool False if the view doesn't exist, true on success |
| 192 | 237 | */ |
| 193 | 238 | function bbp_deregister_view( $view ) { |
| 194 | 239 | $bbp = bbpress(); |
| @@ -193,38 +238,37 @@ | ||
| 193 | 238 | function bbp_deregister_view( $view ) { |
| 194 | 239 | $bbp = bbpress(); |
| 195 | 240 | $view = sanitize_title( $view ); |
| 196 | 241 | |
| 197 | - if ( !isset( $bbp->views[$view] ) ) | |
| 242 | + if ( ! isset( $bbp->views[ $view ] ) ) { | |
| 198 | 243 | return false; |
| 244 | + } | |
| 199 | 245 | |
| 200 | - unset( $bbp->views[$view] ); | |
| 246 | + unset( $bbp->views[ $view ] ); | |
| 201 | 247 | |
| 202 | 248 | return true; |
| 203 | 249 | } |
| 204 | 250 | |
| 205 | 251 | /** |
| 206 | - * Run the view's query | |
| 252 | + * Run the query of a topic-view | |
| 207 | 253 | * |
| 208 | - * @since bbPress (r2789) | |
| 254 | + * @since 2.0.0 bbPress (r2789) | |
| 209 | 255 | * |
| 210 | 256 | * @param string $view Optional. View id |
| 211 | 257 | * @param mixed $new_args New arguments. See {@link bbp_has_topics()} |
| 212 | - * @uses bbp_get_view_id() To get the view id | |
| 213 | - * @uses bbp_get_view_query_args() To get the view query args | |
| 214 | - * @uses sanitize_title() To sanitize the view name | |
| 215 | - * @uses bbp_has_topics() To make the topics query | |
| 216 | 258 | * @return bool False if the view doesn't exist, otherwise if topics are there |
| 217 | 259 | */ |
| 218 | 260 | function bbp_view_query( $view = '', $new_args = '' ) { |
| 219 | 261 | |
| 262 | + // Get view, or bail | |
| 220 | 263 | $view = bbp_get_view_id( $view ); |
| 221 | - if ( empty( $view ) ) | |
| 264 | + if ( empty( $view ) ) { | |
| 222 | 265 | return false; |
| 266 | + } | |
| 223 | 267 | |
| 224 | 268 | $query_args = bbp_get_view_query_args( $view ); |
| 225 | 269 | |
| 226 | - if ( !empty( $new_args ) ) { | |
| 270 | + if ( ! empty( $new_args ) ) { | |
| 227 | 271 | $new_args = bbp_parse_args( $new_args, '', 'view_query' ); |
| 228 | 272 | $query_args = array_merge( $query_args, $new_args ); |
| 229 | 273 | } |
| 230 | 274 | |
| @@ -231,21 +275,24 @@ | ||
| 231 | 275 | return bbp_has_topics( $query_args ); |
| 232 | 276 | } |
| 233 | 277 | |
| 234 | 278 | /** |
| 235 | - * Return the view's query arguments | |
| 279 | + * Return the query arguments of a topic-view | |
| 236 | 280 | * |
| 237 | - * @since bbPress (r2789) | |
| 281 | + * @since 2.0.0 bbPress (r2789) | |
| 238 | 282 | * |
| 239 | 283 | * @param string $view View name |
| 240 | - * @uses bbp_get_view_id() To get the view id | |
| 241 | 284 | * @return array Query arguments |
| 242 | 285 | */ |
| 243 | -function bbp_get_view_query_args( $view ) { | |
| 286 | +function bbp_get_view_query_args( $view = '' ) { | |
| 287 | + $bbp = bbpress(); | |
| 244 | 288 | $view = bbp_get_view_id( $view ); |
| 245 | - $retval = !empty( $view ) ? bbpress()->views[$view]['query'] : false; | |
| 289 | + $retval = ! empty( $view ) && ! empty( $bbp->views[ $view ] ) | |
| 290 | + ? $bbp->views[ $view ]['query'] | |
| 291 | + : array(); | |
| 246 | 292 | |
| 247 | - return apply_filters( 'bbp_get_view_query_args', $retval, $view ); | |
| 293 | + // Filter & return | |
| 294 | + return (array) apply_filters( 'bbp_get_view_query_args', $retval, $view ); | |
| 248 | 295 | } |
| 249 | 296 | |
| 250 | 297 | /** Errors ********************************************************************/ |
| 251 | 298 | |
| @@ -251,12 +298,11 @@ | ||
| 251 | 298 | |
| 252 | 299 | /** |
| 253 | 300 | * Adds an error message to later be output in the theme |
| 254 | 301 | * |
| 255 | - * @since bbPress (r3381) | |
| 302 | + * @since 2.0.0 bbPress (r3381) | |
| 256 | 303 | * |
| 257 | 304 | * @see WP_Error() |
| 258 | - * @uses WP_Error::add(); | |
| 259 | 305 | * |
| 260 | 306 | * @param string $code Unique code for the error message |
| 261 | 307 | * @param string $message Translated error message |
| 262 | 308 | * @param string $data Any additional data passed with the error message |
| @@ -267,47 +313,68 @@ | ||
| 267 | 313 | |
| 268 | 314 | /** |
| 269 | 315 | * Check if error messages exist in queue |
| 270 | 316 | * |
| 271 | - * @since bbPress (r3381) | |
| 317 | + * @since 2.0.0 bbPress (r3381) | |
| 272 | 318 | * |
| 273 | 319 | * @see WP_Error() |
| 320 | + */ | |
| 321 | +function bbp_has_errors() { | |
| 322 | + $has_errors = bbpress()->errors->get_error_codes() | |
| 323 | + ? true | |
| 324 | + : false; | |
| 325 | + | |
| 326 | + return (bool) apply_filters( 'bbp_has_errors', $has_errors, bbpress()->errors ); | |
| 327 | +} | |
| 328 | + | |
| 329 | +/** Mentions ******************************************************************/ | |
| 330 | + | |
| 331 | +/** | |
| 332 | + * Set the pattern used for matching usernames for mentions. | |
| 274 | 333 | * |
| 275 | - * @uses is_wp_error() | |
| 276 | - * @usese WP_Error::get_error_codes() | |
| 334 | + * Moved into its own function to allow filtering of the regex pattern | |
| 335 | + * anywhere mentions might be used. | |
| 336 | + * | |
| 337 | + * @since 2.4.0 bbPress (r4997) | |
| 338 | + * @deprecated 2.6.0 bbp_make_clickable() | |
| 339 | + * | |
| 340 | + * @return string Pattern to match usernames with | |
| 277 | 341 | */ |
| 278 | -function bbp_has_errors() { | |
| 279 | - $has_errors = bbpress()->errors->get_error_codes() ? true : false; | |
| 342 | +function bbp_find_mentions_pattern() { | |
| 280 | 343 | |
| 281 | - return apply_filters( 'bbp_has_errors', $has_errors, bbpress()->errors ); | |
| 344 | + // Filter & return | |
| 345 | + return apply_filters( 'bbp_find_mentions_pattern', '/[@]+([A-Za-z0-9-_\.@]+)\b/' ); | |
| 282 | 346 | } |
| 283 | 347 | |
| 284 | 348 | /** |
| 285 | 349 | * Searches through the content to locate usernames, designated by an @ sign. |
| 286 | 350 | * |
| 287 | - * @since bbPress (r4323) | |
| 351 | + * @since 2.2.0 bbPress (r4323) | |
| 352 | + * @deprecated 2.6.0 bbp_make_clickable() | |
| 288 | 353 | * |
| 289 | 354 | * @param string $content The content |
| 290 | 355 | * @return bool|array $usernames Existing usernames. False if no matches. |
| 291 | 356 | */ |
| 292 | 357 | function bbp_find_mentions( $content = '' ) { |
| 293 | - $pattern = '/[@]+([A-Za-z0-9-_\.@]+)\b/'; | |
| 358 | + $pattern = bbp_find_mentions_pattern(); | |
| 294 | 359 | preg_match_all( $pattern, $content, $usernames ); |
| 295 | 360 | $usernames = array_unique( array_filter( $usernames[1] ) ); |
| 296 | 361 | |
| 297 | 362 | // Bail if no usernames |
| 298 | - if ( empty( $usernames ) ) | |
| 299 | - return false; | |
| 363 | + if ( empty( $usernames ) ) { | |
| 364 | + $usernames = false; | |
| 365 | + } | |
| 300 | 366 | |
| 301 | - return $usernames; | |
| 367 | + // Filter & return | |
| 368 | + return apply_filters( 'bbp_find_mentions', $usernames, $pattern, $content ); | |
| 302 | 369 | } |
| 303 | 370 | |
| 304 | 371 | /** |
| 305 | 372 | * Finds and links @-mentioned users in the content |
| 306 | 373 | * |
| 307 | - * @since bbPress (r4323) | |
| 374 | + * @since 2.2.0 bbPress (r4323) | |
| 375 | + * @deprecated 2.6.0 bbp_make_clickable() | |
| 308 | 376 | * |
| 309 | - * @uses bbp_find_mentions() To get usernames in content areas | |
| 310 | 377 | * @return string $content Content filtered for mentions |
| 311 | 378 | */ |
| 312 | 379 | function bbp_mention_filter( $content = '' ) { |
| 313 | 380 | |
| @@ -312,21 +379,29 @@ | ||
| 312 | 379 | function bbp_mention_filter( $content = '' ) { |
| 313 | 380 | |
| 314 | 381 | // Get Usernames and bail if none exist |
| 315 | 382 | $usernames = bbp_find_mentions( $content ); |
| 316 | - if ( empty( $usernames ) ) | |
| 383 | + if ( empty( $usernames ) ) { | |
| 317 | 384 | return $content; |
| 385 | + } | |
| 318 | 386 | |
| 319 | 387 | // Loop through usernames and link to profiles |
| 320 | - foreach( (array) $usernames as $username ) { | |
| 388 | + foreach ( (array) $usernames as $username ) { | |
| 321 | 389 | |
| 322 | 390 | // Skip if username does not exist or user is not active |
| 323 | - $user_id = username_exists( $username ); | |
| 324 | - if ( empty( $user_id ) || bbp_is_user_inactive( $user_id ) ) | |
| 391 | + $user = get_user_by( 'slug', $username ); | |
| 392 | + if ( empty( $user->ID ) || bbp_is_user_inactive( $user->ID ) ) { | |
| 325 | 393 | continue; |
| 394 | + } | |
| 326 | 395 | |
| 396 | + // Link | |
| 397 | + $profile_url = bbp_get_user_profile_url( $user->ID ); | |
| 398 | + $profile_link = sprintf( '<a href="%1$s">@%2$s</a>', esc_url( $profile_url ), esc_html( $username ) ); | |
| 399 | + $no_followed = bbp_rel_nofollow( $profile_link ); | |
| 400 | + $pattern = "/(@{$username}\b)/"; | |
| 401 | + | |
| 327 | 402 | // Replace name in content |
| 328 | - $content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bbp_get_user_profile_url( $user_id ) . "' rel='nofollow' class='bbp-mention-link $username'>@$username</a>", $content ); | |
| 403 | + $content = preg_replace( $pattern, $no_followed, $content ); | |
| 329 | 404 | } |
| 330 | 405 | |
| 331 | 406 | // Return modified content |
| 332 | 407 | return $content; |
| @@ -336,9 +411,9 @@ | ||
| 336 | 411 | |
| 337 | 412 | /** |
| 338 | 413 | * Return the public post status ID |
| 339 | 414 | * |
| 340 | - * @since bbPress (r3504) | |
| 415 | + * @since 2.0.0 bbPress (r3504) | |
| 341 | 416 | * |
| 342 | 417 | * @return string |
| 343 | 418 | */ |
| 344 | 419 | function bbp_get_public_status_id() { |
| @@ -347,9 +422,9 @@ | ||
| 347 | 422 | |
| 348 | 423 | /** |
| 349 | 424 | * Return the pending post status ID |
| 350 | 425 | * |
| 351 | - * @since bbPress (r3581) | |
| 426 | + * @since 2.1.0 bbPress (r3581) | |
| 352 | 427 | * |
| 353 | 428 | * @return string |
| 354 | 429 | */ |
| 355 | 430 | function bbp_get_pending_status_id() { |
| @@ -358,9 +433,9 @@ | ||
| 358 | 433 | |
| 359 | 434 | /** |
| 360 | 435 | * Return the private post status ID |
| 361 | 436 | * |
| 362 | - * @since bbPress (r3504) | |
| 437 | + * @since 2.0.0 bbPress (r3504) | |
| 363 | 438 | * |
| 364 | 439 | * @return string |
| 365 | 440 | */ |
| 366 | 441 | function bbp_get_private_status_id() { |
| @@ -369,9 +444,9 @@ | ||
| 369 | 444 | |
| 370 | 445 | /** |
| 371 | 446 | * Return the hidden post status ID |
| 372 | 447 | * |
| 373 | - * @since bbPress (r3504) | |
| 448 | + * @since 2.0.0 bbPress (r3504) | |
| 374 | 449 | * |
| 375 | 450 | * @return string |
| 376 | 451 | */ |
| 377 | 452 | function bbp_get_hidden_status_id() { |
| @@ -380,9 +455,9 @@ | ||
| 380 | 455 | |
| 381 | 456 | /** |
| 382 | 457 | * Return the closed post status ID |
| 383 | 458 | * |
| 384 | - * @since bbPress (r3504) | |
| 459 | + * @since 2.0.0 bbPress (r3504) | |
| 385 | 460 | * |
| 386 | 461 | * @return string |
| 387 | 462 | */ |
| 388 | 463 | function bbp_get_closed_status_id() { |
| @@ -391,9 +466,9 @@ | ||
| 391 | 466 | |
| 392 | 467 | /** |
| 393 | 468 | * Return the spam post status ID |
| 394 | 469 | * |
| 395 | - * @since bbPress (r3504) | |
| 470 | + * @since 2.0.0 bbPress (r3504) | |
| 396 | 471 | * |
| 397 | 472 | * @return string |
| 398 | 473 | */ |
| 399 | 474 | function bbp_get_spam_status_id() { |
| @@ -402,9 +477,9 @@ | ||
| 402 | 477 | |
| 403 | 478 | /** |
| 404 | 479 | * Return the trash post status ID |
| 405 | 480 | * |
| 406 | - * @since bbPress (r3504) | |
| 481 | + * @since 2.0.0 bbPress (r3504) | |
| 407 | 482 | * |
| 408 | 483 | * @return string |
| 409 | 484 | */ |
| 410 | 485 | function bbp_get_trash_status_id() { |
| @@ -413,9 +488,9 @@ | ||
| 413 | 488 | |
| 414 | 489 | /** |
| 415 | 490 | * Return the orphan post status ID |
| 416 | 491 | * |
| 417 | - * @since bbPress (r3504) | |
| 492 | + * @since 2.0.0 bbPress (r3504) | |
| 418 | 493 | * |
| 419 | 494 | * @return string |
| 420 | 495 | */ |
| 421 | 496 | function bbp_get_orphan_status_id() { |
| @@ -426,9 +501,10 @@ | ||
| 426 | 501 | |
| 427 | 502 | /** |
| 428 | 503 | * Return the unique ID for user profile rewrite rules |
| 429 | 504 | * |
| 430 | - * @since bbPress (r3762) | |
| 505 | + * @since 2.1.0 bbPress (r3762) | |
| 506 | + * | |
| 431 | 507 | * @return string |
| 432 | 508 | */ |
| 433 | 509 | function bbp_get_user_rewrite_id() { |
| 434 | 510 | return bbpress()->user_id; |
| @@ -434,11 +510,12 @@ | ||
| 434 | 510 | return bbpress()->user_id; |
| 435 | 511 | } |
| 436 | 512 | |
| 437 | 513 | /** |
| 438 | - * Return the enique ID for all edit rewrite rules (forum|topic|reply|tag|user) | |
| 514 | + * Return the unique ID for all edit rewrite rules (forum|topic|reply|tag|user) | |
| 439 | 515 | * |
| 440 | - * @since bbPress (r3762) | |
| 516 | + * @since 2.1.0 bbPress (r3762) | |
| 517 | + * | |
| 441 | 518 | * @return string |
| 442 | 519 | */ |
| 443 | 520 | function bbp_get_edit_rewrite_id() { |
| 444 | 521 | return bbpress()->edit_id; |
| @@ -444,11 +521,23 @@ | ||
| 444 | 521 | return bbpress()->edit_id; |
| 445 | 522 | } |
| 446 | 523 | |
| 447 | 524 | /** |
| 525 | + * Return the unique ID for all search rewrite rules | |
| 526 | + * | |
| 527 | + * @since 2.3.0 bbPress (r4579) | |
| 528 | + * | |
| 529 | + * @return string | |
| 530 | + */ | |
| 531 | +function bbp_get_search_rewrite_id() { | |
| 532 | + return bbpress()->search_id; | |
| 533 | +} | |
| 534 | + | |
| 535 | +/** | |
| 448 | 536 | * Return the unique ID for user topics rewrite rules |
| 449 | 537 | * |
| 450 | - * @since bbPress (r4321) | |
| 538 | + * @since 2.2.0 bbPress (r4321) | |
| 539 | + * | |
| 451 | 540 | * @return string |
| 452 | 541 | */ |
| 453 | 542 | function bbp_get_user_topics_rewrite_id() { |
| 454 | 543 | return bbpress()->tops_id; |
| @@ -456,9 +545,10 @@ | ||
| 456 | 545 | |
| 457 | 546 | /** |
| 458 | 547 | * Return the unique ID for user replies rewrite rules |
| 459 | 548 | * |
| 460 | - * @since bbPress (r4321) | |
| 549 | + * @since 2.2.0 bbPress (r4321) | |
| 550 | + * | |
| 461 | 551 | * @return string |
| 462 | 552 | */ |
| 463 | 553 | function bbp_get_user_replies_rewrite_id() { |
| 464 | 554 | return bbpress()->reps_id; |
| @@ -464,11 +554,12 @@ | ||
| 464 | 554 | return bbpress()->reps_id; |
| 465 | 555 | } |
| 466 | 556 | |
| 467 | 557 | /** |
| 468 | - * Return the unique ID for user caps rewrite rules | |
| 558 | + * Return the unique ID for user favorites rewrite rules | |
| 469 | 559 | * |
| 470 | - * @since bbPress (r4181) | |
| 560 | + * @since 2.2.0 bbPress (r4181) | |
| 561 | + * | |
| 471 | 562 | * @return string |
| 472 | 563 | */ |
| 473 | 564 | function bbp_get_user_favorites_rewrite_id() { |
| 474 | 565 | return bbpress()->favs_id; |
| @@ -474,11 +565,12 @@ | ||
| 474 | 565 | return bbpress()->favs_id; |
| 475 | 566 | } |
| 476 | 567 | |
| 477 | 568 | /** |
| 478 | - * Return the unique ID for user caps rewrite rules | |
| 569 | + * Return the unique ID for user subscriptions rewrite rules | |
| 479 | 570 | * |
| 480 | - * @since bbPress (r4181) | |
| 571 | + * @since 2.2.0 bbPress (r4181) | |
| 572 | + * | |
| 481 | 573 | * @return string |
| 482 | 574 | */ |
| 483 | 575 | function bbp_get_user_subscriptions_rewrite_id() { |
| 484 | 576 | return bbpress()->subs_id; |
| @@ -484,11 +576,23 @@ | ||
| 484 | 576 | return bbpress()->subs_id; |
| 485 | 577 | } |
| 486 | 578 | |
| 487 | 579 | /** |
| 580 | + * Return the unique ID for user engagement rewrite rules | |
| 581 | + * | |
| 582 | + * @since 2.6.0 bbPress (r6320) | |
| 583 | + * | |
| 584 | + * @return string | |
| 585 | + */ | |
| 586 | +function bbp_get_user_engagements_rewrite_id() { | |
| 587 | + return bbpress()->engagements_id; | |
| 588 | +} | |
| 589 | + | |
| 590 | +/** | |
| 488 | 591 | * Return the unique ID for topic view rewrite rules |
| 489 | 592 | * |
| 490 | - * @since bbPress (r3762) | |
| 593 | + * @since 2.1.0 bbPress (r3762) | |
| 594 | + * | |
| 491 | 595 | * @return string |
| 492 | 596 | */ |
| 493 | 597 | function bbp_get_view_rewrite_id() { |
| 494 | 598 | return bbpress()->view_id; |
| @@ -493,13 +597,106 @@ | ||
| 493 | 597 | function bbp_get_view_rewrite_id() { |
| 494 | 598 | return bbpress()->view_id; |
| 495 | 599 | } |
| 496 | 600 | |
| 601 | +/** Rewrite Extras ************************************************************/ | |
| 602 | + | |
| 497 | 603 | /** |
| 604 | + * Get the id used for paginated requests | |
| 605 | + * | |
| 606 | + * @since 2.4.0 bbPress (r4926) | |
| 607 | + * | |
| 608 | + * @return string | |
| 609 | + */ | |
| 610 | +function bbp_get_paged_rewrite_id() { | |
| 611 | + return bbpress()->paged_id; | |
| 612 | +} | |
| 613 | + | |
| 614 | +/** | |
| 498 | 615 | * Delete a blogs rewrite rules, so that they are automatically rebuilt on |
| 499 | 616 | * the subsequent page load. |
| 500 | 617 | * |
| 501 | - * @since bbPress (r4198) | |
| 618 | + * @since 2.2.0 bbPress (r4198) | |
| 502 | 619 | */ |
| 503 | 620 | function bbp_delete_rewrite_rules() { |
| 504 | 621 | delete_option( 'rewrite_rules' ); |
| 622 | +} | |
| 623 | + | |
| 624 | +/** Requests ******************************************************************/ | |
| 625 | + | |
| 626 | +/** | |
| 627 | + * Return true|false if this is a POST request | |
| 628 | + * | |
| 629 | + * @since 2.3.0 bbPress (r4790) | |
| 630 | + * | |
| 631 | + * @return bool | |
| 632 | + */ | |
| 633 | +function bbp_is_post_request() { | |
| 634 | + return (bool) ( 'POST' === strtoupper( $_SERVER['REQUEST_METHOD'] ) ); | |
| 635 | +} | |
| 636 | + | |
| 637 | +/** | |
| 638 | + * Return true|false if this is a GET request | |
| 639 | + * | |
| 640 | + * @since 2.3.0 bbPress (r4790) | |
| 641 | + * | |
| 642 | + * @return bool | |
| 643 | + */ | |
| 644 | +function bbp_is_get_request() { | |
| 645 | + return (bool) ( 'GET' === strtoupper( $_SERVER['REQUEST_METHOD'] ) ); | |
| 646 | +} | |
| 647 | + | |
| 648 | +/** Redirection ***************************************************************/ | |
| 649 | + | |
| 650 | +/** | |
| 651 | + * Perform a safe, local redirect somewhere inside the current site | |
| 652 | + * | |
| 653 | + * On some setups, passing the value of wp_get_referer() may result in an empty | |
| 654 | + * value for $location, which results in an error on redirection. If $location | |
| 655 | + * is empty, we can safely redirect back to the forum root. This might change | |
| 656 | + * in a future version, possibly to the site root. | |
| 657 | + * | |
| 658 | + * @since 2.6.0 bbPress (r5658) | |
| 659 | + * | |
| 660 | + * @see bbp_redirect_to_field() | |
| 661 | + * | |
| 662 | + * @param string $location The URL to redirect the user to. | |
| 663 | + * @param int $status Optional. The numeric code to give in the redirect | |
| 664 | + * headers. Default: 302. | |
| 665 | + */ | |
| 666 | +function bbp_redirect( $location = '', $status = 302 ) { | |
| 667 | + | |
| 668 | + // Prevent errors from empty $location | |
| 669 | + if ( empty( $location ) ) { | |
| 670 | + $location = bbp_get_forums_url(); | |
| 671 | + } | |
| 672 | + | |
| 673 | + // Setup the safe redirect | |
| 674 | + wp_safe_redirect( $location, $status ); | |
| 675 | + | |
| 676 | + // Exit so the redirect takes place immediately | |
| 677 | + exit(); | |
| 678 | +} | |
| 679 | + | |
| 680 | +/** Global Helpers ************************************************************/ | |
| 681 | + | |
| 682 | +/** | |
| 683 | + * Return if debugging scripts or not | |
| 684 | + * | |
| 685 | + * @since 2.6.7 (r7188) | |
| 686 | + * | |
| 687 | + * @return bool True if debugging scripts. False if not debugging scripts. | |
| 688 | + */ | |
| 689 | +function bbp_doing_script_debug() { | |
| 690 | + return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG; | |
| 691 | +} | |
| 692 | + | |
| 693 | +/** | |
| 694 | + * Return if auto-saving or not | |
| 695 | + * | |
| 696 | + * @since 2.6.7 (r7188) | |
| 697 | + * | |
| 698 | + * @return bool True if mid auto-save. False if not mid auto-save. | |
| 699 | + */ | |
| 700 | +function bbp_doing_autosave() { | |
| 701 | + return defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE; | |
| 505 | 702 | } |