BBP_Admin::network_update_screen()
Update all bbPress forums across all sites
Description Description
Source Source
File: includes/admin/classes/class-bbp-admin.php
public static function network_update_screen() {
$bbp_db = bbp_db();
// Get action
$action = isset( $_GET['action'] ) ? $_GET['action'] : ''; ?>
<div class="wrap">
<h1 class="wp-heading-inline"><?php esc_html_e( 'Update Forums', 'bbpress' ); ?></h1>
<hr class="wp-header-end">
<?php
// Taking action
switch ( $action ) {
case 'bbpress-update' :
// Site counter
$n = isset( $_GET['n'] ) ? intval( $_GET['n'] ) : 0;
// Get blogs 5 at a time
$blogs = $bbp_db->get_results( "SELECT * FROM {$bbp_db->blogs} WHERE site_id = '{$bbp_db->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC LIMIT {$n}, 5", ARRAY_A );
// No blogs so all done!
if ( empty( $blogs ) ) : ?>
<p><?php esc_html_e( 'All done!', 'bbpress' ); ?></p>
<a class="button" href="update-core.php?page=bbpress-update"><?php esc_html_e( 'Go Back', 'bbpress' ); ?></a>
<?php
// Still have sites to loop through
else : ?>
<ul>
<?php foreach ( (array) $blogs as $details ) :
// Get site URLs
$site_url = get_site_url( $details['blog_id'] );
$admin_url = get_site_url( $details['blog_id'], 'wp-admin.php', 'admin' );
$remote_url = add_query_arg( array(
'page' => 'bbp-update',
'action' => 'bbp-update'
), $admin_url ); ?>
<li><?php echo esc_html( $site_url ); ?></li>
<?php
// Get the response of the bbPress update on this site
$response = wp_remote_get(
$remote_url,
array(
'timeout' => 30,
'httpversion' => '1.1'
)
);
// Site errored out, no response?
if ( is_wp_error( $response ) ) {
wp_die( sprintf( esc_html__( 'Warning! Problem updating %1$s. Your server may not be able to connect to sites running on it. Error message: %2$s', 'bbpress' ), $site_url, '<em>' . $response->get_error_message() . '</em>' ) );
}
// Switch to the new site
bbp_switch_to_site( $details[ 'blog_id' ] );
$basename = bbpress()->basename;
// Run the updater on this site
if ( is_plugin_active_for_network( $basename ) || is_plugin_active( $basename ) ) {
bbp_version_updater();
}
// Restore original site
bbp_restore_current_site();
// Do some actions to allow plugins to do things too
do_action( 'after_bbpress_upgrade', $response );
do_action( 'bbp_upgrade_site', $details[ 'blog_id' ] );
endforeach; ?>
</ul>
<p>
<?php esc_html_e( 'If your browser doesn’t start loading the next page automatically, click this link:', 'bbpress' ); ?>
<a class="button" href="update-core.php?page=bbpress-update&action=bbpress-update&n=<?php echo ( $n + 5 ); ?>"><?php esc_html_e( 'Next Forums', 'bbpress' ); ?></a>
</p>
<script type='text/javascript'>
<!--
function nextpage() {
location.href = 'update-core.php?page=bbpress-update&action=bbpress-update&n=<?php echo ( $n + 5 ) ?>';
}
setTimeout( 'nextpage()', 250 );
//-->
</script><?php
endif;
break;
case 'show' :
default : ?>
<p><?php esc_html_e( 'You can update all the forums on your network through this page. It works by calling the update script of each site automatically. Hit the link below to update.', 'bbpress' ); ?></p>
<p><a class="button" href="update-core.php?page=bbpress-update&action=bbpress-update"><?php esc_html_e( 'Update Forums', 'bbpress' ); ?></a></p>
<?php break;
} ?>
</div><?php
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |