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 |
---|
22 | if ( !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 | */ |
---|
40 | add_action( 'plugins_loaded', 'bbp_loaded', 10 ); |
---|
41 | add_action( 'init', 'bbp_init', 0 ); // Early for bbp_register |
---|
42 | add_action( 'parse_query', 'bbp_parse_query', 2 ); // Early for overrides |
---|
43 | add_action( 'widgets_init', 'bbp_widgets_init', 10 ); |
---|
44 | add_action( 'generate_rewrite_rules', 'bbp_generate_rewrite_rules', 10 ); |
---|
45 | add_action( 'wp_enqueue_scripts', 'bbp_enqueue_scripts', 10 ); |
---|
46 | add_action( 'wp_head', 'bbp_head', 10 ); |
---|
47 | add_action( 'wp_footer', 'bbp_footer', 10 ); |
---|
48 | add_action( 'set_current_user', 'bbp_setup_current_user', 10 ); |
---|
49 | add_action( 'setup_theme', 'bbp_setup_theme', 10 ); |
---|
50 | add_action( 'after_setup_theme', 'bbp_after_setup_theme', 10 ); |
---|
51 | add_action( 'template_redirect', 'bbp_template_redirect', 10 ); |
---|
52 | add_action( 'login_form_login', 'bbp_login_form_login', 10 ); |
---|
53 | add_action( 'profile_update', 'bbp_profile_update', 10, 2 ); // user_id and old_user_data |
---|
54 | add_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 | */ |
---|
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_packages', 14 ); |
---|
70 | add_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 | */ |
---|
79 | add_action( 'bbp_init', 'bbp_load_textdomain', 0 ); |
---|
80 | add_action( 'bbp_init', 'bbp_register', 0 ); |
---|
81 | add_action( 'bbp_init', 'bbp_add_rewrite_tags', 20 ); |
---|
82 | add_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 | */ |
---|
90 | add_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 | */ |
---|
105 | add_action( 'switch_blog', 'bbp_set_current_user_default_role' ); |
---|
106 | add_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 | */ |
---|
115 | add_action( 'bbp_register', 'bbp_register_post_types', 2 ); |
---|
116 | add_action( 'bbp_register', 'bbp_register_post_statuses', 4 ); |
---|
117 | add_action( 'bbp_register', 'bbp_register_taxonomies', 6 ); |
---|
118 | add_action( 'bbp_register', 'bbp_register_views', 8 ); |
---|
119 | add_action( 'bbp_register', 'bbp_register_shortcodes', 10 ); |
---|
120 | |
---|
121 | // Autoembeds |
---|
122 | add_action( 'bbp_init', 'bbp_reply_content_autoembed', 8 ); |
---|
123 | add_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 | */ |
---|
132 | add_action( 'bbp_ready', 'bbp_setup_akismet', 2 ); // Spam prevention for topics and replies |
---|
133 | add_action( 'bp_include', 'bbp_setup_buddypress', 10 ); // Social network integration |
---|
134 | |
---|
135 | // Try to load the bbpress-functions.php file from the active themes |
---|
136 | add_action( 'bbp_after_setup_theme', 'bbp_load_theme_functions', 10 ); |
---|
137 | |
---|
138 | // Widgets |
---|
139 | add_action( 'bbp_widgets_init', array( 'BBP_Login_Widget', 'register_widget' ), 10 ); |
---|
140 | add_action( 'bbp_widgets_init', array( 'BBP_Views_Widget', 'register_widget' ), 10 ); |
---|
141 | add_action( 'bbp_widgets_init', array( 'BBP_Search_Widget', 'register_widget' ), 10 ); |
---|
142 | add_action( 'bbp_widgets_init', array( 'BBP_Forums_Widget', 'register_widget' ), 10 ); |
---|
143 | add_action( 'bbp_widgets_init', array( 'BBP_Topics_Widget', 'register_widget' ), 10 ); |
---|
144 | add_action( 'bbp_widgets_init', array( 'BBP_Replies_Widget', 'register_widget' ), 10 ); |
---|
145 | add_action( 'bbp_widgets_init', array( 'BBP_Stats_Widget', 'register_widget' ), 10 ); |
---|
146 | |
---|
147 | // Template - Head, foot, errors and messages |
---|
148 | add_action( 'bbp_loaded', 'bbp_login_notices' ); |
---|
149 | add_action( 'bbp_head', 'bbp_topic_notices' ); |
---|
150 | add_action( 'bbp_template_notices', 'bbp_template_notices' ); |
---|
151 | |
---|
152 | // Always exclude private/hidden forums if needed |
---|
153 | add_action( 'pre_get_posts', 'bbp_pre_get_posts_exclude_forums', 4 ); |
---|
154 | |
---|
155 | // Profile Page Messages |
---|
156 | add_action( 'bbp_template_notices', 'bbp_notice_edit_user_success' ); |
---|
157 | add_action( 'bbp_template_notices', 'bbp_notice_edit_user_is_super_admin', 2 ); |
---|
158 | |
---|
159 | // Before Delete/Trash/Untrash Topic |
---|
160 | add_action( 'wp_trash_post', 'bbp_trash_forum' ); |
---|
161 | add_action( 'trash_post', 'bbp_trash_forum' ); |
---|
162 | add_action( 'untrash_post', 'bbp_untrash_forum' ); |
---|
163 | add_action( 'delete_post', 'bbp_delete_forum' ); |
---|
164 | |
---|
165 | // After Deleted/Trashed/Untrashed Topic |
---|
166 | add_action( 'trashed_post', 'bbp_trashed_forum' ); |
---|
167 | add_action( 'untrashed_post', 'bbp_untrashed_forum' ); |
---|
168 | add_action( 'deleted_post', 'bbp_deleted_forum' ); |
---|
169 | |
---|
170 | // Auto trash/untrash/delete a forums topics |
---|
171 | add_action( 'bbp_delete_forum', 'bbp_delete_forum_topics', 10 ); |
---|
172 | add_action( 'bbp_trash_forum', 'bbp_trash_forum_topics', 10 ); |
---|
173 | add_action( 'bbp_untrash_forum', 'bbp_untrash_forum_topics', 10 ); |
---|
174 | |
---|
175 | // New/Edit Forum |
---|
176 | add_action( 'bbp_new_forum', 'bbp_update_forum', 10 ); |
---|
177 | add_action( 'bbp_edit_forum', 'bbp_update_forum', 10 ); |
---|
178 | |
---|
179 | // Save forum extra metadata |
---|
180 | add_action( 'bbp_new_forum_post_extras', 'bbp_save_forum_extras', 2 ); |
---|
181 | add_action( 'bbp_edit_forum_post_extras', 'bbp_save_forum_extras', 2 ); |
---|
182 | add_action( 'bbp_forum_attributes_metabox_save', 'bbp_save_forum_extras', 2 ); |
---|
183 | |
---|
184 | // New/Edit Reply |
---|
185 | add_action( 'bbp_new_reply', 'bbp_update_reply', 10, 6 ); |
---|
186 | add_action( 'bbp_edit_reply', 'bbp_update_reply', 10, 6 ); |
---|
187 | |
---|
188 | // Before Delete/Trash/Untrash Reply |
---|
189 | add_action( 'wp_trash_post', 'bbp_trash_reply' ); |
---|
190 | add_action( 'trash_post', 'bbp_trash_reply' ); |
---|
191 | add_action( 'untrash_post', 'bbp_untrash_reply' ); |
---|
192 | add_action( 'delete_post', 'bbp_delete_reply' ); |
---|
193 | |
---|
194 | // After Deleted/Trashed/Untrashed Reply |
---|
195 | add_action( 'trashed_post', 'bbp_trashed_reply' ); |
---|
196 | add_action( 'untrashed_post', 'bbp_untrashed_reply' ); |
---|
197 | add_action( 'deleted_post', 'bbp_deleted_reply' ); |
---|
198 | |
---|
199 | // New/Edit Topic |
---|
200 | add_action( 'bbp_new_topic', 'bbp_update_topic', 10, 5 ); |
---|
201 | add_action( 'bbp_edit_topic', 'bbp_update_topic', 10, 5 ); |
---|
202 | |
---|
203 | // Split/Merge Topic |
---|
204 | add_action( 'bbp_merged_topic', 'bbp_merge_topic_count', 1, 3 ); |
---|
205 | add_action( 'bbp_post_split_topic', 'bbp_split_topic_count', 1, 3 ); |
---|
206 | |
---|
207 | // Move Reply |
---|
208 | add_action( 'bbp_post_move_reply', 'bbp_move_reply_count', 1, 3 ); |
---|
209 | |
---|
210 | // Before Delete/Trash/Untrash Topic |
---|
211 | add_action( 'wp_trash_post', 'bbp_trash_topic' ); |
---|
212 | add_action( 'trash_post', 'bbp_trash_topic' ); |
---|
213 | add_action( 'untrash_post', 'bbp_untrash_topic' ); |
---|
214 | add_action( 'delete_post', 'bbp_delete_topic' ); |
---|
215 | |
---|
216 | // After Deleted/Trashed/Untrashed Topic |
---|
217 | add_action( 'trashed_post', 'bbp_trashed_topic' ); |
---|
218 | add_action( 'untrashed_post', 'bbp_untrashed_topic' ); |
---|
219 | add_action( 'deleted_post', 'bbp_deleted_topic' ); |
---|
220 | |
---|
221 | // Favorites |
---|
222 | add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_favorites' ); |
---|
223 | add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_favorites' ); |
---|
224 | |
---|
225 | // Subscriptions |
---|
226 | add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_subscriptions' ); |
---|
227 | add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_subscriptions' ); |
---|
228 | add_action( 'bbp_new_reply', 'bbp_notify_subscribers', 11, 5 ); |
---|
229 | |
---|
230 | // Sticky |
---|
231 | add_action( 'bbp_trash_topic', 'bbp_unstick_topic' ); |
---|
232 | add_action( 'bbp_delete_topic', 'bbp_unstick_topic' ); |
---|
233 | |
---|
234 | // Update topic branch |
---|
235 | add_action( 'bbp_trashed_topic', 'bbp_update_topic_walker' ); |
---|
236 | add_action( 'bbp_untrashed_topic', 'bbp_update_topic_walker' ); |
---|
237 | add_action( 'bbp_deleted_topic', 'bbp_update_topic_walker' ); |
---|
238 | add_action( 'bbp_spammed_topic', 'bbp_update_topic_walker' ); |
---|
239 | add_action( 'bbp_unspammed_topic', 'bbp_update_topic_walker' ); |
---|
240 | |
---|
241 | // Update reply branch |
---|
242 | add_action( 'bbp_trashed_reply', 'bbp_update_reply_walker' ); |
---|
243 | add_action( 'bbp_untrashed_reply', 'bbp_update_reply_walker' ); |
---|
244 | add_action( 'bbp_deleted_reply', 'bbp_update_reply_walker' ); |
---|
245 | add_action( 'bbp_spammed_reply', 'bbp_update_reply_walker' ); |
---|
246 | add_action( 'bbp_unspammed_reply', 'bbp_update_reply_walker' ); |
---|
247 | |
---|
248 | // User status |
---|
249 | // @todo make these sub-actions |
---|
250 | add_action( 'make_ham_user', 'bbp_make_ham_user' ); |
---|
251 | add_action( 'make_spam_user', 'bbp_make_spam_user' ); |
---|
252 | |
---|
253 | // User role |
---|
254 | add_action( 'bbp_profile_update', 'bbp_profile_update_role' ); |
---|
255 | |
---|
256 | // Hook WordPress admin actions to bbPress profiles on save |
---|
257 | add_action( 'bbp_user_edit_after', 'bbp_user_edit_after' ); |
---|
258 | |
---|
259 | // Caches |
---|
260 | add_action( 'bbp_new_forum_pre_extras', 'bbp_clean_post_cache' ); |
---|
261 | add_action( 'bbp_new_forum_post_extras', 'bbp_clean_post_cache' ); |
---|
262 | add_action( 'bbp_new_topic_pre_extras', 'bbp_clean_post_cache' ); |
---|
263 | add_action( 'bbp_new_topic_post_extras', 'bbp_clean_post_cache' ); |
---|
264 | add_action( 'bbp_new_reply_pre_extras', 'bbp_clean_post_cache' ); |
---|
265 | add_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 | */ |
---|
275 | add_action( 'bbp_template_redirect', 'bbp_forum_enforce_blocked', 1 ); |
---|
276 | add_action( 'bbp_template_redirect', 'bbp_forum_enforce_hidden', 1 ); |
---|
277 | add_action( 'bbp_template_redirect', 'bbp_forum_enforce_private', 1 ); |
---|
278 | add_action( 'bbp_template_redirect', 'bbp_post_request', 10 ); |
---|
279 | add_action( 'bbp_template_redirect', 'bbp_get_request', 10 ); |
---|
280 | add_action( 'bbp_template_redirect', 'bbp_check_user_edit', 10 ); |
---|
281 | add_action( 'bbp_template_redirect', 'bbp_check_forum_edit', 10 ); |
---|
282 | add_action( 'bbp_template_redirect', 'bbp_check_topic_edit', 10 ); |
---|
283 | add_action( 'bbp_template_redirect', 'bbp_check_reply_edit', 10 ); |
---|
284 | add_action( 'bbp_template_redirect', 'bbp_check_topic_tag_edit', 10 ); |
---|
285 | |
---|
286 | // Theme-side POST requests |
---|
287 | add_action( 'bbp_post_request', 'bbp_do_ajax', 1 ); |
---|
288 | add_action( 'bbp_post_request', 'bbp_edit_topic_tag_handler', 1 ); |
---|
289 | add_action( 'bbp_post_request', 'bbp_edit_user_handler', 1 ); |
---|
290 | add_action( 'bbp_post_request', 'bbp_edit_forum_handler', 1 ); |
---|
291 | add_action( 'bbp_post_request', 'bbp_edit_reply_handler', 1 ); |
---|
292 | add_action( 'bbp_post_request', 'bbp_edit_topic_handler', 1 ); |
---|
293 | add_action( 'bbp_post_request', 'bbp_merge_topic_handler', 1 ); |
---|
294 | add_action( 'bbp_post_request', 'bbp_split_topic_handler', 1 ); |
---|
295 | add_action( 'bbp_post_request', 'bbp_move_reply_handler', 1 ); |
---|
296 | add_action( 'bbp_post_request', 'bbp_new_forum_handler', 10 ); |
---|
297 | add_action( 'bbp_post_request', 'bbp_new_reply_handler', 10 ); |
---|
298 | add_action( 'bbp_post_request', 'bbp_new_topic_handler', 10 ); |
---|
299 | |
---|
300 | // Theme-side GET requests |
---|
301 | add_action( 'bbp_get_request', 'bbp_toggle_topic_handler', 1 ); |
---|
302 | add_action( 'bbp_get_request', 'bbp_toggle_reply_handler', 1 ); |
---|
303 | add_action( 'bbp_get_request', 'bbp_favorites_handler', 1 ); |
---|
304 | add_action( 'bbp_get_request', 'bbp_subscriptions_handler', 1 ); |
---|
305 | |
---|
306 | // Maybe convert the users password |
---|
307 | add_action( 'bbp_login_form_login', 'bbp_user_maybe_convert_pass' ); |
---|
308 | |
---|
309 | add_action( 'bbp_activation', 'bbp_add_activation_redirect' ); |
---|