| @@ -6,16 +6,19 @@ | ||
| 6 | 6 | * The purpose of the following hooks is to mimic the behavior of something |
| 7 | 7 | * called 'plugin dependency' which enables a plugin to have plugins of their |
| 8 | 8 | * own in a safe and reliable way. |
| 9 | 9 | * |
| 10 | - * We do this in bbPress by mirroring existing WordPress hookss in many places | |
| 10 | + * We do this in bbPress by mirroring existing WordPress hooks in many places | |
| 11 | 11 | * allowing dependant plugins to hook into the bbPress specific ones, thus |
| 12 | 12 | * guaranteeing proper code execution only when bbPress is active. |
| 13 | 13 | * |
| 14 | - * The following functions are wrappers for hookss, allowing them to be | |
| 14 | + * The following functions are wrappers for hooks, allowing them to be | |
| 15 | 15 | * manually called and/or piggy-backed on top of other hooks if needed. |
| 16 | 16 | * |
| 17 | - * @todo use anonymous functions when PHP minimun requirement allows (5.3) | |
| 17 | + * @package bbPress | |
| 18 | + * @subpackage Core | |
| 19 | + * | |
| 20 | + * @todo use anonymous functions when PHP minimum requirement allows (5.3) | |
| 18 | 21 | */ |
| 19 | 22 | |
| 20 | 23 | /** Activation Actions ********************************************************/ |
| 21 | 24 | |
| @@ -21,11 +24,9 @@ | ||
| 21 | 24 | |
| 22 | 25 | /** |
| 23 | 26 | * Runs on bbPress activation |
| 24 | 27 | * |
| 25 | - * @since bbPress (r2509) | |
| 26 | - * @uses register_uninstall_hook() To register our own uninstall hook | |
| 27 | - * @uses do_action() Calls 'bbp_activation' hook | |
| 28 | + * @since 2.0.0 bbPress (r2509) | |
| 28 | 29 | */ |
| 29 | 30 | function bbp_activation() { |
| 30 | 31 | do_action( 'bbp_activation' ); |
| 31 | 32 | } |
| @@ -32,10 +33,9 @@ | ||
| 32 | 33 | |
| 33 | 34 | /** |
| 34 | 35 | * Runs on bbPress deactivation |
| 35 | 36 | * |
| 36 | - * @since bbPress (r2509) | |
| 37 | - * @uses do_action() Calls 'bbp_deactivation' hook | |
| 37 | + * @since 2.0.0 bbPress (r2509) | |
| 38 | 38 | */ |
| 39 | 39 | function bbp_deactivation() { |
| 40 | 40 | do_action( 'bbp_deactivation' ); |
| 41 | 41 | } |
| @@ -42,10 +42,9 @@ | ||
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * Runs when uninstalling bbPress |
| 45 | 45 | * |
| 46 | - * @since bbPress (r2509) | |
| 47 | - * @uses do_action() Calls 'bbp_uninstall' hook | |
| 46 | + * @since 2.0.0 bbPress (r2509) | |
| 48 | 47 | */ |
| 49 | 48 | function bbp_uninstall() { |
| 50 | 49 | do_action( 'bbp_uninstall' ); |
| 51 | 50 | } |
| @@ -54,10 +53,9 @@ | ||
| 54 | 53 | |
| 55 | 54 | /** |
| 56 | 55 | * Main action responsible for constants, globals, and includes |
| 57 | 56 | * |
| 58 | - * @since bbPress (r2599) | |
| 59 | - * @uses do_action() Calls 'bbp_loaded' | |
| 57 | + * @since 2.0.0 bbPress (r2599) | |
| 60 | 58 | */ |
| 61 | 59 | function bbp_loaded() { |
| 62 | 60 | do_action( 'bbp_loaded' ); |
| 63 | 61 | } |
| @@ -64,10 +62,9 @@ | ||
| 64 | 62 | |
| 65 | 63 | /** |
| 66 | 64 | * Setup constants |
| 67 | 65 | * |
| 68 | - * @since bbPress (r2599) | |
| 69 | - * @uses do_action() Calls 'bbp_constants' | |
| 66 | + * @since 2.0.0 bbPress (r2599) | |
| 70 | 67 | */ |
| 71 | 68 | function bbp_constants() { |
| 72 | 69 | do_action( 'bbp_constants' ); |
| 73 | 70 | } |
| @@ -74,10 +71,9 @@ | ||
| 74 | 71 | |
| 75 | 72 | /** |
| 76 | 73 | * Setup globals BEFORE includes |
| 77 | 74 | * |
| 78 | - * @since bbPress (r2599) | |
| 79 | - * @uses do_action() Calls 'bbp_boot_strap_globals' | |
| 75 | + * @since 2.0.0 bbPress (r2599) | |
| 80 | 76 | */ |
| 81 | 77 | function bbp_boot_strap_globals() { |
| 82 | 78 | do_action( 'bbp_boot_strap_globals' ); |
| 83 | 79 | } |
| @@ -84,10 +80,9 @@ | ||
| 84 | 80 | |
| 85 | 81 | /** |
| 86 | 82 | * Include files |
| 87 | 83 | * |
| 88 | - * @since bbPress (r2599) | |
| 89 | - * @uses do_action() Calls 'bbp_includes' | |
| 84 | + * @since 2.0.0 bbPress (r2599) | |
| 90 | 85 | */ |
| 91 | 86 | function bbp_includes() { |
| 92 | 87 | do_action( 'bbp_includes' ); |
| 93 | 88 | } |
| @@ -94,10 +89,9 @@ | ||
| 94 | 89 | |
| 95 | 90 | /** |
| 96 | 91 | * Setup globals AFTER includes |
| 97 | 92 | * |
| 98 | - * @since bbPress (r2599) | |
| 99 | - * @uses do_action() Calls 'bbp_setup_globals' | |
| 93 | + * @since 2.0.0 bbPress (r2599) | |
| 100 | 94 | */ |
| 101 | 95 | function bbp_setup_globals() { |
| 102 | 96 | do_action( 'bbp_setup_globals' ); |
| 103 | 97 | } |
| @@ -104,10 +98,9 @@ | ||
| 104 | 98 | |
| 105 | 99 | /** |
| 106 | 100 | * Register any objects before anything is initialized |
| 107 | 101 | * |
| 108 | - * @since bbPress (r4180) | |
| 109 | - * @uses do_action() Calls 'bbp_register' | |
| 102 | + * @since 2.2.0 bbPress (r4180) | |
| 110 | 103 | */ |
| 111 | 104 | function bbp_register() { |
| 112 | 105 | do_action( 'bbp_register' ); |
| 113 | 106 | } |
| @@ -114,10 +107,9 @@ | ||
| 114 | 107 | |
| 115 | 108 | /** |
| 116 | 109 | * Initialize any code after everything has been loaded |
| 117 | 110 | * |
| 118 | - * @since bbPress (r2599) | |
| 119 | - * @uses do_action() Calls 'bbp_init' | |
| 111 | + * @since 2.0.0 bbPress (r2599) | |
| 120 | 112 | */ |
| 121 | 113 | function bbp_init() { |
| 122 | 114 | do_action( 'bbp_init' ); |
| 123 | 115 | } |
| @@ -122,12 +114,44 @@ | ||
| 122 | 114 | do_action( 'bbp_init' ); |
| 123 | 115 | } |
| 124 | 116 | |
| 125 | 117 | /** |
| 118 | + * Initialize the bbPress REST API | |
| 119 | + * | |
| 120 | + * @since 2.6.17 | |
| 121 | + */ | |
| 122 | +function bbp_rest_api_init() { | |
| 123 | + do_action( 'bbp_rest_api_init' ); | |
| 124 | +} | |
| 125 | + | |
| 126 | +/** | |
| 127 | + * Pass an XML-RPC request through bbPress. | |
| 128 | + * | |
| 129 | + * @since 2.6.17 bbPress | |
| 130 | + * | |
| 131 | + * @param string $method XML-RPC method name. | |
| 132 | + * @param array $args XML-RPC method arguments. | |
| 133 | + * @param wp_xmlrpc_server $server XML-RPC server instance. | |
| 134 | + */ | |
| 135 | +function bbp_xmlrpc_call( $method = '', $args = array(), $server = null ) { | |
| 136 | + do_action( 'bbp_xmlrpc_call', $method, $args, $server ); | |
| 137 | +} | |
| 138 | + | |
| 139 | +/** | |
| 140 | + * Initialize roles | |
| 141 | + * | |
| 142 | + * @since 2.6.0 bbPress (r6106) | |
| 143 | + * | |
| 144 | + * @param WP_Roles $wp_roles The array of WP_Role objects that was initialized | |
| 145 | + */ | |
| 146 | +function bbp_roles_init( $wp_roles ) { | |
| 147 | + do_action( 'bbp_roles_init', $wp_roles ); | |
| 148 | +} | |
| 149 | + | |
| 150 | +/** | |
| 126 | 151 | * Initialize widgets |
| 127 | 152 | * |
| 128 | - * @since bbPress (r3389) | |
| 129 | - * @uses do_action() Calls 'bbp_widgets_init' | |
| 153 | + * @since 2.0.0 bbPress (r3389) | |
| 130 | 154 | */ |
| 131 | 155 | function bbp_widgets_init() { |
| 132 | 156 | do_action( 'bbp_widgets_init' ); |
| 133 | 157 | } |
| @@ -134,22 +158,32 @@ | ||
| 134 | 158 | |
| 135 | 159 | /** |
| 136 | 160 | * Setup the currently logged-in user |
| 137 | 161 | * |
| 138 | - * @since bbPress (r2695) | |
| 139 | - * @uses do_action() Calls 'bbp_setup_current_user' | |
| 162 | + * @link https://bbpress.trac.wordpress.org/ticket/2309 | |
| 163 | + * @link https://core.trac.wordpress.org/ticket/24169 | |
| 164 | + * | |
| 165 | + * @since 2.0.0 bbPress (r2695) | |
| 140 | 166 | */ |
| 141 | 167 | function bbp_setup_current_user() { |
| 142 | 168 | do_action( 'bbp_setup_current_user' ); |
| 143 | 169 | } |
| 144 | 170 | |
| 171 | +/** | |
| 172 | + * Setup the user engagements strategy | |
| 173 | + * | |
| 174 | + * @since 2.6.0 bbPress (r6875) | |
| 175 | + */ | |
| 176 | +function bbp_setup_engagements() { | |
| 177 | + do_action( 'bbp_setup_engagements' ); | |
| 178 | +} | |
| 179 | + | |
| 145 | 180 | /** Supplemental Actions ******************************************************/ |
| 146 | 181 | |
| 147 | 182 | /** |
| 148 | 183 | * Load translations for current language |
| 149 | 184 | * |
| 150 | - * @since bbPress (r2599) | |
| 151 | - * @uses do_action() Calls 'bbp_load_textdomain' | |
| 185 | + * @since 2.0.0 bbPress (r2599) | |
| 152 | 186 | */ |
| 153 | 187 | function bbp_load_textdomain() { |
| 154 | 188 | do_action( 'bbp_load_textdomain' ); |
| 155 | 189 | } |
| @@ -156,10 +190,9 @@ | ||
| 156 | 190 | |
| 157 | 191 | /** |
| 158 | 192 | * Setup the post types |
| 159 | 193 | * |
| 160 | - * @since bbPress (r2464) | |
| 161 | - * @uses do_action() Calls 'bbp_register_post_type' | |
| 194 | + * @since 2.0.0 bbPress (r2464) | |
| 162 | 195 | */ |
| 163 | 196 | function bbp_register_post_types() { |
| 164 | 197 | do_action( 'bbp_register_post_types' ); |
| 165 | 198 | } |
| @@ -166,10 +199,9 @@ | ||
| 166 | 199 | |
| 167 | 200 | /** |
| 168 | 201 | * Setup the post statuses |
| 169 | 202 | * |
| 170 | - * @since bbPress (r2727) | |
| 171 | - * @uses do_action() Calls 'bbp_register_post_statuses' | |
| 203 | + * @since 2.0.0 bbPress (r2727) | |
| 172 | 204 | */ |
| 173 | 205 | function bbp_register_post_statuses() { |
| 174 | 206 | do_action( 'bbp_register_post_statuses' ); |
| 175 | 207 | } |
| @@ -176,10 +208,9 @@ | ||
| 176 | 208 | |
| 177 | 209 | /** |
| 178 | 210 | * Register the built in bbPress taxonomies |
| 179 | 211 | * |
| 180 | - * @since bbPress (r2464) | |
| 181 | - * @uses do_action() Calls 'bbp_register_taxonomies' | |
| 212 | + * @since 2.0.0 bbPress (r2464) | |
| 182 | 213 | */ |
| 183 | 214 | function bbp_register_taxonomies() { |
| 184 | 215 | do_action( 'bbp_register_taxonomies' ); |
| 185 | 216 | } |
| @@ -186,10 +217,9 @@ | ||
| 186 | 217 | |
| 187 | 218 | /** |
| 188 | 219 | * Register the default bbPress views |
| 189 | 220 | * |
| 190 | - * @since bbPress (r2789) | |
| 191 | - * @uses do_action() Calls 'bbp_register_views' | |
| 221 | + * @since 2.0.0 bbPress (r2789) | |
| 192 | 222 | */ |
| 193 | 223 | function bbp_register_views() { |
| 194 | 224 | do_action( 'bbp_register_views' ); |
| 195 | 225 | } |
| @@ -196,10 +226,9 @@ | ||
| 196 | 226 | |
| 197 | 227 | /** |
| 198 | 228 | * Register the default bbPress shortcodes |
| 199 | 229 | * |
| 200 | - * @since bbPress (r4211) | |
| 201 | - * @uses do_action() Calls 'bbp_register_shortcodes' | |
| 230 | + * @since 2.2.0 bbPress (r4211) | |
| 202 | 231 | */ |
| 203 | 232 | function bbp_register_shortcodes() { |
| 204 | 233 | do_action( 'bbp_register_shortcodes' ); |
| 205 | 234 | } |
| @@ -204,12 +233,20 @@ | ||
| 204 | 233 | do_action( 'bbp_register_shortcodes' ); |
| 205 | 234 | } |
| 206 | 235 | |
| 207 | 236 | /** |
| 237 | + * Register the default bbPress meta-data | |
| 238 | + * | |
| 239 | + * @since 2.6.0 bbPress (r46300) | |
| 240 | + */ | |
| 241 | +function bbp_register_meta() { | |
| 242 | + do_action( 'bbp_register_meta' ); | |
| 243 | +} | |
| 244 | + | |
| 245 | +/** | |
| 208 | 246 | * Enqueue bbPress specific CSS and JS |
| 209 | 247 | * |
| 210 | - * @since bbPress (r3373) | |
| 211 | - * @uses do_action() Calls 'bbp_enqueue_scripts' | |
| 248 | + * @since 2.0.0 bbPress (r3373) | |
| 212 | 249 | */ |
| 213 | 250 | function bbp_enqueue_scripts() { |
| 214 | 251 | do_action( 'bbp_enqueue_scripts' ); |
| 215 | 252 | } |
| @@ -216,10 +253,9 @@ | ||
| 216 | 253 | |
| 217 | 254 | /** |
| 218 | 255 | * Add the bbPress-specific rewrite tags |
| 219 | 256 | * |
| 220 | - * @since bbPress (r2753) | |
| 221 | - * @uses do_action() Calls 'bbp_add_rewrite_tags' | |
| 257 | + * @since 2.0.0 bbPress (r2753) | |
| 222 | 258 | */ |
| 223 | 259 | function bbp_add_rewrite_tags() { |
| 224 | 260 | do_action( 'bbp_add_rewrite_tags' ); |
| 225 | 261 | } |
| @@ -224,27 +260,88 @@ | ||
| 224 | 260 | do_action( 'bbp_add_rewrite_tags' ); |
| 225 | 261 | } |
| 226 | 262 | |
| 227 | 263 | /** |
| 264 | + * Add the bbPress-specific rewrite rules | |
| 265 | + * | |
| 266 | + * @since 2.4.0 bbPress (r4918) | |
| 267 | + */ | |
| 268 | +function bbp_add_rewrite_rules() { | |
| 269 | + do_action( 'bbp_add_rewrite_rules' ); | |
| 270 | +} | |
| 271 | + | |
| 272 | +/** | |
| 273 | + * Add the bbPress-specific permalink structures | |
| 274 | + * | |
| 275 | + * @since 2.4.0 bbPress (r4918) | |
| 276 | + */ | |
| 277 | +function bbp_add_permastructs() { | |
| 278 | + do_action( 'bbp_add_permastructs' ); | |
| 279 | +} | |
| 280 | + | |
| 281 | +/** | |
| 228 | 282 | * Add the bbPress-specific login forum action |
| 229 | 283 | * |
| 230 | - * @since bbPress (r2753) | |
| 231 | - * @uses do_action() Calls 'bbp_login_form_login' | |
| 284 | + * @since 2.0.0 bbPress (r2753) | |
| 232 | 285 | */ |
| 233 | 286 | function bbp_login_form_login() { |
| 234 | 287 | do_action( 'bbp_login_form_login' ); |
| 235 | 288 | } |
| 236 | 289 | |
| 290 | +/** | |
| 291 | + * Add the bbPress-specific post status transition action | |
| 292 | + * | |
| 293 | + * @since 2.6.0 bbPress (r6792) | |
| 294 | + * | |
| 295 | + * @param string $new_status New post status | |
| 296 | + * @param string $old_status Old post status | |
| 297 | + * @param WP_Post $post Post object | |
| 298 | + */ | |
| 299 | +function bbp_transition_post_status( $new_status = '', $old_status = '', $post = false ) { | |
| 300 | + | |
| 301 | + // Get bbPress post types | |
| 302 | + $post_type = get_post_type( $post ); | |
| 303 | + $types = bbp_get_post_types(); | |
| 304 | + | |
| 305 | + // Bail if post is not a bbPress post type | |
| 306 | + if ( ! in_array( $post_type, $types, true ) ) { | |
| 307 | + return; | |
| 308 | + } | |
| 309 | + | |
| 310 | + // Do the action | |
| 311 | + do_action( 'bbp_transition_post_status', $new_status, $old_status, $post ); | |
| 312 | +} | |
| 313 | + | |
| 314 | +/** | |
| 315 | + * Add the bbPress-specific post updated action. | |
| 316 | + * | |
| 317 | + * @since 2.6.17 | |
| 318 | + * | |
| 319 | + * @param int $post_id Post ID. | |
| 320 | + * @param WP_Post $post_after Post object following the update. | |
| 321 | + * @param WP_Post $post_before Post object before the update. | |
| 322 | + */ | |
| 323 | +function bbp_post_updated( $post_id = 0, $post_after = false, $post_before = false ) { | |
| 324 | + $post_types = bbp_get_post_types(); | |
| 325 | + | |
| 326 | + // Bail if neither version is a bbPress post type | |
| 327 | + if ( ! in_array( $post_after->post_type, $post_types, true ) && ! in_array( $post_before->post_type, $post_types, true ) ) { | |
| 328 | + return; | |
| 329 | + } | |
| 330 | + | |
| 331 | + // Do the action | |
| 332 | + do_action( 'bbp_post_updated', $post_id, $post_after, $post_before ); | |
| 333 | +} | |
| 334 | + | |
| 237 | 335 | /** User Actions **************************************************************/ |
| 238 | 336 | |
| 239 | 337 | /** |
| 240 | 338 | * The main action for hooking into when a user account is updated |
| 241 | 339 | * |
| 242 | - * @since bbPress (r4304) | |
| 340 | + * @since 2.2.0 bbPress (r4304) | |
| 243 | 341 | * |
| 244 | 342 | * @param int $user_id ID of user being edited |
| 245 | 343 | * @param array $old_user_data The old, unmodified user data |
| 246 | - * @uses do_action() Calls 'bbp_profile_update' | |
| 247 | 344 | */ |
| 248 | 345 | function bbp_profile_update( $user_id = 0, $old_user_data = array() ) { |
| 249 | 346 | do_action( 'bbp_profile_update', $user_id, $old_user_data ); |
| 250 | 347 | } |
| @@ -251,11 +348,11 @@ | ||
| 251 | 348 | |
| 252 | 349 | /** |
| 253 | 350 | * The main action for hooking into a user being registered |
| 254 | 351 | * |
| 255 | - * @since bbPress (r4304) | |
| 352 | + * @since 2.2.0 bbPress (r4304) | |
| 353 | + * | |
| 256 | 354 | * @param int $user_id ID of user being edited |
| 257 | - * @uses do_action() Calls 'bbp_user_register' | |
| 258 | 355 | */ |
| 259 | 356 | function bbp_user_register( $user_id = 0 ) { |
| 260 | 357 | do_action( 'bbp_user_register', $user_id ); |
| 261 | 358 | } |
| @@ -264,10 +361,9 @@ | ||
| 264 | 361 | |
| 265 | 362 | /** |
| 266 | 363 | * bbPress has loaded and initialized everything, and is okay to go |
| 267 | 364 | * |
| 268 | - * @since bbPress (r2618) | |
| 269 | - * @uses do_action() Calls 'bbp_ready' | |
| 365 | + * @since 2.0.0 bbPress (r2618) | |
| 270 | 366 | */ |
| 271 | 367 | function bbp_ready() { |
| 272 | 368 | do_action( 'bbp_ready' ); |
| 273 | 369 | } |
| @@ -277,10 +373,9 @@ | ||
| 277 | 373 | /** |
| 278 | 374 | * The main action used for redirecting bbPress theme actions that are not |
| 279 | 375 | * permitted by the current_user |
| 280 | 376 | * |
| 281 | - * @since bbPress (r3605) | |
| 282 | - * @uses do_action() | |
| 377 | + * @since 2.1.0 bbPress (r3605) | |
| 283 | 378 | */ |
| 284 | 379 | function bbp_template_redirect() { |
| 285 | 380 | do_action( 'bbp_template_redirect' ); |
| 286 | 381 | } |
| @@ -289,10 +384,9 @@ | ||
| 289 | 384 | |
| 290 | 385 | /** |
| 291 | 386 | * The main action used for executing code before the theme has been setup |
| 292 | 387 | * |
| 293 | - * @since bbPress (r3829) | |
| 294 | - * @uses do_action() | |
| 388 | + * @since 2.1.0 bbPress (r3829) | |
| 295 | 389 | */ |
| 296 | 390 | function bbp_register_theme_packages() { |
| 297 | 391 | do_action( 'bbp_register_theme_packages' ); |
| 298 | 392 | } |
| @@ -299,10 +393,9 @@ | ||
| 299 | 393 | |
| 300 | 394 | /** |
| 301 | 395 | * The main action used for executing code before the theme has been setup |
| 302 | 396 | * |
| 303 | - * @since bbPress (r3732) | |
| 304 | - * @uses do_action() | |
| 397 | + * @since 2.1.0 bbPress (r3732) | |
| 305 | 398 | */ |
| 306 | 399 | function bbp_setup_theme() { |
| 307 | 400 | do_action( 'bbp_setup_theme' ); |
| 308 | 401 | } |
| @@ -309,10 +402,9 @@ | ||
| 309 | 402 | |
| 310 | 403 | /** |
| 311 | 404 | * The main action used for executing code after the theme has been setup |
| 312 | 405 | * |
| 313 | - * @since bbPress (r3732) | |
| 314 | - * @uses do_action() | |
| 406 | + * @since 2.1.0 bbPress (r3732) | |
| 315 | 407 | */ |
| 316 | 408 | function bbp_after_setup_theme() { |
| 317 | 409 | do_action( 'bbp_after_setup_theme' ); |
| 318 | 410 | } |
| @@ -317,29 +409,100 @@ | ||
| 317 | 409 | do_action( 'bbp_after_setup_theme' ); |
| 318 | 410 | } |
| 319 | 411 | |
| 320 | 412 | /** |
| 413 | + * The main action used for handling theme-side POST requests | |
| 414 | + * | |
| 415 | + * @since 2.3.0 bbPress (r4550) | |
| 416 | + */ | |
| 417 | +function bbp_post_request() { | |
| 418 | + | |
| 419 | + // Bail if not a POST action | |
| 420 | + if ( ! bbp_is_post_request() ) { | |
| 421 | + return; | |
| 422 | + } | |
| 423 | + | |
| 424 | + // Bail if no action, or if not a string (arrays not supported) | |
| 425 | + if ( empty( $_POST['action'] ) || ! is_string( $_POST['action'] ) ) { | |
| 426 | + return; | |
| 427 | + } | |
| 428 | + | |
| 429 | + // Sanitize the POST action | |
| 430 | + $action = sanitize_key( $_POST['action'] ); | |
| 431 | + | |
| 432 | + // Bail if action was totally invalid | |
| 433 | + if ( empty( $action ) ) { | |
| 434 | + return; | |
| 435 | + } | |
| 436 | + | |
| 437 | + // This dynamic action is probably the one you want to use. It narrows down | |
| 438 | + // the scope of the 'action' without needing to check it in your function. | |
| 439 | + do_action( 'bbp_post_request_' . $action ); | |
| 440 | + | |
| 441 | + // Use this static action if you don't mind checking the 'action' yourself. | |
| 442 | + do_action( 'bbp_post_request', $action ); | |
| 443 | +} | |
| 444 | + | |
| 445 | +/** | |
| 446 | + * The main action used for handling theme-side GET requests | |
| 447 | + * | |
| 448 | + * @since 2.3.0 bbPress (r4550) | |
| 449 | + */ | |
| 450 | +function bbp_get_request() { | |
| 451 | + | |
| 452 | + // Bail if not a POST action | |
| 453 | + if ( ! bbp_is_get_request() ) { | |
| 454 | + return; | |
| 455 | + } | |
| 456 | + | |
| 457 | + // Bail if no action, or if not a string (arrays not supported) | |
| 458 | + if ( empty( $_GET['action'] ) || ! is_string( $_GET['action'] ) ) { | |
| 459 | + return; | |
| 460 | + } | |
| 461 | + | |
| 462 | + // Sanitize the GET action | |
| 463 | + $action = sanitize_key( $_GET['action'] ); | |
| 464 | + | |
| 465 | + // Bail if action was totally invalid | |
| 466 | + if ( empty( $action ) ) { | |
| 467 | + return; | |
| 468 | + } | |
| 469 | + | |
| 470 | + // This dynamic action is probably the one you want to use. It narrows down | |
| 471 | + // the scope of the 'action' without needing to check it in your function. | |
| 472 | + do_action( 'bbp_get_request_' . $action ); | |
| 473 | + | |
| 474 | + // Use this static action if you don't mind checking the 'action' yourself. | |
| 475 | + do_action( 'bbp_get_request', $action ); | |
| 476 | +} | |
| 477 | + | |
| 478 | +/** Filters *******************************************************************/ | |
| 479 | + | |
| 480 | +/** | |
| 321 | 481 | * Filter the plugin locale and domain. |
| 322 | 482 | * |
| 323 | - * @since bbPress (r4213) | |
| 483 | + * @since 2.2.0 bbPress (r4213) | |
| 324 | 484 | * |
| 325 | 485 | * @param string $locale |
| 326 | 486 | * @param string $domain |
| 327 | 487 | */ |
| 328 | 488 | function bbp_plugin_locale( $locale = '', $domain = '' ) { |
| 489 | + | |
| 490 | + // Filter & return | |
| 329 | 491 | return apply_filters( 'bbp_plugin_locale', $locale, $domain ); |
| 330 | 492 | } |
| 331 | 493 | |
| 332 | -/** Filters *******************************************************************/ | |
| 333 | - | |
| 334 | 494 | /** |
| 335 | 495 | * Piggy back filter for WordPress's 'request' filter |
| 336 | 496 | * |
| 337 | - * @since bbPress (r3758) | |
| 497 | + * @since 2.1.0 bbPress (r3758) | |
| 498 | + * | |
| 338 | 499 | * @param array $query_vars |
| 339 | 500 | * @return array |
| 340 | 501 | */ |
| 341 | 502 | function bbp_request( $query_vars = array() ) { |
| 503 | + | |
| 504 | + // Filter & return | |
| 342 | 505 | return apply_filters( 'bbp_request', $query_vars ); |
| 343 | 506 | } |
| 344 | 507 | |
| 345 | 508 | /** |
| @@ -345,14 +508,16 @@ | ||
| 345 | 508 | /** |
| 346 | 509 | * The main filter used for theme compatibility and displaying custom bbPress |
| 347 | 510 | * theme files. |
| 348 | 511 | * |
| 349 | - * @since bbPress (r3311) | |
| 350 | - * @uses apply_filters() | |
| 512 | + * @since 2.0.0 bbPress (r3311) | |
| 513 | + * | |
| 351 | 514 | * @param string $template |
| 352 | 515 | * @return string Template file to use |
| 353 | 516 | */ |
| 354 | 517 | function bbp_template_include( $template = '' ) { |
| 518 | + | |
| 519 | + // Filter & return | |
| 355 | 520 | return apply_filters( 'bbp_template_include', $template ); |
| 356 | 521 | } |
| 357 | 522 | |
| 358 | 523 | /** |
| @@ -357,11 +522,13 @@ | ||
| 357 | 522 | |
| 358 | 523 | /** |
| 359 | 524 | * Generate bbPress-specific rewrite rules |
| 360 | 525 | * |
| 361 | - * @since bbPress (r2688) | |
| 526 | + * @since 2.0.0 bbPress (r2688) | |
| 527 | + * | |
| 528 | + * @deprecated 2.4.0 bbPress (r4918) | |
| 529 | + * | |
| 362 | 530 | * @param WP_Rewrite $wp_rewrite |
| 363 | - * @uses do_action() Calls 'bbp_generate_rewrite_rules' with {@link WP_Rewrite} | |
| 364 | 531 | */ |
| 365 | 532 | function bbp_generate_rewrite_rules( $wp_rewrite ) { |
| 366 | 533 | do_action_ref_array( 'bbp_generate_rewrite_rules', array( &$wp_rewrite ) ); |
| 367 | 534 | } |
| @@ -368,24 +535,62 @@ | ||
| 368 | 535 | |
| 369 | 536 | /** |
| 370 | 537 | * Filter the allowed themes list for bbPress specific themes |
| 371 | 538 | * |
| 372 | - * @since bbPress (r2944) | |
| 373 | - * @uses apply_filters() Calls 'bbp_allowed_themes' with the allowed themes list | |
| 539 | + * @since 2.0.0 bbPress (r2944) | |
| 540 | + * | |
| 541 | + * @param array $themes | |
| 542 | + * | |
| 543 | + * @return array Array of allowed themes | |
| 374 | 544 | */ |
| 375 | 545 | function bbp_allowed_themes( $themes ) { |
| 376 | - return apply_filters( 'bbp_allowed_themes', $themes ); | |
| 546 | + | |
| 547 | + // Filter & return | |
| 548 | + return (array) apply_filters( 'bbp_allowed_themes', $themes ); | |
| 377 | 549 | } |
| 378 | 550 | |
| 379 | 551 | /** |
| 380 | 552 | * Maps forum/topic/reply caps to built in WordPress caps |
| 381 | 553 | * |
| 382 | - * @since bbPress (r2593) | |
| 554 | + * @since 2.0.0 bbPress (r2593) | |
| 383 | 555 | * |
| 384 | 556 | * @param array $caps Capabilities for meta capability |
| 385 | 557 | * @param string $cap Capability name |
| 386 | 558 | * @param int $user_id User id |
| 387 | - * @param mixed $args Arguments | |
| 559 | + * @param array $args Arguments | |
| 560 | + * | |
| 561 | + * @return array Array of capabilities | |
| 388 | 562 | */ |
| 389 | 563 | function bbp_map_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) { |
| 390 | - return apply_filters( 'bbp_map_meta_caps', $caps, $cap, $user_id, $args ); | |
| 564 | + | |
| 565 | + // Filter & return | |
| 566 | + return (array) apply_filters( 'bbp_map_meta_caps', $caps, $cap, $user_id, $args ); | |
| 567 | +} | |
| 568 | + | |
| 569 | +/** | |
| 570 | + * Filter the arguments used by wp_mail for bbPress specific emails | |
| 571 | + * | |
| 572 | + * @since 2.6.0 bbPress (r6918) | |
| 573 | + * | |
| 574 | + * @param array $args A compacted array of wp_mail() arguments, including the "to" email, | |
| 575 | + * subject, message, headers, and attachments values. | |
| 576 | + * | |
| 577 | + * @return array Array of capabilities | |
| 578 | + */ | |
| 579 | +function bbp_mail( $args = array() ) { | |
| 580 | + | |
| 581 | + // Bail if headers are missing/malformed | |
| 582 | + if ( empty( $args['headers'] ) || ! is_array( $args['headers'] ) ) { | |
| 583 | + return $args; | |
| 584 | + } | |
| 585 | + | |
| 586 | + // Header to search all headers for | |
| 587 | + $bbp_header = bbp_get_email_header(); | |
| 588 | + | |
| 589 | + // Bail if no bbPress header found | |
| 590 | + if ( false === array_search( $bbp_header, $args['headers'], true ) ) { | |
| 591 | + return $args; | |
| 592 | + } | |
| 593 | + | |
| 594 | + // Filter & return | |
| 595 | + return (array) apply_filters( 'bbp_mail', $args ); | |
| 391 | 596 | } |