PluginProbe
bbPress / 2.1.1
bbPress v2.1.1
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 2.2.2 All 71 releases
bbpress / bbp-admin / bbp-admin.php

bbp-admin.php in bbPress 2.1.1, at bbp-admin/bbp-admin.php

831 lines 23.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Main bbPress Admin Class
5 *
6 * @package bbPress
7 * @subpackage Administration
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 if ( !class_exists( 'BBP_Admin' ) ) :
14 /**
15 * Loads bbPress plugin admin area
16 *
17 * @package bbPress
18 * @subpackage Administration
19 * @since bbPress (r2464)
20 */
21 class BBP_Admin {
22
23 /** Directory *************************************************************/
24
25 /**
26 * @var string Path to the bbPress admin directory
27 */
28 public $admin_dir = '';
29
30 /** URLs ******************************************************************/
31
32 /**
33 * @var string URL to the bbPress admin directory
34 */
35 public $admin_url = '';
36
37 /**
38 * @var string URL to the bbPress images directory
39 */
40 public $images_url = '';
41
42 /**
43 * @var string URL to the bbPress admin styles directory
44 */
45 public $styles_url = '';
46
47 /** Capability ************************************************************/
48
49 /**
50 * @var bool Minimum capability to access Tools and Settings
51 */
52 public $minimum_capability = 'manage_options';
53
54 /** Admin Scheme **********************************************************/
55
56 /**
57 * @var int Depth of custom WP_CONTENT_DIR difference
58 */
59 public $content_depth = 0;
60
61 /** Functions *************************************************************/
62
63 /**
64 * The main bbPress admin loader
65 *
66 * @since bbPress (r2515)
67 *
68 * @uses BBP_Admin::setup_globals() Setup the globals needed
69 * @uses BBP_Admin::includes() Include the required files
70 * @uses BBP_Admin::setup_actions() Setup the hooks and actions
71 */
72 public function __construct() {
73 $this->setup_globals();
74 $this->includes();
75 $this->setup_actions();
76 }
77
78 /**
79 * Admin globals
80 *
81 * @since bbPress (r2646)
82 * @access private
83 */
84 private function setup_globals() {
85 $bbp = bbpress();
86 $this->admin_dir = trailingslashit( $bbp->plugin_dir . 'bbp-admin' ); // Admin path
87 $this->admin_url = trailingslashit( $bbp->plugin_url . 'bbp-admin' ); // Admin url
88 $this->images_url = trailingslashit( $this->admin_url . 'images' ); // Admin images URL
89 $this->styles_url = trailingslashit( $this->admin_url . 'styles' ); // Admin styles URL
90 }
91
92 /**
93 * Include required files
94 *
95 * @since bbPress (r2646)
96 * @access private
97 */
98 private function includes() {
99 require( $this->admin_dir . 'bbp-tools.php' );
100 require( $this->admin_dir . 'bbp-converter.php' );
101 require( $this->admin_dir . 'bbp-settings.php' );
102 require( $this->admin_dir . 'bbp-functions.php' );
103 require( $this->admin_dir . 'bbp-metaboxes.php' );
104 require( $this->admin_dir . 'bbp-forums.php' );
105 require( $this->admin_dir . 'bbp-topics.php' );
106 require( $this->admin_dir . 'bbp-replies.php' );
107 }
108
109 /**
110 * Setup the admin hooks, actions and filters
111 *
112 * @since bbPress (r2646)
113 * @access private
114 *
115 * @uses add_action() To add various actions
116 * @uses add_filter() To add various filters
117 */
118 private function setup_actions() {
119
120 /** General Actions ***************************************************/
121
122 add_action( 'bbp_admin_menu', array( $this, 'admin_menus' ) ); // Add menu item to settings menu
123 add_action( 'bbp_admin_head', array( $this, 'admin_head' ) ); // Add some general styling to the admin area
124 add_action( 'bbp_admin_notices', array( $this, 'activation_notice' ) ); // Add notice if not using a bbPress theme
125 add_action( 'bbp_register_admin_style', array( $this, 'register_admin_style' ) ); // Add green admin style
126 add_action( 'bbp_register_admin_settings', array( $this, 'register_admin_settings' ) ); // Add settings
127 add_action( 'bbp_activation', array( $this, 'new_install' ) ); // Add menu item to settings menu
128 add_action( 'wp_dashboard_setup', array( $this, 'dashboard_widget_right_now' ) ); // Forums 'Right now' Dashboard widget
129
130 /** Filters ***********************************************************/
131
132 // Add link to settings page
133 add_filter( 'plugin_action_links', array( $this, 'add_settings_link' ), 10, 2 );
134
135 /** Network Admin *****************************************************/
136
137 // Add menu item to settings menu
138 add_action( 'network_admin_menu', array( $this, 'network_admin_menus' ) );
139
140 /** Dependencies ******************************************************/
141
142 // Allow plugins to modify these actions
143 do_action_ref_array( 'bbp_admin_loaded', array( &$this ) );
144 }
145
146 /**
147 * Add the admin menus
148 *
149 * @since bbPress (r2646)
150 *
151 * @uses add_management_page() To add the Recount page in Tools section
152 * @uses add_options_page() To add the Forums settings page in Settings
153 * section
154 */
155 public function admin_menus() {
156
157 $hooks = array();
158
159 // These are later removed in admin_head
160 if ( bbp_current_user_can_see( 'bbp_tools_page' ) ) {
161 if ( bbp_current_user_can_see( 'bbp_tools_repair_page' ) ) {
162 $hooks[] = add_management_page(
163 __( 'Repair Forums', 'bbpress' ),
164 __( 'Forum Repair', 'bbpress' ),
165 $this->minimum_capability,
166 'bbp-repair',
167 'bbp_admin_repair'
168 );
169 }
170
171 if ( bbp_current_user_can_see( 'bbp_tools_import_page' ) ) {
172 $hooks[] = add_management_page(
173 __( 'Import Forums', 'bbpress' ),
174 __( 'Forum Import', 'bbpress' ),
175 $this->minimum_capability,
176 'bbp-converter',
177 'bbp_converter_settings'
178 );
179 }
180
181 if ( bbp_current_user_can_see( 'bbp_tools_reset_page' ) ) {
182 $hooks[] = add_management_page(
183 __( 'Reset Forums', 'bbpress' ),
184 __( 'Forum Reset', 'bbpress' ),
185 $this->minimum_capability,
186 'bbp-reset',
187 'bbp_admin_reset'
188 );
189 }
190
191 // Fudge the highlighted subnav item when on a bbPress admin page
192 foreach( $hooks as $hook ) {
193 add_action( "admin_head-$hook", 'bbp_tools_modify_menu_highlight' );
194 }
195
196 // Forums Tools Root
197 add_management_page(
198 __( 'Forums', 'bbpress' ),
199 __( 'Forums', 'bbpress' ),
200 $this->minimum_capability,
201 'bbp-repair',
202 'bbp_admin_repair'
203 );
204 }
205
206 // Are settings enabled?
207 if ( bbp_current_user_can_see( 'bbp_settings_page' ) ) {
208 add_options_page(
209 __( 'Forums', 'bbpress' ),
210 __( 'Forums', 'bbpress' ),
211 $this->minimum_capability,
212 'bbpress',
213 'bbp_admin_settings'
214 );
215 }
216 }
217
218 /**
219 * Add the network admin menus
220 *
221 * @since bbPress (r3689)
222 * @uses add_submenu_page() To add the Update Forums page in Updates
223 */
224 public function network_admin_menus() {
225 add_submenu_page(
226 'upgrade.php',
227 __( 'Update Forums', 'bbpress' ),
228 __( 'Update Forums', 'bbpress' ),
229 'manage_network',
230 'bbpress-update',
231 array( $this, 'network_update_screen' )
232 );
233 }
234
235 /**
236 * If this is a new installation, create some initial forum content.
237 *
238 * @since bbPress (r3767)
239 * @return type
240 */
241 public static function new_install() {
242 if ( !bbp_is_install() )
243 return;
244
245 bbp_create_initial_content();
246 }
247
248 /**
249 * Register the settings
250 *
251 * @since bbPress (r2737)
252 *
253 * @uses add_settings_section() To add our own settings section
254 * @uses add_settings_field() To add various settings fields
255 * @uses register_setting() To register various settings
256 * @todo Put fields into multidimensional array
257 */
258 public static function register_admin_settings() {
259
260 // Bail if no sections available
261 if ( ! $sections = bbp_admin_get_settings_sections() )
262 return false;
263
264 // Loop through sections
265 foreach ( $sections as $section_id => $section ) {
266
267 // Only proceed if current user can see this section
268 if ( ! bbp_current_user_can_see( $section_id ) )
269 continue;
270
271 // Only add section and fields if section has fields
272 if ( $fields = bbp_admin_get_settings_fields_for_section( $section_id ) ) {
273
274 // Add the section
275 add_settings_section( $section_id, $section['title'], $section['callback'], $section['page'] );
276
277 // Loop through fields for this section
278 foreach ( $fields as $field_id => $field ) {
279
280 // Add the field
281 add_settings_field( $field_id, $field['title'], $field['callback'], $section['page'], $section_id, $field['args'] );
282
283 // Register the setting
284 register_setting( $section['page'], $field_id, $field['sanitize_callback'] );
285 }
286 }
287 }
288 }
289
290 /**
291 * Register the importers
292 *
293 * @since bbPress (r2737)
294 *
295 * @uses apply_filters() Calls 'bbp_importer_path' filter to allow plugins
296 * to customize the importer script locations.
297 */
298 public function register_importers() {
299
300 // Leave if we're not in the import section
301 if ( !defined( 'WP_LOAD_IMPORTERS' ) )
302 return;
303
304 // Load Importer API
305 require_once( ABSPATH . 'wp-admin/includes/import.php' );
306
307 // Load our importers
308 $importers = apply_filters( 'bbp_importers', array( 'bbpress' ) );
309
310 // Loop through included importers
311 foreach ( $importers as $importer ) {
312
313 // Allow custom importer directory
314 $import_dir = apply_filters( 'bbp_importer_path', $this->admin_dir . 'importers', $importer );
315
316 // Compile the importer path
317 $import_file = trailingslashit( $import_dir ) . $importer . '.php';
318
319 // If the file exists, include it
320 if ( file_exists( $import_file ) ) {
321 require( $import_file );
322 }
323 }
324 }
325
326 /**
327 * Admin area activation notice
328 *
329 * Shows a nag message in admin area about the theme not supporting bbPress
330 *
331 * @since bbPress (r2743)
332 *
333 * @uses current_user_can() To check notice should be displayed.
334 */
335 public function activation_notice() {
336 // @todo - something fun
337 }
338
339 /**
340 * Add Settings link to plugins area
341 *
342 * @since bbPress (r2737)
343 *
344 * @param array $links Links array in which we would prepend our link
345 * @param string $file Current plugin basename
346 * @return array Processed links
347 */
348 public static function add_settings_link( $links, $file ) {
349
350 if ( plugin_basename( bbpress()->file ) == $file ) {
351 $settings_link = '<a href="' . add_query_arg( array( 'page' => 'bbpress' ), admin_url( 'options-general.php' ) ) . '">' . __( 'Settings', 'bbpress' ) . '</a>';
352 array_unshift( $links, $settings_link );
353 }
354
355 return $links;
356 }
357
358 /**
359 * Add the 'Right now in Forums' dashboard widget
360 *
361 * @since bbPress (r2770)
362 *
363 * @uses wp_add_dashboard_widget() To add the dashboard widget
364 */
365 public static function dashboard_widget_right_now() {
366 wp_add_dashboard_widget( 'bbp-dashboard-right-now', __( 'Right Now in Forums', 'bbpress' ), 'bbp_dashboard_widget_right_now' );
367 }
368
369 /**
370 * Add some general styling to the admin area
371 *
372 * @since bbPress (r2464)
373 *
374 * @uses bbp_get_forum_post_type() To get the forum post type
375 * @uses bbp_get_topic_post_type() To get the topic post type
376 * @uses bbp_get_reply_post_type() To get the reply post type
377 * @uses sanitize_html_class() To sanitize the classes
378 */
379 public function admin_head() {
380
381 // Remove the individual recount and converter menus.
382 // They are grouped together by h2 tabs
383 remove_submenu_page( 'tools.php', 'bbp-repair' );
384 remove_submenu_page( 'tools.php', 'bbp-converter' );
385 remove_submenu_page( 'tools.php', 'bbp-reset' );
386
387 // Icons for top level admin menus
388 $version = bbp_get_version();
389 $menu_icon_url = $this->images_url . 'menu.png?ver=' . $version;
390 $icon32_url = $this->images_url . 'icons32.png?ver=' . $version;
391 $menu_icon_url_2x = $this->images_url . 'menu-2x.png?ver=' . $version;
392 $icon32_url_2x = $this->images_url . 'icons32-2x.png?ver=' . $version;
393
394 // Top level menu classes
395 $forum_class = sanitize_html_class( bbp_get_forum_post_type() );
396 $topic_class = sanitize_html_class( bbp_get_topic_post_type() );
397 $reply_class = sanitize_html_class( bbp_get_reply_post_type() ); ?>
398
399 <style type="text/css" media="screen">
400 /*<![CDATA[*/
401
402 #bbp-dashboard-right-now p.sub,
403 #bbp-dashboard-right-now .table,
404 #bbp-dashboard-right-now .versions {
405 margin: -12px;
406 }
407
408 #bbp-dashboard-right-now .inside {
409 font-size: 12px;
410 padding-top: 20px;
411 margin-bottom: 0;
412 }
413
414 #bbp-dashboard-right-now p.sub {
415 padding: 5px 0 15px;
416 color: #8f8f8f;
417 font-size: 14px;
418 position: absolute;
419 top: -17px;
420 left: 15px;
421 }
422 body.rtl #bbp-dashboard-right-now p.sub {
423 right: 15px;
424 left: 0;
425 }
426
427 #bbp-dashboard-right-now .table {
428 margin: 0;
429 padding: 0;
430 position: relative;
431 }
432
433 #bbp-dashboard-right-now .table_content {
434 float: left;
435 border-top: #ececec 1px solid;
436 width: 45%;
437 }
438 body.rtl #bbp-dashboard-right-now .table_content {
439 float: right;
440 }
441
442 #bbp-dashboard-right-now .table_discussion {
443 float: right;
444 border-top: #ececec 1px solid;
445 width: 45%;
446 }
447 body.rtl #bbp-dashboard-right-now .table_discussion {
448 float: left;
449 }
450
451 #bbp-dashboard-right-now table td {
452 padding: 3px 0;
453 white-space: nowrap;
454 }
455
456 #bbp-dashboard-right-now table tr.first td {
457 border-top: none;
458 }
459
460 #bbp-dashboard-right-now td.b {
461 padding-right: 6px;
462 text-align: right;
463 font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
464 font-size: 14px;
465 width: 1%;
466 }
467 body.rtl #bbp-dashboard-right-now td.b {
468 padding-left: 6px;
469 padding-right: 0;
470 }
471
472 #bbp-dashboard-right-now td.b a {
473 font-size: 18px;
474 }
475
476 #bbp-dashboard-right-now td.b a:hover {
477 color: #d54e21;
478 }
479
480 #bbp-dashboard-right-now .t {
481 font-size: 12px;
482 padding-right: 12px;
483 padding-top: 6px;
484 color: #777;
485 }
486 body.rtl #bbp-dashboard-right-now .t {
487 padding-left: 12px;
488 padding-right: 0;
489 }
490
491 #bbp-dashboard-right-now .t a {
492 white-space: nowrap;
493 }
494
495 #bbp-dashboard-right-now .spam {
496 color: red;
497 }
498
499 #bbp-dashboard-right-now .waiting {
500 color: #e66f00;
501 }
502
503 #bbp-dashboard-right-now .approved {
504 color: green;
505 }
506
507 #bbp-dashboard-right-now .versions {
508 padding: 6px 10px 12px;
509 clear: both;
510 }
511
512 #bbp-dashboard-right-now .versions .b {
513 font-weight: bold;
514 }
515
516 #bbp-dashboard-right-now a.button {
517 float: right;
518 clear: right;
519 position: relative;
520 top: -5px;
521 }
522 body.rtl #bbp-dashboard-right-now a.button {
523 float: left;
524 clear: left;
525 }
526
527 /* Icon 32 */
528 #icon-edit.icon32-posts-<?php echo $forum_class; ?>,
529 #icon-edit.icon32-posts-<?php echo $topic_class; ?>,
530 #icon-edit.icon32-posts-<?php echo $reply_class; ?> {
531 background: url('<?php echo $icon32_url; ?>');
532 background-repeat: no-repeat;
533 }
534
535 /* Icon Positions */
536 #icon-edit.icon32-posts-<?php echo $forum_class; ?> {
537 background-position: -4px 0px;
538 }
539
540 #icon-edit.icon32-posts-<?php echo $topic_class; ?> {
541 background-position: -4px -90px;
542 }
543
544 #icon-edit.icon32-posts-<?php echo $reply_class; ?> {
545 background-position: -4px -180px;
546 }
547
548 /* Icon 32 2x */
549 @media only screen and (-webkit-min-device-pixel-ratio: 1.5) {
550 #icon-edit.icon32-posts-<?php echo $forum_class; ?>,
551 #icon-edit.icon32-posts-<?php echo $topic_class; ?>,
552 #icon-edit.icon32-posts-<?php echo $reply_class; ?> {
553 background-image: url('<?php echo $icon32_url_2x; ?>');
554 background-size: 45px 255px;
555 }
556 }
557
558 /* Menu */
559 #menu-posts-<?php echo $forum_class; ?> .wp-menu-image,
560 #menu-posts-<?php echo $topic_class; ?> .wp-menu-image,
561 #menu-posts-<?php echo $reply_class; ?> .wp-menu-image,
562
563 #menu-posts-<?php echo $forum_class; ?>:hover .wp-menu-image,
564 #menu-posts-<?php echo $topic_class; ?>:hover .wp-menu-image,
565 #menu-posts-<?php echo $reply_class; ?>:hover .wp-menu-image,
566
567 #menu-posts-<?php echo $forum_class; ?>.wp-has-current-submenu .wp-menu-image,
568 #menu-posts-<?php echo $topic_class; ?>.wp-has-current-submenu .wp-menu-image,
569 #menu-posts-<?php echo $reply_class; ?>.wp-has-current-submenu .wp-menu-image {
570 background: url('<?php echo $menu_icon_url; ?>');
571 background-repeat: no-repeat;
572 }
573
574 /* Menu Positions */
575 #menu-posts-<?php echo $forum_class; ?> .wp-menu-image {
576 background-position: 0px -32px;
577 }
578 #menu-posts-<?php echo $forum_class; ?>:hover .wp-menu-image,
579 #menu-posts-<?php echo $forum_class; ?>.wp-has-current-submenu .wp-menu-image {
580 background-position: 0px 0px;
581 }
582 #menu-posts-<?php echo $topic_class; ?> .wp-menu-image {
583 background-position: -70px -32px;
584 }
585 #menu-posts-<?php echo $topic_class; ?>:hover .wp-menu-image,
586 #menu-posts-<?php echo $topic_class; ?>.wp-has-current-submenu .wp-menu-image {
587 background-position: -70px 0px;
588 }
589 #menu-posts-<?php echo $reply_class; ?> .wp-menu-image {
590 background-position: -35px -32px;
591 }
592 #menu-posts-<?php echo $reply_class; ?>:hover .wp-menu-image,
593 #menu-posts-<?php echo $reply_class; ?>.wp-has-current-submenu .wp-menu-image {
594 background-position: -35px 0px;
595 }
596
597 /* Menu 2x */
598 @media only screen and (-webkit-min-device-pixel-ratio: 1.5) {
599 #menu-posts-<?php echo $forum_class; ?> .wp-menu-image,
600 #menu-posts-<?php echo $topic_class; ?> .wp-menu-image,
601 #menu-posts-<?php echo $reply_class; ?> .wp-menu-image,
602
603 #menu-posts-<?php echo $forum_class; ?>:hover .wp-menu-image,
604 #menu-posts-<?php echo $topic_class; ?>:hover .wp-menu-image,
605 #menu-posts-<?php echo $reply_class; ?>:hover .wp-menu-image,
606
607 #menu-posts-<?php echo $forum_class; ?>.wp-has-current-submenu .wp-menu-image,
608 #menu-posts-<?php echo $topic_class; ?>.wp-has-current-submenu .wp-menu-image,
609 #menu-posts-<?php echo $reply_class; ?>.wp-has-current-submenu .wp-menu-image {
610 background-image: url('<?php echo $menu_icon_url_2x; ?>');
611 background-size: 100px 64px;
612 }
613 }
614
615 /*]]>*/
616 </style>
617
618 <?php
619 }
620
621 /**
622 * Registers the bbPress admin color scheme
623 *
624 * Because wp-content can exist outside of the WordPress root there is no
625 * way to be certain what the relative path of the admin images is.
626 * We are including the two most common configurations here, just in case.
627 *
628 * @since bbPress (r2521)
629 *
630 * @uses wp_admin_css_color() To register the color scheme
631 */
632 public function register_admin_style () {
633
634 // Normal wp-content dir
635 if ( 0 === $this->content_depth )
636 $css_file = $this->styles_url . 'admin.css';
637
638 // Custom wp-content dir is 1 level away
639 elseif ( 1 === $this->content_depth )
640 $css_file = $this->styles_url . 'admin-1.css';
641
642 // Custom wp-content dir is 1 level away
643 elseif ( 2 === $this->content_depth )
644 $css_file = $this->styles_url . 'admin-2.css';
645
646 // Load the admin CSS styling
647 wp_admin_css_color( 'bbpress', __( 'Green', 'bbpress' ), $css_file, array( '#222222', '#006600', '#deece1', '#6eb469' ) );
648 }
649
650 /** Updaters **************************************************************/
651
652 /**
653 * Update all bbPress forums across all sites
654 *
655 * @since bbPress (r3689)
656 *
657 * @global WPDB $wpdb
658 * @uses get_blog_option()
659 * @uses wp_remote_get()
660 */
661 public static function update_screen() {
662
663 // Get action
664 $action = isset( $_GET['action'] ) ? $_GET['action'] : ''; ?>
665
666 <div class="wrap">
667 <div id="icon-edit" class="icon32 icon32-posts-topic"><br /></div>
668 <h2><?php _e( 'Update Forum', 'bbpress' ); ?></h2>
669
670 <?php
671
672 // Taking action
673 switch ( $action ) {
674 case 'bbpress-update' :
675
676 // @todo more update stuff here, evaluate performance
677
678 // Remove roles and caps
679 bbp_remove_roles();
680 bbp_remove_caps();
681
682 // Make sure roles, capabilities, and options exist
683 bbp_add_roles();
684 bbp_add_caps();
685 bbp_add_options();
686
687 // Ensure any new permalinks are created
688 flush_rewrite_rules();
689
690 // Ensure proper version in the DB
691 bbp_version_bump();
692
693 ?>
694
695 <p><?php _e( 'All done!', 'bbpress' ); ?></p>
696 <a class="button" href="index.php?page=bbpress-update"><?php _e( 'Go Back', 'bbpress' ); ?></a>
697
698 <?php
699
700 break;
701
702 case 'show' :
703 default : ?>
704
705 <p><?php _e( 'You can update your forum through this page. Hit the link below to update.', 'bbpress' ); ?></p>
706 <p><a class="button" href="index.php?page=bbpress-update&amp;action=bbpress-update"><?php _e( 'Update Forum', 'bbpress' ); ?></a></p>
707
708 <?php break;
709
710 } ?>
711
712 </div><?php
713 }
714
715 /**
716 * Update all bbPress forums across all sites
717 *
718 * @since bbPress (r3689)
719 *
720 * @global WPDB $wpdb
721 * @uses get_blog_option()
722 * @uses wp_remote_get()
723 */
724 public static function network_update_screen() {
725 global $wpdb;
726
727 // Get action
728 $action = isset( $_GET['action'] ) ? $_GET['action'] : ''; ?>
729
730 <div class="wrap">
731 <div id="icon-edit" class="icon32 icon32-posts-topic"><br /></div>
732 <h2><?php _e( 'Update Forums', 'bbpress' ); ?></h2>
733
734 <?php
735
736 // Taking action
737 switch ( $action ) {
738 case 'bbpress-update' :
739
740 // Site counter
741 $n = isset( $_GET['n'] ) ? intval( $_GET['n'] ) : 0;
742
743 // Get blogs 5 at a time
744 $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 );
745
746 // No blogs so all done!
747 if ( empty( $blogs ) ) : ?>
748
749 <p><?php _e( 'All done!', 'bbpress' ); ?></p>
750 <a class="button" href="update-core.php?page=bbpress-update"><?php _e( 'Go Back', 'bbpress' ); ?></a>
751
752 <?php break; ?>
753
754 <?php
755
756 // Still have sites to loop through
757 else : ?>
758
759 <ul>
760
761 <?php foreach ( (array) $blogs as $details ) :
762
763 $siteurl = get_blog_option( $details['blog_id'], 'siteurl' ); ?>
764
765 <li><?php echo $siteurl; ?></li>
766
767 <?php
768
769 // Get the response of the bbPress update on this site
770 $response = wp_remote_get(
771 trailingslashit( $siteurl ) . 'wp-admin/index.php?page=bbpress-update&step=bbpress-update',
772 array( 'timeout' => 120, 'httpversion' => '1.1' )
773 );
774
775 // Site errored out, no response?
776 if ( is_wp_error( $response ) )
777 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() ) );
778
779 // Do some actions to allow plugins to do things too
780 do_action( 'after_bbpress_upgrade', $response );
781 do_action( 'bbp_upgrade_site', $details[ 'blog_id' ] );
782
783 endforeach; ?>
784
785 </ul>
786
787 <p>
788 <?php _e( 'If your browser doesn&#8217;t start loading the next page automatically, click this link:', 'bbpress' ); ?>
789 <a class="button" href="update-core.php?page=bbpress-update&amp;action=bbpress-update&amp;n=<?php echo ( $n + 5 ); ?>"><?php _e( 'Next Forums', 'bbpress' ); ?></a>
790 </p>
791 <script type='text/javascript'>
792 <!--
793 function nextpage() {
794 location.href = 'update-core.php?page=bbpress-update&action=bbpress-update&n=<?php echo ( $n + 5 ) ?>';
795 }
796 setTimeout( 'nextpage()', 250 );
797 //-->
798 </script><?php
799
800 endif;
801
802 break;
803
804 case 'show' :
805 default : ?>
806
807 <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>
808 <p><a class="button" href="update-core.php?page=bbpress-update&amp;action=bbpress-update"><?php _e( 'Update Forums', 'bbpress' ); ?></a></p>
809
810 <?php break;
811
812 } ?>
813
814 </div><?php
815 }
816 }
817 endif; // class_exists check
818
819 /**
820 * Setup bbPress Admin
821 *
822 * @since bbPress (r2596)
823 *
824 * @uses BBP_Admin
825 */
826 function bbp_admin() {
827 bbpress()->admin = new BBP_Admin();
828
829 bbpress()->admin->converter = new BBP_Converter();
830 }
831