PluginProbe
bbPress / 2.6.17
bbPress v2.6.17
2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 All 72 releases
bbpress / includes / core / sub-actions.php

sub-actions.php in bbPress 2.6.17, at includes/core/sub-actions.php

597 lines 13.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Dependency
5 *
6 * The purpose of the following hooks is to mimic the behavior of something
7 * called 'plugin dependency' which enables a plugin to have plugins of their
8 * own in a safe and reliable way.
9 *
10 * We do this in bbPress by mirroring existing WordPress hooks in many places
11 * allowing dependant plugins to hook into the bbPress specific ones, thus
12 * guaranteeing proper code execution only when bbPress is active.
13 *
14 * The following functions are wrappers for hooks, allowing them to be
15 * manually called and/or piggy-backed on top of other hooks if needed.
16 *
17 * @package bbPress
18 * @subpackage Core
19 *
20 * @todo use anonymous functions when PHP minimum requirement allows (5.3)
21 */
22
23 /** Activation Actions ********************************************************/
24
25 /**
26 * Runs on bbPress activation
27 *
28 * @since 2.0.0 bbPress (r2509)
29 */
30 function bbp_activation() {
31 do_action( 'bbp_activation' );
32 }
33
34 /**
35 * Runs on bbPress deactivation
36 *
37 * @since 2.0.0 bbPress (r2509)
38 */
39 function bbp_deactivation() {
40 do_action( 'bbp_deactivation' );
41 }
42
43 /**
44 * Runs when uninstalling bbPress
45 *
46 * @since 2.0.0 bbPress (r2509)
47 */
48 function bbp_uninstall() {
49 do_action( 'bbp_uninstall' );
50 }
51
52 /** Main Actions **************************************************************/
53
54 /**
55 * Main action responsible for constants, globals, and includes
56 *
57 * @since 2.0.0 bbPress (r2599)
58 */
59 function bbp_loaded() {
60 do_action( 'bbp_loaded' );
61 }
62
63 /**
64 * Setup constants
65 *
66 * @since 2.0.0 bbPress (r2599)
67 */
68 function bbp_constants() {
69 do_action( 'bbp_constants' );
70 }
71
72 /**
73 * Setup globals BEFORE includes
74 *
75 * @since 2.0.0 bbPress (r2599)
76 */
77 function bbp_boot_strap_globals() {
78 do_action( 'bbp_boot_strap_globals' );
79 }
80
81 /**
82 * Include files
83 *
84 * @since 2.0.0 bbPress (r2599)
85 */
86 function bbp_includes() {
87 do_action( 'bbp_includes' );
88 }
89
90 /**
91 * Setup globals AFTER includes
92 *
93 * @since 2.0.0 bbPress (r2599)
94 */
95 function bbp_setup_globals() {
96 do_action( 'bbp_setup_globals' );
97 }
98
99 /**
100 * Register any objects before anything is initialized
101 *
102 * @since 2.2.0 bbPress (r4180)
103 */
104 function bbp_register() {
105 do_action( 'bbp_register' );
106 }
107
108 /**
109 * Initialize any code after everything has been loaded
110 *
111 * @since 2.0.0 bbPress (r2599)
112 */
113 function bbp_init() {
114 do_action( 'bbp_init' );
115 }
116
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 /**
151 * Initialize widgets
152 *
153 * @since 2.0.0 bbPress (r3389)
154 */
155 function bbp_widgets_init() {
156 do_action( 'bbp_widgets_init' );
157 }
158
159 /**
160 * Setup the currently logged-in user
161 *
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)
166 */
167 function bbp_setup_current_user() {
168 do_action( 'bbp_setup_current_user' );
169 }
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
180 /** Supplemental Actions ******************************************************/
181
182 /**
183 * Load translations for current language
184 *
185 * @since 2.0.0 bbPress (r2599)
186 */
187 function bbp_load_textdomain() {
188 do_action( 'bbp_load_textdomain' );
189 }
190
191 /**
192 * Setup the post types
193 *
194 * @since 2.0.0 bbPress (r2464)
195 */
196 function bbp_register_post_types() {
197 do_action( 'bbp_register_post_types' );
198 }
199
200 /**
201 * Setup the post statuses
202 *
203 * @since 2.0.0 bbPress (r2727)
204 */
205 function bbp_register_post_statuses() {
206 do_action( 'bbp_register_post_statuses' );
207 }
208
209 /**
210 * Register the built in bbPress taxonomies
211 *
212 * @since 2.0.0 bbPress (r2464)
213 */
214 function bbp_register_taxonomies() {
215 do_action( 'bbp_register_taxonomies' );
216 }
217
218 /**
219 * Register the default bbPress views
220 *
221 * @since 2.0.0 bbPress (r2789)
222 */
223 function bbp_register_views() {
224 do_action( 'bbp_register_views' );
225 }
226
227 /**
228 * Register the default bbPress shortcodes
229 *
230 * @since 2.2.0 bbPress (r4211)
231 */
232 function bbp_register_shortcodes() {
233 do_action( 'bbp_register_shortcodes' );
234 }
235
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 /**
246 * Enqueue bbPress specific CSS and JS
247 *
248 * @since 2.0.0 bbPress (r3373)
249 */
250 function bbp_enqueue_scripts() {
251 do_action( 'bbp_enqueue_scripts' );
252 }
253
254 /**
255 * Add the bbPress-specific rewrite tags
256 *
257 * @since 2.0.0 bbPress (r2753)
258 */
259 function bbp_add_rewrite_tags() {
260 do_action( 'bbp_add_rewrite_tags' );
261 }
262
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 /**
282 * Add the bbPress-specific login forum action
283 *
284 * @since 2.0.0 bbPress (r2753)
285 */
286 function bbp_login_form_login() {
287 do_action( 'bbp_login_form_login' );
288 }
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
335 /** User Actions **************************************************************/
336
337 /**
338 * The main action for hooking into when a user account is updated
339 *
340 * @since 2.2.0 bbPress (r4304)
341 *
342 * @param int $user_id ID of user being edited
343 * @param array $old_user_data The old, unmodified user data
344 */
345 function bbp_profile_update( $user_id = 0, $old_user_data = array() ) {
346 do_action( 'bbp_profile_update', $user_id, $old_user_data );
347 }
348
349 /**
350 * The main action for hooking into a user being registered
351 *
352 * @since 2.2.0 bbPress (r4304)
353 *
354 * @param int $user_id ID of user being edited
355 */
356 function bbp_user_register( $user_id = 0 ) {
357 do_action( 'bbp_user_register', $user_id );
358 }
359
360 /** Final Action **************************************************************/
361
362 /**
363 * bbPress has loaded and initialized everything, and is okay to go
364 *
365 * @since 2.0.0 bbPress (r2618)
366 */
367 function bbp_ready() {
368 do_action( 'bbp_ready' );
369 }
370
371 /** Theme Permissions *********************************************************/
372
373 /**
374 * The main action used for redirecting bbPress theme actions that are not
375 * permitted by the current_user
376 *
377 * @since 2.1.0 bbPress (r3605)
378 */
379 function bbp_template_redirect() {
380 do_action( 'bbp_template_redirect' );
381 }
382
383 /** Theme Helpers *************************************************************/
384
385 /**
386 * The main action used for executing code before the theme has been setup
387 *
388 * @since 2.1.0 bbPress (r3829)
389 */
390 function bbp_register_theme_packages() {
391 do_action( 'bbp_register_theme_packages' );
392 }
393
394 /**
395 * The main action used for executing code before the theme has been setup
396 *
397 * @since 2.1.0 bbPress (r3732)
398 */
399 function bbp_setup_theme() {
400 do_action( 'bbp_setup_theme' );
401 }
402
403 /**
404 * The main action used for executing code after the theme has been setup
405 *
406 * @since 2.1.0 bbPress (r3732)
407 */
408 function bbp_after_setup_theme() {
409 do_action( 'bbp_after_setup_theme' );
410 }
411
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 /**
481 * Filter the plugin locale and domain.
482 *
483 * @since 2.2.0 bbPress (r4213)
484 *
485 * @param string $locale
486 * @param string $domain
487 */
488 function bbp_plugin_locale( $locale = '', $domain = '' ) {
489
490 // Filter & return
491 return apply_filters( 'bbp_plugin_locale', $locale, $domain );
492 }
493
494 /**
495 * Piggy back filter for WordPress's 'request' filter
496 *
497 * @since 2.1.0 bbPress (r3758)
498 *
499 * @param array $query_vars
500 * @return array
501 */
502 function bbp_request( $query_vars = array() ) {
503
504 // Filter & return
505 return apply_filters( 'bbp_request', $query_vars );
506 }
507
508 /**
509 * The main filter used for theme compatibility and displaying custom bbPress
510 * theme files.
511 *
512 * @since 2.0.0 bbPress (r3311)
513 *
514 * @param string $template
515 * @return string Template file to use
516 */
517 function bbp_template_include( $template = '' ) {
518
519 // Filter & return
520 return apply_filters( 'bbp_template_include', $template );
521 }
522
523 /**
524 * Generate bbPress-specific rewrite rules
525 *
526 * @since 2.0.0 bbPress (r2688)
527 *
528 * @deprecated 2.4.0 bbPress (r4918)
529 *
530 * @param WP_Rewrite $wp_rewrite
531 */
532 function bbp_generate_rewrite_rules( $wp_rewrite ) {
533 do_action_ref_array( 'bbp_generate_rewrite_rules', array( &$wp_rewrite ) );
534 }
535
536 /**
537 * Filter the allowed themes list for bbPress specific themes
538 *
539 * @since 2.0.0 bbPress (r2944)
540 *
541 * @param array $themes
542 *
543 * @return array Array of allowed themes
544 */
545 function bbp_allowed_themes( $themes ) {
546
547 // Filter & return
548 return (array) apply_filters( 'bbp_allowed_themes', $themes );
549 }
550
551 /**
552 * Maps forum/topic/reply caps to built in WordPress caps
553 *
554 * @since 2.0.0 bbPress (r2593)
555 *
556 * @param array $caps Capabilities for meta capability
557 * @param string $cap Capability name
558 * @param int $user_id User id
559 * @param array $args Arguments
560 *
561 * @return array Array of capabilities
562 */
563 function bbp_map_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) {
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 );
596 }
597