BBP_Admin::network_update_screen()

Update all forums across all sites

Description

Source

File: bp-forums/admin/admin.php

799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
public static function network_update_screen() {
    global $wpdb;
 
    // Get action
    $action = isset( $_GET['action'] ) ? $_GET['action'] : ''; ?>
 
    <div class="wrap">
        <div id="icon-edit" class="icon32 icon32-posts-topic"><br /></div>
        <h2><?php esc_html_e( 'Update Forums', 'buddyboss' ); ?></h2>
 
    <?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 = $wpdb->get_results( "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->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!', 'buddyboss' ); ?></p>
                <a class="button" href="update-core.php?page=bbpress-update"><?php esc_html_e( 'Go Back', 'buddyboss' ); ?></a>
 
            <?php
 
            // Still have sites to loop through
            else : ?>
 
                <ul>
 
                    <?php foreach ( (array) $blogs as $details ) :
 
                        $siteurl = get_blog_option( $details['blog_id'], 'siteurl' ); ?>
 
                        <li><?php echo $siteurl; ?></li>
 
                        <?php
 
                        // Get the response of the Forums update on this site
                        $response = wp_remote_get(
                            trailingslashit( $siteurl ) . 'wp-admin/index.php?page=bbp-update&action=bbp-update',
                            array( 'timeout' => 30, 'httpversion' => '1.1' )
                        );
 
                        // Site errored out, no response?
                        if ( is_wp_error( $response ) )
                            wp_die( sprintf( __( 'Warning! Problem updating %1$s. Your server may not be able to connect to sites running on it. Error message: <em>%2$s</em>', 'buddyboss' ), $siteurl, $response->get_error_message() ) );
 
                        // Switch to the new blog
                        switch_to_blog( $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 blog
                        restore_current_blog();
 
                        // 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:', 'buddyboss' ); ?>
                    <a class="button" href="update-core.php?page=bbpress-update&amp;action=bbpress-update&amp;n=<?php echo ( $n + 5 ); ?>"><?php esc_html_e( 'Next Forums', 'buddyboss' ); ?></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.', 'buddyboss' ); ?></p>
            <p><a class="button" href="update-core.php?page=bbpress-update&amp;action=bbpress-update"><?php esc_html_e( 'Update Forums', 'buddyboss' ); ?></a></p>
 
        <?php break;
 
    } ?>
 
    </div><?php
}

Changelog

Changelog
Version Description
bbPress (r3689) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.