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