PluginProbe
bbPress / 2.1-rc3
bbPress v2.1-rc3
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 / bbp-includes / bbp-core-actions.php

bbp-core-actions.php in bbPress 2.1-rc3, at bbp-includes/bbp-core-actions.php

541 lines 17.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Actions
5 *
6 * @package bbPress
7 * @subpackage Core
8 *
9 * This file contains the actions that are used through-out bbPress. They are
10 * consolidated here to make searching for them easier, and to help developers
11 * understand at a glance the order in which things occur.
12 *
13 * There are a few common places that additional actions can currently be found
14 *
15 * - bbPress: In {@link bbPress::setup_actions()} in bbpress.php
16 * - Component: In {@link BBP_Component::setup_actions()} in
17 * bbp-includes/bbp-classes.php
18 * - Admin: More in {@link BBP_Admin::setup_actions()} in
19 * bbp-admin/bbp-admin.php
20 *
21 * @see bbp-core-filters.php
22 */
23
24 // Exit if accessed directly
25 if ( !defined( 'ABSPATH' ) ) exit;
26
27 /**
28 * Attach bbPress to WordPress
29 *
30 * bbPress uses its own internal actions to help aid in third-party plugin
31 * development, and to limit the amount of potential future code changes when
32 * updates to WordPress core occur.
33 *
34 * These actions exist to create the concept of 'plugin dependencies'. They
35 * provide a safe way for plugins to execute code *only* when bbPress is
36 * installed and activated, without needing to do complicated guesswork.
37 *
38 * For more information on how this works, see the 'Plugin Dependency' section
39 * near the bottom of this file.
40 *
41 * v--WordPress Actions v--bbPress Sub-actions
42 */
43 add_action( 'plugins_loaded', 'bbp_loaded', 10 );
44 add_action( 'init', 'bbp_init', 10 );
45 add_action( 'widgets_init', 'bbp_widgets_init', 10 );
46 add_action( 'parse_query', 'bbp_parse_query', 2 ); // Early for overrides
47 add_action( 'generate_rewrite_rules', 'bbp_generate_rewrite_rules', 10 );
48 add_action( 'wp_enqueue_scripts', 'bbp_enqueue_scripts', 10 );
49 add_action( 'wp_head', 'bbp_head', 10 );
50 add_action( 'wp_footer', 'bbp_footer', 10 );
51 add_action( 'set_current_user', 'bbp_setup_current_user', 10 );
52 add_action( 'setup_theme', 'bbp_setup_theme', 10 );
53 add_action( 'after_setup_theme', 'bbp_after_setup_theme', 10 );
54 add_action( 'template_redirect', 'bbp_template_redirect', 10 );
55
56 /**
57 * bbp_loaded - Attached to 'plugins_loaded' above
58 *
59 * Attach various loader actions to the bbp_loaded action.
60 * The load order helps to execute code at the correct time.
61 * v---Load order
62 */
63 add_action( 'bbp_loaded', 'bbp_constants', 2 );
64 add_action( 'bbp_loaded', 'bbp_boot_strap_globals', 4 );
65 add_action( 'bbp_loaded', 'bbp_includes', 6 );
66 add_action( 'bbp_loaded', 'bbp_setup_globals', 8 );
67 add_action( 'bbp_loaded', 'bbp_setup_option_filters', 10 );
68 add_action( 'bbp_loaded', 'bbp_setup_user_option_filters', 12 );
69 add_action( 'bbp_loaded', 'bbp_register_theme_directory', 14 );
70 add_action( 'bbp_loaded', 'bbp_register_theme_packages', 16 );
71
72 /**
73 * bbp_init - Attached to 'init' above
74 *
75 * Attach various initialization actions to the init action.
76 * The load order helps to execute code at the correct time.
77 * v---Load order
78 */
79 add_action( 'bbp_init', 'bbp_load_textdomain', 2 );
80 add_action( 'bbp_init', 'bbp_register_post_types', 10 );
81 add_action( 'bbp_init', 'bbp_register_post_statuses', 12 );
82 add_action( 'bbp_init', 'bbp_register_taxonomies', 14 );
83 add_action( 'bbp_init', 'bbp_register_views', 16 );
84 add_action( 'bbp_init', 'bbp_register_shortcodes', 18 );
85 add_action( 'bbp_init', 'bbp_add_rewrite_tags', 20 );
86 add_action( 'bbp_init', 'bbp_ready', 999 );
87
88 // Autoembeds
89 add_action( 'bbp_init', 'bbp_reply_content_autoembed', 8 );
90 add_action( 'bbp_init', 'bbp_topic_content_autoembed', 8 );
91
92 /**
93 * bbp_ready - attached to end 'bbp_init' above
94 *
95 * Attach actions to the ready action after bbPress has fully initialized.
96 * The load order helps to execute code at the correct time.
97 * v---Load order
98 */
99 add_action( 'bbp_ready', 'bbp_setup_akismet', 2 ); // Spam prevention for topics and replies
100 add_action( 'bp_include', 'bbp_setup_buddypress', 10 ); // Social network integration
101
102 // Try to load the bbpress-functions.php file from the active themes
103 add_action( 'bbp_after_setup_theme', 'bbp_load_theme_functions', 10 );
104
105 // Multisite Global Forum Access
106 add_action( 'bbp_setup_current_user', 'bbp_global_access_role_mask', 10 );
107
108 // Widgets
109 add_action( 'bbp_widgets_init', array( 'BBP_Login_Widget', 'register_widget' ), 10 );
110 add_action( 'bbp_widgets_init', array( 'BBP_Views_Widget', 'register_widget' ), 10 );
111 add_action( 'bbp_widgets_init', array( 'BBP_Forums_Widget', 'register_widget' ), 10 );
112 add_action( 'bbp_widgets_init', array( 'BBP_Topics_Widget', 'register_widget' ), 10 );
113 add_action( 'bbp_widgets_init', array( 'BBP_Replies_Widget', 'register_widget' ), 10 );
114
115 // Template - Head, foot, errors and messages
116 add_action( 'bbp_loaded', 'bbp_login_notices' );
117 add_action( 'bbp_head', 'bbp_topic_notices' );
118 add_action( 'bbp_template_notices', 'bbp_template_notices' );
119
120 // Always exclude private/hidden forums if needed
121 add_action( 'pre_get_posts', 'bbp_pre_get_posts_exclude_forums', 4 );
122
123 // Profile Page Messages
124 add_action( 'bbp_template_notices', 'bbp_notice_edit_user_success' );
125 add_action( 'bbp_template_notices', 'bbp_notice_edit_user_is_super_admin', 2 );
126
127 // Before Delete/Trash/Untrash Topic
128 add_action( 'wp_trash_post', 'bbp_trash_forum' );
129 add_action( 'trash_post', 'bbp_trash_forum' );
130 add_action( 'untrash_post', 'bbp_untrash_forum' );
131 add_action( 'delete_post', 'bbp_delete_forum' );
132
133 // After Deleted/Trashed/Untrashed Topic
134 add_action( 'trashed_post', 'bbp_trashed_forum' );
135 add_action( 'untrashed_post', 'bbp_untrashed_forum' );
136 add_action( 'deleted_post', 'bbp_deleted_forum' );
137
138 // Auto trash/untrash/delete a forums topics
139 add_action( 'bbp_delete_forum', 'bbp_delete_forum_topics', 10 );
140 add_action( 'bbp_trash_forum', 'bbp_trash_forum_topics', 10 );
141 add_action( 'bbp_untrash_forum', 'bbp_untrash_forum_topics', 10 );
142
143 // New/Edit Forum
144 add_action( 'bbp_new_forum', 'bbp_update_forum', 10 );
145 add_action( 'bbp_edit_forum', 'bbp_update_forum', 10 );
146
147 // Save forum extra metadata
148 add_action( 'bbp_new_forum_post_extras', 'bbp_save_forum_extras', 2 );
149 add_action( 'bbp_edit_forum_post_extras', 'bbp_save_forum_extras', 2 );
150 add_action( 'bbp_forum_attributes_metabox_save', 'bbp_save_forum_extras', 2 );
151
152 // New/Edit Reply
153 add_action( 'bbp_new_reply', 'bbp_update_reply', 10, 6 );
154 add_action( 'bbp_edit_reply', 'bbp_update_reply', 10, 6 );
155
156 // Before Delete/Trash/Untrash Reply
157 add_action( 'wp_trash_post', 'bbp_trash_reply' );
158 add_action( 'trash_post', 'bbp_trash_reply' );
159 add_action( 'untrash_post', 'bbp_untrash_reply' );
160 add_action( 'delete_post', 'bbp_delete_reply' );
161
162 // After Deleted/Trashed/Untrashed Reply
163 add_action( 'trashed_post', 'bbp_trashed_reply' );
164 add_action( 'untrashed_post', 'bbp_untrashed_reply' );
165 add_action( 'deleted_post', 'bbp_deleted_reply' );
166
167 // New/Edit Topic
168 add_action( 'bbp_new_topic', 'bbp_update_topic', 10, 5 );
169 add_action( 'bbp_edit_topic', 'bbp_update_topic', 10, 5 );
170
171 // Split/Merge Topic
172 add_action( 'bbp_merged_topic', 'bbp_merge_topic_count', 1, 3 );
173 add_action( 'bbp_post_split_topic', 'bbp_split_topic_count', 1, 3 );
174
175 // Before Delete/Trash/Untrash Topic
176 add_action( 'wp_trash_post', 'bbp_trash_topic' );
177 add_action( 'trash_post', 'bbp_trash_topic' );
178 add_action( 'untrash_post', 'bbp_untrash_topic' );
179 add_action( 'delete_post', 'bbp_delete_topic' );
180
181 // After Deleted/Trashed/Untrashed Topic
182 add_action( 'trashed_post', 'bbp_trashed_topic' );
183 add_action( 'untrashed_post', 'bbp_untrashed_topic' );
184 add_action( 'deleted_post', 'bbp_deleted_topic' );
185
186 // Favorites
187 add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_favorites' );
188 add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_favorites' );
189
190 // Subscriptions
191 add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_subscriptions' );
192 add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_subscriptions' );
193 add_action( 'bbp_new_reply', 'bbp_notify_subscribers', 1, 5 );
194
195 // Sticky
196 add_action( 'bbp_trash_topic', 'bbp_unstick_topic' );
197 add_action( 'bbp_delete_topic', 'bbp_unstick_topic' );
198
199 // Update topic branch
200 add_action( 'bbp_trashed_topic', 'bbp_update_topic_walker' );
201 add_action( 'bbp_untrashed_topic', 'bbp_update_topic_walker' );
202 add_action( 'bbp_deleted_topic', 'bbp_update_topic_walker' );
203 add_action( 'bbp_spammed_topic', 'bbp_update_topic_walker' );
204 add_action( 'bbp_unspammed_topic', 'bbp_update_topic_walker' );
205
206 // Update reply branch
207 add_action( 'bbp_trashed_reply', 'bbp_update_reply_walker' );
208 add_action( 'bbp_untrashed_reply', 'bbp_update_reply_walker' );
209 add_action( 'bbp_deleted_reply', 'bbp_update_reply_walker' );
210 add_action( 'bbp_spammed_reply', 'bbp_update_reply_walker' );
211 add_action( 'bbp_unspammed_reply', 'bbp_update_reply_walker' );
212
213 // User status
214 add_action( 'make_ham_user', 'bbp_make_ham_user' );
215 add_action( 'make_spam_user', 'bbp_make_spam_user' );
216
217 // User role
218 add_action( 'bbp_new_topic', 'bbp_global_access_auto_role' );
219 add_action( 'bbp_new_reply', 'bbp_global_access_auto_role' );
220
221 /**
222 * bbPress needs to redirect the user around in a few different circumstances:
223 *
224 * 1. Form submission within a theme (new and edit)
225 * 2. Accessing private or hidden forums
226 * 3. Editing forums, topics, replies, users, and tags
227 */
228 add_action( 'bbp_template_redirect', 'bbp_forum_enforce_hidden', -1 );
229 add_action( 'bbp_template_redirect', 'bbp_forum_enforce_private', -1 );
230 add_action( 'bbp_template_redirect', 'bbp_new_forum_handler', 10 );
231 add_action( 'bbp_template_redirect', 'bbp_new_reply_handler', 10 );
232 add_action( 'bbp_template_redirect', 'bbp_new_topic_handler', 10 );
233 add_action( 'bbp_template_redirect', 'bbp_edit_topic_tag_handler', 1 );
234 add_action( 'bbp_template_redirect', 'bbp_edit_user_handler', 1 );
235 add_action( 'bbp_template_redirect', 'bbp_edit_forum_handler', 1 );
236 add_action( 'bbp_template_redirect', 'bbp_edit_reply_handler', 1 );
237 add_action( 'bbp_template_redirect', 'bbp_edit_topic_handler', 1 );
238 add_action( 'bbp_template_redirect', 'bbp_merge_topic_handler', 1 );
239 add_action( 'bbp_template_redirect', 'bbp_split_topic_handler', 1 );
240 add_action( 'bbp_template_redirect', 'bbp_toggle_topic_handler', 1 );
241 add_action( 'bbp_template_redirect', 'bbp_toggle_reply_handler', 1 );
242 add_action( 'bbp_template_redirect', 'bbp_favorites_handler', 1 );
243 add_action( 'bbp_template_redirect', 'bbp_subscriptions_handler', 1 );
244 add_action( 'bbp_template_redirect', 'bbp_check_user_edit', 10 );
245 add_action( 'bbp_template_redirect', 'bbp_check_forum_edit', 10 );
246 add_action( 'bbp_template_redirect', 'bbp_check_topic_edit', 10 );
247 add_action( 'bbp_template_redirect', 'bbp_check_reply_edit', 10 );
248 add_action( 'bbp_template_redirect', 'bbp_check_topic_tag_edit', 10 );
249
250 /**
251 * Requires and creates the BuddyPress extension, and adds component creation
252 * action to bp_init hook. @see bbp_setup_buddypress_component()
253 *
254 * @since bbPress (r3395)
255 * @return If BuddyPress is not active
256 */
257 function bbp_setup_buddypress() {
258 global $bp;
259
260 // Bail if no BuddyPress
261 if ( !empty( $bp->maintenance_mode ) || !defined( 'BP_VERSION' ) ) return;
262
263 // Include the BuddyPress Component
264 require( bbpress()->plugin_dir . 'bbp-includes/bbp-extend-buddypress.php' );
265
266 // Instantiate BuddyPress for bbPress
267 bbpress()->extend->buddypress = new BBP_BuddyPress();
268
269 // Add component setup to bp_init action
270 add_action( 'bp_init', 'bbp_setup_buddypress_component' );
271 }
272
273 /**
274 * Plugin Dependency
275 *
276 * The purpose of the following actions is to mimic the behavior of something
277 * called 'plugin dependency' which enables a plugin to have plugins of their
278 * own in a safe and reliable way.
279 *
280 * We do this in bbPress by mirroring existing WordPress actions in many places
281 * allowing dependant plugins to hook into the bbPress specific ones, thus
282 * guaranteeing proper code execution only when bbPress is active.
283 *
284 * The following functions are wrappers for their actions, allowing them to be
285 * manually called and/or piggy-backed on top of other actions if needed.
286 */
287
288 /** Activation Actions ********************************************************/
289
290 /**
291 * Runs on bbPress activation
292 *
293 * @since bbPress (r2509)
294 * @uses register_uninstall_hook() To register our own uninstall hook
295 * @uses do_action() Calls 'bbp_activation' hook
296 */
297 function bbp_activation() {
298 do_action( 'bbp_activation' );
299 }
300
301 /**
302 * Runs on bbPress deactivation
303 *
304 * @since bbPress (r2509)
305 * @uses do_action() Calls 'bbp_deactivation' hook
306 */
307 function bbp_deactivation() {
308 do_action( 'bbp_deactivation' );
309 }
310
311 /**
312 * Runs when uninstalling bbPress
313 *
314 * @since bbPress (r2509)
315 * @uses do_action() Calls 'bbp_uninstall' hook
316 */
317 function bbp_uninstall() {
318 do_action( 'bbp_uninstall' );
319 }
320
321 /** Main Actions **************************************************************/
322
323 /**
324 * Main action responsible for constants, globals, and includes
325 *
326 * @since bbPress (r2599)
327 * @uses do_action() Calls 'bbp_loaded'
328 */
329 function bbp_loaded() {
330 do_action( 'bbp_loaded' );
331 }
332
333 /**
334 * Setup constants
335 *
336 * @since bbPress (r2599)
337 * @uses do_action() Calls 'bbp_constants'
338 */
339 function bbp_constants() {
340 do_action( 'bbp_constants' );
341 }
342
343 /**
344 * Setup globals BEFORE includes
345 *
346 * @since bbPress (r2599)
347 * @uses do_action() Calls 'bbp_boot_strap_globals'
348 */
349 function bbp_boot_strap_globals() {
350 do_action( 'bbp_boot_strap_globals' );
351 }
352
353 /**
354 * Include files
355 *
356 * @since bbPress (r2599)
357 * @uses do_action() Calls 'bbp_includes'
358 */
359 function bbp_includes() {
360 do_action( 'bbp_includes' );
361 }
362
363 /**
364 * Setup globals AFTER includes
365 *
366 * @since bbPress (r2599)
367 * @uses do_action() Calls 'bbp_setup_globals'
368 */
369 function bbp_setup_globals() {
370 do_action( 'bbp_setup_globals' );
371 }
372
373 /**
374 * Initialize any code after everything has been loaded
375 *
376 * @since bbPress (r2599)
377 * @uses do_action() Calls 'bbp_init'
378 */
379 function bbp_init() {
380 do_action ( 'bbp_init' );
381 }
382
383 /**
384 * Initialize widgets
385 *
386 * @since bbPress (r3389)
387 * @uses do_action() Calls 'bbp_widgets_init'
388 */
389 function bbp_widgets_init() {
390 do_action ( 'bbp_widgets_init' );
391 }
392
393 /**
394 * Setup the currently logged-in user
395 *
396 * @since bbPress (r2695)
397 * @uses do_action() Calls 'bbp_setup_current_user'
398 */
399 function bbp_setup_current_user() {
400 do_action ( 'bbp_setup_current_user' );
401 }
402
403 /** Supplemental Actions ******************************************************/
404
405 /**
406 * Load translations for current language
407 *
408 * @since bbPress (r2599)
409 * @uses do_action() Calls 'bbp_load_textdomain'
410 */
411 function bbp_load_textdomain() {
412 do_action( 'bbp_load_textdomain' );
413 }
414
415 /**
416 * Sets up the theme directory
417 *
418 * @since bbPress (r2507)
419 * @uses do_action() Calls 'bbp_register_theme_directory'
420 */
421 function bbp_register_theme_directory() {
422 do_action( 'bbp_register_theme_directory' );
423 }
424
425 /**
426 * Setup the post types
427 *
428 * @since bbPress (r2464)
429 * @uses do_action() Calls 'bbp_register_post_type'
430 */
431 function bbp_register_post_types() {
432 do_action ( 'bbp_register_post_types' );
433 }
434
435 /**
436 * Setup the post statuses
437 *
438 * @since bbPress (r2727)
439 * @uses do_action() Calls 'bbp_register_post_statuses'
440 */
441 function bbp_register_post_statuses() {
442 do_action ( 'bbp_register_post_statuses' );
443 }
444
445 /**
446 * Register the built in bbPress taxonomies
447 *
448 * @since bbPress (r2464)
449 * @uses do_action() Calls 'bbp_register_taxonomies'
450 */
451 function bbp_register_taxonomies() {
452 do_action ( 'bbp_register_taxonomies' );
453 }
454
455 /**
456 * Register the default bbPress views
457 *
458 * @since bbPress (r2789)
459 * @uses do_action() Calls 'bbp_register_views'
460 */
461 function bbp_register_views() {
462 do_action ( 'bbp_register_views' );
463 }
464
465 /**
466 * Enqueue bbPress specific CSS and JS
467 *
468 * @since bbPress (r3373)
469 * @uses do_action() Calls 'bbp_enqueue_scripts'
470 */
471 function bbp_enqueue_scripts() {
472 do_action ( 'bbp_enqueue_scripts' );
473 }
474
475 /**
476 * Add the bbPress-specific rewrite tags
477 *
478 * @since bbPress (r2753)
479 * @uses do_action() Calls 'bbp_add_rewrite_tags'
480 */
481 function bbp_add_rewrite_tags() {
482 do_action ( 'bbp_add_rewrite_tags' );
483 }
484
485 /** Final Action **************************************************************/
486
487 /**
488 * bbPress has loaded and initialized everything, and is okay to go
489 *
490 * @since bbPress (r2618)
491 * @uses do_action() Calls 'bbp_ready'
492 */
493 function bbp_ready() {
494 do_action( 'bbp_ready' );
495 }
496
497 /** Theme Permissions *********************************************************/
498
499 /**
500 * The main action used for redirecting bbPress theme actions that are not
501 * permitted by the current_user
502 *
503 * @since bbPress (r3605)
504 * @uses do_action()
505 */
506 function bbp_template_redirect() {
507 do_action( 'bbp_template_redirect' );
508 }
509
510 /** Theme Helpers *************************************************************/
511
512 /**
513 * The main action used for executing code before the theme has been setup
514 *
515 * @since bbPress (r3829)
516 * @uses do_action()
517 */
518 function bbp_register_theme_packages() {
519 do_action( 'bbp_register_theme_packages' );
520 }
521
522 /**
523 * The main action used for executing code before the theme has been setup
524 *
525 * @since bbPress (r3732)
526 * @uses do_action()
527 */
528 function bbp_setup_theme() {
529 do_action( 'bbp_setup_theme' );
530 }
531
532 /**
533 * The main action used for executing code after the theme has been setup
534 *
535 * @since bbPress (r3732)
536 * @uses do_action()
537 */
538 function bbp_after_setup_theme() {
539 do_action( 'bbp_after_setup_theme' );
540 }
541