This repository has been archived by the owner on Oct 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
bbp-core-filters.php
295 lines (263 loc) · 12.3 KB
/
bbp-core-filters.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<?php
/**
* bbPress Filters
*
* @package bbPress
* @subpackage Core
*
* This file contains the filters that are used through-out bbPress. They are
* consolidated here to make searching for them easier, and to help developers
* understand at a glance the order in which things occur.
*
* There are a few common places that additional filters can currently be found
*
* - bbPress: In {@link bbPress::setup_actions()} in bbpress.php
* - Component: In {@link BBP_Component::setup_actions()} in
* bbp-includes/bbp-classes.php
* - Admin: More in {@link BBP_Admin::setup_actions()} in
* bbp-admin/bbp-admin.php
*
* @see bbp-core-actions.php
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Attach bbPress to WordPress
*
* bbPress uses its own internal actions to help aid in third-party plugin
* development, and to limit the amount of potential future code changes when
* updates to WordPress core occur.
*
* These actions exist to create the concept of 'plugin dependencies'. They
* provide a safe way for plugins to execute code *only* when bbPress is
* installed and activated, without needing to do complicated guesswork.
*
* For more information on how this works, see the 'Plugin Dependency' section
* near the bottom of this file.
*
* v--WordPress Actions v--bbPress Sub-actions
*/
add_filter( 'request', 'bbp_request', 10 );
add_filter( 'template_include', 'bbp_template_include', 10 );
add_filter( 'wp_title', 'bbp_title', 10, 3 );
add_filter( 'body_class', 'bbp_body_class', 10, 2 );
add_filter( 'map_meta_cap', 'bbp_map_meta_caps', 10, 4 );
add_filter( 'allowed_themes', 'bbp_allowed_themes', 10 );
add_filter( 'redirect_canonical', 'bbp_redirect_canonical', 10 );
add_filter( 'login_redirect', 'bbp_redirect_login', 2, 3 );
add_filter( 'logout_url', 'bbp_logout_url', 2, 2 );
// Fix post author id for anonymous posts (set it back to 0) when the post status is changed
add_filter( 'wp_insert_post_data', 'bbp_fix_post_author', 30, 2 );
// Force comments_status on bbPress post types
add_filter( 'comments_open', 'bbp_force_comment_status' );
// Add post_parent__in to posts_where
add_filter( 'posts_where', 'bbp_query_post_parent__in', 10, 2 );
/**
* Feeds
*
* bbPress comes with a number of custom RSS2 feeds that get handled outside
* the normal scope of feeds that WordPress would normally serve. To do this,
* we filter every page request, listen for a feed request, and trap it.
*/
add_filter( 'bbp_request', 'bbp_request_feed_trap' );
/**
* Template Compatibility
*
* If you want to completely bypass this and manage your own custom bbPress
* template hierarchy, start here by removing this filter, then look at how
* bbp_template_include() works and do something similar. :)
*/
add_filter( 'bbp_template_include', 'bbp_template_include_theme_supports', 2, 1 );
add_filter( 'bbp_template_include', 'bbp_template_include_theme_compat', 4, 2 );
// Links
add_filter( 'paginate_links', 'bbp_add_view_all' );
add_filter( 'bbp_get_topic_permalink', 'bbp_add_view_all' );
add_filter( 'bbp_get_reply_permalink', 'bbp_add_view_all' );
add_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
// wp_filter_kses on new/edit topic/reply title
add_filter( 'bbp_new_reply_pre_title', 'wp_filter_kses' );
add_filter( 'bbp_new_topic_pre_title', 'wp_filter_kses' );
add_filter( 'bbp_edit_reply_pre_title', 'wp_filter_kses' );
add_filter( 'bbp_edit_topic_pre_title', 'wp_filter_kses' );
// balanceTags, wp_filter_kses and wp_rel_nofollow on new/edit topic/reply text
add_filter( 'bbp_new_reply_pre_content', 'balanceTags' );
add_filter( 'bbp_new_reply_pre_content', 'wp_rel_nofollow' );
add_filter( 'bbp_new_reply_pre_content', 'wp_filter_kses' );
add_filter( 'bbp_new_topic_pre_content', 'balanceTags' );
add_filter( 'bbp_new_topic_pre_content', 'wp_rel_nofollow' );
add_filter( 'bbp_new_topic_pre_content', 'wp_filter_kses' );
add_filter( 'bbp_edit_reply_pre_content', 'balanceTags' );
add_filter( 'bbp_edit_reply_pre_content', 'wp_rel_nofollow' );
add_filter( 'bbp_edit_reply_pre_content', 'wp_filter_kses' );
add_filter( 'bbp_edit_topic_pre_content', 'balanceTags' );
add_filter( 'bbp_edit_topic_pre_content', 'wp_rel_nofollow' );
add_filter( 'bbp_edit_topic_pre_content', 'wp_filter_kses' );
// No follow and stripslashes on user profile links
add_filter( 'bbp_get_reply_author_link', 'wp_rel_nofollow' );
add_filter( 'bbp_get_reply_author_link', 'stripslashes' );
add_filter( 'bbp_get_topic_author_link', 'wp_rel_nofollow' );
add_filter( 'bbp_get_topic_author_link', 'stripslashes' );
add_filter( 'bbp_get_user_favorites_link', 'wp_rel_nofollow' );
add_filter( 'bbp_get_user_favorites_link', 'stripslashes' );
add_filter( 'bbp_get_user_subscribe_link', 'wp_rel_nofollow' );
add_filter( 'bbp_get_user_subscribe_link', 'stripslashes' );
add_filter( 'bbp_get_user_profile_link', 'wp_rel_nofollow' );
add_filter( 'bbp_get_user_profile_link', 'stripslashes' );
add_filter( 'bbp_get_user_profile_edit_link', 'wp_rel_nofollow' );
add_filter( 'bbp_get_user_profile_edit_link', 'stripslashes' );
// Run filters on reply content
add_filter( 'bbp_get_reply_content', 'capital_P_dangit' );
add_filter( 'bbp_get_reply_content', 'wptexturize', 3 );
add_filter( 'bbp_get_reply_content', 'convert_chars', 5 );
add_filter( 'bbp_get_reply_content', 'make_clickable', 9 );
add_filter( 'bbp_get_reply_content', 'force_balance_tags', 25 );
add_filter( 'bbp_get_reply_content', 'convert_smilies', 20 );
add_filter( 'bbp_get_reply_content', 'wpautop', 30 );
// Run filters on topic content
add_filter( 'bbp_get_topic_content', 'capital_P_dangit' );
add_filter( 'bbp_get_topic_content', 'wptexturize', 3 );
add_filter( 'bbp_get_topic_content', 'convert_chars', 5 );
add_filter( 'bbp_get_topic_content', 'make_clickable', 9 );
add_filter( 'bbp_get_topic_content', 'force_balance_tags', 25 );
add_filter( 'bbp_get_topic_content', 'convert_smilies', 20 );
add_filter( 'bbp_get_topic_content', 'wpautop', 30 );
// Add number format filter to functions requiring numeric output
add_filter( 'bbp_get_user_topic_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_user_reply_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_user_post_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_forum_subforum_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_forum_topic_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_forum_reply_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_forum_post_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_topic_voice_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_topic_reply_count', 'bbp_number_format', 10 );
add_filter( 'bbp_get_topic_post_count', 'bbp_number_format', 10 );
// Run wp_kses_data on topic/reply content in admin section
if ( is_admin() ) {
add_filter( 'bbp_get_reply_content', 'wp_kses_data' );
add_filter( 'bbp_get_topic_content', 'wp_kses_data' );
// Revisions (only when not in admin)
} else {
add_filter( 'bbp_get_reply_content', 'bbp_reply_content_append_revisions', 1, 2 );
add_filter( 'bbp_get_topic_content', 'bbp_topic_content_append_revisions', 1, 2 );
}
// Suppress private forum details
add_filter( 'bbp_get_forum_topic_count', 'bbp_suppress_private_forum_meta', 10, 2 );
add_filter( 'bbp_get_forum_reply_count', 'bbp_suppress_private_forum_meta', 10, 2 );
add_filter( 'bbp_get_forum_post_count', 'bbp_suppress_private_forum_meta', 10, 2 );
add_filter( 'bbp_get_forum_freshness_link', 'bbp_suppress_private_forum_meta', 10, 2 );
add_filter( 'bbp_get_author_link', 'bbp_suppress_private_author_link', 10, 2 );
add_filter( 'bbp_get_topic_author_link', 'bbp_suppress_private_author_link', 10, 2 );
add_filter( 'bbp_get_reply_author_link', 'bbp_suppress_private_author_link', 10, 2 );
// Filter bbPress template locations
add_filter( 'bbp_get_template_part', 'bbp_add_template_locations' );
add_filter( 'bbp_get_profile_template', 'bbp_add_template_locations' );
add_filter( 'bbp_get_profileedit_template', 'bbp_add_template_locations' );
add_filter( 'bbp_get_singleview_template', 'bbp_add_template_locations' );
add_filter( 'bbp_get_forumedit_template', 'bbp_add_template_locations' );
add_filter( 'bbp_get_topicedit_template', 'bbp_add_template_locations' );
add_filter( 'bbp_get_topicsplit_template', 'bbp_add_template_locations' );
add_filter( 'bbp_get_topicmerge_template', 'bbp_add_template_locations' );
add_filter( 'bbp_get_topictag_template', 'bbp_add_template_locations' );
add_filter( 'bbp_get_topictagedit_template', 'bbp_add_template_locations' );
/**
* Add filters to anonymous post author data
*/
// Post author name
add_filter( 'bbp_pre_anonymous_post_author_name', 'trim', 10 );
add_filter( 'bbp_pre_anonymous_post_author_name', 'sanitize_text_field', 10 );
add_filter( 'bbp_pre_anonymous_post_author_name', 'wp_filter_kses', 10 );
add_filter( 'bbp_pre_anonymous_post_author_name', '_wp_specialchars', 30 );
// Save email
add_filter( 'bbp_pre_anonymous_post_author_email', 'trim', 10 );
add_filter( 'bbp_pre_anonymous_post_author_email', 'sanitize_email', 10 );
add_filter( 'bbp_pre_anonymous_post_author_email', 'wp_filter_kses', 10 );
// Save URL
add_filter( 'bbp_pre_anonymous_post_author_website', 'trim', 10 );
add_filter( 'bbp_pre_anonymous_post_author_website', 'wp_strip_all_tags', 10 );
add_filter( 'bbp_pre_anonymous_post_author_website', 'esc_url_raw', 10 );
add_filter( 'bbp_pre_anonymous_post_author_website', 'wp_filter_kses', 10 );
/** Functions *****************************************************************/
/**
* Piggy back filter for WordPress's 'request' filter
*
* @since bbPress (r3758)
* @param array $query_vars
* @return array
*/
function bbp_request( $query_vars = array() ) {
return apply_filters( 'bbp_request', $query_vars );
}
/**
* The main filter used for theme compatibility and displaying custom bbPress
* theme files.
*
* @since bbPress (r3311)
* @uses apply_filters()
* @param string $template
* @return string Template file to use
*/
function bbp_template_include( $template = '' ) {
return apply_filters( 'bbp_template_include', $template );
}
/**
* Generate bbPress-specific rewrite rules
*
* @since bbPress (r2688)
* @param WP_Rewrite $wp_rewrite
* @uses do_action() Calls 'bbp_generate_rewrite_rules' with {@link WP_Rewrite}
*/
function bbp_generate_rewrite_rules( $wp_rewrite ) {
do_action_ref_array( 'bbp_generate_rewrite_rules', array( &$wp_rewrite ) );
}
/**
* Filter the allowed themes list for bbPress specific themes
*
* @since bbPress (r2944)
* @uses apply_filters() Calls 'bbp_allowed_themes' with the allowed themes list
*/
function bbp_allowed_themes( $themes ) {
return apply_filters( 'bbp_allowed_themes', $themes );
}
/** Deprecated ****************************************************************/
/**
* The following filters are deprecated.
*
* These filters were most likely replaced by bbp_parse_args(), which includes
* both passive and aggressive filters anywhere parse_args is used to compare
* default arguments to passed arguments, without needing to litter the
* codebase with _before_ and _after_ filters everywhere.
*/
/**
* Deprecated forums query filter
*
* @since bbPress (r3961)
* @param type $args
* @return type
*/
function _bbp_has_forums_query( $args = array() ) {
return apply_filters( 'bbp_has_forums_query', $args );
}
add_filter( 'bbp_after_has_forums_parse_args', '_bbp_has_forums_query' );
/**
* Deprecated topics query filter
*
* @since bbPress (r3961)
* @param type $args
* @return type
*/
function _bbp_has_topics_query( $args = array() ) {
return apply_filters( 'bbp_has_topics_query', $args );
}
add_filter( 'bbp_after_has_topics_parse_args', '_bbp_has_topics_query' );
/**
* Deprecated replies query filter
*
* @since bbPress (r3961)
* @param type $args
* @return type
*/
function _bbp_has_replies_query( $args = array() ) {
return apply_filters( 'bbp_has_replies_query', $args );
}
add_filter( 'bbp_after_has_replies_parse_args', '_bbp_has_replies_query' );