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

549 lines 17.9 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 add_action( 'bbp_loaded', 'bbp_load_textdomain', 18 );
72
73 /**
74 * bbp_init - Attached to 'init' above
75 *
76 * Attach various initialization actions to the init action.
77 * The load order helps to execute code at the correct time.
78 * v---Load order
79 */
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 // Caches
222 add_action( 'bbp_new_forum_pre_extras', 'bbp_clean_post_cache' );
223 add_action( 'bbp_new_forum_post_extras', 'bbp_clean_post_cache' );
224 add_action( 'bbp_new_topic_pre_extras', 'bbp_clean_post_cache' );
225 add_action( 'bbp_new_topic_post_extras', 'bbp_clean_post_cache' );
226 add_action( 'bbp_new_reply_pre_extras', 'bbp_clean_post_cache' );
227 add_action( 'bbp_new_reply_post_extras', 'bbp_clean_post_cache' );
228
229 /**
230 * bbPress needs to redirect the user around in a few different circumstances:
231 *
232 * 1. Form submission within a theme (new and edit)
233 * 2. Accessing private or hidden forums
234 * 3. Editing forums, topics, replies, users, and tags
235 */
236 add_action( 'bbp_template_redirect', 'bbp_forum_enforce_hidden', -1 );
237 add_action( 'bbp_template_redirect', 'bbp_forum_enforce_private', -1 );
238 add_action( 'bbp_template_redirect', 'bbp_new_forum_handler', 10 );
239 add_action( 'bbp_template_redirect', 'bbp_new_reply_handler', 10 );
240 add_action( 'bbp_template_redirect', 'bbp_new_topic_handler', 10 );
241 add_action( 'bbp_template_redirect', 'bbp_edit_topic_tag_handler', 1 );
242 add_action( 'bbp_template_redirect', 'bbp_edit_user_handler', 1 );
243 add_action( 'bbp_template_redirect', 'bbp_edit_forum_handler', 1 );
244 add_action( 'bbp_template_redirect', 'bbp_edit_reply_handler', 1 );
245 add_action( 'bbp_template_redirect', 'bbp_edit_topic_handler', 1 );
246 add_action( 'bbp_template_redirect', 'bbp_merge_topic_handler', 1 );
247 add_action( 'bbp_template_redirect', 'bbp_split_topic_handler', 1 );
248 add_action( 'bbp_template_redirect', 'bbp_toggle_topic_handler', 1 );
249 add_action( 'bbp_template_redirect', 'bbp_toggle_reply_handler', 1 );
250 add_action( 'bbp_template_redirect', 'bbp_favorites_handler', 1 );
251 add_action( 'bbp_template_redirect', 'bbp_subscriptions_handler', 1 );
252 add_action( 'bbp_template_redirect', 'bbp_check_user_edit', 10 );
253 add_action( 'bbp_template_redirect', 'bbp_check_forum_edit', 10 );
254 add_action( 'bbp_template_redirect', 'bbp_check_topic_edit', 10 );
255 add_action( 'bbp_template_redirect', 'bbp_check_reply_edit', 10 );
256 add_action( 'bbp_template_redirect', 'bbp_check_topic_tag_edit', 10 );
257
258 /**
259 * Requires and creates the BuddyPress extension, and adds component creation
260 * action to bp_init hook. @see bbp_setup_buddypress_component()
261 *
262 * @since bbPress (r3395)
263 * @return If BuddyPress is not active
264 */
265 function bbp_setup_buddypress() {
266 global $bp;
267
268 // Bail if no BuddyPress
269 if ( !empty( $bp->maintenance_mode ) || !defined( 'BP_VERSION' ) ) return;
270
271 // Include the BuddyPress Component
272 require( bbpress()->plugin_dir . 'bbp-includes/bbp-extend-buddypress.php' );
273
274 // Instantiate BuddyPress for bbPress
275 bbpress()->extend->buddypress = new BBP_BuddyPress();
276
277 // Add component setup to bp_init action
278 add_action( 'bp_init', 'bbp_setup_buddypress_component' );
279 }
280
281 /**
282 * Plugin Dependency
283 *
284 * The purpose of the following actions is to mimic the behavior of something
285 * called 'plugin dependency' which enables a plugin to have plugins of their
286 * own in a safe and reliable way.
287 *
288 * We do this in bbPress by mirroring existing WordPress actions in many places
289 * allowing dependant plugins to hook into the bbPress specific ones, thus
290 * guaranteeing proper code execution only when bbPress is active.
291 *
292 * The following functions are wrappers for their actions, allowing them to be
293 * manually called and/or piggy-backed on top of other actions if needed.
294 */
295
296 /** Activation Actions ********************************************************/
297
298 /**
299 * Runs on bbPress activation
300 *
301 * @since bbPress (r2509)
302 * @uses register_uninstall_hook() To register our own uninstall hook
303 * @uses do_action() Calls 'bbp_activation' hook
304 */
305 function bbp_activation() {
306 do_action( 'bbp_activation' );
307 }
308
309 /**
310 * Runs on bbPress deactivation
311 *
312 * @since bbPress (r2509)
313 * @uses do_action() Calls 'bbp_deactivation' hook
314 */
315 function bbp_deactivation() {
316 do_action( 'bbp_deactivation' );
317 }
318
319 /**
320 * Runs when uninstalling bbPress
321 *
322 * @since bbPress (r2509)
323 * @uses do_action() Calls 'bbp_uninstall' hook
324 */
325 function bbp_uninstall() {
326 do_action( 'bbp_uninstall' );
327 }
328
329 /** Main Actions **************************************************************/
330
331 /**
332 * Main action responsible for constants, globals, and includes
333 *
334 * @since bbPress (r2599)
335 * @uses do_action() Calls 'bbp_loaded'
336 */
337 function bbp_loaded() {
338 do_action( 'bbp_loaded' );
339 }
340
341 /**
342 * Setup constants
343 *
344 * @since bbPress (r2599)
345 * @uses do_action() Calls 'bbp_constants'
346 */
347 function bbp_constants() {
348 do_action( 'bbp_constants' );
349 }
350
351 /**
352 * Setup globals BEFORE includes
353 *
354 * @since bbPress (r2599)
355 * @uses do_action() Calls 'bbp_boot_strap_globals'
356 */
357 function bbp_boot_strap_globals() {
358 do_action( 'bbp_boot_strap_globals' );
359 }
360
361 /**
362 * Include files
363 *
364 * @since bbPress (r2599)
365 * @uses do_action() Calls 'bbp_includes'
366 */
367 function bbp_includes() {
368 do_action( 'bbp_includes' );
369 }
370
371 /**
372 * Setup globals AFTER includes
373 *
374 * @since bbPress (r2599)
375 * @uses do_action() Calls 'bbp_setup_globals'
376 */
377 function bbp_setup_globals() {
378 do_action( 'bbp_setup_globals' );
379 }
380
381 /**
382 * Initialize any code after everything has been loaded
383 *
384 * @since bbPress (r2599)
385 * @uses do_action() Calls 'bbp_init'
386 */
387 function bbp_init() {
388 do_action ( 'bbp_init' );
389 }
390
391 /**
392 * Initialize widgets
393 *
394 * @since bbPress (r3389)
395 * @uses do_action() Calls 'bbp_widgets_init'
396 */
397 function bbp_widgets_init() {
398 do_action ( 'bbp_widgets_init' );
399 }
400
401 /**
402 * Setup the currently logged-in user
403 *
404 * @since bbPress (r2695)
405 * @uses do_action() Calls 'bbp_setup_current_user'
406 */
407 function bbp_setup_current_user() {
408 do_action ( 'bbp_setup_current_user' );
409 }
410
411 /** Supplemental Actions ******************************************************/
412
413 /**
414 * Load translations for current language
415 *
416 * @since bbPress (r2599)
417 * @uses do_action() Calls 'bbp_load_textdomain'
418 */
419 function bbp_load_textdomain() {
420 do_action( 'bbp_load_textdomain' );
421 }
422
423 /**
424 * Sets up the theme directory
425 *
426 * @since bbPress (r2507)
427 * @uses do_action() Calls 'bbp_register_theme_directory'
428 */
429 function bbp_register_theme_directory() {
430 do_action( 'bbp_register_theme_directory' );
431 }
432
433 /**
434 * Setup the post types
435 *
436 * @since bbPress (r2464)
437 * @uses do_action() Calls 'bbp_register_post_type'
438 */
439 function bbp_register_post_types() {
440 do_action ( 'bbp_register_post_types' );
441 }
442
443 /**
444 * Setup the post statuses
445 *
446 * @since bbPress (r2727)
447 * @uses do_action() Calls 'bbp_register_post_statuses'
448 */
449 function bbp_register_post_statuses() {
450 do_action ( 'bbp_register_post_statuses' );
451 }
452
453 /**
454 * Register the built in bbPress taxonomies
455 *
456 * @since bbPress (r2464)
457 * @uses do_action() Calls 'bbp_register_taxonomies'
458 */
459 function bbp_register_taxonomies() {
460 do_action ( 'bbp_register_taxonomies' );
461 }
462
463 /**
464 * Register the default bbPress views
465 *
466 * @since bbPress (r2789)
467 * @uses do_action() Calls 'bbp_register_views'
468 */
469 function bbp_register_views() {
470 do_action ( 'bbp_register_views' );
471 }
472
473 /**
474 * Enqueue bbPress specific CSS and JS
475 *
476 * @since bbPress (r3373)
477 * @uses do_action() Calls 'bbp_enqueue_scripts'
478 */
479 function bbp_enqueue_scripts() {
480 do_action ( 'bbp_enqueue_scripts' );
481 }
482
483 /**
484 * Add the bbPress-specific rewrite tags
485 *
486 * @since bbPress (r2753)
487 * @uses do_action() Calls 'bbp_add_rewrite_tags'
488 */
489 function bbp_add_rewrite_tags() {
490 do_action ( 'bbp_add_rewrite_tags' );
491 }
492
493 /** Final Action **************************************************************/
494
495 /**
496 * bbPress has loaded and initialized everything, and is okay to go
497 *
498 * @since bbPress (r2618)
499 * @uses do_action() Calls 'bbp_ready'
500 */
501 function bbp_ready() {
502 do_action( 'bbp_ready' );
503 }
504
505 /** Theme Permissions *********************************************************/
506
507 /**
508 * The main action used for redirecting bbPress theme actions that are not
509 * permitted by the current_user
510 *
511 * @since bbPress (r3605)
512 * @uses do_action()
513 */
514 function bbp_template_redirect() {
515 do_action( 'bbp_template_redirect' );
516 }
517
518 /** Theme Helpers *************************************************************/
519
520 /**
521 * The main action used for executing code before the theme has been setup
522 *
523 * @since bbPress (r3829)
524 * @uses do_action()
525 */
526 function bbp_register_theme_packages() {
527 do_action( 'bbp_register_theme_packages' );
528 }
529
530 /**
531 * The main action used for executing code before the theme has been setup
532 *
533 * @since bbPress (r3732)
534 * @uses do_action()
535 */
536 function bbp_setup_theme() {
537 do_action( 'bbp_setup_theme' );
538 }
539
540 /**
541 * The main action used for executing code after the theme has been setup
542 *
543 * @since bbPress (r3732)
544 * @uses do_action()
545 */
546 function bbp_after_setup_theme() {
547 do_action( 'bbp_after_setup_theme' );
548 }
549