PluginProbe
bbPress / 2.6.17
bbPress v2.6.17
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
← All changes | includes/core/update.php +448 -96 2.2.12.6.17 View file →
@@ -3,21 +3,19 @@
3 3 /**
4 4 * bbPress Updater
5 5 *
6 6 * @package bbPress
7 - * @subpackage Updater
7 + * @subpackage Core
8 8 */
9 9
10 10 // Exit if accessed directly
11 -if ( !defined( 'ABSPATH' ) ) exit;
11 +defined( 'ABSPATH' ) || exit;
12 12
13 13 /**
14 14 * If there is no raw DB version, this is the first installation
15 15 *
16 - * @since bbPress (r3764)
16 + * @since 2.1.0 bbPress (r3764)
17 17 *
18 - * @uses get_option()
19 - * @uses bbp_get_db_version() To get bbPress's database version
20 18 * @return bool True if update, False if not
21 19 */
22 20 function bbp_is_install() {
23 21 return ! bbp_get_db_version_raw();
@@ -25,12 +23,10 @@
25 23
26 24 /**
27 25 * Compare the bbPress version to the DB version to determine if updating
28 26 *
29 - * @since bbPress (r3421)
27 + * @since 2.0.0 bbPress (r3421)
30 28 *
31 - * @uses get_option()
32 - * @uses bbp_get_db_version() To get bbPress's database version
33 29 * @return bool True if update, False if not
34 30 */
35 31 function bbp_is_update() {
36 32 $raw = (int) bbp_get_db_version_raw();
@@ -44,27 +40,36 @@
44 40 *
45 41 * Note that this function currently is not used in bbPress core and is here
46 42 * for third party plugins to use to check for bbPress activation.
47 43 *
48 - * @since bbPress (r3421)
44 + * @since 2.0.0 bbPress (r3421)
49 45 *
50 46 * @return bool True if activating bbPress, false if not
51 47 */
52 48 function bbp_is_activation( $basename = '' ) {
53 - $bbp = bbpress();
49 + global $pagenow;
54 50
51 + $bbp = bbpress();
55 52 $action = false;
56 - if ( ! empty( $_REQUEST['action'] ) && ( '-1' != $_REQUEST['action'] ) )
53 +
54 + // Bail if not in admin/plugins
55 + if ( ! ( is_admin() && ( 'plugins.php' === $pagenow ) ) ) {
56 + return false;
57 + }
58 +
59 + if ( ! empty( $_REQUEST['action'] ) && ( '-1' !== $_REQUEST['action'] ) ) {
57 60 $action = $_REQUEST['action'];
58 - elseif ( ! empty( $_REQUEST['action2'] ) && ( '-1' != $_REQUEST['action2'] ) )
61 + } elseif ( ! empty( $_REQUEST['action2'] ) && ( '-1' !== $_REQUEST['action2'] ) ) {
59 62 $action = $_REQUEST['action2'];
63 + }
60 64
61 65 // Bail if not activating
62 - if ( empty( $action ) || !in_array( $action, array( 'activate', 'activate-selected' ) ) )
66 + if ( empty( $action ) || ! in_array( $action, array( 'activate', 'activate-selected' ), true ) ) {
63 67 return false;
68 + }
64 69
65 70 // The plugin(s) being activated
66 - if ( $action == 'activate' ) {
71 + if ( 'activate' === $action ) {
67 72 $plugins = isset( $_GET['plugin'] ) ? array( $_GET['plugin'] ) : array();
68 73 } else {
69 74 $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
70 75 }
@@ -69,40 +74,52 @@
69 74 $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
70 75 }
71 76
72 77 // Set basename if empty
73 - if ( empty( $basename ) && !empty( $bbp->basename ) )
78 + if ( empty( $basename ) && ! empty( $bbp->basename ) ) {
74 79 $basename = $bbp->basename;
80 + }
75 81
76 82 // Bail if no basename
77 - if ( empty( $basename ) )
83 + if ( empty( $basename ) ) {
78 84 return false;
85 + }
79 86
80 87 // Is bbPress being activated?
81 - return in_array( $basename, $plugins );
88 + return in_array( $basename, $plugins, true );
82 89 }
83 90
84 91 /**
85 92 * Determine if bbPress is being deactivated
86 93 *
87 - * @since bbPress (r3421)
94 + * @since 2.0.0 bbPress (r3421)
95 + *
88 96 * @return bool True if deactivating bbPress, false if not
89 97 */
90 98 function bbp_is_deactivation( $basename = '' ) {
91 - $bbp = bbpress();
99 + global $pagenow;
92 100
101 + $bbp = bbpress();
93 102 $action = false;
94 - if ( ! empty( $_REQUEST['action'] ) && ( '-1' != $_REQUEST['action'] ) )
103 +
104 + // Bail if not in admin/plugins
105 + if ( ! ( is_admin() && ( 'plugins.php' === $pagenow ) ) ) {
106 + return false;
107 + }
108 +
109 + if ( ! empty( $_REQUEST['action'] ) && ( '-1' !== $_REQUEST['action'] ) ) {
95 110 $action = $_REQUEST['action'];
96 - elseif ( ! empty( $_REQUEST['action2'] ) && ( '-1' != $_REQUEST['action2'] ) )
111 + } elseif ( ! empty( $_REQUEST['action2'] ) && ( '-1' !== $_REQUEST['action2'] ) ) {
97 112 $action = $_REQUEST['action2'];
113 + }
98 114
99 115 // Bail if not deactivating
100 - if ( empty( $action ) || !in_array( $action, array( 'deactivate', 'deactivate-selected' ) ) )
116 + if ( empty( $action ) || ! in_array( $action, array( 'deactivate', 'deactivate-selected' ), true ) ) {
101 117 return false;
118 + }
102 119
103 120 // The plugin(s) being deactivated
104 - if ( $action == 'deactivate' ) {
121 + if ( 'deactivate' === $action ) {
105 122 $plugins = isset( $_GET['plugin'] ) ? array( $_GET['plugin'] ) : array();
106 123 } else {
107 124 $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
108 125 }
@@ -107,45 +124,41 @@
107 124 $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
108 125 }
109 126
110 127 // Set basename if empty
111 - if ( empty( $basename ) && !empty( $bbp->basename ) )
128 + if ( empty( $basename ) && ! empty( $bbp->basename ) ) {
112 129 $basename = $bbp->basename;
130 + }
113 131
114 132 // Bail if no basename
115 - if ( empty( $basename ) )
133 + if ( empty( $basename ) ) {
116 134 return false;
135 + }
117 136
118 137 // Is bbPress being deactivated?
119 - return in_array( $basename, $plugins );
138 + return in_array( $basename, $plugins, true );
120 139 }
121 140
122 141 /**
123 142 * Update the DB to the latest version
124 143 *
125 - * @since bbPress (r3421)
126 - * @uses update_option()
127 - * @uses bbp_get_db_version() To get bbPress's database version
144 + * @since 2.0.0 bbPress (r3421)
128 145 */
129 146 function bbp_version_bump() {
130 - $db_version = bbp_get_db_version();
131 - update_option( '_bbp_db_version', $db_version );
147 + update_option( '_bbp_db_version', bbp_get_db_version() );
132 148 }
133 149
134 150 /**
135 151 * Setup the bbPress updater
136 152 *
137 - * @since bbPress (r3419)
138 - *
139 - * @uses bbp_version_updater()
140 - * @uses bbp_version_bump()
141 - * @uses flush_rewrite_rules()
153 + * @since 2.0.0 bbPress (r3419)
142 154 */
143 155 function bbp_setup_updater() {
144 156
145 157 // Bail if no update needed
146 - if ( ! bbp_is_update() )
158 + if ( ! bbp_is_update() ) {
147 159 return;
160 + }
148 161
149 162 // Call the automated updater
150 163 bbp_version_updater();
151 164 }
@@ -150,52 +163,104 @@
150 163 bbp_version_updater();
151 164 }
152 165
153 166 /**
167 + * Runs when a new site is created in a multisite network, and bbPress is active
168 + * on that site (hooked to `bbp_new_site`)
169 + *
170 + * @since 2.6.0 bbPress (r6779)
171 + */
172 +function bbp_setup_new_site( $site_id = 0 ) {
173 +
174 + // Look for initial content
175 + $created = is_multisite()
176 + ? get_blog_option( $site_id, '_bbp_flag_initial_content', false )
177 + : get_option( '_bbp_flag_initial_content', false );
178 +
179 + // Maybe create the initial content
180 + if ( ! empty( $created ) ) {
181 + bbp_create_initial_content();
182 +
183 + // Flag initial content as created
184 + is_multisite()
185 + ? update_blog_option( $site_id, '_bbp_flag_initial_content', true )
186 + : update_option( '_bbp_flag_initial_content', true );
187 + }
188 +}
189 +
190 +/**
154 191 * Create a default forum, topic, and reply
155 192 *
156 - * @since bbPress (r3767)
193 + * @since 2.1.0 bbPress (r3767)
194 + *
157 195 * @param array $args Array of arguments to override default values
158 196 */
159 197 function bbp_create_initial_content( $args = array() ) {
160 198
161 - $defaults = array(
162 - 'forum_parent' => 0,
163 - 'forum_status' => 'publish',
164 - 'forum_title' => __( 'General', 'bbpress' ),
165 - 'forum_content' => __( 'General chit-chat', 'bbpress' ),
166 - 'topic_title' => __( 'Hello World!', 'bbpress' ),
167 - 'topic_content' => __( 'I am the first topic in your new forums.', 'bbpress' ),
168 - 'reply_title' => __( 'Re: Hello World!', 'bbpress' ),
169 - 'reply_content' => __( 'Oh, and this is what a reply looks like.', 'bbpress' ),
199 + // Cannot use bbp_get_current_user_id() during activation process
200 + $user_id = get_current_user_id();
201 +
202 + // Parse arguments against default values
203 + $r = bbp_parse_args(
204 + $args,
205 + array(
206 + 'forum_author' => $user_id,
207 + 'forum_parent' => 0,
208 + 'forum_status' => 'publish',
209 + 'forum_title' => esc_html__( 'General', 'bbpress' ),
210 + 'forum_content' => esc_html__( 'General Discussion', 'bbpress' ),
211 +
212 + 'topic_author' => $user_id,
213 + 'topic_title' => esc_html__( 'Hello World!', 'bbpress' ),
214 + 'topic_content' => esc_html__( 'This is the very first topic in these forums.', 'bbpress' ),
215 +
216 + 'reply_author' => $user_id,
217 + 'reply_content' => esc_html__( 'And this is the very first reply.', 'bbpress' ),
218 + ),
219 + 'create_initial_content'
170 220 );
171 - $r = bbp_parse_args( $args, $defaults, 'create_initial_content' );
172 - extract( $r );
173 221
222 + // Use the same time for each post
223 + // phpcs:disable WordPress.DateTime.RestrictedFunctions.date_date
224 + $current_time = time();
225 + $forum_time = date( 'Y-m-d H:i:s', $current_time - 60 * 60 * 80 );
226 + $topic_time = date( 'Y-m-d H:i:s', $current_time - 60 * 60 * 60 );
227 + $reply_time = date( 'Y-m-d H:i:s', $current_time - 60 * 60 * 40 );
228 + // phpcs:enable
229 +
174 230 // Create the initial forum
175 - $forum_id = bbp_insert_forum( array(
176 - 'post_parent' => $forum_parent,
177 - 'post_status' => $forum_status,
178 - 'post_title' => $forum_title,
179 - 'post_content' => $forum_content
180 - ) );
231 + $forum_id = bbp_insert_forum(
232 + array(
233 + 'post_author' => $r['forum_author'],
234 + 'post_parent' => $r['forum_parent'],
235 + 'post_status' => $r['forum_status'],
236 + 'post_title' => $r['forum_title'],
237 + 'post_content' => $r['forum_content'],
238 + 'post_date' => $forum_time
239 + )
240 + );
181 241
182 242 // Create the initial topic
183 243 $topic_id = bbp_insert_topic(
184 244 array(
245 + 'post_author' => $r['topic_author'],
185 246 'post_parent' => $forum_id,
186 - 'post_title' => $topic_title,
187 - 'post_content' => $topic_content
247 + 'post_title' => $r['topic_title'],
248 + 'post_content' => $r['topic_content'],
249 + 'post_date' => $topic_time,
188 250 ),
189 - array( 'forum_id' => $forum_id )
251 + array(
252 + 'forum_id' => $forum_id
253 + )
190 254 );
191 255
192 256 // Create the initial reply
193 257 $reply_id = bbp_insert_reply(
194 258 array(
259 + 'post_author' => $r['reply_author'],
195 260 'post_parent' => $topic_id,
196 - 'post_title' => $reply_title,
197 - 'post_content' => $reply_content
261 + 'post_content' => $r['reply_content'],
262 + 'post_date' => $reply_time
198 263 ),
199 264 array(
200 265 'forum_id' => $forum_id,
201 266 'topic_id' => $topic_id
@@ -209,15 +274,15 @@
209 274 );
210 275 }
211 276
212 277 /**
213 - * bbPress's version updater looks at what the current database version is, and
278 + * The version updater looks at what the current database version is, and
214 279 * runs whatever other code is needed.
215 280 *
216 281 * This is most-often used when the data schema changes, but should also be used
217 282 * to correct issues with bbPress meta-data silently on software update.
218 283 *
219 - * @since bbPress (r4104)
284 + * @since 2.2.0 bbPress (r4104)
220 285 */
221 286 function bbp_version_updater() {
222 287
223 288 // Get the raw database version
@@ -222,42 +287,128 @@
222 287
223 288 // Get the raw database version
224 289 $raw_db_version = (int) bbp_get_db_version_raw();
225 290
226 - /** 2.0 Branch ************************************************************/
291 + // Only run updater if previous installation exists
292 + if ( ! empty( $raw_db_version ) ) {
227 293
228 - // 2.0, 2.0.1, 2.0.2, 2.0.3
229 - if ( $raw_db_version < 200 ) {
230 - // Do nothing
231 - }
294 + /** 2.0 Branch ********************************************************/
232 295
233 - /** 2.1 Branch ************************************************************/
296 + // 2.0, 2.0.1, 2.0.2, 2.0.3
297 + // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
298 + if ( $raw_db_version < 200 ) {
299 + // No changes
300 + }
234 301
235 - // 2.1, 2.1.1
236 - if ( $raw_db_version < 211 ) {
302 + /** 2.1 Branch ********************************************************/
237 303
238 - /**
239 - * Repair private and hidden forum data
240 - *
241 - * @link http://bbpress.trac.wordpress.org/ticket/1891
242 - */
243 - bbp_admin_repair_forum_visibility();
244 - }
304 + // 2.1, 2.1.1
305 + if ( $raw_db_version < 211 ) {
245 306
246 - /** 2.2 Branch ************************************************************/
307 + /**
308 + * Repair private and hidden forum data
309 + *
310 + * @link https://bbpress.trac.wordpress.org/ticket/1891
311 + */
312 + bbp_admin_repair_forum_visibility();
313 + }
247 314
248 - // 2.2
249 - if ( $raw_db_version < 220 ) {
315 + /** 2.2 Branch ********************************************************/
250 316
251 - // Remove bbPress 1.1 roles (BuddyPress)
252 - remove_role( 'member' );
253 - remove_role( 'inactive' );
254 - remove_role( 'blocked' );
255 - remove_role( 'moderator' );
256 - remove_role( 'keymaster' );
317 + // 2.2.x
318 + if ( $raw_db_version < 220 ) {
257 319
258 - // Refresh capabilities
259 - bbp_remove_caps();
320 + // Remove any old bbPress roles
321 + bbp_remove_roles();
322 +
323 + // Remove capabilities
324 + bbp_remove_caps();
325 + }
326 +
327 + /** 2.3 Branch ********************************************************/
328 +
329 + // 2.3.x
330 + // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
331 + if ( $raw_db_version < 230 ) {
332 + // No changes
333 + }
334 +
335 + /** 2.4 Branch ********************************************************/
336 +
337 + // 2.4.x
338 + // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
339 + if ( $raw_db_version < 240 ) {
340 + // No changes
341 + }
342 +
343 + /** 2.5 Branch ********************************************************/
344 +
345 + // 2.5.x
346 + // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
347 + if ( $raw_db_version < 250 ) {
348 + // No changes
349 + }
350 +
351 + /** 2.6 Branch ********************************************************/
352 +
353 + // Smaller installs run the upgrades directly
354 + if ( ! bbp_is_large_install() ) {
355 +
356 + /**
357 + * Upgrade user favorites and subscriptions
358 + */
359 + if ( $raw_db_version < 261 ) {
360 + bbp_admin_upgrade_user_favorites();
361 + bbp_admin_upgrade_user_topic_subscriptions();
362 + bbp_admin_upgrade_user_forum_subscriptions();
363 + }
364 +
365 + /**
366 + * Upgrade user engagements
367 + */
368 + if ( $raw_db_version < 262 ) {
369 + bbp_admin_upgrade_user_engagements();
370 + }
371 +
372 + /**
373 + * Repair forum hidden reply count
374 + */
375 + if ( $raw_db_version < 263 ) {
376 + bbp_admin_repair_forum_hidden_reply_count();
377 + }
378 +
379 + // Large installs require manual intervention
380 + } else {
381 +
382 + /**
383 + * Upgrade user favorites and subscriptions
384 + */
385 + if ( $raw_db_version < 261 ) {
386 + bbp_add_pending_upgrade( 'bbp-user-favorites-move' );
387 + bbp_add_pending_upgrade( 'bbp-user-topic-subscriptions-move' );
388 + bbp_add_pending_upgrade( 'bbp-user-forum-subscriptions-move' );
389 +
390 + // Set strategy to pre-2.6 on large network
391 + update_option( '_bbp_engagements_strategy', 'user' );
392 + }
393 +
394 + /**
395 + * Upgrade user engagements
396 + */
397 + if ( $raw_db_version < 262 ) {
398 + bbp_add_pending_upgrade( 'bbp-user-topic-engagements-move' );
399 +
400 + // Set strategy to pre-2.6 on large network
401 + update_option( '_bbp_engagements_strategy', 'user' );
402 + }
403 +
404 + /**
405 + * Upgrade user engagements
406 + */
407 + if ( $raw_db_version < 263 ) {
408 + bbp_add_pending_upgrade( 'bbp-forum-hidden-replies' );
409 + }
410 + }
260 411 }
261 412
262 413 /** All done! *************************************************************/
263 414
@@ -268,24 +419,225 @@
268 419 bbp_delete_rewrite_rules();
269 420 }
270 421
271 422 /**
272 - * Redirect user to bbPress's What's New page on activation
423 + * Redirect user to the "What's New" page on activation
273 424 *
274 - * @since bbPress (r4389)
425 + * @since 2.2.0 bbPress (r4389)
275 426 *
276 427 * @internal Used internally to redirect bbPress to the about page on activation
277 428 *
278 - * @uses is_network_admin() To bail if being network activated
279 - * @uses set_transient() To drop the activation transient for 30 seconds
280 - *
281 429 * @return If network admin or bulk activation
282 430 */
283 431 function bbp_add_activation_redirect() {
284 432
285 433 // Bail if activating from network, or bulk
286 - if ( is_network_admin() || isset( $_GET['activate-multi'] ) )
434 + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
287 435 return;
436 + }
288 437
289 - // Add the transient to redirect
290 - set_transient( '_bbp_activation_redirect', true, 30 );
438 + // Add the redirect trigger
439 + update_user_option( get_current_user_id(), '_bbp_activation_redirect', true );
440 +}
441 +
442 +/**
443 + * Redirect user to "What's New" page on activation
444 + *
445 + * @since 2.2.0 bbPress (r4389)
446 + *
447 + * @internal Used internally to redirect bbPress to the about page on activation
448 + *
449 + * @return If no transient, or in network admin, or is bulk activation
450 + */
451 +function bbp_do_activation_redirect() {
452 +
453 + // Bail if no redirect trigger
454 + if ( ! get_user_option( '_bbp_activation_redirect' ) ) {
455 + return;
456 + }
457 +
458 + // Delete the redirect trigger
459 + delete_user_option( get_current_user_id(), '_bbp_activation_redirect' );
460 +
461 + // Bail if activating from network, or bulk
462 + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
463 + return;
464 + }
465 +
466 + // Bail if the current user cannot see the about page
467 + if ( ! current_user_can( 'bbp_about_page' ) ) {
468 + return;
469 + }
470 +
471 + // Redirect to bbPress about page
472 + bbp_redirect( add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php' ) ) );
473 +}
474 +
475 +/**
476 + * Hooked to the 'bbp_activate' action, this helper function automatically makes
477 + * the current user a Key Master in the forums if they just activated bbPress,
478 + * regardless of the bbp_allow_global_access() setting.
479 + *
480 + * @since 2.4.0 bbPress (r4910)
481 + *
482 + * @internal Used to internally make the current user a keymaster on activation
483 + *
484 + * @return If user can't activate plugins or is already a keymaster
485 + */
486 +function bbp_make_current_user_keymaster() {
487 +
488 + // Catch all, to prevent premature user initialization
489 + if ( ! did_action( 'set_current_user' ) ) {
490 + return;
491 + }
492 +
493 + // Bail if not logged in or already a member of this site
494 + if ( ! is_user_logged_in() ) {
495 + return;
496 + }
497 +
498 + // Bail if the current user can't activate plugins since previous pageload
499 + if ( ! current_user_can( 'activate_plugins' ) ) {
500 + return;
501 + }
502 +
503 + // Cannot use bbp_get_current_user_id() during activation process
504 + $user_id = get_current_user_id();
505 +
506 + // Get the current blog ID, to know if they should be promoted here
507 + $blog_id = get_current_blog_id();
508 +
509 + // Bail if user is not actually a member of this site
510 + if ( ! is_user_member_of_blog( $user_id, $blog_id ) ) {
511 + return;
512 + }
513 +
514 + // Bail if the current user already has a forum role to prevent
515 + // unexpected role and capability escalation.
516 + if ( bbp_get_user_role( $user_id ) ) {
517 + return;
518 + }
519 +
520 + // Make the current user a keymaster
521 + bbp_set_user_role( $user_id, bbp_get_keymaster_role() );
522 +
523 + // Reload the current user so caps apply immediately
524 + wp_get_current_user();
525 +}
526 +
527 +/** Pending Upgrades **********************************************************/
528 +
529 +/**
530 + * Return the number of pending upgrades
531 + *
532 + * @since 2.6.0 bbPress (r6895)
533 + *
534 + * @param string $type Type of pending upgrades (upgrade|repair|empty)
535 + *
536 + * @return int
537 + */
538 +function bbp_get_pending_upgrade_count( $type = '' ) {
539 + return count( (array) bbp_get_pending_upgrades( $type ) );
540 +}
541 +
542 +/**
543 + * Return an array of pending upgrades
544 + *
545 + * @since 2.6.0 bbPress (r6895)
546 + *
547 + * @param string $type Type of pending upgrades (upgrade|repair|empty)
548 + *
549 + * @return array
550 + */
551 +function bbp_get_pending_upgrades( $type = '' ) {
552 +
553 + // Get the pending upgrades
554 + $retval = (array) get_option( '_bbp_db_pending_upgrades', array() );
555 +
556 + // Looking for a specific type?
557 + if ( ! empty( $type ) ) {
558 + $tools = bbp_get_admin_repair_tools( $type );
559 + $plucked = array_keys( wp_list_pluck( $tools, 'type' ) );
560 + $retval = array_intersect( $retval, $plucked );
561 + }
562 +
563 + return (array) $retval;
564 +}
565 +
566 +/**
567 + * Add an upgrade ID to pending upgrades array
568 + *
569 + * @since 2.6.0 bbPress (r6895)
570 + *
571 + * @param string $upgrade_id
572 + */
573 +function bbp_add_pending_upgrade( $upgrade_id = '' ) {
574 +
575 + // Get the pending upgrades option
576 + $pending = bbp_get_pending_upgrades();
577 +
578 + // Maybe add upgrade ID to end of pending array
579 + if ( false === array_search( $upgrade_id, $pending, true ) ) {
580 + array_push( $pending, $upgrade_id );
581 + }
582 +
583 + // Update and return
584 + return update_option( '_bbp_db_pending_upgrades', $pending );
585 +}
586 +
587 +/**
588 + * Add an upgrade ID to pending upgrades array
589 + *
590 + * @since 2.6.0 bbPress (r6895)
591 + *
592 + * @param string $upgrade_id
593 + */
594 +function bbp_remove_pending_upgrade( $upgrade_id = '' ) {
595 +
596 + // Get the pending upgrades option
597 + $pending = bbp_get_pending_upgrades();
598 +
599 + // Look for this upgrade ID
600 + $index = array_search( $upgrade_id, $pending, true );
601 +
602 + // Maybe remove upgrade ID from pending array
603 + if ( false !== $index ) {
604 + unset( $pending[ $index ] );
605 + }
606 +
607 + // Update and return
608 + return update_option( '_bbp_db_pending_upgrades', $pending );
609 +}
610 +
611 +/**
612 + * Delete all pending upgrades
613 + *
614 + * @since 2.6.0 bbPress (r6895)
615 + */
616 +function bbp_clear_pending_upgrades() {
617 + return delete_option( '_bbp_db_pending_upgrades' );
618 +}
619 +
620 +/**
621 + * Maybe append an upgrade count to a string
622 + *
623 + * @since 2.6.0 bbPress (r6896)
624 + *
625 + * @param string $string Text to append count to
626 + * @param string $type Type of pending upgrades (upgrade|repair|empty)
627 + *
628 + * @return string
629 + */
630 +function bbp_maybe_append_pending_upgrade_count( $string = '', $type = '' ) {
631 +
632 + // Look for an upgrade count
633 + $count = bbp_get_pending_upgrade_count( $type );
634 +
635 + // Append the count to the string
636 + if ( ! empty( $count ) ) {
637 + $suffix = ' <span class="awaiting-mod count-' . absint( $count ) . '"><span class="pending-count">' . bbp_number_format( $count ) . '</span></span>';
638 + $string = "{$string}{$suffix}";
639 + }
640 +
641 + // Return the string, maybe with a count
642 + return $string;
291 643 }