1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * bbPress Core Functions |
---|
5 | * |
---|
6 | * @package bbPress |
---|
7 | * @subpackage Functions |
---|
8 | */ |
---|
9 | |
---|
10 | // Exit if accessed directly |
---|
11 | if ( !defined( 'ABSPATH' ) ) exit; |
---|
12 | |
---|
13 | /** Versions ******************************************************************/ |
---|
14 | |
---|
15 | /** |
---|
16 | * Output the bbPress version |
---|
17 | * |
---|
18 | * @since bbPress (r3468) |
---|
19 | * @uses bbp_get_version() To get the bbPress version |
---|
20 | */ |
---|
21 | function bbp_version() { |
---|
22 | echo bbp_get_version(); |
---|
23 | } |
---|
24 | /** |
---|
25 | * Return the bbPress version |
---|
26 | * |
---|
27 | * @since bbPress (r3468) |
---|
28 | * @retrun string The bbPress version |
---|
29 | */ |
---|
30 | function bbp_get_version() { |
---|
31 | return bbpress()->version; |
---|
32 | } |
---|
33 | |
---|
34 | /** |
---|
35 | * Output the bbPress database version |
---|
36 | * |
---|
37 | * @since bbPress (r3468) |
---|
38 | * @uses bbp_get_version() To get the bbPress version |
---|
39 | */ |
---|
40 | function bbp_db_version() { |
---|
41 | echo bbp_get_db_version(); |
---|
42 | } |
---|
43 | /** |
---|
44 | * Return the bbPress database version |
---|
45 | * |
---|
46 | * @since bbPress (r3468) |
---|
47 | * @retrun string The bbPress version |
---|
48 | */ |
---|
49 | function bbp_get_db_version() { |
---|
50 | return bbpress()->db_version; |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * Output the bbPress database version directly from the database |
---|
55 | * |
---|
56 | * @since bbPress (r3468) |
---|
57 | * @uses bbp_get_version() To get the current bbPress version |
---|
58 | */ |
---|
59 | function bbp_db_version_raw() { |
---|
60 | echo bbp_get_db_version_raw(); |
---|
61 | } |
---|
62 | /** |
---|
63 | * Return the bbPress database version directly from the database |
---|
64 | * |
---|
65 | * @since bbPress (r3468) |
---|
66 | * @retrun string The current bbPress version |
---|
67 | */ |
---|
68 | function bbp_get_db_version_raw() { |
---|
69 | return get_option( '_bbp_db_version', '' ); |
---|
70 | } |
---|
71 | |
---|
72 | /** Post Meta *****************************************************************/ |
---|
73 | |
---|
74 | /** |
---|
75 | * Update a posts forum meta ID |
---|
76 | * |
---|
77 | * @since bbPress (r3181) |
---|
78 | * |
---|
79 | * @param int $post_id The post to update |
---|
80 | * @param int $forum_id The forum |
---|
81 | */ |
---|
82 | function bbp_update_forum_id( $post_id, $forum_id ) { |
---|
83 | |
---|
84 | // Allow the forum ID to be updated 'just in time' before save |
---|
85 | $forum_id = apply_filters( 'bbp_update_forum_id', $forum_id, $post_id ); |
---|
86 | |
---|
87 | // Update the post meta forum ID |
---|
88 | update_post_meta( $post_id, '_bbp_forum_id', (int) $forum_id ); |
---|
89 | } |
---|
90 | |
---|
91 | /** |
---|
92 | * Update a posts topic meta ID |
---|
93 | * |
---|
94 | * @since bbPress (r3181) |
---|
95 | * |
---|
96 | * @param int $post_id The post to update |
---|
97 | * @param int $forum_id The forum |
---|
98 | */ |
---|
99 | function bbp_update_topic_id( $post_id, $topic_id ) { |
---|
100 | |
---|
101 | // Allow the topic ID to be updated 'just in time' before save |
---|
102 | $topic_id = apply_filters( 'bbp_update_topic_id', $topic_id, $post_id ); |
---|
103 | |
---|
104 | // Update the post meta topic ID |
---|
105 | update_post_meta( $post_id, '_bbp_topic_id', (int) $topic_id ); |
---|
106 | } |
---|
107 | |
---|
108 | /** |
---|
109 | * Update a posts reply meta ID |
---|
110 | * |
---|
111 | * @since bbPress (r3181) |
---|
112 | * |
---|
113 | * @param int $post_id The post to update |
---|
114 | * @param int $forum_id The forum |
---|
115 | */ |
---|
116 | function bbp_update_reply_id( $post_id, $reply_id ) { |
---|
117 | |
---|
118 | // Allow the reply ID to be updated 'just in time' before save |
---|
119 | $reply_id = apply_filters( 'bbp_update_reply_id', $reply_id, $post_id ); |
---|
120 | |
---|
121 | // Update the post meta reply ID |
---|
122 | update_post_meta( $post_id, '_bbp_reply_id',(int) $reply_id ); |
---|
123 | } |
---|
124 | |
---|
125 | /** Views *********************************************************************/ |
---|
126 | |
---|
127 | /** |
---|
128 | * Get the registered views |
---|
129 | * |
---|
130 | * Does nothing much other than return the {@link $bbp->views} variable |
---|
131 | * |
---|
132 | * @since bbPress (r2789) |
---|
133 | * |
---|
134 | * @return array Views |
---|
135 | */ |
---|
136 | function bbp_get_views() { |
---|
137 | return bbpress()->views; |
---|
138 | } |
---|
139 | |
---|
140 | /** |
---|
141 | * Register a bbPress view |
---|
142 | * |
---|
143 | * @todo Implement feeds - See {@link http://trac.bbpress.org/ticket/1422} |
---|
144 | * |
---|
145 | * @since bbPress (r2789) |
---|
146 | * |
---|
147 | * @param string $view View name |
---|
148 | * @param string $title View title |
---|
149 | * @param mixed $query_args {@link bbp_has_topics()} arguments. |
---|
150 | * @param bool $feed Have a feed for the view? Defaults to true. NOT IMPLEMENTED |
---|
151 | * @uses sanitize_title() To sanitize the view name |
---|
152 | * @uses esc_html() To sanitize the view title |
---|
153 | * @return array The just registered (but processed) view |
---|
154 | */ |
---|
155 | function bbp_register_view( $view, $title, $query_args = '', $feed = true ) { |
---|
156 | $bbp = bbpress(); |
---|
157 | $view = sanitize_title( $view ); |
---|
158 | $title = esc_html( $title ); |
---|
159 | |
---|
160 | if ( empty( $view ) || empty( $title ) ) |
---|
161 | return false; |
---|
162 | |
---|
163 | $query_args = bbp_parse_args( $query_args, '', 'register_view' ); |
---|
164 | |
---|
165 | // Set exclude_stickies to true if it wasn't supplied |
---|
166 | if ( !isset( $query_args['show_stickies'] ) ) |
---|
167 | $query_args['show_stickies'] = false; |
---|
168 | |
---|
169 | $bbp->views[$view] = array( |
---|
170 | 'title' => $title, |
---|
171 | 'query' => $query_args, |
---|
172 | 'feed' => $feed |
---|
173 | ); |
---|
174 | |
---|
175 | return $bbp->views[$view]; |
---|
176 | } |
---|
177 | |
---|
178 | /** |
---|
179 | * Deregister a bbPress view |
---|
180 | * |
---|
181 | * @since bbPress (r2789) |
---|
182 | * |
---|
183 | * @param string $view View name |
---|
184 | * @uses sanitize_title() To sanitize the view name |
---|
185 | * @return bool False if the view doesn't exist, true on success |
---|
186 | */ |
---|
187 | function bbp_deregister_view( $view ) { |
---|
188 | $bbp = bbpress(); |
---|
189 | $view = sanitize_title( $view ); |
---|
190 | |
---|
191 | if ( !isset( $bbp->views[$view] ) ) |
---|
192 | return false; |
---|
193 | |
---|
194 | unset( $bbp->views[$view] ); |
---|
195 | |
---|
196 | return true; |
---|
197 | } |
---|
198 | |
---|
199 | /** |
---|
200 | * Run the view's query |
---|
201 | * |
---|
202 | * @since bbPress (r2789) |
---|
203 | * |
---|
204 | * @param string $view Optional. View id |
---|
205 | * @param mixed $new_args New arguments. See {@link bbp_has_topics()} |
---|
206 | * @uses bbp_get_view_id() To get the view id |
---|
207 | * @uses bbp_get_view_query_args() To get the view query args |
---|
208 | * @uses sanitize_title() To sanitize the view name |
---|
209 | * @uses bbp_has_topics() To make the topics query |
---|
210 | * @return bool False if the view doesn't exist, otherwise if topics are there |
---|
211 | */ |
---|
212 | function bbp_view_query( $view = '', $new_args = '' ) { |
---|
213 | |
---|
214 | $view = bbp_get_view_id( $view ); |
---|
215 | if ( empty( $view ) ) |
---|
216 | return false; |
---|
217 | |
---|
218 | $query_args = bbp_get_view_query_args( $view ); |
---|
219 | |
---|
220 | if ( !empty( $new_args ) ) { |
---|
221 | $new_args = bbp_parse_args( $new_args, '', 'view_query' ); |
---|
222 | $query_args = array_merge( $query_args, $new_args ); |
---|
223 | } |
---|
224 | |
---|
225 | return bbp_has_topics( $query_args ); |
---|
226 | } |
---|
227 | |
---|
228 | /** |
---|
229 | * Return the view's query arguments |
---|
230 | * |
---|
231 | * @since bbPress (r2789) |
---|
232 | * |
---|
233 | * @param string $view View name |
---|
234 | * @uses bbp_get_view_id() To get the view id |
---|
235 | * @return array Query arguments |
---|
236 | */ |
---|
237 | function bbp_get_view_query_args( $view ) { |
---|
238 | $view = bbp_get_view_id( $view ); |
---|
239 | $retval = !empty( $view ) ? bbpress()->views[$view]['query'] : false; |
---|
240 | |
---|
241 | return apply_filters( 'bbp_get_view_query_args', $retval, $view ); |
---|
242 | } |
---|
243 | |
---|
244 | /** Errors ********************************************************************/ |
---|
245 | |
---|
246 | /** |
---|
247 | * Adds an error message to later be output in the theme |
---|
248 | * |
---|
249 | * @since bbPress (r3381) |
---|
250 | * |
---|
251 | * @see WP_Error() |
---|
252 | * @uses WP_Error::add(); |
---|
253 | * |
---|
254 | * @param string $code Unique code for the error message |
---|
255 | * @param string $message Translated error message |
---|
256 | * @param string $data Any additional data passed with the error message |
---|
257 | */ |
---|
258 | function bbp_add_error( $code = '', $message = '', $data = '' ) { |
---|
259 | bbpress()->errors->add( $code, $message, $data ); |
---|
260 | } |
---|
261 | |
---|
262 | /** |
---|
263 | * Check if error messages exist in queue |
---|
264 | * |
---|
265 | * @since bbPress (r3381) |
---|
266 | * |
---|
267 | * @see WP_Error() |
---|
268 | * |
---|
269 | * @uses is_wp_error() |
---|
270 | * @usese WP_Error::get_error_codes() |
---|
271 | */ |
---|
272 | function bbp_has_errors() { |
---|
273 | $has_errors = bbpress()->errors->get_error_codes() ? true : false; |
---|
274 | |
---|
275 | return apply_filters( 'bbp_has_errors', $has_errors, bbpress()->errors ); |
---|
276 | } |
---|
277 | |
---|
278 | /** Post Statuses *************************************************************/ |
---|
279 | |
---|
280 | /** |
---|
281 | * Return the public post status ID |
---|
282 | * |
---|
283 | * @since bbPress (r3504) |
---|
284 | * |
---|
285 | * @return string |
---|
286 | */ |
---|
287 | function bbp_get_public_status_id() { |
---|
288 | return bbpress()->public_status_id; |
---|
289 | } |
---|
290 | |
---|
291 | /** |
---|
292 | * Return the pending post status ID |
---|
293 | * |
---|
294 | * @since bbPress (r3581) |
---|
295 | * |
---|
296 | * @return string |
---|
297 | */ |
---|
298 | function bbp_get_pending_status_id() { |
---|
299 | return bbpress()->pending_status_id; |
---|
300 | } |
---|
301 | |
---|
302 | /** |
---|
303 | * Return the private post status ID |
---|
304 | * |
---|
305 | * @since bbPress (r3504) |
---|
306 | * |
---|
307 | * @return string |
---|
308 | */ |
---|
309 | function bbp_get_private_status_id() { |
---|
310 | return bbpress()->private_status_id; |
---|
311 | } |
---|
312 | |
---|
313 | /** |
---|
314 | * Return the hidden post status ID |
---|
315 | * |
---|
316 | * @since bbPress (r3504) |
---|
317 | * |
---|
318 | * @return string |
---|
319 | */ |
---|
320 | function bbp_get_hidden_status_id() { |
---|
321 | return bbpress()->hidden_status_id; |
---|
322 | } |
---|
323 | |
---|
324 | /** |
---|
325 | * Return the closed post status ID |
---|
326 | * |
---|
327 | * @since bbPress (r3504) |
---|
328 | * |
---|
329 | * @return string |
---|
330 | */ |
---|
331 | function bbp_get_closed_status_id() { |
---|
332 | return bbpress()->closed_status_id; |
---|
333 | } |
---|
334 | |
---|
335 | /** |
---|
336 | * Return the spam post status ID |
---|
337 | * |
---|
338 | * @since bbPress (r3504) |
---|
339 | * |
---|
340 | * @return string |
---|
341 | */ |
---|
342 | function bbp_get_spam_status_id() { |
---|
343 | return bbpress()->spam_status_id; |
---|
344 | } |
---|
345 | |
---|
346 | /** |
---|
347 | * Return the trash post status ID |
---|
348 | * |
---|
349 | * @since bbPress (r3504) |
---|
350 | * |
---|
351 | * @return string |
---|
352 | */ |
---|
353 | function bbp_get_trash_status_id() { |
---|
354 | return bbpress()->trash_status_id; |
---|
355 | } |
---|
356 | |
---|
357 | /** |
---|
358 | * Return the orphan post status ID |
---|
359 | * |
---|
360 | * @since bbPress (r3504) |
---|
361 | * |
---|
362 | * @return string |
---|
363 | */ |
---|
364 | function bbp_get_orphan_status_id() { |
---|
365 | return bbpress()->orphan_status_id; |
---|
366 | } |
---|
367 | |
---|
368 | /** |
---|
369 | * Return the bozo post status ID |
---|
370 | * |
---|
371 | * @since bbPress (r4167) |
---|
372 | * |
---|
373 | * @return string |
---|
374 | */ |
---|
375 | function bbp_get_bozo_status_id() { |
---|
376 | return bbpress()->bozo_status_id; |
---|
377 | } |
---|
378 | |
---|
379 | /** Rewrite IDs ***************************************************************/ |
---|
380 | |
---|
381 | /** |
---|
382 | * Return the unique ID for user profile rewrite rules |
---|
383 | * |
---|
384 | * @since bbPress (r3762) |
---|
385 | * @return string |
---|
386 | */ |
---|
387 | function bbp_get_user_rewrite_id() { |
---|
388 | return bbpress()->user_id; |
---|
389 | } |
---|
390 | |
---|
391 | /** |
---|
392 | * Return the enique ID for all edit rewrite rules (forum|topic|reply|tag|user) |
---|
393 | * |
---|
394 | * @since bbPress (r3762) |
---|
395 | * @return string |
---|
396 | */ |
---|
397 | function bbp_get_edit_rewrite_id() { |
---|
398 | return bbpress()->edit_id; |
---|
399 | } |
---|
400 | |
---|
401 | /** |
---|
402 | * Return the unique ID for user caps rewrite rules |
---|
403 | * |
---|
404 | * @since bbPress (r4181) |
---|
405 | * @return string |
---|
406 | */ |
---|
407 | function bbp_get_user_favorites_rewrite_id() { |
---|
408 | return bbpress()->favs_id; |
---|
409 | } |
---|
410 | |
---|
411 | /** |
---|
412 | * Return the unique ID for user caps rewrite rules |
---|
413 | * |
---|
414 | * @since bbPress (r4181) |
---|
415 | * @return string |
---|
416 | */ |
---|
417 | function bbp_get_user_subscriptions_rewrite_id() { |
---|
418 | return bbpress()->subs_id; |
---|
419 | } |
---|
420 | |
---|
421 | /** |
---|
422 | * Return the unique ID for topic view rewrite rules |
---|
423 | * |
---|
424 | * @since bbPress (r3762) |
---|
425 | * @return string |
---|
426 | */ |
---|
427 | function bbp_get_view_rewrite_id() { |
---|
428 | return bbpress()->view_id; |
---|
429 | } |
---|
430 | |
---|
431 | /** |
---|
432 | * Delete a blogs rewrite rules, so that they are automatically rebuilt on |
---|
433 | * the subsequent page load. |
---|
434 | * |
---|
435 | * @since bbPress (r4198) |
---|
436 | */ |
---|
437 | function bbp_delete_rewrite_rules() { |
---|
438 | delete_option( 'rewrite_rules' ); |
---|
439 | } |
---|