PluginProbe
bbPress / 2.0-beta-2b
bbPress v2.0-beta-2b
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-hooks.php

bbp-core-hooks.php in bbPress 2.0-beta-2b, at bbp-includes/bbp-core-hooks.php

373 lines 15.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 Filters & Actions
5 *
6 * @package bbPress
7 * @subpackage Hooks
8 *
9 * This file contains the actions and filters that are used through-out bbPress.
10 * They are consolidated here to make searching for them easier, and to help
11 * developers 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
22 // Exit if accessed directly
23 if ( !defined( 'ABSPATH' ) ) exit;
24
25 /** ACTIONS *******************************************************************/
26
27 /**
28 * Attach bbPress to WordPress
29 *
30 * bbPress uses its own internal actions to help aid in additional plugin
31 * development, and to limit the amount of potential future code changes when
32 * updates to WordPress occur.
33 */
34 add_action( 'plugins_loaded', 'bbp_loaded', 10 );
35 add_action( 'init', 'bbp_init', 10 );
36 add_action( 'generate_rewrite_rules', 'bbp_generate_rewrite_rules', 12 );
37 add_action( 'after_setup_theme', 'bbp_setup_theme_compat', 12 );
38
39 /**
40 * bbp_loaded - Attached to 'plugins_loaded' above
41 *
42 * Attach various loader actions to the bbp_loaded action.
43 * The load order helps to load code at the correct time.
44 * v---Load order
45 */
46 add_action( 'bbp_loaded', 'bbp_constants', 2 );
47 add_action( 'bbp_loaded', 'bbp_boot_strap_globals', 4 );
48 add_action( 'bbp_loaded', 'bbp_includes', 6 );
49 add_action( 'bbp_loaded', 'bbp_setup_globals', 8 );
50 add_action( 'bbp_loaded', 'bbp_register_theme_directory', 10 );
51
52 /**
53 * bbp_init - Attached to 'init' above
54 *
55 * Attach various initialization actions to the init action.
56 * The load order helps to load code at the correct time.
57 * v---Load order
58 */
59 add_action( 'bbp_init', 'bbp_register_textdomain', 2 );
60 add_action( 'bbp_init', 'bbp_setup_current_user', 4 );
61 add_action( 'bbp_init', 'bbp_register_post_types', 6 );
62 add_action( 'bbp_init', 'bbp_register_post_statuses', 8 );
63 add_action( 'bbp_init', 'bbp_register_taxonomies', 10 );
64 add_action( 'bbp_init', 'bbp_register_views', 12 );
65 add_action( 'bbp_init', 'bbp_register_shortcodes', 14 );
66 add_action( 'bbp_init', 'bbp_add_rewrite_tags', 16 );
67 add_action( 'bbp_init', 'bbp_ready', 999 );
68
69 // Admin
70 if ( is_admin() ) {
71 add_action( 'bbp_init', 'bbp_admin' );
72 add_action( 'bbp_admin_init', 'bbp_forums_admin' );
73 add_action( 'bbp_admin_init', 'bbp_topics_admin' );
74 add_action( 'bbp_admin_init', 'bbp_replies_admin' );
75 add_action( 'bbp_admin_init', 'bbp_admin_settings_help' );
76 add_action( 'admin_menu', 'bbp_admin_separator' );
77 add_action( 'custom_menu_order', 'bbp_admin_custom_menu_order' );
78 add_action( 'menu_order', 'bbp_admin_menu_order' );
79 }
80
81 // Widgets
82 add_action( 'widgets_init', create_function( '', 'return register_widget("BBP_Login_Widget");' ) );
83 add_action( 'widgets_init', create_function( '', 'return register_widget("BBP_Views_Widget");' ) );
84 add_action( 'widgets_init', create_function( '', 'return register_widget("BBP_Forums_Widget");' ) );
85 add_action( 'widgets_init', create_function( '', 'return register_widget("BBP_Topics_Widget");' ) );
86 add_action( 'widgets_init', create_function( '', 'return register_widget("BBP_Replies_Widget");' ) );
87
88 // Template - Head, foot, errors and messages
89 add_action( 'wp_head', 'bbp_head' );
90 add_filter( 'wp_title', 'bbp_title', 10, 3 );
91 add_action( 'wp_footer', 'bbp_footer' );
92 add_action( 'bbp_loaded', 'bbp_login_notices' );
93 add_action( 'bbp_head', 'bbp_topic_notices' );
94 add_action( 'bbp_template_notices', 'bbp_template_notices' );
95
96 // Add to body class
97 add_filter( 'body_class', 'bbp_body_class', 10, 2 );
98
99 // Caps & Roles
100 add_filter( 'map_meta_cap', 'bbp_map_meta_caps', 10, 4 );
101 add_action( 'bbp_activation', 'bbp_add_roles', 1 );
102 add_action( 'bbp_activation', 'bbp_add_caps', 2 );
103 add_action( 'bbp_deactivation', 'bbp_remove_caps', 1 );
104 add_action( 'bbp_deactivation', 'bbp_remove_roles', 2 );
105
106 // Options & Settings
107 add_action( 'bbp_activation', 'bbp_add_options', 1 );
108
109 // Topic Tag Page
110 add_action( 'template_redirect', 'bbp_manage_topic_tag_handler', 1 );
111
112 // Before and After the Query
113 add_action( 'pre_get_posts', 'bbp_pre_get_posts', 1 );
114 add_action( 'template_redirect', 'bbp_forum_visibility_check', -1 );
115
116 // Profile Edit
117 add_action( 'template_redirect', 'bbp_edit_user_handler', 1 );
118
119 // Profile Page Messages
120 add_action( 'bbp_template_notices', 'bbp_notice_edit_user_success' );
121 add_action( 'bbp_template_notices', 'bbp_notice_edit_user_is_super_admin', 2 );
122
123 // New/Edit Forum
124 if ( is_admin() )
125 add_action( 'wp_insert_post', 'bbp_new_forum_admin_handler', 10, 2 );
126
127 // Update forum branch
128 add_action( 'bbp_trashed_forum', 'bbp_update_forum_walker' );
129 add_action( 'bbp_untrashed_forum', 'bbp_update_forum_walker' );
130 add_action( 'bbp_deleted_forum', 'bbp_update_forum_walker' );
131 add_action( 'bbp_spammed_forum', 'bbp_update_forum_walker' );
132 add_action( 'bbp_unspammed_forum', 'bbp_update_forum_walker' );
133
134 // New/Edit Reply
135 add_action( 'template_redirect', 'bbp_new_reply_handler' );
136 add_action( 'template_redirect', 'bbp_edit_reply_handler', 1 );
137 add_action( 'bbp_new_reply', 'bbp_update_reply', 10, 6 );
138 add_action( 'bbp_edit_reply', 'bbp_update_reply', 10, 6 );
139 if ( is_admin() )
140 add_action( 'wp_insert_post', 'bbp_new_reply_admin_handler', 10, 2 );
141
142 // Before Delete/Trash/Untrash Reply
143 add_action( 'trash_post', 'bbp_trash_reply' );
144 add_action( 'untrash_post', 'bbp_untrash_reply' );
145 add_action( 'delete_post', 'bbp_delete_reply' );
146
147 // After Deleted/Trashed/Untrashed Reply
148 add_action( 'trashed_post', 'bbp_trashed_reply' );
149 add_action( 'untrashed_post', 'bbp_untrashed_reply' );
150 add_action( 'deleted_post', 'bbp_deleted_reply' );
151
152 // New/Edit Topic
153 add_action( 'template_redirect', 'bbp_new_topic_handler' );
154 add_action( 'template_redirect', 'bbp_edit_topic_handler', 1 );
155 add_action( 'bbp_new_topic', 'bbp_update_topic', 10, 5 );
156 add_action( 'bbp_edit_topic', 'bbp_update_topic', 10, 5 );
157 if ( is_admin() )
158 add_action( 'wp_insert_post', 'bbp_new_topic_admin_handler', 10, 2 );
159
160 // Split/Merge Topic
161 add_action( 'template_redirect', 'bbp_merge_topic_handler', 1 );
162 add_action( 'template_redirect', 'bbp_split_topic_handler', 1 );
163 add_action( 'bbp_merged_topic', 'bbp_merge_topic_count', 1, 3 );
164 add_action( 'bbp_post_split_topic', 'bbp_split_topic_count', 1, 3 );
165
166 // Before Delete/Trash/Untrash Topic
167 add_action( 'trash_post', 'bbp_trash_topic' );
168 add_action( 'untrash_post', 'bbp_untrash_topic' );
169 add_action( 'delete_post', 'bbp_delete_topic' );
170
171 // After Deleted/Trashed/Untrashed Topic
172 add_action( 'trashed_post', 'bbp_trashed_topic' );
173 add_action( 'untrashed_post', 'bbp_untrashed_topic' );
174 add_action( 'deleted_post', 'bbp_deleted_topic' );
175
176 // Topic/Reply Actions
177 add_action( 'template_redirect', 'bbp_toggle_topic_handler', 1 );
178 add_action( 'template_redirect', 'bbp_toggle_reply_handler', 1 );
179
180 // Favorites
181 add_action( 'template_redirect', 'bbp_favorites_handler', 1 );
182 add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_favorites' );
183 add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_favorites' );
184
185 // Subscriptions
186 add_action( 'template_redirect', 'bbp_subscriptions_handler', 1 );
187 add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_subscriptions' );
188 add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_subscriptions' );
189 add_action( 'bbp_new_reply', 'bbp_notify_subscribers', 1, 1 );
190
191 // Sticky
192 add_action( 'bbp_trash_topic', 'bbp_unstick_topic' );
193 add_action( 'bbp_delete_topic', 'bbp_unstick_topic' );
194
195 // Update topic branch
196 add_action( 'bbp_trashed_topic', 'bbp_update_topic_walker' );
197 add_action( 'bbp_untrashed_topic', 'bbp_update_topic_walker' );
198 add_action( 'bbp_deleted_topic', 'bbp_update_topic_walker' );
199 add_action( 'bbp_spammed_topic', 'bbp_update_topic_walker' );
200 add_action( 'bbp_unspammed_topic', 'bbp_update_topic_walker' );
201
202 // Update reply branch
203 add_action( 'bbp_trashed_reply', 'bbp_update_reply_walker' );
204 add_action( 'bbp_untrashed_reply', 'bbp_update_reply_walker' );
205 add_action( 'bbp_deleted_reply', 'bbp_update_reply_walker' );
206 add_action( 'bbp_spammed_reply', 'bbp_update_reply_walker' );
207 add_action( 'bbp_unspammed_reply', 'bbp_update_reply_walker' );
208
209 /** FILTERS *******************************************************************/
210
211 /**
212 * Template Compatibility
213 *
214 * If you want to completely bypass this and manage your own custom bbPress
215 * template hierarchy, start here by removing this filter, then look at how
216 * bbp_template_include() works and do something similar. :)
217 */
218 add_filter( 'template_include', 'bbp_template_include' );
219
220 /**
221 * Feeds
222 *
223 * bbPress comes with a number of custom RSS2 feeds that get handled outside
224 * the normal scope of feeds that WordPress would normally serve. To do this,
225 * we filter every page request, listen for a feed request, and trap it.
226 */
227 add_filter( 'request', 'bbp_request_feed_trap' );
228
229 // Links
230 add_filter( 'paginate_links', 'bbp_add_view_all' );
231 add_filter( 'bbp_get_topic_permalink', 'bbp_add_view_all' );
232 add_filter( 'bbp_get_reply_permalink', 'bbp_add_view_all' );
233 add_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
234
235 // wp_filter_kses on new/edit topic/reply title
236 add_filter( 'bbp_new_reply_pre_title', 'wp_filter_kses' );
237 add_filter( 'bbp_new_topic_pre_title', 'wp_filter_kses' );
238 add_filter( 'bbp_edit_reply_pre_title', 'wp_filter_kses' );
239 add_filter( 'bbp_edit_topic_pre_title', 'wp_filter_kses' );
240
241 // balanceTags, wp_filter_kses and wp_rel_nofollow on new/edit topic/reply text
242 add_filter( 'bbp_new_reply_pre_content', 'balanceTags' );
243 add_filter( 'bbp_new_reply_pre_content', 'wp_rel_nofollow' );
244 add_filter( 'bbp_new_reply_pre_content', 'wp_filter_kses' );
245 add_filter( 'bbp_new_topic_pre_content', 'balanceTags' );
246 add_filter( 'bbp_new_topic_pre_content', 'wp_rel_nofollow' );
247 add_filter( 'bbp_new_topic_pre_content', 'wp_filter_kses' );
248 add_filter( 'bbp_edit_reply_pre_content', 'balanceTags' );
249 add_filter( 'bbp_edit_reply_pre_content', 'wp_rel_nofollow' );
250 add_filter( 'bbp_edit_reply_pre_content', 'wp_filter_kses' );
251 add_filter( 'bbp_edit_topic_pre_content', 'balanceTags' );
252 add_filter( 'bbp_edit_topic_pre_content', 'wp_rel_nofollow' );
253 add_filter( 'bbp_edit_topic_pre_content', 'wp_filter_kses' );
254
255 // Add number format filter to functions requiring numeric output
256 add_filter( 'bbp_get_forum_topic_count', 'bbp_number_format' );
257 add_filter( 'bbp_get_forum_topic_reply_count', 'bbp_number_format' );
258
259 // No follow and stripslashes on user profile links
260 add_filter( 'bbp_get_reply_author_link', 'wp_rel_nofollow' );
261 add_filter( 'bbp_get_reply_author_link', 'stripslashes' );
262 add_filter( 'bbp_get_topic_author_link', 'wp_rel_nofollow' );
263 add_filter( 'bbp_get_topic_author_link', 'stripslashes' );
264 add_filter( 'bbp_get_user_favorites_link', 'wp_rel_nofollow' );
265 add_filter( 'bbp_get_user_favorites_link', 'stripslashes' );
266 add_filter( 'bbp_get_user_subscribe_link', 'wp_rel_nofollow' );
267 add_filter( 'bbp_get_user_subscribe_link', 'stripslashes' );
268 add_filter( 'bbp_get_user_profile_link', 'wp_rel_nofollow' );
269 add_filter( 'bbp_get_user_profile_link', 'stripslashes' );
270 add_filter( 'bbp_get_user_profile_edit_link', 'wp_rel_nofollow' );
271 add_filter( 'bbp_get_user_profile_edit_link', 'stripslashes' );
272
273 // Run wp_kses_data on topic/reply content in admin section
274 if ( is_admin() ) {
275 add_filter( 'bbp_get_reply_content', 'wp_kses_data' );
276 add_filter( 'bbp_get_topic_content', 'wp_kses_data' );
277 }
278
279 // Run filters on reply content
280 if ( !is_admin() )
281 add_filter( 'bbp_get_reply_content', 'bbp_reply_content_append_revisions', 1, 2 );
282 add_filter( 'bbp_get_reply_content', 'capital_P_dangit' );
283 add_filter( 'bbp_get_reply_content', 'wptexturize', 3 );
284 add_filter( 'bbp_get_reply_content', 'convert_chars', 5 );
285 add_filter( 'bbp_get_reply_content', 'make_clickable', 9 );
286 add_filter( 'bbp_get_reply_content', 'force_balance_tags', 25 );
287 add_filter( 'bbp_get_reply_content', 'convert_smilies', 20 );
288 add_filter( 'bbp_get_reply_content', 'wpautop', 30 );
289
290 // Run filters on topic content
291 if ( !is_admin() )
292 add_filter( 'bbp_get_topic_content', 'bbp_topic_content_append_revisions', 1, 2 );
293 add_filter( 'bbp_get_topic_content', 'capital_P_dangit' );
294 add_filter( 'bbp_get_topic_content', 'wptexturize', 3 );
295 add_filter( 'bbp_get_topic_content', 'convert_chars', 5 );
296 add_filter( 'bbp_get_topic_content', 'make_clickable', 9 );
297 add_filter( 'bbp_get_topic_content', 'force_balance_tags', 25 );
298 add_filter( 'bbp_get_topic_content', 'convert_smilies', 20 );
299 add_filter( 'bbp_get_topic_content', 'wpautop', 30 );
300
301 // Canonical
302 add_filter( 'redirect_canonical', 'bbp_redirect_canonical' );
303
304 // Login/Register/Lost Password
305 add_filter( 'login_redirect', 'bbp_redirect_login', 2, 3 );
306 add_filter( 'logout_url', 'bbp_logout_url', 2, 2 );
307
308 // Fix post author id for anonymous posts (set it back to 0) when the post status is changed
309 add_filter( 'wp_insert_post_data', 'bbp_fix_post_author', 30, 2 );
310
311 // Suppress private forum details
312 add_filter( 'bbp_get_forum_topic_count', 'bbp_suppress_private_forum_meta', 10, 2 );
313 add_filter( 'bbp_get_forum_reply_count', 'bbp_suppress_private_forum_meta', 10, 2 );
314 add_filter( 'bbp_get_forum_post_count', 'bbp_suppress_private_forum_meta', 10, 2 );
315 add_filter( 'bbp_get_forum_freshness_link', 'bbp_suppress_private_forum_meta', 10, 2 );
316 add_filter( 'bbp_get_author_link', 'bbp_suppress_private_author_link', 10, 2 );
317 add_filter( 'bbp_get_topic_author_link', 'bbp_suppress_private_author_link', 10, 2 );
318 add_filter( 'bbp_get_reply_author_link', 'bbp_suppress_private_author_link', 10, 2 );
319
320 /**
321 * Add filters to anonymous post author data
322 *
323 * This is used to clean-up any anonymous user data that is submitted via the
324 * new topic and new reply forms.
325 *
326 * @uses add_filter() To add filters
327 */
328 function bbp_pre_anonymous_filters () {
329
330 // Post author name
331 $filters = array(
332 'trim' => 10,
333 'sanitize_text_field' => 10,
334 'wp_filter_kses' => 10,
335 '_wp_specialchars' => 30
336 );
337 foreach ( $filters as $filter => $priority )
338 add_filter( 'bbp_pre_anonymous_post_author_name', $filter, $priority );
339
340 // Email saves
341 foreach ( array( 'trim', 'sanitize_email', 'wp_filter_kses' ) as $filter )
342 add_filter( 'bbp_pre_anonymous_post_author_email', $filter );
343
344 // Save URL
345 foreach ( array( 'trim', 'wp_strip_all_tags', 'esc_url_raw', 'wp_filter_kses' ) as $filter )
346 add_filter( 'bbp_pre_anonymous_post_author_website', $filter );
347 }
348 bbp_pre_anonymous_filters();
349
350 /**
351 * On multisite installations you must first allow themes to be activated and
352 * show up on the theme selection screen. This function will let the bbPress
353 * bundled themes show up and bypass this step.
354 *
355 * @since bbPress (r2944)
356 *
357 * @uses is_super_admin() To check if the user is site admin
358 * @uses apply_filters() Calls 'bbp_allowed_themes' with the allowed themes list
359 */
360 function bbp_allowed_themes( $themes ) {
361
362 // Only force bbp-twentyten theme for super admins
363 if ( !is_super_admin() )
364 return $themes;
365
366 $themes['bbp-twentyten'] = 1;
367
368 return apply_filters( 'bbp_allowed_themes', $themes );
369 }
370 add_filter( 'allowed_themes', 'bbp_allowed_themes' );
371
372 ?>
373