db_version < 240 ) { // No changes } /** 2.5 Branch ********************************************************/ // 2.5.x if ( $raw_db_version < 250 ) { // No changes } /** 2.6 Branch ********************************************************/ // Smaller installs run the upgrades directly if ( ! bbp_is_large_install() ) { /** * Upgrade user favorites and subscriptions */ if ( $raw_db_version < 261 ) { bbp_admin_upgrade_user_favorites(); bbp_admin_upgrade_user_topic_subscriptions(); bbp_admin_upgrade_user_forum_subscriptions(); } /** * Upgrade user engagements */ if ( $raw_db_version < 262 ) { bbp_admin_upgrade_user_engagements(); } /** * Repair forum hidden reply count */ if ( $raw_db_version < 263 ) { bbp_admin_repair_forum_hidden_reply_count(); } // Large installs require manual intervention } else { /** * Upgrade user favorites and subscriptions */ if ( $raw_db_version < 261 ) { bbp_add_pending_upgrade( 'bbp-user-favorites-move' ); bbp_add_pending_upgrade( 'bbp-user-topic-subscriptions-move' ); bbp_add_pending_upgrade( 'bbp-user-forum-subscriptions-move' ); // Set strategy to pre-2.6 on large network update_option( '_bbp_engagements_strategy', 'user' ); } /** * Upgrade user engagements */ if ( $raw_db_version < 262 ) { bbp_add_pending_upgrade( 'bbp-user-topic-engagements-move' ); // Set strategy to pre-2.6 on large network update_option( '_bbp_engagements_strategy', 'user' ); } /** * Upgrade user engagements */ if ( $raw_db_version < 263 ) { bbp_add_pending_upgrade( 'bbp-forum-hidden-replies' ); } } } /** All done! *************************************************************/ // Bump the version bbp_version_bump(); // Delete rewrite rules to force a flush bbp_delete_rewrite_rules(); } /** * Redirect user to the "What's New" page on activation * * @since 2.2.0 bbPress (r4389) * * @internal Used internally to redirect bbPress to the about page on activation * * @return If network admin or bulk activation */ function bbp_add_activation_redirect() { // Bail if activating from network, or bulk if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { return; } // Add the redirect trigger update_user_option( get_current_user_id(), '_bbp_activation_redirect', true ); } /** * Redirect user to "What's New" page on activation * * @since 2.2.0 bbPress (r4389) * * @internal Used internally to redirect bbPress to the about page on activation * * @return If no transient, or in network admin, or is bulk activation */ function bbp_do_activation_redirect() { // Bail if no redirect trigger if ( ! get_user_option( '_bbp_activation_redirect' ) ) { return; } // Delete the redirect trigger delete_user_option( get_current_user_id(), '_bbp_activation_redirect' ); // Bail if activating from network, or bulk if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { return; } // Bail if the current user cannot see the about page if ( ! current_user_can( 'bbp_about_page' ) ) { return; } // Redirect to bbPress about page bbp_redirect( add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php' ) ) ); } /** * Hooked to the 'bbp_activate' action, this helper function automatically makes * the current user a Key Master in the forums if they just activated bbPress, * regardless of the bbp_allow_global_access() setting. * * @since 2.4.0 bbPress (r4910) * * @internal Used to internally make the current user a keymaster on activation * * @return If user can't activate plugins or is already a keymaster */ function bbp_make_current_user_keymaster() { // Catch all, to prevent premature user initialization if ( ! did_action( 'set_current_user' ) ) { return; } // Bail if not logged in or already a member of this site if ( ! is_user_logged_in() ) { return; } // Bail if the current user can't activate plugins since previous pageload if ( ! current_user_can( 'activate_plugins' ) ) { return; } // Cannot use bbp_get_current_user_id() during activation process $user_id = get_current_user_id(); // Get the current blog ID, to know if they should be promoted here $blog_id = get_current_blog_id(); // Bail if user is not actually a member of this site if ( ! is_user_member_of_blog( $user_id, $blog_id ) ) { return; } // Bail if the current user already has a forum role to prevent // unexpected role and capability escalation. if ( bbp_get_user_role( $user_id ) ) { return; } // Make the current user a keymaster bbp_set_user_role( $user_id, bbp_get_keymaster_role() ); // Reload the current user so caps apply immediately wp_get_current_user(); } /** Pending Upgrades **********************************************************/ /** * Return the number of pending upgrades * * @since 2.6.0 bbPress (r6895) * * @param string $type Type of pending upgrades (upgrade|repair|empty) * * @return int */ function bbp_get_pending_upgrade_count( $type = '' ) { return count( (array) bbp_get_pending_upgrades( $type ) ); } /** * Return an array of pending upgrades * * @since 2.6.0 bbPress (r6895) * * @param string $type Type of pending upgrades (upgrade|repair|empty) * * @return array */ function bbp_get_pending_upgrades( $type = '' ) { // Get the pending upgrades $retval = (array) get_option( '_bbp_db_pending_upgrades', array() ); // Looking for a specific type? if ( ! empty( $type ) ) { $tools = bbp_get_admin_repair_tools( $type ); $plucked = array_keys( wp_list_pluck( $tools, 'type' ) ); $retval = array_intersect( $retval, $plucked ); } return (array) $retval; } /** * Add an upgrade ID to pending upgrades array * * @since 2.6.0 bbPress (r6895) * * @param string $upgrade_id */ function bbp_add_pending_upgrade( $upgrade_id = '' ) { // Get the pending upgrades option $pending = bbp_get_pending_upgrades(); // Maybe add upgrade ID to end of pending array if ( false === array_search( $upgrade_id, $pending, true ) ) { array_push( $pending, $upgrade_id ); } // Update and return return update_option( '_bbp_db_pending_upgrades', $pending ); } /** * Add an upgrade ID to pending upgrades array * * @since 2.6.0 bbPress (r6895) * * @param string $upgrade_id */ function bbp_remove_pending_upgrade( $upgrade_id = '' ) { // Get the pending upgrades option $pending = bbp_get_pending_upgrades(); // Look for this upgrade ID $index = array_search( $upgrade_id, $pending, true ); // Maybe remove upgrade ID from pending array if ( false !== $index ) { unset( $pending[ $index ] ); } // Update and return return update_option( '_bbp_db_pending_upgrades', $pending ); } /** * Delete all pending upgrades * * @since 2.6.0 bbPress (r6895) */ function bbp_clear_pending_upgrades() { return delete_option( '_bbp_db_pending_upgrades' ); } /** * Maybe append an upgrade count to a string * * @since 2.6.0 bbPress (r6896) * * @param string $string Text to append count to * @param string $type Type of pending upgrades (upgrade|repair|empty) * * @return string */ function bbp_maybe_append_pending_upgrade_count( $string = '', $type = '' ) { // Look for an upgrade count $count = bbp_get_pending_upgrade_count( $type ); // Append the count to the string if ( ! empty( $count ) ) { $suffix = ' ' . bbp_number_format( $count ) . ''; $string = "{$string}{$suffix}"; } // Return the string, maybe with a count return $string; }