Skip to:
Content

bbPress.org

source: trunk/includes/core/actions.php @ 4579

Last change on this file since 4579 was 4579, checked in by jmdodd, 12 years ago

Introduce dedicated forum search.

  • Search forums, topics, and replies.
  • Add new search functions, including bbp_has_search_results().
  • Provide templates for search results.
  • Fixes #1575.
  • Property svn:eol-style set to native
File size: 13.7 KB
Line 
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 *  - Admin: More in {@link BBP_Admin::setup_actions()} in admin.php
17 *
18 * @see /core/filters.php
19 */
20
21// Exit if accessed directly
22if ( !defined( 'ABSPATH' ) ) exit;
23
24/**
25 * Attach bbPress to WordPress
26 *
27 * bbPress uses its own internal actions to help aid in third-party plugin
28 * development, and to limit the amount of potential future code changes when
29 * updates to WordPress core occur.
30 *
31 * These actions exist to create the concept of 'plugin dependencies'. They
32 * provide a safe way for plugins to execute code *only* when bbPress is
33 * installed and activated, without needing to do complicated guesswork.
34 *
35 * For more information on how this works, see the 'Plugin Dependency' section
36 * near the bottom of this file.
37 *
38 *           v--WordPress Actions        v--bbPress Sub-actions
39 */
40add_action( 'plugins_loaded',           'bbp_loaded',                   10    );
41add_action( 'init',                     'bbp_init',                     0     ); // Early for bbp_register
42add_action( 'parse_query',              'bbp_parse_query',              2     ); // Early for overrides
43add_action( 'widgets_init',             'bbp_widgets_init',             10    );
44add_action( 'generate_rewrite_rules',   'bbp_generate_rewrite_rules',   10    );
45add_action( 'wp_enqueue_scripts',       'bbp_enqueue_scripts',          10    );
46add_action( 'wp_head',                  'bbp_head',                     10    );
47add_action( 'wp_footer',                'bbp_footer',                   10    );
48add_action( 'set_current_user',         'bbp_setup_current_user',       10    );
49add_action( 'setup_theme',              'bbp_setup_theme',              10    );
50add_action( 'after_setup_theme',        'bbp_after_setup_theme',        10    );
51add_action( 'template_redirect',        'bbp_template_redirect',        10    );
52add_action( 'login_form_login',         'bbp_login_form_login',         10    );
53add_action( 'profile_update',           'bbp_profile_update',           10, 2 ); // user_id and old_user_data
54add_action( 'user_register',            'bbp_user_register',            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 */
63add_action( 'bbp_loaded', 'bbp_constants',                 2  );
64add_action( 'bbp_loaded', 'bbp_boot_strap_globals',        4  );
65add_action( 'bbp_loaded', 'bbp_includes',                  6  );
66add_action( 'bbp_loaded', 'bbp_setup_globals',             8  );
67add_action( 'bbp_loaded', 'bbp_setup_option_filters',      10 );
68add_action( 'bbp_loaded', 'bbp_setup_user_option_filters', 12 );
69add_action( 'bbp_loaded', 'bbp_register_theme_packages',   14 );
70add_action( 'bbp_loaded', 'bbp_filter_user_roles_option',  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 */
79add_action( 'bbp_init', 'bbp_load_textdomain',  0   );
80add_action( 'bbp_init', 'bbp_register',         0   );
81add_action( 'bbp_init', 'bbp_add_rewrite_tags', 20  );
82add_action( 'bbp_init', 'bbp_ready',            999 );
83
84/**
85 * There is no action API for roles to use, so hook in immediately after the
86 * $wp_roles global is set, which is the 'setup_theme' action.
87 *
88 * This is kind of lame, but is all we have for now.
89 */
90add_action( 'bbp_setup_theme', 'bbp_add_forums_roles', 1 );
91
92/**
93 * When switching to a new blog, a users mapped role will get wiped out by
94 * WP_User::for_blog() and WP_User::_init_caps().
95 *
96 * This happens naturally in multisite setups during WP_Admin_Bar::initialize(),
97 * which is annoying because it will happen on each page-load.
98 *
99 * Resetting the role on blog-switch enables us to maintain the user's dynamic
100 * role between sites. Note that if a user already has a role on that site, no
101 * mapping will occur.
102 *
103 * We also hook to 'bbp_setup_current_user' -- naturally.
104 */
105add_action( 'switch_blog',            'bbp_set_current_user_default_role' );
106add_action( 'bbp_setup_current_user', 'bbp_set_current_user_default_role' );
107
108/**
109 * bbp_register - Attached to 'init' above on 0 priority
110 *
111 * Attach various initialization actions early to the init action.
112 * The load order helps to execute code at the correct time.
113 *                                                         v---Load order
114 */
115add_action( 'bbp_register', 'bbp_register_post_types',     2  );
116add_action( 'bbp_register', 'bbp_register_post_statuses',  4  );
117add_action( 'bbp_register', 'bbp_register_taxonomies',     6  );
118add_action( 'bbp_register', 'bbp_register_views',          8  );
119add_action( 'bbp_register', 'bbp_register_shortcodes',     10 );
120
121// Autoembeds
122add_action( 'bbp_init', 'bbp_reply_content_autoembed', 8   );
123add_action( 'bbp_init', 'bbp_topic_content_autoembed', 8   );
124
125/**
126 * bbp_ready - attached to end 'bbp_init' above
127 *
128 * Attach actions to the ready action after bbPress has fully initialized.
129 * The load order helps to execute code at the correct time.
130 *                                                v---Load order
131 */
132add_action( 'bbp_ready',  'bbp_setup_akismet',    2  ); // Spam prevention for topics and replies
133add_action( 'bp_include', 'bbp_setup_buddypress', 10 ); // Social network integration
134
135// Try to load the bbpress-functions.php file from the active themes
136add_action( 'bbp_after_setup_theme', 'bbp_load_theme_functions', 10 );
137
138// Widgets
139add_action( 'bbp_widgets_init', array( 'BBP_Login_Widget',   'register_widget' ), 10 );
140add_action( 'bbp_widgets_init', array( 'BBP_Views_Widget',   'register_widget' ), 10 );
141add_action( 'bbp_widgets_init', array( 'BBP_Search_Widget',  'register_widget' ), 10 );
142add_action( 'bbp_widgets_init', array( 'BBP_Forums_Widget',  'register_widget' ), 10 );
143add_action( 'bbp_widgets_init', array( 'BBP_Topics_Widget',  'register_widget' ), 10 );
144add_action( 'bbp_widgets_init', array( 'BBP_Replies_Widget', 'register_widget' ), 10 );
145add_action( 'bbp_widgets_init', array( 'BBP_Stats_Widget',   'register_widget' ), 10 );
146
147// Template - Head, foot, errors and messages
148add_action( 'bbp_loaded',           'bbp_login_notices'    );
149add_action( 'bbp_head',             'bbp_topic_notices'    );
150add_action( 'bbp_template_notices', 'bbp_template_notices' );
151
152// Always exclude private/hidden forums if needed
153add_action( 'pre_get_posts', 'bbp_pre_get_posts_exclude_forums', 4 );
154
155// Profile Page Messages
156add_action( 'bbp_template_notices', 'bbp_notice_edit_user_success'           );
157add_action( 'bbp_template_notices', 'bbp_notice_edit_user_is_super_admin', 2 );
158
159// Before Delete/Trash/Untrash Topic
160add_action( 'wp_trash_post', 'bbp_trash_forum'   );
161add_action( 'trash_post',    'bbp_trash_forum'   );
162add_action( 'untrash_post',  'bbp_untrash_forum' );
163add_action( 'delete_post',   'bbp_delete_forum'  );
164
165// After Deleted/Trashed/Untrashed Topic
166add_action( 'trashed_post',   'bbp_trashed_forum'   );
167add_action( 'untrashed_post', 'bbp_untrashed_forum' );
168add_action( 'deleted_post',   'bbp_deleted_forum'   );
169
170// Auto trash/untrash/delete a forums topics
171add_action( 'bbp_delete_forum',  'bbp_delete_forum_topics',  10 );
172add_action( 'bbp_trash_forum',   'bbp_trash_forum_topics',   10 );
173add_action( 'bbp_untrash_forum', 'bbp_untrash_forum_topics', 10 );
174
175// New/Edit Forum
176add_action( 'bbp_new_forum',  'bbp_update_forum', 10 );
177add_action( 'bbp_edit_forum', 'bbp_update_forum', 10 );
178
179// Save forum extra metadata
180add_action( 'bbp_new_forum_post_extras',         'bbp_save_forum_extras', 2 );
181add_action( 'bbp_edit_forum_post_extras',        'bbp_save_forum_extras', 2 );
182add_action( 'bbp_forum_attributes_metabox_save', 'bbp_save_forum_extras', 2 );
183
184// New/Edit Reply
185add_action( 'bbp_new_reply',  'bbp_update_reply', 10, 6 );
186add_action( 'bbp_edit_reply', 'bbp_update_reply', 10, 6 );
187
188// Before Delete/Trash/Untrash Reply
189add_action( 'wp_trash_post', 'bbp_trash_reply'   );
190add_action( 'trash_post',    'bbp_trash_reply'   );
191add_action( 'untrash_post',  'bbp_untrash_reply' );
192add_action( 'delete_post',   'bbp_delete_reply'  );
193
194// After Deleted/Trashed/Untrashed Reply
195add_action( 'trashed_post',   'bbp_trashed_reply'   );
196add_action( 'untrashed_post', 'bbp_untrashed_reply' );
197add_action( 'deleted_post',   'bbp_deleted_reply'   );
198
199// New/Edit Topic
200add_action( 'bbp_new_topic',  'bbp_update_topic', 10, 5 );
201add_action( 'bbp_edit_topic', 'bbp_update_topic', 10, 5 );
202
203// Split/Merge Topic
204add_action( 'bbp_merged_topic',     'bbp_merge_topic_count', 1, 3 );
205add_action( 'bbp_post_split_topic', 'bbp_split_topic_count', 1, 3 );
206
207// Move Reply
208add_action( 'bbp_post_move_reply', 'bbp_move_reply_count', 1, 3 );
209
210// Before Delete/Trash/Untrash Topic
211add_action( 'wp_trash_post', 'bbp_trash_topic'   );
212add_action( 'trash_post',    'bbp_trash_topic'   );
213add_action( 'untrash_post',  'bbp_untrash_topic' );
214add_action( 'delete_post',   'bbp_delete_topic'  );
215
216// After Deleted/Trashed/Untrashed Topic
217add_action( 'trashed_post',   'bbp_trashed_topic'   );
218add_action( 'untrashed_post', 'bbp_untrashed_topic' );
219add_action( 'deleted_post',   'bbp_deleted_topic'   );
220
221// Favorites
222add_action( 'bbp_trash_topic',  'bbp_remove_topic_from_all_favorites' );
223add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_favorites' );
224
225// Subscriptions
226add_action( 'bbp_trash_topic',  'bbp_remove_topic_from_all_subscriptions'       );
227add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_subscriptions'       );
228add_action( 'bbp_new_reply',    'bbp_notify_subscribers',                 11, 5 );
229
230// Sticky
231add_action( 'bbp_trash_topic',  'bbp_unstick_topic' );
232add_action( 'bbp_delete_topic', 'bbp_unstick_topic' );
233
234// Update topic branch
235add_action( 'bbp_trashed_topic',   'bbp_update_topic_walker' );
236add_action( 'bbp_untrashed_topic', 'bbp_update_topic_walker' );
237add_action( 'bbp_deleted_topic',   'bbp_update_topic_walker' );
238add_action( 'bbp_spammed_topic',   'bbp_update_topic_walker' );
239add_action( 'bbp_unspammed_topic', 'bbp_update_topic_walker' );
240
241// Update reply branch
242add_action( 'bbp_trashed_reply',   'bbp_update_reply_walker' );
243add_action( 'bbp_untrashed_reply', 'bbp_update_reply_walker' );
244add_action( 'bbp_deleted_reply',   'bbp_update_reply_walker' );
245add_action( 'bbp_spammed_reply',   'bbp_update_reply_walker' );
246add_action( 'bbp_unspammed_reply', 'bbp_update_reply_walker' );
247
248// User status
249// @todo make these sub-actions
250add_action( 'make_ham_user',  'bbp_make_ham_user'  );
251add_action( 'make_spam_user', 'bbp_make_spam_user' );
252
253// User role
254add_action( 'bbp_profile_update', 'bbp_profile_update_role' );
255
256// Hook WordPress admin actions to bbPress profiles on save
257add_action( 'bbp_user_edit_after', 'bbp_user_edit_after' );
258
259// Caches
260add_action( 'bbp_new_forum_pre_extras',  'bbp_clean_post_cache' );
261add_action( 'bbp_new_forum_post_extras', 'bbp_clean_post_cache' );
262add_action( 'bbp_new_topic_pre_extras',  'bbp_clean_post_cache' );
263add_action( 'bbp_new_topic_post_extras', 'bbp_clean_post_cache' );
264add_action( 'bbp_new_reply_pre_extras',  'bbp_clean_post_cache' );
265add_action( 'bbp_new_reply_post_extras', 'bbp_clean_post_cache' );
266
267/**
268 * bbPress needs to redirect the user around in a few different circumstances:
269 *
270 * 1. POST and GET requests
271 * 2. Accessing private or hidden content (forums/topics/replies)
272 * 3. Editing forums, topics, replies, users, and tags
273 * 4. bbPress specific AJAX requests
274 */
275add_action( 'bbp_template_redirect', 'bbp_forum_enforce_blocked', 1  );
276add_action( 'bbp_template_redirect', 'bbp_forum_enforce_hidden',  1  );
277add_action( 'bbp_template_redirect', 'bbp_forum_enforce_private', 1  );
278add_action( 'bbp_template_redirect', 'bbp_post_request',          10 );
279add_action( 'bbp_template_redirect', 'bbp_get_request',           10 );
280add_action( 'bbp_template_redirect', 'bbp_check_user_edit',       10 );
281add_action( 'bbp_template_redirect', 'bbp_check_forum_edit',      10 );
282add_action( 'bbp_template_redirect', 'bbp_check_topic_edit',      10 );
283add_action( 'bbp_template_redirect', 'bbp_check_reply_edit',      10 );
284add_action( 'bbp_template_redirect', 'bbp_check_topic_tag_edit',  10 );
285
286// Theme-side POST requests
287add_action( 'bbp_post_request', 'bbp_do_ajax',                1  );
288add_action( 'bbp_post_request', 'bbp_edit_topic_tag_handler', 1  );
289add_action( 'bbp_post_request', 'bbp_edit_user_handler',      1  );
290add_action( 'bbp_post_request', 'bbp_edit_forum_handler',     1  );
291add_action( 'bbp_post_request', 'bbp_edit_reply_handler',     1  );
292add_action( 'bbp_post_request', 'bbp_edit_topic_handler',     1  );
293add_action( 'bbp_post_request', 'bbp_merge_topic_handler',    1  );
294add_action( 'bbp_post_request', 'bbp_split_topic_handler',    1  );
295add_action( 'bbp_post_request', 'bbp_move_reply_handler',     1  );
296add_action( 'bbp_post_request', 'bbp_new_forum_handler',      10 );
297add_action( 'bbp_post_request', 'bbp_new_reply_handler',      10 );
298add_action( 'bbp_post_request', 'bbp_new_topic_handler',      10 );
299
300// Theme-side GET requests
301add_action( 'bbp_get_request', 'bbp_toggle_topic_handler',   1  );
302add_action( 'bbp_get_request', 'bbp_toggle_reply_handler',   1  );
303add_action( 'bbp_get_request', 'bbp_favorites_handler',      1  );
304add_action( 'bbp_get_request', 'bbp_subscriptions_handler',  1  );
305
306// Maybe convert the users password
307add_action( 'bbp_login_form_login', 'bbp_user_maybe_convert_pass' );
308
309add_action( 'bbp_activation', 'bbp_add_activation_redirect' );
Note: See TracBrowser for help on using the repository browser.