Skip to:
Content

bbPress.org

Ticket #1725: 1725.patch

File 1725.patch, 6.5 KB (added by johnjamesjacoby, 14 years ago)

First pass

  • bbp-admin/bbp-admin.php

     
    119119
    120120                // Add sample permalink filter
    121121                add_filter( 'post_type_link',     'bbp_filter_sample_permalink',        10, 4 );
     122
     123                /** Network Admin *****************************************************/
     124
     125                // Add menu item to settings menu
     126                add_action( 'network_admin_menu',  array( $this, 'network_admin_menus' ) );
    122127        }
    123128
    124129        /**
     
    162167        }
    163168
    164169        /**
    165          * Add the navigational menu elements
     170         * Add the admin menus
    166171         *
    167172         * @since bbPress (r2646)
    168173         *
     
    177182                        add_management_page( __( 'Recount', 'bbpress' ), __( 'Recount', 'bbpress' ), 'manage_options', 'bbp-recount', 'bbp_admin_tools' );
    178183
    179184                // Forums settings
    180                 add_options_page   ( __( 'Forums',  'bbpress' ), __( 'Forums',  'bbpress' ), 'manage_options', 'bbpress', 'bbp_admin_settings' );
     185                add_options_page( __( 'Forums',  'bbpress' ), __( 'Forums',  'bbpress' ), 'manage_options', 'bbpress', 'bbp_admin_settings' );
     186
     187                // Update single forum
     188                $cap = is_multisite() ? 'manage_network' : 'manage_options';
     189                add_dashboard_page( __( 'Update Forum', 'bbpress' ), __( 'Update Forum', 'bbpress' ), $cap, 'bbpress', array( $this, 'update_screen' ) );
    181190        }
    182191
    183192        /**
     193         * Add the network admin menus
     194         *
     195         * @since bbPress (r3689)
     196         * @uses add_submenu_page() To add the Update Forums page in Updates
     197         */
     198        public function network_admin_menus() {
     199                add_submenu_page( 'upgrade.php', __( 'Update Forums', 'bbpress' ), __( 'Update Forums', 'bbpress' ), 'manage_network', 'bbpress', array( $this, 'network_update_screen' ) );
     200        }
     201
     202        /**
    184203         * Register the settings
    185204         *
    186205         * @since bbPress (r2737)
     
    694713                // Load the admin CSS styling
    695714                wp_admin_css_color( 'bbpress', __( 'Green', 'bbpress' ), $css_file, array( '#222222', '#006600', '#deece1', '#6eb469' ) );
    696715        }
     716
     717        /**
     718         * Update all bbPress forums across all sites
     719         *
     720         * @since bbPress (r3689)
     721         *
     722         * @global WPDB $wpdb
     723         * @uses get_blog_option()
     724         * @uses wp_remote_get()
     725         */
     726        function update_screen() {
     727
     728                // Get action
     729                $action = isset( $_GET['action'] ) ? $_GET['action'] : ''; ?>
     730
     731                <div class="wrap">
     732                        <div id="icon-edit" class="icon32 icon32-posts-topic"><br /></div>
     733                        <h2><?php _e( 'Update Forum', 'bbpress' ); ?></h2>
     734
     735                <?php
     736
     737                // Taking action
     738                switch ( $action ) {
     739                        case 'bbpress-update' :
     740
     741                                // @todo more update stuff here, evaluate performance
     742
     743                                // Remove roles and caps
     744                                bbp_remove_roles();
     745                                bbp_remove_caps();
     746
     747                                // Make sure roles, capabilities, and options exist
     748                                bbp_add_roles();
     749                                bbp_add_caps();
     750                                bbp_add_options();
     751
     752                                // Ensure any new permalinks are created
     753                                flush_rewrite_rules();
     754
     755                                // Ensure proper version in the DB
     756                                bbp_version_bump();
     757
     758                                ?>
     759                       
     760                                <p><?php _e( 'All done!', 'bbpress' ); ?></p>
     761                                <a class="button" href="index.php?page=bbpress"><?php _e( 'Go Back', 'bbpress' ); ?></a>
     762
     763                                <?php
     764
     765                                break;
     766
     767                        case 'show' :
     768                        default : ?>
     769
     770                                <p><?php _e( 'You can update your forum through this page. Hit the link below to update.', 'bbpress' ); ?></p>
     771                                <p><a class="button" href="index.php?page=bbpress&amp;action=bbpress-update"><?php _e( 'Update Forum', 'bbpress' ); ?></a></p>
     772
     773                        <?php break;
     774
     775                } ?>
     776
     777                </div><?php
     778        }
     779
     780        /**
     781         * Update all bbPress forums across all sites
     782         *
     783         * @since bbPress (r3689)
     784         *
     785         * @global WPDB $wpdb
     786         * @uses get_blog_option()
     787         * @uses wp_remote_get()
     788         */
     789        function network_update_screen() {
     790                global $wpdb;
     791
     792                // Get action
     793                $action = isset( $_GET['action'] ) ? $_GET['action'] : ''; ?>
     794
     795                <div class="wrap">
     796                        <div id="icon-edit" class="icon32 icon32-posts-topic"><br /></div>
     797                        <h2><?php _e( 'Update Forums', 'bbpress' ); ?></h2>
     798
     799                <?php
     800
     801                // Taking action
     802                switch ( $action ) {
     803                        case 'bbpress-update' :
     804
     805                                // Site counter
     806                                $n = isset( $_GET['n'] ) ? intval( $_GET['n'] ) : 0;
     807
     808                                // Get blogs 5 at a time
     809                                $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 );
     810
     811                                // No blogs so all done!
     812                                if ( empty( $blogs ) ) : ?>
     813
     814                                        <p><?php _e( 'All done!', 'bbpress' ); ?></p>
     815                                        <a class="button" href="update-core.php?page=bbpress"><?php _e( 'Go Back', 'bbpress' ); ?></a>
     816
     817                                        <?php break; ?>
     818
     819                                <?php
     820
     821                                // Still have sites to loop through
     822                                else : ?>
     823
     824                                        <ul>
     825
     826                                                <?php foreach ( (array) $blogs as $details ) :
     827
     828                                                        $siteurl = get_blog_option( $details['blog_id'], 'siteurl' ); ?>
     829
     830                                                        <li><?php echo $siteurl; ?></li>
     831
     832                                                        <?php
     833
     834                                                        // Get the response of the bbPress update on this site
     835                                                        $response = wp_remote_get(
     836                                                                trailingslashit( $siteurl ) . 'wp-admin/index.php?page=bbpress&step=bbpress-update',
     837                                                                array( 'timeout' => 120, 'httpversion' => '1.1' )
     838                                                        );
     839
     840                                                        // Site errored out, no response?
     841                                                        if ( is_wp_error( $response ) )
     842                                                                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>', 'bbpress' ), $siteurl, $response->get_error_message() ) );
     843
     844                                                        // Do some actions to allow plugins to do things too
     845                                                        do_action( 'after_bbpress_upgrade', $response             );
     846                                                        do_action( 'bbp_upgrade_site',      $details[ 'blog_id' ] );
     847
     848                                                endforeach; ?>
     849
     850                                        </ul>
     851
     852                                        <p>
     853                                                <?php _e( 'If your browser doesn&#8217;t start loading the next page automatically, click this link:', 'bbpress' ); ?>
     854                                                <a class="button" href="update-core.php?page=bbpress&amp;action=bbpress-update&amp;n=<?php echo ( $n + 5 ); ?>"><?php _e( 'Next Forums', 'bbpress' ); ?></a>
     855                                        </p>
     856                                        <script type='text/javascript'>
     857                                                <!--
     858                                                function nextpage() {
     859                                                        location.href = 'update-core.php?page=bbpress&action=bbpress-update&n=<?php echo ( $n + 5 ) ?>';
     860                                                }
     861                                                setTimeout( 'nextpage()', 250 );
     862                                                //-->
     863                                        </script><?php
     864
     865                                endif;
     866
     867                                break;
     868
     869                        case 'show' :
     870                        default : ?>
     871
     872                                <p><?php _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>
     873                                <p><a class="button" href="update-core.php?page=bbpress&amp;action=bbpress-update"><?php _e( 'Update Forums', 'bbpress' ); ?></a></p>
     874
     875                        <?php break;
     876
     877                } ?>
     878
     879                </div><?php
     880        }
    697881}
    698882endif; // class_exists check