PluginProbe
bbPress / 2.1
bbPress v2.1
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 2.2.2 All 71 releases
bbpress / bbp-includes / bbp-core-functions.php

bbp-core-functions.php in bbPress 2.1, at bbp-includes/bbp-core-functions.php

408 lines 8.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
274 // Assume no errors
275 $has_errors = false;
276
277 // Check for errors
278 if ( bbpress()->errors->get_error_codes() )
279 $has_errors = true;
280
281 // Filter return value
282 $has_errors = apply_filters( 'bbp_has_errors', $has_errors, bbpress()->errors );
283
284 return $has_errors;
285 }
286
287 /** Post Statuses *************************************************************/
288
289 /**
290 * Return the public post status ID
291 *
292 * @since bbPress (r3504)
293 *
294 * @return string
295 */
296 function bbp_get_public_status_id() {
297 return bbpress()->public_status_id;
298 }
299
300 /**
301 * Return the pending post status ID
302 *
303 * @since bbPress (r3581)
304 *
305 * @return string
306 */
307 function bbp_get_pending_status_id() {
308 return bbpress()->pending_status_id;
309 }
310
311 /**
312 * Return the private post status ID
313 *
314 * @since bbPress (r3504)
315 *
316 * @return string
317 */
318 function bbp_get_private_status_id() {
319 return bbpress()->private_status_id;
320 }
321
322 /**
323 * Return the hidden post status ID
324 *
325 * @since bbPress (r3504)
326 *
327 * @return string
328 */
329 function bbp_get_hidden_status_id() {
330 return bbpress()->hidden_status_id;
331 }
332
333 /**
334 * Return the closed post status ID
335 *
336 * @since bbPress (r3504)
337 *
338 * @return string
339 */
340 function bbp_get_closed_status_id() {
341 return bbpress()->closed_status_id;
342 }
343
344 /**
345 * Return the spam post status ID
346 *
347 * @since bbPress (r3504)
348 *
349 * @return string
350 */
351 function bbp_get_spam_status_id() {
352 return bbpress()->spam_status_id;
353 }
354
355 /**
356 * Return the trash post status ID
357 *
358 * @since bbPress (r3504)
359 *
360 * @return string
361 */
362 function bbp_get_trash_status_id() {
363 return bbpress()->trash_status_id;
364 }
365
366 /**
367 * Return the orphan post status ID
368 *
369 * @since bbPress (r3504)
370 *
371 * @return string
372 */
373 function bbp_get_orphan_status_id() {
374 return bbpress()->orphan_status_id;
375 }
376
377 /** Rewrite IDs ***************************************************************/
378
379 /**
380 * Return the unique ID for user profile rewrite rules
381 *
382 * @since bbPress (r3762)
383 * @return string
384 */
385 function bbp_get_user_rewrite_id() {
386 return bbpress()->user_id;
387 }
388
389 /**
390 * Return the enique ID for all edit rewrite rules (forum|topic|reply|tag|user)
391 *
392 * @since bbPress (r3762)
393 * @return string
394 */
395 function bbp_get_edit_rewrite_id() {
396 return bbpress()->edit_id;
397 }
398
399 /**
400 * Return the unique ID for topic view rewrite rules
401 *
402 * @since bbPress (r3762)
403 * @return string
404 */
405 function bbp_get_view_rewrite_id() {
406 return bbpress()->view_id;
407 }
408