` and `` tags. Used along with the
123 | * `mb_code_trick()` function as a callback. This is code from the original standalone bbPress software
124 | * (not the plugin).
125 | *
126 | * @author bbPress
127 | * @license http://www.gnu.org/licenses/gpl-2.0.html
128 | * @link http://bbpress.org
129 | * @link http://bbpress.org/download/legacy/
130 | *
131 | * @since 1.0.0
132 | * @access public
133 | * @param string $text
134 | * @return string
135 | */
136 | function mb_encodeit( $matches ) {
137 |
138 | $text = trim( $matches[2] );
139 | $text = htmlspecialchars( $text, ENT_QUOTES );
140 |
141 | $text = str_replace( array( "\r\n", "\r" ), "\n", $text );
142 | $text = preg_replace( "|\n\n\n+|", "\n\n", $text );
143 | $text = str_replace( '&', '&', $text );
144 | $text = str_replace( '<', '<', $text );
145 | $text = str_replace( '>', '>', $text );
146 | $text = str_replace( array( '"' ), '"', $text );
147 |
148 | $text = str_replace( '[', '[', $text );
149 |
150 | $text = "$text
";
151 |
152 | if ( "`" != $matches[1] )
153 | $text = "$text
";
154 |
155 | return $text;
156 | }
157 |
158 | /**
159 | * Function for decoding encoded HTML and wrapping the output in backtick (`) characters. Used along with
160 | * the `mb_code_trick_reverse()` function as a callback. This is code from the original standalone bbPress
161 | * software (not the plugin).
162 | *
163 | * @author bbPress
164 | * @license http://www.gnu.org/licenses/gpl-2.0.html
165 | * @link http://bbpress.org
166 | * @link http://bbpress.org/download/legacy/
167 | *
168 | * @since 1.0.0
169 | * @access public
170 | * @param string $text
171 | * @return string
172 | */
173 | function mb_decodeit( $matches ) {
174 |
175 | $text = $matches[2];
176 | $trans_table = array_flip( get_html_translation_table( HTML_ENTITIES ) );
177 | $text = strtr( $text, $trans_table );
178 |
179 | $text = str_replace( '
', '', $text );
180 | $text = str_replace( '', '', $text );
181 | $text = str_replace( '
', '', $text );
182 | $text = str_replace( array( '&', '&','&' ), '&', $text );
183 | $text = str_replace( array( ''', ''' ), "'", $text );
184 | $text = str_replace( array( '"' ), '"', $text );
185 |
186 | if ( '' == $matches[1] )
187 | return preg_replace( "|\n\n\n+|", "\n\n", "\n`\n$text\n`" );
188 |
189 | return "`$text`";
190 | }
191 |
192 | /**
193 | * Helper function.
194 | *
195 | * @author bbPress
196 | * @license http://www.gnu.org/licenses/gpl-2.0.html
197 | * @link http://bbpress.org
198 | * @link http://bbpress.org/download/legacy/
199 | *
200 | * @since 1.0.0
201 | * @access private
202 | * @param string $text
203 | * @param string $key
204 | * @param string $preg
205 | * @return string
206 | */
207 | function _mb_encode_bad_empty( &$text, $key, $preg ) {
208 | if ( strpos( $text, '`' ) !== 0 )
209 | $text = preg_replace( "|<($preg)\s*?/*?>|i", '<$1 />', $text );
210 | }
211 |
212 | /**
213 | * Helper function.
214 | *
215 | * @author bbPress
216 | * @license http://www.gnu.org/licenses/gpl-2.0.html
217 | * @link http://bbpress.org
218 | * @link http://bbpress.org/download/legacy/
219 | *
220 | * @since 1.0.0
221 | * @access private
222 | * @param string $text
223 | * @param string $key
224 | * @param string $preg
225 | * @return string
226 | */
227 | function _mb_encode_bad_normal( &$text, $key, $preg ) {
228 | if ( strpos( $text, '`' ) !== 0 )
229 | $text = preg_replace( "|<(/?$preg)>|i", '<$1>', $text );
230 | }
231 |
232 | /**
233 | * Helper function.
234 | *
235 | * @author bbPress
236 | * @license http://www.gnu.org/licenses/gpl-2.0.html
237 | * @link http://bbpress.org
238 | * @link http://bbpress.org/download/legacy/
239 | *
240 | * @since 1.0.0
241 | * @access public
242 | * @param string $text
243 | * @param string $key
244 | * @param string $preg
245 | * @return string
246 | */
247 | function mb_encode_bad( $text ) {
248 |
249 | $text = preg_split( '@(`[^`]*`)@m', $text, -1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE );
250 |
251 | $allowed = mb_allowed_tags();
252 | $empty = array( 'br' => true, 'hr' => true, 'img' => true, 'input' => true, 'param' => true, 'area' => true, 'col' => true, 'embed' => true );
253 |
254 | foreach ( $allowed as $tag => $args ) {
255 | $preg = $args ? "$tag(?:\s.*?)?" : $tag;
256 |
257 | if ( isset( $empty[ $tag ] ) )
258 | array_walk( $text, '_mb_encode_bad_empty', $preg );
259 | else
260 | array_walk( $text, '_mb_encode_bad_normal', $preg );
261 | }
262 |
263 | return join( '', $text );
264 | }
265 |
266 | /**
267 | * Returns allowed tags.
268 | *
269 | * @since 1.0.0
270 | * @access public
271 | * @return array
272 | */
273 | function mb_allowed_tags() {
274 |
275 | $not_allowed = array(
276 | 'area',
277 | 'aside',
278 | 'article',
279 | 'button',
280 | 'col',
281 | 'colgroup',
282 | 'details',
283 | 'div',
284 | 'fieldset',
285 | 'font',
286 | 'footer',
287 | 'form',
288 | 'header',
289 | 'hgroup',
290 | 'input',
291 | 'label',
292 | 'legend',
293 | 'map',
294 | 'menu',
295 | 'nav',
296 | 'option',
297 | 'section',
298 | 'select',
299 | 'summary',
300 | 'textarea',
301 | 'title'
302 | );
303 |
304 | $allowed = wp_kses_allowed_html( 'post' );
305 |
306 | foreach ( $not_allowed as $remove ) {
307 | if ( isset( $allowed[ $remove ] ) )
308 | unset( $allowed[ $remove ] );
309 | }
310 |
311 | return apply_filters( 'mb_allowed_tags', $allowed );
312 | }
313 |
--------------------------------------------------------------------------------
/inc/core/meta.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright Copyright (c) 2014, Justin Tadlock
9 | * @link https://github.com/justintadlock/message-board
10 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11 | */
12 |
13 | /* Register custom meta keys. */
14 | add_action( 'init', 'mb_register_meta' );
15 |
16 | /**
17 | * Registers custom meta keys with WordPress and provides callbacks for sanitizing and authorizing
18 | * the metadata.
19 | *
20 | * @since 1.0.0
21 | * @access public
22 | * @return void
23 | */
24 | function mb_register_meta() {
25 |
26 | /* General post meta. */
27 | register_meta( 'post', mb_get_prev_status_meta_key(), 'sanitize_key', '__return_true' );
28 |
29 | /* Forum meta. */
30 | register_meta( 'post', mb_get_forum_activity_datetime_meta_key(), 'esc_html', '__return_true' );
31 | register_meta( 'post', mb_get_forum_activity_datetime_epoch_meta_key(), 'esc_html', '__return_true' );
32 | register_meta( 'post', mb_get_forum_last_topic_id_meta_key(), 'absint', '__return_true' );
33 | register_meta( 'post', mb_get_forum_last_reply_id_meta_key(), 'absint', '__return_true' );
34 | register_meta( 'post', mb_get_forum_subforum_count_meta_key(), 'absint', '__return_true' );
35 | register_meta( 'post', mb_get_forum_topic_count_meta_key(), 'absint', '__return_true' );
36 | register_meta( 'post', mb_get_forum_reply_count_meta_key(), 'absint', '__return_true' );
37 | register_meta( 'post', mb_get_forum_type_meta_key(), 'esc_html', '__return_true' );
38 | register_meta( 'post', mb_get_forum_level_meta_key(), 'absint', '__return_true' );
39 |
40 | /* Topic meta. */
41 | register_meta( 'post', mb_get_topic_activity_datetime_meta_key(), 'esc_html', '__return_true' );
42 | register_meta( 'post', mb_get_topic_activity_datetime_epoch_meta_key(), 'esc_html', '__return_true' );
43 | register_meta( 'post', mb_get_topic_last_reply_id_meta_key(), 'absint', '__return_true' );
44 | register_meta( 'post', mb_get_topic_voices_meta_key(), 'esc_html', '__return_true' );
45 | register_meta( 'post', mb_get_topic_voice_count_meta_key(), 'absint', '__return_true' );
46 | register_meta( 'post', mb_get_topic_reply_count_meta_key(), 'absint', '__return_true' );
47 | register_meta( 'post', mb_get_topic_type_meta_key(), 'esc_html', '__return_true' );
48 |
49 | /* User meta. */
50 | register_meta( 'user', mb_get_user_forum_subscriptions_meta_key(), 'esc_html', '__return_true' );
51 | register_meta( 'user', mb_get_user_topic_subscriptions_meta_key(), 'esc_html', '__return_true' );
52 | register_meta( 'user', mb_get_user_topic_bookmarks_meta_key(), 'esc_html', '__return_true' );
53 | register_meta( 'user', mb_get_user_forum_count_meta_key(), 'absint', '__return_true' );
54 | register_meta( 'user', mb_get_user_topic_count_meta_key(), 'absint', '__return_true' );
55 | register_meta( 'user', mb_get_user_reply_count_meta_key(), 'absint', '__return_true' );
56 | }
57 |
58 | /**
59 | * Returns the meta key used for the "previous post status" for the any post type.
60 | *
61 | * @since 1.0.0
62 | * @access public
63 | * @return string
64 | */
65 | function mb_get_prev_status_meta_key() {
66 | return apply_filters( 'mb_get_prev_status_meta_key', '_prev_post_status' );
67 | }
68 |
69 | /**
70 | * Returns the meta key used for the "activity datetime" for the "forum" post type.
71 | *
72 | * @since 1.0.0
73 | * @access public
74 | * @return string
75 | */
76 | function mb_get_forum_activity_datetime_meta_key() {
77 | return apply_filters( 'mb_get_forum_activity_datetime_meta_key', '_forum_activity_datetime' );
78 | }
79 |
80 | /**
81 | * Returns the meta key used for the "activity epoch datetime" for the "forum" post type.
82 | *
83 | * @since 1.0.0
84 | * @access public
85 | * @return string
86 | */
87 | function mb_get_forum_activity_datetime_epoch_meta_key() {
88 | return apply_filters( 'mb_get_forum_activity_datetime_epoch_meta_key', '_forum_activity_datetime_epoch' );
89 | }
90 |
91 | /**
92 | * Returns the meta key used for the "last topic ID" for the "forum" post type.
93 | *
94 | * @since 1.0.0
95 | * @access public
96 | * @return string
97 | */
98 | function mb_get_forum_last_topic_id_meta_key() {
99 | return apply_filters( 'mb_get_forum_last_topic_id_meta_key', '_forum_last_topic_id' );
100 | }
101 |
102 | /**
103 | * Returns the meta key used for the "last reply ID" for the "forum" post type.
104 | *
105 | * @since 1.0.0
106 | * @access public
107 | * @return string
108 | */
109 | function mb_get_forum_last_reply_id_meta_key() {
110 | return apply_filters( 'mb_get_forum_last_reply_id_meta_key', '_forum_last_reply_id' );
111 | }
112 |
113 | /**
114 | * Returns the meta key used for the "subforum count" for the "forum" post type.
115 | *
116 | * @since 1.0.0
117 | * @access public
118 | * @return string
119 | */
120 | function mb_get_forum_subforum_count_meta_key() {
121 | return apply_filters( 'mb_get_forum_subforum_count_meta_key', '_forum_subforum_count' );
122 | }
123 |
124 | /**
125 | * Returns the meta key used for the "topic count" for the "forum" post type.
126 | *
127 | * @since 1.0.0
128 | * @access public
129 | * @return string
130 | */
131 | function mb_get_forum_topic_count_meta_key() {
132 | return apply_filters( 'mb_get_forum_topic_count_meta_key', '_forum_topic_count' );
133 | }
134 |
135 | /**
136 | * Returns the meta key used for the "reply count" for the "forum" post type.
137 | *
138 | * @since 1.0.0
139 | * @access public
140 | * @return string
141 | */
142 | function mb_get_forum_reply_count_meta_key() {
143 | return apply_filters( 'mb_get_forum_reply_count_meta_key', '_forum_reply_count' );
144 | }
145 |
146 | /**
147 | * Returns the meta key used for the "forum type" for the "forum" post type.
148 | *
149 | * @since 1.0.0
150 | * @access public
151 | * @return string
152 | */
153 | function mb_get_forum_type_meta_key() {
154 | return apply_filters( 'mb_get_forum_type_meta_key', '_forum_type' );
155 | }
156 |
157 | /**
158 | * Returns the meta key used for the "forum level" for the "forum" post type.
159 | *
160 | * @since 1.0.0
161 | * @access public
162 | * @return string
163 | */
164 | function mb_get_forum_level_meta_key() {
165 | return apply_filters( 'mb_get_forum_level_meta_key', '_forum_level' );
166 | }
167 |
168 | /**
169 | * Returns the meta key used for the "activity datetime" for the "topic" post type.
170 | *
171 | * @since 1.0.0
172 | * @access public
173 | * @return string
174 | */
175 | function mb_get_topic_activity_datetime_meta_key() {
176 | return apply_filters( 'mb_get_topic_activity_datetime_meta_key', '_topic_activity_datetime' );
177 | }
178 |
179 | /**
180 | * Returns the meta key used for the "activity epoch datetime" for the "topic" post type.
181 | *
182 | * @since 1.0.0
183 | * @access public
184 | * @return string
185 | */
186 | function mb_get_topic_activity_datetime_epoch_meta_key() {
187 | return apply_filters( 'mb_get_topic_activity_datetime_epoch_meta_key', '_topic_activity_datetime_epoch' );
188 | }
189 |
190 | /**
191 | * Returns the meta key used for the "last reply ID" for the "topic" post type.
192 | *
193 | * @since 1.0.0
194 | * @access public
195 | * @return string
196 | */
197 | function mb_get_topic_last_reply_id_meta_key() {
198 | return apply_filters( 'mb_get_topic_last_reply_id_meta_key', '_topic_last_reply_id' );
199 | }
200 |
201 | /**
202 | * Returns the meta key used for the "voices" for the "topic" post type.
203 | *
204 | * @since 1.0.0
205 | * @access public
206 | * @return string
207 | */
208 | function mb_get_topic_voices_meta_key() {
209 | return apply_filters( 'mb_get_topic_voices_meta_key', '_topic_voices' );
210 | }
211 |
212 | /**
213 | * Returns the meta key used for the "voice count" for the "topic" post type.
214 | *
215 | * @since 1.0.0
216 | * @access public
217 | * @return string
218 | */
219 | function mb_get_topic_voice_count_meta_key() {
220 | return apply_filters( 'mb_get_topic_voice_count_meta_key', '_topic_voice_count' );
221 | }
222 |
223 | /**
224 | * Returns the meta key used for the "reply count" for the "topic" post type.
225 | *
226 | * @since 1.0.0
227 | * @access public
228 | * @return string
229 | */
230 | function mb_get_topic_reply_count_meta_key() {
231 | return apply_filters( 'mb_get_topic_reply_count_meta_key', '_topic_reply_count' );
232 | }
233 |
234 | /**
235 | * Returns the meta key used for the "topic type" for the "topic" post type.
236 | *
237 | * @since 1.0.0
238 | * @access public
239 | * @return string
240 | */
241 | function mb_get_topic_type_meta_key() {
242 | return apply_filters( 'mb_get_topic_type_meta_key', '_topic_type' );
243 | }
244 |
245 | /**
246 | * Returns the meta key used for user "forum subscriptions".
247 | *
248 | * @since 1.0.0
249 | * @access public
250 | * @return string
251 | */
252 | function mb_get_user_forum_subscriptions_meta_key() {
253 | return apply_filters( 'mb_get_user_forum_subscriptions_meta_key', '_forum_subscriptions' );
254 | }
255 |
256 | /**
257 | * Returns the meta key used for user "topic subscriptions".
258 | *
259 | * @since 1.0.0
260 | * @access public
261 | * @return string
262 | */
263 | function mb_get_user_topic_subscriptions_meta_key() {
264 | return apply_filters( 'mb_get_user_topic_subscriptions_meta_key', '_topic_subscriptions' );
265 | }
266 |
267 | /**
268 | * Returns the meta key used for user "topic bookmarks".
269 | *
270 | * @since 1.0.0
271 | * @access public
272 | * @return string
273 | */
274 | function mb_get_user_topic_bookmarks_meta_key() {
275 | return apply_filters( 'mb_get_user_topic_bookmarks_meta_key', '_topic_bookmarks' );
276 | }
277 |
278 | /**
279 | * Returns the meta key used for user "topic count".
280 | *
281 | * @since 1.0.0
282 | * @access public
283 | * @return string
284 | */
285 | function mb_get_user_forum_count_meta_key() {
286 | return apply_filters( 'mb_get_user_forum_count_meta_key', '_forum_count' );
287 | }
288 |
289 | /**
290 | * Returns the meta key used for user "topic count".
291 | *
292 | * @since 1.0.0
293 | * @access public
294 | * @return string
295 | */
296 | function mb_get_user_topic_count_meta_key() {
297 | return apply_filters( 'mb_get_user_topic_count_meta_key', '_topic_count' );
298 | }
299 |
300 | /**
301 | * Returns the meta key used for user "reply count".
302 | *
303 | * @since 1.0.0
304 | * @access public
305 | * @return string
306 | */
307 | function mb_get_user_reply_count_meta_key() {
308 | return apply_filters( 'mb_get_user_reply_count_meta_key', '_reply_count' );
309 | }
310 |
--------------------------------------------------------------------------------
/inc/core/options.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright Copyright (c) 2014, Justin Tadlock
9 | * @link https://github.com/justintadlock/message-board
10 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11 | */
12 |
13 | /**
14 | * Returns what to show on the forum front page.
15 | *
16 | * @todo Plugin setting.
17 | *
18 | * @since 1.0.0
19 | * @access public
20 | * @return string forums|topics
21 | */
22 | function mb_get_show_on_front() {
23 | return apply_filters( 'mb_get_show_on_front', get_option( 'mb_show_on_front', 'forums' ) );
24 | }
25 |
26 | /**
27 | * Returns the forum archive display (hierarchical or flat).
28 | *
29 | * @todo Plugin setting.
30 | *
31 | * @since 1.0.0
32 | * @access public
33 | * @return string
34 | */
35 | function mb_get_forum_archive_display() {
36 | return apply_filters( 'mb_get_forum_archive_display', get_option( 'mb_forum_archive_display', 'hierarchical' ) );
37 | }
38 |
39 | /**
40 | * Returns the number of forums to show per page.
41 | *
42 | * @todo Plugin setting.
43 | *
44 | * @since 1.0.0
45 | * @access public
46 | * @return int
47 | */
48 | function mb_get_forums_per_page() {
49 | return intval( apply_filters( 'mb_get_forums_per_page', get_option( 'mb_forums_per_page', 15 ) ) );
50 | }
51 |
52 | /**
53 | * Returns the number of topics to show per page.
54 | *
55 | * @todo Plugin setting.
56 | *
57 | * @since 1.0.0
58 | * @access public
59 | * @return int
60 | */
61 | function mb_get_topics_per_page() {
62 | return intval( apply_filters( 'mb_get_topics_per_page', get_option( 'mb_topics_per_page', 15 ) ) );
63 | }
64 |
65 | /**
66 | * Returns the number of replies to show per page.
67 | *
68 | * @todo Plugin setting.
69 | *
70 | * @since 1.0.0
71 | * @access public
72 | * @return int
73 | */
74 | function mb_get_replies_per_page() {
75 | return intval( apply_filters( 'mb_get_replies_per_page', get_option( 'mb_replies_per_page', 15 ) ) );
76 | }
77 |
78 | /**
79 | * Returns the number of users to show per page on the user archive.
80 | *
81 | * @todo Plugin setting.
82 | *
83 | * @since 1.0.0
84 | * @access public
85 | * @return int
86 | */
87 | function mb_get_users_per_page() {
88 | return intval( apply_filters( 'mb_get_users_per_page', get_option( 'mb_users_per_page', 15 ) ) );
89 | }
90 |
91 | /**
92 | * Returns the number of roles to show per page on the role archive.
93 | *
94 | * @since 1.0.0
95 | * @access public
96 | * @return int
97 | */
98 | function mb_get_roles_per_page() {
99 | return apply_filters( 'mb_get_roles_per_page', 15 );
100 | }
101 |
102 | /**
103 | * Returns the default forum ID. This is the first-selected forum in drop-down lists for forums. Also,
104 | * this forum should not be allowed to be trashed/deleted. Any permanently-deleted forum's topics should
105 | * be assigned to the default forum.
106 | *
107 | * @since 1.0.0
108 | * @access public
109 | * @return int
110 | */
111 | function mb_get_default_forum_id() {
112 | return absint( apply_filters( 'mb_get_default_forum_id', get_option( 'mb_default_forum_id', 0 ) ) );
113 | }
114 |
115 | /**
116 | * Returns the ID/slug of the default forum role. By default, this is set to the `mb_participant` role.
117 | *
118 | * @since 1.0.0
119 | * @access public
120 | * @return string
121 | */
122 | function mb_get_default_role() {
123 | return apply_filters( 'mb_get_default_role', get_option( 'mb_default_forum_role', mb_get_participant_role() ) );
124 | }
125 |
126 | /**
127 | * Returns TRUE if the bookmarks feature is enabled. Returns FALSE if disabled.
128 | *
129 | * @since 1.0.0
130 | * @access public
131 | * @return bool
132 | */
133 | function mb_is_bookmarks_active() {
134 | return apply_filters( 'mb_is_bookmarks_active', get_option( 'mb_enable_bookmarks', true ) );
135 | }
136 |
137 | /**
138 | * Returns TRUE if the subscriptions feature is enabled. Returns FALSE if disabled.
139 | *
140 | * @since 1.0.0
141 | * @access public
142 | * @return bool
143 | */
144 | function mb_is_subscriptions_active() {
145 | return apply_filters( 'mb_is_subscriptions_active', get_option( 'mb_enable_subscriptions', true ) );
146 | }
147 |
148 | /**
149 | * Returns an array of super sticky topics.
150 | *
151 | * @since 1.0.0
152 | * @access public
153 | * @return array
154 | */
155 | function mb_get_super_topics() {
156 | return apply_filters( 'mb_get_super_sticky_topics', get_option( 'mb_super_topics', array() ) );
157 | }
158 |
159 | /**
160 | * Returns an array of sticky topics.
161 | *
162 | * @since 1.0.0
163 | * @access public
164 | * @return array
165 | */
166 | function mb_get_sticky_topics() {
167 | return apply_filters( 'mb_get_sticky_topics', get_option( 'mb_sticky_topics', array() ) );
168 | }
169 |
--------------------------------------------------------------------------------
/inc/core/shortcodes.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright Copyright (c) 2014, Justin Tadlock
9 | * @link https://github.com/justintadlock/message-board
10 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11 | */
12 |
13 | /**
14 | * Returns an array of allowed shortcodes. By default, only the WordPress-bundled shortcodes are
15 | * allowed. Note that auto-embeds are handled separately.
16 | *
17 | * @since 1.0.0
18 | * @access public
19 | * @return array
20 | */
21 | function mb_get_allowed_shortcodes() {
22 | $allowed = array( 'embed', 'wp_caption', 'caption', 'gallery', 'playlist', 'audio', 'video' );
23 |
24 | return apply_filters( 'mb_allowed_shortcodes', $allowed );
25 | }
26 |
27 | /**
28 | * Content filter that removes all shortcodes and only allows allowed shortcodes to be run. This is a
29 | * wrapper for the `do_shortcode()` function.
30 | *
31 | * @since 1.0.0
32 | * @access public
33 | * @param string $content
34 | * @return string
35 | */
36 | function mb_do_shortcode( $content ) {
37 | global $shortcode_tags;
38 |
39 | $temp = $shortcode_tags;
40 |
41 | foreach ( $shortcode_tags as $tag => $func ) {
42 |
43 | if ( !in_array( $tag, mb_get_allowed_shortcodes() ) )
44 | remove_shortcode( $tag );
45 | }
46 |
47 | $content = do_shortcode( $content );
48 |
49 | $shortcode_tags = $temp;
50 |
51 | return $content;
52 | }
53 |
54 | /**
55 | * Content filter for only "un-auto-p'ing" allowed shortcodes. This is a wrapper for `shortcode_unautop()`.
56 | *
57 | * @since 1.0.0
58 | * @access public
59 | * @param string $content
60 | * @return string
61 | */
62 | function mb_shortcode_unautop( $content ) {
63 | global $shortcode_tags;
64 |
65 | $temp = $shortcode_tags;
66 |
67 | foreach ( $shortcode_tags as $tag => $func ) {
68 |
69 | if ( !in_array( $tag, mb_get_allowed_shortcodes() ) )
70 | remove_shortcode( $tag );
71 | }
72 |
73 | $content = shortcode_unautop( $content );
74 |
75 | $shortcode_tags = $temp;
76 |
77 | return $content;
78 | }
79 |
--------------------------------------------------------------------------------
/inc/core/theme.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright Copyright (c) 2014, Justin Tadlock
9 | * @link https://github.com/justintadlock/message-board
10 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11 | */
12 |
13 | /* Override the template hierarchy when viewing the forums. */
14 | add_filter( 'template_include', 'mb_template_include', 95 );
15 |
16 | /* Adds the theme compatibility layer. */
17 | add_action( 'mb_theme_compat', 'mb_theme_compat' );
18 |
19 | /**
20 | * Returns the theme folder that houses the templates for the plugin.
21 | *
22 | * @since 1.0.0
23 | * @access public
24 | * @return string
25 | */
26 | function mb_get_theme_template_folder() {
27 | return apply_filters( 'mb_get_theme_template_folder', 'board' );
28 | }
29 |
30 | /**
31 | * Returns the plugin's template folder name. This is the fallback used when a template can't be found
32 | * in the theme.
33 | *
34 | * @since 1.0.0
35 | * @access public
36 | * @return string
37 | */
38 | function mb_get_plugin_template_folder() {
39 | return trailingslashit( message_board()->dir_path ) . 'templates';
40 | }
41 |
42 | /**
43 | * Function for loading template parts. This is similar to the WordPress `get_template_part()` function
44 | * with the exception that it will fall back to templates in the plugin's `/templates` folder.
45 | *
46 | * @since 1.0.0
47 | * @access public
48 | * @param string $slug
49 | * @param string $name
50 | * @return void
51 | */
52 | function mb_get_template_part( $slug, $name = '' ) {
53 |
54 | /* Get theme and plugin templates paths. */
55 | $theme_dir = mb_get_theme_template_folder();
56 | $plugin_dir = mb_get_plugin_template_folder();
57 |
58 | /* Build the templates array for the theme. */
59 | $templates = array();
60 |
61 | if ( !empty( $name ) )
62 | $templates[] = "{$theme_dir}/{$slug}-{$name}.php";
63 |
64 | $templates[] = "{$theme_dir}/{$slug}.php";
65 |
66 | /* Attempt to find the template in the theme. */
67 | $has_template = locate_template( $templates, false, false );
68 |
69 | /* If no theme template found, check for name + slug template in plugin. */
70 | if ( !$has_template && !empty( $name ) && file_exists( "{$plugin_dir}/{$slug}-{$name}.php" ) )
71 | $has_template = "{$plugin_dir}/{$slug}-{$name}.php";
72 |
73 | /* Else, if no theme template found, check for it in the plugin. */
74 | elseif ( !$has_template && file_exists( "{$plugin_dir}/{$slug}.php" ) )
75 | $has_template = "{$plugin_dir}/{$slug}.php";
76 |
77 | /* If we found a template, load it. */
78 | if ( $has_template )
79 | require( $has_template );
80 | }
81 |
82 | /**
83 | * Callback function on WordPress' `template_include` filter hook. This function looks for a template within
84 | * the theme for handling the current page's output. If no template is found, it falls back to a default
85 | * `board.php` template within the plugin.
86 | *
87 | * @since 1.0.0
88 | * @access public
89 | * @param string $template
90 | * @return string
91 | */
92 | function mb_template_include( $template ) {
93 |
94 | /* If not viewing a message board page, bail. */
95 | if ( !mb_is_message_board() )
96 | return $template;
97 |
98 | /* Set up some default variables. */
99 | $hierarchy = mb_get_template_hierarchy();
100 | $theme_dir = mb_get_theme_template_folder();
101 | $plugin_dir = mb_get_plugin_template_folder();
102 | $_templates = array();
103 |
104 | foreach ( $hierarchy as $hier )
105 | $_templates[] = "{$theme_dir}/{$hier}";
106 |
107 | /* Check to see if we can find one of our templates. */
108 | $has_template = locate_template( $_templates );
109 |
110 | /* Allow devs to overwrite template. */
111 | $has_template = apply_filters( 'mb_template_include', $has_template, $theme_dir );
112 |
113 | /* If we have a template return it. */
114 | if ( $has_template )
115 | return $has_template;
116 |
117 | /* Load our fallback if nothing is found at this point. */
118 | require_once( "{$plugin_dir}/board.php" );
119 | return '';
120 | }
121 |
122 | /**
123 | * Callback function on the `mb_theme_compat` hook. This hook is used to output the plugin's content
124 | * as a fallback in the case that a theme doesn't handle the templates. This function first looks for
125 | * a template within the theme for compatibility. If it doesn't find one, it'll load its own.
126 | *
127 | * @since 1.0.0
128 | * @access public
129 | * @return void
130 | */
131 | function mb_theme_compat() {
132 |
133 | $hierarchy = mb_get_template_hierarchy();
134 | $theme_dir = mb_get_theme_template_folder();
135 | $plugin_dir = mb_get_plugin_template_folder();
136 | $theme_templates = array();
137 |
138 | /* Set up the theme templates to search for. */
139 | foreach ( $hierarchy as $hier )
140 | $theme_templates[] = "{$theme_dir}/content-{$hier}";
141 |
142 | /* Check to see if we can find one of our templates. */
143 | $has_template = locate_template( $theme_templates );
144 |
145 | /* If no theme template was found, check the plugin. */
146 | if ( !$has_template ) {
147 |
148 | /* Loop through the hierarchy. */
149 | foreach ( $hierarchy as $hier ) {
150 |
151 | /* If the template exists in the plugin, use it. */
152 | if ( file_exists( "{$plugin_dir}/content-{$hier}" ) ) {
153 | $has_template = "{$plugin_dir}/content-{$hier}";
154 | break;
155 | }
156 | }
157 | }
158 |
159 | /* If we've found a template, load it once. */
160 | if ( $has_template )
161 | require_once( $has_template );
162 | }
163 |
164 | /**
165 | * Builds the template hierarchy for the plugin. This function figures out what the current page
166 | * is and returns an array of possible templates to use. Note that this function only returns
167 | * the templates name and not a full paths. It is meant to be used within other functions that actually
168 | * locate/load the templates.
169 | *
170 | * @since 1.0.0
171 | * @access public
172 | * @return array
173 | */
174 | function mb_get_template_hierarchy() {
175 |
176 | $hierarchy = array();
177 |
178 | /* If viewing a single forum page. */
179 | if ( mb_is_single_forum() ) {
180 |
181 | $hierarchy[] = 'single-forum.php';
182 |
183 | /* If viewing the forum archive (default forum front). */
184 | } elseif ( mb_is_forum_archive() ) {
185 |
186 | $hierarchy[] = 'archive-forum.php';
187 |
188 | /* If viewing a single topic. */
189 | } elseif ( mb_is_single_topic() ) {
190 |
191 | $hierarchy[] = "single-topic.php";
192 |
193 | /* If viewing the topic archive (possible forum front page). */
194 | } elseif ( mb_is_topic_archive() ) {
195 |
196 | $hierarchy[] = 'archive-topic.php';
197 |
198 | /* If viewing a single reply. */
199 | } elseif ( mb_is_single_reply() ) {
200 |
201 | $hierarchy[] = "single-reply.php";
202 |
203 | /* If viewing the reply archive. */
204 | } elseif ( mb_is_reply_archive() ) {
205 |
206 | $hierarchy[] = 'archive-reply.php';
207 |
208 | } elseif ( mb_is_role_archive() ) {
209 |
210 | $hierarchy[] = 'archive-role.php';
211 |
212 | } elseif ( mb_is_single_role() ) {
213 |
214 | $hierarchy[] = 'single-role.php';
215 |
216 | /* If viewing a user sub-page. */
217 | } elseif ( mb_is_user_page() ) {
218 |
219 | $page = sanitize_key( get_query_var( 'mb_user_page' ) );
220 |
221 | $hierarchy[] = "single-user-{$page}.php";
222 | $hierarchy[] = 'single-user.php';
223 |
224 | /* If viewing a user profile page. */
225 | } elseif ( mb_is_single_user() ) {
226 |
227 | $hierarchy[] = 'single-user.php';
228 |
229 | /* If viewing the user archive. */
230 | } elseif ( mb_is_user_archive() ) {
231 |
232 | $hierarchy[] = 'archive-user.php';
233 |
234 | /* If viewing a search results page. */
235 | } elseif ( mb_is_search_results() ) {
236 |
237 | $hierarchy[] = 'search-results.php';
238 |
239 | /* If viewing the advanced search page. */
240 | } elseif ( mb_is_search() ) {
241 |
242 | $hierarchy[] = 'search.php';
243 |
244 | /* If viewing the forum login page. */
245 | } elseif ( mb_is_forum_login() ) {
246 |
247 | $hierarchy[] = 'login.php';
248 |
249 | /* If viewing an edit page. */
250 | } elseif ( mb_is_edit() ) {
251 |
252 | if ( mb_is_forum_edit() )
253 | $hierarchy[] = 'edit-forum.php';
254 |
255 | elseif ( mb_is_topic_edit() )
256 | $hierarchy[] = 'edit-topic.php';
257 |
258 | elseif ( mb_is_reply_edit() )
259 | $hierarchy[] = 'edit-reply.php';
260 |
261 | elseif ( mb_is_user_edit() )
262 | $hierarchy[] = 'edit-user.php';
263 |
264 | $hierarchy[] = 'edit.php';
265 | }
266 |
267 | /* Add the fallback template. */
268 | $hierarchy[] = 'board.php';
269 |
270 | return apply_filters( 'mb_get_template_hierarchy', $hierarchy );
271 | }
272 |
--------------------------------------------------------------------------------
/inc/ext/breadcrumb-trail.php:
--------------------------------------------------------------------------------
1 |
10 | * @copyright Copyright (c) 2014, Justin Tadlock
11 | * @link https://github.com/justintadlock/message-board
12 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
13 | */
14 |
15 | /* Filter the breadcrumb object. */
16 | add_filter( 'breadcrumb_trail_object', 'mb_breadcrumb_trail_object', 10, 2 );
17 |
18 | /**
19 | * Filter on `breadcrumb_trail_object`. This filter returns a custom object if viewing a page from
20 | * the Message Board plugin.
21 | *
22 | * @since 1.0.0
23 | * @access public
24 | * @param object|null $breadcrumb
25 | * @param array $args
26 | * @return object|null
27 | */
28 | function mb_breadcrumb_trail_object( $breadcrumb, $args ) {
29 | return mb_is_message_board() ? new MB_Breadcrumb_Trail( $args ) : $breadcrumb;
30 | }
31 |
32 | /**
33 | * Class that extends the main Breadcrumb Trail class. We'll create our own breadcrumb trail items
34 | * for plugin pages only.
35 | *
36 | * @since 1.0.0
37 | * @access public
38 | */
39 | class MB_Breadcrumb_Trail extends Breadcrumb_Trail {
40 |
41 | /**
42 | * Overwrites the `do_trail_items()` method and creates custom trail items.
43 | *
44 | * @since 1.0.0
45 | * @access public
46 | * @return void
47 | */
48 | public function do_trail_items() {
49 |
50 | /* Add the network and site home links. */
51 | $this->do_network_home_link();
52 | $this->do_site_home_link();
53 | $this->mb_do_board_home_link();
54 |
55 | /* Single forum, topic, or reply. */
56 | if ( mb_is_single_forum() || mb_is_single_topic() || mb_is_single_reply() ) {
57 | $this->do_singular_items();
58 | }
59 |
60 | /* Forum archive. */
61 | elseif ( mb_is_forum_archive() || mb_is_topic_archive() || mb_is_reply_archive() ) {
62 | $this->do_post_type_archive_items();
63 | }
64 |
65 | /* Role archive. */
66 | elseif ( mb_is_role_archive() ) {
67 | $this->mb_do_user_archive_link();
68 |
69 | if ( is_paged() )
70 | $this->items[] = sprintf( '%s', mb_get_role_archive_url(), mb_get_role_archive_title() );
71 |
72 | elseif ( $this->args['show_title'] )
73 | $this->items[] = mb_get_role_archive_title();
74 | }
75 |
76 | /* Single role. */
77 | elseif ( mb_is_single_role() ) {
78 | $this->mb_do_user_archive_link();
79 | $this->mb_do_role_archive_link();
80 |
81 | if ( is_paged() )
82 | $this->items[] = sprintf( '%s', mb_get_role_url(), mb_get_single_role_title() );
83 |
84 | elseif ( $this->args['show_title'] )
85 | $this->items[] = mb_get_single_role_title();
86 | }
87 |
88 | /* User archive. */
89 | elseif ( mb_is_user_archive() ) {
90 |
91 | if ( is_paged() )
92 | $this->items[] = sprintf( '%s', mb_get_user_archive_url(), mb_get_user_archive_title() );
93 |
94 | elseif ( $this->args['show_title'] )
95 | $this->items[] = mb_get_user_archive_title();
96 | }
97 |
98 | /* Single user. */
99 | elseif ( mb_is_single_user() ) {
100 | $this->mb_do_user_archive_link();
101 |
102 | /* If single user subpage. */
103 | if ( mb_is_user_page() ) {
104 | $this->items[] = sprintf( '%s', mb_get_user_url(), get_the_author_meta( 'display_name', mb_get_user_id() ) );
105 |
106 | if ( is_paged() ) {
107 |
108 | if ( mb_is_user_forums() )
109 | $this->items[] = sprintf( '%s', mb_get_user_forums_url(), mb_get_user_forums_title() );
110 |
111 | elseif ( mb_is_user_topics() )
112 | $this->items[] = sprintf( '%s', mb_get_user_topics_url(), mb_get_user_topics_title() );
113 |
114 | elseif ( mb_is_user_replies() )
115 | $this->items[] = sprintf( '%s', mb_get_user_replies_url(), mb_get_user_replies_title() );
116 |
117 | elseif ( mb_is_user_bookmarks() )
118 | $this->items[] = sprintf( '%s', mb_get_user_bookmarks_url(), mb_get_user_bookmarks_title() );
119 |
120 | elseif ( mb_is_user_forum_subscriptions() )
121 | $this->items[] = sprintf( '%s', mb_get_user_forum_subscriptions_url(), mb_get_user_forum_subscriptions_title() );
122 |
123 | elseif ( mb_is_user_topic_subscriptions() )
124 | $this->items[] = sprintf( '%s', mb_get_user_topic_subscriptions_url(), mb_get_user_topic_subscriptions_title() );
125 |
126 | } elseif ( $this->args['show_title'] ) {
127 |
128 | $this->items[] = mb_get_user_page_title();
129 | }
130 |
131 | /* If viewing the single user page but not a subpage. */
132 | } elseif ( $this->args['show_title'] ) {
133 |
134 | $this->items[] = mb_get_single_user_title();
135 | }
136 |
137 | /* Login page. */
138 | } elseif ( mb_is_forum_login() ) {
139 |
140 | $this->items[] = mb_get_login_page_title();
141 | }
142 |
143 | /* Add paged items. */
144 | $this->do_paged_items();
145 |
146 | /* Return the board breadcrumb trail items. */
147 | $this->items = apply_filters( 'mb_get_breadcrumb_trail_items', $this->items, $this->args );
148 | }
149 |
150 | /**
151 | * Adds the board home link to `$items` array.
152 | *
153 | * @since 1.0.0
154 | * @access public
155 | * @return void
156 | */
157 | public function mb_do_board_home_link() {
158 |
159 | if ( mb_is_forum_front() )
160 | return;
161 |
162 | $show_on_front = mb_get_show_on_front();
163 |
164 | if ( 'forums' === $show_on_front ) {
165 | $object = get_post_type_object( mb_get_forum_post_type() );
166 | $label = mb_get_forum_label( 'archive_title' );
167 |
168 | } elseif ( 'topics' === $show_on_front ) {
169 | $object = get_post_type_object( mb_get_topic_post_type() );
170 | $label = mb_get_topic_label( 'archive_title' );
171 | }
172 |
173 | $this->items[] = sprintf( '%s', esc_url( get_post_type_archive_link( $object->name ) ), $label );
174 | }
175 |
176 | /**
177 | * Adds the user archive link to `$items` array.
178 | *
179 | * @since 1.0.0
180 | * @access public
181 | * @return void
182 | */
183 | public function mb_do_user_archive_link() {
184 |
185 | $this->items[] = sprintf( '%s', mb_get_user_archive_url(), mb_get_user_archive_title() );
186 | }
187 |
188 | /**
189 | * Adds the role archive link to `$items` array.
190 | *
191 | * @since 1.0.0
192 | * @access public
193 | * @return void
194 | */
195 | public function mb_do_role_archive_link() {
196 |
197 | $this->items[] = sprintf( '%s', mb_get_role_archive_url(), mb_get_role_archive_title() );
198 | }
199 | }
200 |
--------------------------------------------------------------------------------
/inc/ext/members.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright Copyright (c) 2014, Justin Tadlock
9 | * @link https://github.com/justintadlock/message-board
10 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11 | */
12 |
13 | add_action( 'members_register_role_groups', 'mb_register_role_groups' );
14 |
15 | function mb_register_role_groups() {
16 |
17 | members_register_role_group(
18 | 'message-board',
19 | array(
20 | 'label' => esc_html__( 'Forum', 'message-board' ),
21 | 'label_count' => _n_noop( 'Forum %s', 'Forum %s', 'message-board' ),
22 | 'roles' => array_keys( mb_get_dynamic_roles() ),
23 | )
24 | );
25 | }
26 |
--------------------------------------------------------------------------------
/inc/forum/capabilities.php:
--------------------------------------------------------------------------------
1 |
8 | * @copyright Copyright (c) 2014, Justin Tadlock
9 | * @link https://github.com/justintadlock/message-board
10 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11 | */
12 |
13 | /* Filter meta cap checks. */
14 | add_filter( 'map_meta_cap', 'mb_forum_map_meta_cap', 10, 4 );
15 |
16 | /**
17 | * Returns an array of capabilities for the "forum" post type.
18 | *
19 | * @since 1.0.0
20 | * @access public
21 | * @return array
22 | */
23 | function mb_get_forum_capabilities() {
24 |
25 | $caps = array(
26 | // meta caps (don't assign these to roles)
27 | 'edit_post' => 'edit_forum',
28 | 'read_post' => 'read_forum',
29 | 'delete_post' => 'delete_forum',
30 |
31 | // primitive/meta caps
32 | 'create_posts' => 'create_forums',
33 |
34 | // primitive caps used outside of map_meta_cap()
35 | 'publish_posts' => 'create_forums',
36 | 'open_posts' => 'open_forums', // custom
37 | 'close_posts' => 'close_forums', // custom
38 | 'privatize_posts' => 'privatize_forums', // custom
39 | 'hide_posts' => 'hide_forums', // custom
40 | 'archive_posts' => 'archive_forums', // custom
41 |
42 | 'edit_posts' => 'edit_forums',
43 |
44 | 'read_private_posts' => 'read_private_forums',
45 | 'read_hidden_forums' => 'read_hidden_forums', // custom
46 | 'read_archived_forums' => 'read_archived_forums', // custom
47 | 'read_others_forums' => 'read_forums', // custom
48 |
49 | // primitive caps used inside of map_meta_cap()
50 | 'edit_published_posts' => 'edit_forums',
51 | 'edit_others_posts' => 'edit_others_forums',
52 | 'edit_private_posts' => 'edit_private_forums',
53 | 'edit_open_forums' => 'edit_open_forums', // custom
54 | 'edit_hidden_forums' => 'edit_hidden_forums', // custom
55 | 'edit_closed_forums' => 'edit_closed_forums', // custom
56 | 'edit_archived_forums' => 'edit_archived_forums', // custom
57 | 'delete_posts' => 'delete_forums',
58 | 'delete_published_posts' => 'delete_forums',
59 | 'delete_others_posts' => 'delete_others_forums',
60 | 'read' => 'read_forums',
61 | );
62 |
63 | return apply_filters( 'mb_get_forum_capabilities', $caps );
64 | }
65 |
66 | /**
67 | * Overwrites capabilities in certain scenarios.
68 | *
69 | * @since 1.0.0
70 | * @access public
71 | * @param array $caps
72 | * @param string $cap
73 | * @param int $user_id
74 | * @param array $args
75 | * @return array
76 | */
77 | function mb_forum_map_meta_cap( $caps, $cap, $user_id, $args ) {
78 |
79 | /* Checks if a user can read a specific forum. */
80 | if ( 'read_post' === $cap && mb_is_forum( $args[0] ) ) {
81 | $post = get_post( $args[0] );
82 |
83 | if ( $user_id != $post->post_author ) {
84 |
85 | $parent_id = $post->post_parent;
86 |
87 | /* If we have a parent forum and the user can't read it, don't allow reading this forum. */
88 | if ( 0 < $parent_id && !mb_user_can( $user_id, 'read_forum', $parent_id ) ) {
89 |
90 | $caps = array( 'do_not_allow' );
91 |
92 | /* If the user can read the parent forum, check if they can read this one. */
93 | } else {
94 | $post_type = get_post_type_object( $post->post_type );
95 | $post_status = mb_get_forum_status( $post->ID );
96 | $status_obj = get_post_status_object( $post_status );
97 |
98 | if ( mb_get_hidden_post_status() === $status_obj->name )
99 | $caps[] = $post_type->cap->read_hidden_forums;
100 |
101 | elseif ( mb_get_private_post_status() === $status_obj->name )
102 | $caps[] = $post_type->cap->read_private_posts;
103 |
104 | elseif ( $post_type->cap->read !== $post_type->cap->read_others_forums )
105 | $caps[] = $post_type->cap->read_others_forums;
106 |
107 | else
108 | $caps = array();
109 | }
110 | } else {
111 | $caps = array();
112 | }
113 |
114 | /* Meta cap for editing a single forum. */
115 | } elseif ( 'edit_post' === $cap && mb_is_forum( $args[0] ) ) {
116 |
117 | $post = get_post( $args[0] );
118 | $forum_obj = get_post_type_object( mb_get_forum_post_type() );
119 |
120 | if ( $user_id != $post->post_author ) {
121 |
122 | // Open forums.
123 | if ( mb_is_forum_open( $args[0] ) )
124 | $caps[] = $forum_obj->cap->edit_open_forums;
125 |
126 | // Closed forums.
127 | elseif ( mb_is_forum_closed( $args[0] ) )
128 | $caps[] = $forum_obj->cap->edit_closed_forums;
129 |
130 | // Hidden forums.
131 | elseif ( mb_is_forum_hidden( $args[0] ) )
132 | $caps[] = $forum_obj->cap->edit_hidden_forums;
133 | }
134 |
135 | /* Meta cap for opening a single forum. */
136 | } elseif ( 'open_forum' === $cap ) {
137 |
138 | $caps = array();
139 | $caps[] = user_can( $user_id, 'edit_forum', $args[0] ) ? 'open_forums' : 'do_not_allow';
140 |
141 | /* Meta cap for closing a single forum. */
142 | } elseif ( 'close_forum' === $cap ) {
143 |
144 | $caps = array();
145 | $caps[] = user_can( $user_id, 'edit_forum', $args[0] ) ? 'close_forums' : 'do_not_allow';
146 |
147 | /* Meta cap for privatizing a single forum. */
148 | } elseif ( 'privatize_forum' === $cap ) {
149 |
150 | $caps = array();
151 | $caps[] = user_can( $user_id, 'edit_forum', $args[0] ) ? 'privatize_forums' : 'do_not_allow';
152 |
153 | /* Meta cap for hiding a single forum. */
154 | } elseif ( 'hide_forum' === $cap ) {
155 |
156 | $caps = array();
157 | $caps[] = user_can( $user_id, 'edit_forum', $args[0] ) ? 'hide_forums' : 'do_not_allow';
158 |
159 | /* Meta cap for spamming a single forum. */
160 | } elseif ( 'archive_forum' === $cap ) {
161 |
162 | $caps = array();
163 | $caps[] = user_can( $user_id, 'edit_forum', $args[0] ) ? 'archive_forums' : 'do_not_allow';
164 |
165 |
166 | /* Meta cap for deleting a specific forum. */
167 | } elseif ( 'delete_post' === $cap && mb_is_forum( $args[0] ) ) {
168 |
169 | $forum_id = mb_get_forum_id( $args[0] );
170 |
171 | if ( mb_get_default_forum_id() === $forum_id )
172 | $caps = array( 'do_not_allow' );
173 |
174 | /* Meta cap check for accessing the forum form. */
175 | } elseif ( 'access_forum_form' === $cap ) {
176 |
177 | $caps = array( 'create_forums' );
178 |
179 | /* If this is a single forum page, check if user can create sub-forums. */
180 | if ( mb_is_single_forum() ) {
181 |
182 | $forum_id = mb_get_forum_id();
183 |
184 | if ( !current_user_can( 'read_forum', $forum_id ) )
185 | $caps[] = 'do_not_allow';
186 |
187 | elseif ( !mb_forum_allows_subforums( $forum_id ) )
188 | $caps[] = 'do_not_allow';
189 |
190 | } elseif ( mb_is_forum_edit() && !user_can( $user_id, 'edit_post', mb_get_forum_id() ) ) {
191 | $caps[] = 'do_not_allow';
192 | }
193 | }
194 |
195 | return $caps;
196 | }
197 |
--------------------------------------------------------------------------------
/inc/forum/types.php:
--------------------------------------------------------------------------------
1 |
9 | * @copyright Copyright (c) 2014, Justin Tadlock
10 | * @link https://github.com/justintadlock/message-board
11 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
12 | */
13 |
14 | /* Register forum types. */
15 | add_action( 'init', 'mb_register_forum_types' );
16 |
17 | /**
18 | * Returns the "normal" forum type.
19 | *
20 | * @since 1.0.0
21 | * @access public
22 | * @return string
23 | */
24 | function mb_get_normal_forum_type() {
25 | return apply_filters( 'mb_get_normal_forum_type', 'normal' );
26 | }
27 |
28 | /**
29 | * Returns the "category" forum type.
30 | *
31 | * @since 1.0.0
32 | * @access public
33 | * @return string
34 | */
35 | function mb_get_category_forum_type() {
36 | return apply_filters( 'mb_get_category_forum_type', 'category' );
37 | }
38 |
39 | /**
40 | * Registers custom forum types.
41 | *
42 | * @since 1.0.0
43 | * @access public
44 | * @return void
45 | */
46 | function mb_register_forum_types() {
47 |
48 | /* Normal type args. */
49 | $normal_args = array(
50 | 'topics_allowed' => true,
51 | 'subforums_allowed' => true,
52 | '_builtin' => true,
53 | '_internal' => true,
54 | 'label' => __( 'Normal', 'message-board' ),
55 | );
56 |
57 | /* Category type args. */
58 | $category_args = array(
59 | 'topics_allowed' => false,
60 | 'subforums_allowed' => true,
61 | '_builtin' => true,
62 | '_internal' => false,
63 | 'label' => __( 'Category', 'message-board' ),
64 | );
65 |
66 | /* Register forum types. */
67 | mb_register_forum_type( mb_get_normal_forum_type(), apply_filters( 'mb_normal_forum_type_args', $normal_args ) );
68 | mb_register_forum_type( mb_get_category_forum_type(), apply_filters( 'mb_category_forum_type_args', $category_args ) );
69 | }
70 |
71 | /**
72 | * Registers a new forum type.
73 | *
74 | * @since 1.0.0
75 | * @access public
76 | * @param string $name
77 | * @param array $args
78 | * @return void
79 | */
80 | function mb_register_forum_type( $name, $args = array() ) {
81 |
82 | $name = sanitize_key( $name );
83 |
84 | if ( !mb_forum_type_exists( $name ) ) {
85 |
86 | $defaults = array(
87 | 'topics_allowed' => true, // Whether new topics can be posted.
88 | 'subforums_allowed' => true, // Whether new subforums can be created.
89 | '_builtin' => false, // Internal use only! Whether the type is built in.
90 | '_internal' => false, // Internal use only! Whether the type is internal (cannot be unregistered).
91 | 'label' => '',
92 | );
93 |
94 | $args = wp_parse_args( $args, $defaults );
95 |
96 | $args['name'] = $name;
97 |
98 | message_board()->forum_types[ $name ] = (object) $args;
99 | }
100 | }
101 |
102 | /**
103 | * Unregister a forum type.
104 | *
105 | * @since 1.0.0
106 | * @access public
107 | * @param string $name
108 | * @return void
109 | */
110 | function mb_unregister_forum_type( $name ) {
111 | if ( mb_forum_type_exists( $name ) && false === mb_get_forum_type_object( $name )->_internal )
112 | unset( message_board()->forum_types[ $name ] );
113 | }
114 |
115 | /**
116 | * Check if a forum type is registered.
117 | *
118 | * @since 1.0.0
119 | * @access public
120 | * @param string $name
121 | * @return bool
122 | */
123 | function mb_forum_type_exists( $name ) {
124 | return isset( message_board()->forum_types[ $name ] );
125 | }
126 |
127 | /**
128 | * Returns an array of the registered forum type objects.
129 | *
130 | * @since 1.0.0
131 | * @access public
132 | * @return array
133 | */
134 | function mb_get_forum_type_objects() {
135 | return message_board()->forum_types;
136 | }
137 |
138 | /**
139 | * Returns a single forum type object.
140 | *
141 | * @since 1.0.0
142 | * @access public
143 | * @param string $name
144 | * @return object|bool
145 | */
146 | function mb_get_forum_type_object( $name ) {
147 | return mb_forum_type_exists( $name ) ? message_board()->forum_types[ $name ] : false;
148 | }
149 |
150 | /**
151 | * Conditional check to see if a forum has the "normal" type.
152 | *
153 | * @since 1.0.0
154 | * @access public
155 | * @param int $forum_id
156 | * @return bool
157 | */
158 | function mb_is_forum_normal( $forum_id = 0 ) {
159 | $forum_id = mb_get_forum_id( $forum_id );
160 |
161 | return mb_get_normal_forum_type() === mb_get_forum_type( $forum_id ) ? true : false;
162 | }
163 |
164 | /**
165 | * Conditional check to see if a forum has the "category" type.
166 | *
167 | * @since 1.0.0
168 | * @access public
169 | * @param int $forum_id
170 | * @return bool
171 | */
172 | function mb_is_forum_category( $forum_id = 0 ) {
173 | $forum_id = mb_get_forum_id( $forum_id );
174 |
175 | return mb_get_category_forum_type() === mb_get_forum_type( $forum_id ) ? true : false;
176 | }
177 |
178 | /**
179 | * Displays the forum type for a specific forum.
180 | *
181 | * @since 1.0.0
182 | * @access public
183 | * @param int $forum_id
184 | * @return void
185 | */
186 | function mb_forum_type( $forum_id = 0 ) {
187 | echo mb_get_forum_type( $forum_id );
188 | }
189 |
190 | /**
191 | * Returns the forum type for a specific forum.
192 | *
193 | * @since 1.0.0
194 | * @access public
195 | * @param int $forum_id
196 | * @return string
197 | */
198 | function mb_get_forum_type( $forum_id = 0 ) {
199 | $forum_id = mb_get_forum_id( $forum_id );
200 |
201 | $forum_type = $forum_id ? get_post_meta( $forum_id, mb_get_forum_type_meta_key(), true ) : '';
202 |
203 | $forum_type = !empty( $forum_type ) && mb_forum_type_exists( $forum_type ) ? $forum_type : mb_get_normal_forum_type();
204 |
205 | return apply_filters( 'mb_get_forum_type', $forum_type, $forum_id );
206 | }
207 |
208 | /**
209 | * Sets the forum type for a specific forum.
210 | *
211 | * @since 1.0.0
212 | * @access public
213 | * @param int $forum_id
214 | * @param string $forum_type
215 | * @return bool
216 | */
217 | function mb_set_forum_type( $forum_id, $type ) {
218 |
219 | $type = mb_forum_type_exists( $type ) ? $type : mb_get_normal_forum_type();
220 |
221 | return update_post_meta( $forum_id, mb_get_forum_type_meta_key(), $type );
222 | }
223 |
224 | /**
225 | * Conditional check to see if a forum type allows new topics to be posted.
226 | *
227 | * @since 1.0.0
228 | * @access public
229 | * @param string $type
230 | * @return bool
231 | */
232 | function mb_forum_type_allows_topics( $type ) {
233 | return mb_get_forum_type_object( $type )->topics_allowed;
234 | }
235 |
236 | /**
237 | * Conditional check to see if a forum type allows new subforums to be created.
238 | *
239 | * @since 1.0.0
240 | * @access public
241 | * @param string $type
242 | * @return bool
243 | */
244 | function mb_forum_type_allows_subforums( $type ) {
245 | return mb_get_forum_type_object( $type )->subforums_allowed;
246 | }
247 |
248 | /**
249 | * Creates a dropdown `
characters.', 'message-board' ); ?>
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/templates/form-reply-new.php:
--------------------------------------------------------------------------------
1 |
4 |
5 |
--------------------------------------------------------------------------------
/templates/form-search-advanced.php:
--------------------------------------------------------------------------------
1 |
5 |
6 |
--------------------------------------------------------------------------------
/templates/form-search-basic.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/templates/form-topic-edit.php:
--------------------------------------------------------------------------------
1 |
5 |
6 |
characters.', 'message-board' ); ?>
30 |