PluginProbe
bbPress / 2.6.15
bbPress v2.6.15
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 / includes / admin / classes / class-bbp-admin.php

class-bbp-admin.php in bbPress 2.6.15, at includes/admin/classes/class-bbp-admin.php

1,449 lines 45.2 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 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 2.0.0 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 /**
48 * @var string URL to the bbPress admin css directory
49 */
50 public $css_url = '';
51
52 /**
53 * @var string URL to the bbPress admin js directory
54 */
55 public $js_url = '';
56
57 /** Capability ************************************************************/
58
59 /**
60 * @var bool Minimum capability to access Tools and Settings
61 */
62 public $minimum_capability = 'keep_gate';
63
64 /** Separator *************************************************************/
65
66 /**
67 * @var bool Whether or not to add an extra top level menu separator
68 */
69 public $show_separator = false;
70
71 /** Tools *****************************************************************/
72
73 /**
74 * @var array Array of available repair tools
75 */
76 public $tools = array();
77
78 /** Notices ***************************************************************/
79
80 /**
81 * @var array Array of notices to output to the current user
82 */
83 public $notices = array();
84
85 /** Components ************************************************************/
86
87 /**
88 * @var BBP_Forums_Admin Forums admin
89 */
90 public $forums = null;
91
92 /**
93 * @var BBP_Topics_Admin Topics admin
94 */
95 public $topics = null;
96
97 /**
98 * @var BBP_Replies_Admin Replies admin
99 */
100 public $replies = null;
101
102 /**
103 * @var BBP_Converter Converter admin
104 */
105 public $converter = null;
106
107 /** Functions *************************************************************/
108
109 /**
110 * The main bbPress admin loader
111 *
112 * @since 2.0.0 bbPress (r2515)
113 */
114 public function __construct() {
115 $this->setup_globals();
116 $this->includes();
117 $this->setup_actions();
118 }
119
120 /**
121 * Admin globals
122 *
123 * @since 2.0.0 bbPress (r2646)
124 *
125 * @access private
126 */
127 private function setup_globals() {
128 $bbp = bbpress();
129 $this->admin_dir = trailingslashit( $bbp->includes_dir . 'admin' ); // Admin path
130 $this->admin_url = trailingslashit( $bbp->includes_url . 'admin' ); // Admin url
131
132 // Assets
133 $this->css_url = trailingslashit( $this->admin_url . 'assets/css' ); // Admin css URL
134 $this->js_url = trailingslashit( $this->admin_url . 'assets/js' ); // Admin js URL
135 $this->styles_url = trailingslashit( $this->admin_url . 'styles' ); // Admin styles URL
136
137 // Deprecated
138 $this->images_url = trailingslashit( $this->admin_url . 'images' ); // Admin images URL
139 }
140
141 /**
142 * Include required files
143 *
144 * @since 2.0.0 bbPress (r2646)
145 *
146 * @access private
147 */
148 private function includes() {
149
150 // Tools
151 require $this->admin_dir . 'tools.php';
152 require $this->admin_dir . 'tools/common.php';
153 require $this->admin_dir . 'tools/converter.php';
154 require $this->admin_dir . 'tools/repair.php';
155 require $this->admin_dir . 'tools/upgrade.php';
156 require $this->admin_dir . 'tools/reset.php';
157 require $this->admin_dir . 'tools/help.php';
158
159 // Components
160 require $this->admin_dir . 'settings.php';
161 require $this->admin_dir . 'common.php';
162 require $this->admin_dir . 'metaboxes.php';
163 require $this->admin_dir . 'forums.php';
164 require $this->admin_dir . 'topics.php';
165 require $this->admin_dir . 'replies.php';
166 require $this->admin_dir . 'users.php';
167 }
168
169 /**
170 * Setup the admin hooks, actions and filters
171 *
172 * @since 2.0.0 bbPress (r2646)
173 *
174 * @access private
175 */
176 private function setup_actions() {
177
178 // Bail to prevent interfering with the deactivation process
179 if ( bbp_is_deactivation() ) {
180 return;
181 }
182
183 /** General Actions ***************************************************/
184
185 add_action( 'bbp_admin_menu', array( $this, 'admin_menus' ) );
186 add_action( 'bbp_admin_head', array( $this, 'admin_head' ) );
187 add_action( 'bbp_register_admin_styles', array( $this, 'register_admin_styles' ) );
188 add_action( 'bbp_register_admin_scripts', array( $this, 'register_admin_scripts' ) );
189 add_action( 'bbp_register_admin_settings', array( $this, 'register_admin_settings' ) );
190
191 // Enqueue styles & scripts
192 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
193 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
194
195 /** Notices ***********************************************************/
196
197 add_action( 'bbp_admin_init', array( $this, 'setup_notices' ) );
198 add_action( 'bbp_admin_init', array( $this, 'hide_notices' ) );
199 add_action( 'bbp_admin_notices', array( $this, 'output_notices' ) );
200
201 /** Upgrades **********************************************************/
202
203 add_action( 'bbp_admin_init', array( $this, 'add_upgrade_count' ) );
204
205 /** Ajax **************************************************************/
206
207 // No _nopriv_ equivalent - users must be logged in
208 add_action( 'wp_ajax_bbp_suggest_topic', array( $this, 'suggest_topic' ) );
209 add_action( 'wp_ajax_bbp_suggest_user', array( $this, 'suggest_user' ) );
210
211 /** Filters ***********************************************************/
212
213 // Modify admin links
214 add_filter( 'plugin_action_links', array( $this, 'modify_plugin_action_links' ), 10, 2 );
215
216 // Map settings capabilities
217 add_filter( 'bbp_map_meta_caps', array( $this, 'map_settings_meta_caps' ), 10, 4 );
218
219 // Allow keymasters to save forums settings
220 add_filter( 'option_page_capability_bbpress', array( $this, 'option_page_capability_bbpress' ) );
221
222 /** Network Admin *****************************************************/
223
224 // Add menu item to settings menu
225 add_action( 'network_admin_menu', array( $this, 'network_admin_menus' ) );
226
227 /** Dependencies ******************************************************/
228
229 // Allow plugins to modify these actions
230 do_action_ref_array( 'bbp_admin_loaded', array( &$this ) );
231 }
232
233 /**
234 * Setup general admin area notices.
235 *
236 * @since 2.6.0 bbPress (r6701)
237 */
238 public function setup_notices() {
239
240 // Avoid malformed notices variable
241 if ( ! is_array( $this->notices ) ) {
242 $this->notices = array();
243 }
244
245 // Get page
246 $page = ! empty( $_GET['page'] )
247 ? sanitize_key( $_GET['page'] )
248 : false;
249
250 // Pending database upgrades!
251 if ( ( 'bbp-upgrade' !== $page ) && bbp_get_pending_upgrades() && current_user_can( 'bbp_tools_upgrade_page' ) ) {
252
253 // Link to upgrade page
254 $upgrade_url = add_query_arg( array( 'page' => 'bbp-upgrade', 'status' => 'pending' ), admin_url( 'tools.php' ) );
255 $dismiss_url = wp_nonce_url( add_query_arg( array( 'bbp-hide-notice' => 'bbp-skip-upgrades' ) ), 'bbp-hide-notice' );
256 $upgrade_link = '<a href="' . esc_url( $upgrade_url ) . '">' . esc_html__( 'Learn More', 'bbpress' ) . '</a>';
257 $dismiss_link = '<a href="' . esc_url( $dismiss_url ) . '">' . esc_html__( 'Hide For Now', 'bbpress' ) . '</a>';
258 $bbp_dashicon = '<span class="bbpress-logo-icon"></span>';
259 $message = $bbp_dashicon . sprintf(
260 esc_html__( 'bbPress requires a manual database upgrade. %s or %s.', 'bbpress' ),
261 $upgrade_link,
262 $dismiss_link
263 );
264
265 // Add tools feedback
266 $this->add_notice( $message, 'notice-bbpress', false );
267 }
268 }
269
270 /**
271 * Handle hiding of general admin area notices.
272 *
273 * @since 2.6.0 bbPress (r6701)
274 */
275 public function hide_notices() {
276
277 // Hiding a notice?
278 $hiding_notice = ! empty( $_GET['bbp-hide-notice'] )
279 ? sanitize_key( $_GET['bbp-hide-notice'] )
280 : false;
281
282 // Bail if not hiding a notice
283 if ( empty( $hiding_notice ) ) {
284 return;
285 }
286
287 // Bail if user cannot visit upgrade page (cannot clear notice either!)
288 if ( ! current_user_can( 'bbp_tools_upgrade_page' ) ) {
289 return;
290 }
291
292 // Check the admin referer
293 check_admin_referer( 'bbp-hide-notice' );
294
295 // Maybe delete notices
296 switch ( $hiding_notice ) {
297
298 // Skipped upgrade notice
299 case 'bbp-skip-upgrades' :
300 bbp_clear_pending_upgrades();
301 break;
302 }
303 }
304
305 /**
306 * Output all admin area notices
307 *
308 * @since 2.6.0 bbPress (r6771)
309 */
310 public function output_notices() {
311
312 // Bail if no notices
313 if ( empty( $this->notices ) || ! is_array( $this->notices ) ) {
314 return;
315 }
316
317 // Start an output buffer
318 ob_start();
319
320 // Loop through notices, and add them to buffer
321 foreach ( $this->notices as $notice ) {
322 echo $notice;
323 }
324
325 // Output the current buffer
326 echo ob_get_clean();
327 }
328
329 /**
330 * Add a notice to the notices array
331 *
332 * @since 2.6.0 bbPress (r6771)
333 *
334 * @param string|WP_Error $message A message to be displayed or {@link WP_Error}
335 * @param string $class Optional. A class to be added to the message div
336 * @param bool $is_dismissible Optional. True to dismiss, false to persist
337 *
338 * @return void
339 */
340 public function add_notice( $message, $class = false, $is_dismissible = true ) {
341
342 // One message as string
343 if ( is_string( $message ) ) {
344 $message = '<p>' . $this->esc_notice( $message ) . '</p>';
345 $default_class ='updated';
346
347 // Messages as objects
348 } elseif ( is_wp_error( $message ) ) {
349 $errors = $message->get_error_messages();
350
351 switch ( count( $errors ) ) {
352 case 0:
353 return false;
354
355 case 1:
356 $message = '<p>' . $this->esc_notice( $errors[0] ) . '</p>';
357 break;
358
359 default:
360 $escaped = array_map( array( $this, 'esc_notice' ), $errors );
361 $message = '<ul>' . "\n\t" . '<li>' . implode( '</li>' . "\n\t" . '<li>', $escaped ) . '</li>' . "\n" . '</ul>';
362 break;
363 }
364
365 $default_class = 'is-error';
366
367 // Message is an unknown format, so bail
368 } else {
369 return false;
370 }
371
372 // CSS Classes
373 $classes = ! empty( $class )
374 ? array( $class )
375 : array( $default_class );
376
377 // Add dismissible class
378 if ( ! empty( $is_dismissible ) ) {
379 array_push( $classes, 'is-dismissible' );
380 }
381
382 // Assemble the message
383 $message = '<div id="message" class="notice ' . implode( ' ', array_map( 'sanitize_html_class', $classes ) ) . '">' . $message . '</div>';
384 $message = str_replace( "'", "\'", $message );
385
386 // Avoid malformed notices variable
387 if ( ! is_array( $this->notices ) ) {
388 $this->notices = array();
389 }
390
391 // Add notice to notices array
392 $this->notices[] = $message;
393 }
394
395 /**
396 * Escape message string output
397 *
398 * @since 2.6.0 bbPress (r6775)
399 *
400 * @param string $message
401 *
402 * @return string
403 */
404 private function esc_notice( $message = '' ) {
405
406 // Get allowed HTML
407 $tags = wp_kses_allowed_html();
408
409 // Allow spans with classes in notices
410 $tags['span'] = array(
411 'class' => 1
412 );
413
414 // Parse the message and remove unsafe tags
415 $text = wp_kses( $message, $tags );
416
417 // Return the message text
418 return $text;
419 }
420
421 /**
422 * Maybe append the pending upgrade count to the "Tools" menu.
423 *
424 * @since 2.6.0 bbPress (r6896)
425 *
426 * @global menu $menu
427 */
428 public function add_upgrade_count() {
429 global $menu;
430
431 // Skip if no menu (AJAX, shortinit, etc...)
432 if ( empty( $menu ) ) {
433 return;
434 }
435
436 // Loop through menus, and maybe add the upgrade count
437 foreach ( $menu as $menu_index => $menu_item ) {
438 $found = array_search( 'tools.php', $menu_item, true );
439
440 if ( false !== $found ) {
441 $menu[ $menu_index ][ 0 ] = bbp_maybe_append_pending_upgrade_count( $menu[ $menu_index ][ 0 ] );
442 continue;
443 }
444 }
445 }
446
447 /**
448 * Add the admin menus
449 *
450 * @since 2.0.0 bbPress (r2646)
451 */
452 public function admin_menus() {
453
454 // Default hooks array
455 $hooks = array();
456
457 // Get the tools pages
458 $tools = bbp_get_tools_admin_pages();
459
460 // Loop through tools and check
461 if ( ! empty( $tools ) ) {
462 foreach ( $tools as $tool ) {
463
464 // Try to add the admin page
465 $page = add_management_page(
466 $tool['name'],
467 $tool['name'],
468 $tool['cap'],
469 $tool['page'],
470 $tool['func']
471 );
472
473 // Add page to hook if user can view it
474 if ( false !== $page ) {
475 $hooks[] = $page;
476 }
477 }
478
479 // Fudge the highlighted subnav item when on a bbPress admin page
480 if ( ! empty( $hooks ) ) {
481 foreach ( $hooks as $hook ) {
482 add_action( "admin_head-{$hook}", 'bbp_tools_modify_menu_highlight' );
483 }
484 }
485 }
486
487 // Forums Tools Root
488 add_management_page(
489 esc_html__( 'Forums', 'bbpress' ),
490 bbp_maybe_append_pending_upgrade_count( esc_html__( 'Forums', 'bbpress' ) ),
491 'bbp_tools_page',
492 'bbp-repair',
493 'bbp_admin_repair_page'
494 );
495
496 // Are settings enabled?
497 if ( 'basic' === bbp_settings_integration() ) {
498 add_options_page(
499 esc_html__( 'Forums', 'bbpress' ),
500 esc_html__( 'Forums', 'bbpress' ),
501 'bbp_settings_page',
502 'bbpress',
503 'bbp_admin_settings'
504 );
505 }
506
507 // These are later removed in admin_head
508 if ( current_user_can( 'bbp_about_page' ) ) {
509
510 // About
511 add_dashboard_page(
512 esc_html__( 'Welcome to bbPress', 'bbpress' ),
513 esc_html__( 'Welcome to bbPress', 'bbpress' ),
514 'bbp_about_page',
515 'bbp-about',
516 array( $this, 'about_screen' )
517 );
518
519 // Credits
520 add_dashboard_page(
521 esc_html__( 'Welcome to bbPress', 'bbpress' ),
522 esc_html__( 'Welcome to bbPress', 'bbpress' ),
523 'bbp_about_page',
524 'bbp-credits',
525 array( $this, 'credits_screen' )
526 );
527 }
528
529 // Bail if plugin is not network activated
530 if ( ! is_plugin_active_for_network( bbpress()->basename ) ) {
531 return;
532 }
533
534 add_submenu_page(
535 'index.php',
536 esc_html__( 'Update Forums', 'bbpress' ),
537 esc_html__( 'Update Forums', 'bbpress' ),
538 'manage_network',
539 'bbp-update',
540 array( $this, 'update_screen' )
541 );
542 }
543
544 /**
545 * Add the network admin menus
546 *
547 * @since 2.1.0 bbPress (r3689)
548 */
549 public function network_admin_menus() {
550
551 // Bail if plugin is not network activated
552 if ( ! is_plugin_active_for_network( bbpress()->basename ) ) {
553 return;
554 }
555
556 add_submenu_page(
557 'upgrade.php',
558 esc_html__( 'Update Forums', 'bbpress' ),
559 esc_html__( 'Update Forums', 'bbpress' ),
560 'manage_network',
561 'bbpress-update',
562 array( $this, 'network_update_screen' )
563 );
564 }
565
566 /**
567 * Register the settings
568 *
569 * @since 2.0.0 bbPress (r2737)
570 *
571 * @todo Put fields into multidimensional array
572 */
573 public static function register_admin_settings() {
574
575 // Bail if no sections available
576 $sections = bbp_admin_get_settings_sections();
577 if ( empty( $sections ) ) {
578 return false;
579 }
580
581 // Are we using settings integration?
582 $settings_integration = bbp_settings_integration();
583
584 // Loop through sections
585 foreach ( (array) $sections as $section_id => $section ) {
586
587 // Only proceed if current user can see this section
588 if ( ! current_user_can( $section_id ) ) {
589 continue;
590 }
591
592 // Only add section and fields if section has fields
593 $fields = bbp_admin_get_settings_fields_for_section( $section_id );
594 if ( empty( $fields ) ) {
595 continue;
596 }
597
598 // Overload the converter page
599 if ( ! empty( $section['page'] ) && ( ( 'converter' === $section['page'] ) || ( 'deep' === $settings_integration ) ) ) {
600 $page = $section['page'];
601 } else {
602 $page = 'bbpress';
603 }
604
605 // Add the section
606 add_settings_section( $section_id, $section['title'], $section['callback'], $page );
607
608 // Loop through fields for this section
609 foreach ( (array) $fields as $field_id => $field ) {
610
611 // Skip field if user is not capable
612 if ( ! empty( $field['capability'] ) && ! current_user_can( $field['capability'] ) ) {
613 continue;
614 }
615
616 // Add the field
617 if ( ! empty( $field['callback'] ) && ! empty( $field['title'] ) ) {
618 add_settings_field( $field_id, $field['title'], $field['callback'], $page, $section_id, $field['args'] );
619 }
620
621 // Register the setting
622 register_setting( $page, $field_id, $field['sanitize_callback'] );
623 }
624 }
625 }
626
627 /**
628 * Maps settings capabilities
629 *
630 * @since 2.2.0 bbPress (r4242)
631 *
632 * @param array $caps Capabilities for meta capability
633 * @param string $cap Capability name
634 * @param int $user_id User id
635 * @param array $args Arguments
636 *
637 * @return array Actual capabilities for meta capability
638 */
639 public static function map_settings_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) {
640
641 // What capability is being checked?
642 switch ( $cap ) {
643
644 // Pages
645 case 'bbp_about_page' : // About and Credits
646 case 'bbp_tools_page' : // Tools Page
647 case 'bbp_tools_repair_page' : // Tools - Repair Page
648 case 'bbp_tools_upgrade_page' : // Tools - Upgrade Page
649 case 'bbp_tools_import_page' : // Tools - Import Page
650 case 'bbp_tools_reset_page' : // Tools - Reset Page
651 case 'bbp_settings_page' : // Settings Page
652
653 // Converter Sections
654 case 'bbp_converter_connection' : // Converter - Connection
655 case 'bbp_converter_options' : // Converter - Options
656
657 // Settings Sections
658 case 'bbp_settings_users' : // Settings - Users
659 case 'bbp_settings_features' : // Settings - Features
660 case 'bbp_settings_theme_compat' : // Settings - Theme compat
661 case 'bbp_settings_root_slugs' : // Settings - Root slugs
662 case 'bbp_settings_single_slugs' : // Settings - Single slugs
663 case 'bbp_settings_user_slugs' : // Settings - User slugs
664 case 'bbp_settings_per_page' : // Settings - Per page
665 case 'bbp_settings_per_rss_page' : // Settings - Per RSS page
666 $caps = array( bbp_admin()->minimum_capability );
667 break;
668
669 // Extend - BuddyPress
670 case 'bbp_settings_buddypress' :
671 if ( ( is_plugin_active( 'buddypress/bp-loader.php' ) && defined( 'BP_VERSION' ) && bp_is_root_blog() ) && is_super_admin() ) {
672 $caps = array( bbp_admin()->minimum_capability );
673 } else {
674 $caps = array( 'do_not_allow' );
675 }
676
677 break;
678
679 // Extend - Akismet
680 case 'bbp_settings_akismet' :
681 if ( ( is_plugin_active( 'akismet/akismet.php' ) && defined( 'AKISMET_VERSION' ) ) && is_super_admin() ) {
682 $caps = array( bbp_admin()->minimum_capability );
683 } else {
684 $caps = array( 'do_not_allow' );
685 }
686
687 break;
688 }
689
690 // Filter & return
691 return (array) apply_filters( 'bbp_map_settings_meta_caps', $caps, $cap, $user_id, $args );
692 }
693
694 /**
695 * Register the importers
696 *
697 * @since 2.0.0 bbPress (r2737)
698 */
699 public function register_importers() {
700
701 // Leave if we're not in the import section
702 if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
703 return;
704 }
705
706 // Load Importer API
707 require_once ABSPATH . 'wp-admin/includes/import.php';
708
709 // Load our importers
710 $importers = apply_filters( 'bbp_importers', array( 'bbpress' ) );
711
712 // Loop through included importers
713 foreach ( $importers as $importer ) {
714
715 // Allow custom importer directory
716 $import_dir = apply_filters( 'bbp_importer_path', $this->admin_dir . 'importers', $importer );
717
718 // Compile the importer path
719 $import_file = trailingslashit( $import_dir ) . $importer . '.php';
720
721 // If the file exists, include it
722 if ( file_exists( $import_file ) ) {
723 require $import_file;
724 }
725 }
726 }
727
728 /**
729 * Add Settings link to plugins area
730 *
731 * @since 2.0.0 bbPress (r2737)
732 *
733 * @param array $links Links array in which we would prepend our link
734 * @param string $file Current plugin basename
735 * @return array Processed links
736 */
737 public static function modify_plugin_action_links( $links, $file ) {
738
739 // Return normal links if not bbPress
740 if ( plugin_basename( bbpress()->basename ) !== $file ) {
741 return $links;
742 }
743
744 // New links to merge into existing links
745 $new_links = array();
746
747 // Settings page link
748 if ( current_user_can( 'bbp_settings_page' ) ) {
749 $new_links['settings'] = '<a href="' . esc_url( add_query_arg( array( 'page' => 'bbpress' ), admin_url( 'options-general.php' ) ) ) . '">' . esc_html__( 'Settings', 'bbpress' ) . '</a>';
750 }
751
752 // About page link
753 if ( current_user_can( 'bbp_about_page' ) ) {
754 $new_links['about'] = '<a href="' . esc_url( add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php' ) ) ) . '">' . esc_html__( 'About', 'bbpress' ) . '</a>';
755 }
756
757 // Add a few links to the existing links array
758 return array_merge( $links, $new_links );
759 }
760
761 /**
762 * Enqueue any admin scripts we might need
763 *
764 * @since 2.2.0 bbPress (r4260)
765 */
766 public function enqueue_scripts() {
767
768 // Get the current screen
769 $current_screen = get_current_screen();
770
771 // Enqueue suggest for forum/topic/reply autocompletes
772 wp_enqueue_script( 'suggest' );
773
774 // Post type checker (only topics and replies)
775 if ( 'post' === $current_screen->base ) {
776 switch ( $current_screen->post_type ) {
777 case bbp_get_reply_post_type() :
778 case bbp_get_topic_post_type() :
779
780 // Enqueue the common JS
781 wp_enqueue_script( 'bbp-admin-common-js' );
782
783 // Topics admin
784 if ( bbp_get_topic_post_type() === $current_screen->post_type ) {
785 wp_enqueue_script( 'bbp-admin-topics-js' );
786
787 // Replies admin
788 } elseif ( bbp_get_reply_post_type() === $current_screen->post_type ) {
789 wp_enqueue_script( 'bbp-admin-replies-js' );
790 }
791
792 break;
793 }
794
795 // Enqueue the badge JS
796 } elseif ( in_array( $current_screen->id, array( 'dashboard_page_bbp-about', 'dashboard_page_bbp-credits' ), true ) ) {
797 wp_enqueue_script( 'bbp-admin-badge-js' );
798 }
799 }
800
801 /**
802 * Enqueue any admin scripts we might need
803 *
804 * @since 2.6.0 bbPress (r5224)
805 */
806 public function enqueue_styles() {
807 wp_enqueue_style( 'bbp-admin-css' );
808 }
809
810 /**
811 * Remove the individual recount and converter menus.
812 * They are grouped together by h2 tabs
813 *
814 * @since 2.0.0 bbPress (r2464)
815 */
816 public function admin_head() {
817
818 // Tools
819 foreach ( bbp_get_tools_admin_pages() as $tool ) {
820 remove_submenu_page( 'tools.php', $tool['page'] );
821 }
822
823 // About
824 remove_submenu_page( 'index.php', 'bbp-about' );
825 remove_submenu_page( 'index.php', 'bbp-credits' );
826 }
827
828 /**
829 * Registers the bbPress admin styling and color schemes
830 *
831 * Because wp-content can exist outside of the WordPress root, there is no
832 * way to be certain what the relative path of admin images is.
833 *
834 * @since 2.6.0 bbPress (r2521)
835 */
836 public function register_admin_styles() {
837
838 // RTL and/or minified
839 $suffix = is_rtl() ? '-rtl' : '';
840 $suffix .= bbp_doing_script_debug() ? '' : '.min';
841
842 // Get the version to use for JS
843 $version = bbp_get_asset_version();
844
845 // Register admin CSS with dashicons dependency
846 wp_register_style( 'bbp-admin-css', $this->css_url . 'admin' . $suffix . '.css', array( 'dashicons' ), $version );
847
848 // Color schemes are not available when running out of src
849 if ( false !== strpos( plugin_basename( bbpress()->file ), 'src' ) ) {
850 return;
851 }
852
853 // Mint
854 wp_admin_css_color(
855 'bbp-mint',
856 esc_html_x( 'Mint', 'admin color scheme', 'bbpress' ),
857 $this->styles_url . 'mint/colors' . $suffix . '.css',
858 array( '#4f6d59', '#33834e', '#5FB37C', '#81c498' ),
859 array( 'base' => '#f1f3f2', 'focus' => '#fff', 'current' => '#fff' )
860 );
861
862 // Evergreen
863 wp_admin_css_color(
864 'bbp-evergreen',
865 esc_html_x( 'Evergreen', 'admin color scheme', 'bbpress' ),
866 $this->styles_url . 'evergreen/colors' . $suffix . '.css',
867 array( '#324d3a', '#446950', '#56b274', '#324d3a' ),
868 array( 'base' => '#f1f3f2', 'focus' => '#fff', 'current' => '#fff' )
869 );
870 }
871
872 /**
873 * Registers the bbPress admin color schemes
874 *
875 * Because wp-content can exist outside of the WordPress root there is no
876 * way to be certain what the relative path of the admin images is.
877 * We are including the two most common configurations here, just in case.
878 *
879 * @since 2.6.0 bbPress (r2521)
880 */
881 public function register_admin_scripts() {
882
883 // Minified
884 $suffix = bbp_doing_script_debug() ? '' : '.min';
885
886 // Get the version to use for JS
887 $version = bbp_get_asset_version();
888
889 // Header JS
890 wp_register_script( 'bbp-admin-common-js', $this->js_url . 'common' . $suffix . '.js', array( 'jquery', 'suggest' ), $version );
891 wp_register_script( 'bbp-admin-topics-js', $this->js_url . 'topics' . $suffix . '.js', array( 'jquery' ), $version );
892 wp_register_script( 'bbp-admin-replies-js', $this->js_url . 'replies' . $suffix . '.js', array( 'jquery', 'suggest' ), $version );
893 wp_register_script( 'bbp-converter', $this->js_url . 'converter' . $suffix . '.js', array( 'jquery', 'postbox', 'dashboard' ), $version );
894
895 // Footer JS
896 wp_register_script( 'bbp-admin-badge-js', $this->js_url . 'badge' . $suffix . '.js', array(), $version, true );
897 }
898
899 /**
900 * Allow keymaster role to save Forums settings
901 *
902 * @since 2.3.0 bbPress (r4678)
903 *
904 * @param string $capability
905 * @return string Return minimum capability
906 */
907 public function option_page_capability_bbpress( $capability = 'manage_options' ) {
908 $capability = $this->minimum_capability;
909 return $capability;
910 }
911
912 /** Ajax ******************************************************************/
913
914 /**
915 * Ajax action for facilitating the forum auto-suggest
916 *
917 * @since 2.2.0 bbPress (r4261)
918 */
919 public function suggest_topic() {
920
921 // Do some very basic request checking
922 $request = ! empty( $_REQUEST['q'] )
923 ? trim( $_REQUEST['q'] )
924 : '';
925
926 // Bail early if empty request
927 if ( empty( $request ) ) {
928 wp_die();
929 }
930
931 // Bail if user cannot moderate
932 if ( ! current_user_can( 'moderate' ) ) {
933 wp_die();
934 }
935
936 // Check the ajax nonce
937 check_ajax_referer( 'bbp_suggest_topic_nonce' );
938
939 // Allow the maximum number of results to be filtered
940 $number = (int) apply_filters( 'bbp_suggest_topic_count', 10 );
941
942 // Try to get some topics
943 $topics = get_posts( array(
944 's' => bbp_db()->esc_like( $_REQUEST['q'] ),
945 'post_type' => bbp_get_topic_post_type(),
946 'posts_per_page' => $number,
947
948 // Performance
949 'nopaging' => true,
950 'suppress_filters' => true,
951 'update_post_term_cache' => false,
952 'update_post_meta_cache' => false,
953 'ignore_sticky_posts' => true,
954 'no_found_rows' => true
955 ) );
956
957 // If we found some topics, loop through and display them
958 if ( ! empty( $topics ) ) {
959 foreach ( (array) $topics as $post ) {
960 printf( esc_html__( '%1$s - %2$s', 'bbpress' ), bbp_get_topic_id( $post->ID ), bbp_get_topic_title( $post->ID ) . "\n" );
961 }
962 }
963 die();
964 }
965
966 /**
967 * Ajax action for facilitating the topic and reply author auto-suggest
968 *
969 * @since 2.4.0 bbPress (r5014)
970 */
971 public function suggest_user() {
972
973 // Do some very basic request checking
974 $request = ! empty( $_REQUEST['q'] )
975 ? trim( $_REQUEST['q'] )
976 : '';
977
978 // Bail early if empty request
979 if ( empty( $request ) ) {
980 wp_die();
981 }
982
983 // Bail if user cannot moderate
984 if ( ! current_user_can( 'moderate' ) ) {
985 wp_die();
986 }
987
988 // Check the ajax nonce
989 check_ajax_referer( 'bbp_suggest_user_nonce' );
990
991 // Fields to retrieve & search by
992 $fields = $search = array( 'ID', 'user_nicename' );
993
994 // Keymasters & Super-Mods can also search by email
995 if ( current_user_can( 'keep_gate' ) || bbp_allow_super_mods() ) {
996
997 // Add user_email to searchable columns
998 array_push( $search, 'user_email' );
999
1000 // Unstrict to also allow some email characters
1001 $strict = false;
1002
1003 // Strict sanitizing if not Keymaster or Super-Mod
1004 } else {
1005 $strict = true;
1006 }
1007
1008 // Sanitize the request value (possibly not strictly)
1009 $suggest = sanitize_user( $request, $strict );
1010
1011 // Bail if searching for invalid user string
1012 if ( empty( $suggest ) ) {
1013 wp_die();
1014 }
1015
1016 // These single characters should not trigger a user query
1017 $disallowed_single_chars = array( '@', '.', '_', '-', '+', '!', '#', '$', '%', '&', '\\', '*', '+', '/', '=', '?', '^', '`', '{', '|', '}', '~' );
1018
1019 // Bail if request is only for the above single characters
1020 if ( in_array( $suggest, $disallowed_single_chars, true ) ) {
1021 wp_die();
1022 }
1023
1024 // Allow the maximum number of results to be filtered
1025 $number = (int) apply_filters( 'bbp_suggest_user_count', 10 );
1026
1027 // Query database for users based on above criteria
1028 $users_query = new WP_User_Query( array(
1029 'search' => '*' . bbp_db()->esc_like( $suggest ) . '*',
1030 'fields' => $fields,
1031 'search_columns' => $search,
1032 'orderby' => 'ID',
1033 'number' => $number,
1034 'count_total' => false
1035 ) );
1036
1037 // If we found some users, loop through and output them to the AJAX
1038 if ( ! empty( $users_query->results ) ) {
1039 foreach ( (array) $users_query->results as $user ) {
1040 printf( esc_html__( '%1$s - %2$s', 'bbpress' ), bbp_get_user_id( $user->ID ), bbp_get_user_nicename( $user->ID, array( 'force' => $user->user_nicename ) ) . "\n" );
1041 }
1042 }
1043 die();
1044 }
1045
1046 /** About *****************************************************************/
1047
1048 /**
1049 * Output the shared screen header for about_screen() & credits_screen()
1050 *
1051 * Contains title, subtitle, and badge area
1052 *
1053 * @since 2.6.0 bbPress (r6604)
1054 */
1055 private function screen_header() {
1056 list( $display_version ) = explode( '-', bbp_get_version() ); ?>
1057
1058 <h1 class="wp-heading-inline"><?php printf( esc_html__( 'Welcome to bbPress %s', 'bbpress' ), $display_version ); ?></h1>
1059 <hr class="wp-header-end">
1060 <div class="about-text"><?php printf( esc_html__( 'bbPress is fun to use, contains no artificial colors or preservatives, and is absolutely wonderful in every environment. Your community is going to love using it.', 'bbpress' ), $display_version ); ?></div>
1061
1062 <span class="bbp-hive" id="bbp-hive"></span>
1063 <div class="bbp-badge" id="bbp-badge">
1064 <span class="bbp-bee" id="bbp-bee"></span>
1065 </div>
1066
1067 <?php
1068 }
1069
1070 /**
1071 * Output the about screen
1072 *
1073 * @since 2.2.0 bbPress (r4159)
1074 *
1075 * @todo Host this remotely.
1076 */
1077 public function about_screen() {
1078 ?>
1079
1080 <div class="wrap about-wrap">
1081
1082 <?php $this->screen_header(); ?>
1083
1084 <h2 class="nav-tab-wrapper">
1085 <a class="nav-tab nav-tab-active" href="<?php echo esc_url( add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php' ) ) ); ?>">
1086 <?php esc_html_e( 'What&#8217;s New', 'bbpress' ); ?>
1087 </a><a class="nav-tab" href="<?php echo esc_url( add_query_arg( array( 'page' => 'bbp-credits' ), admin_url( 'index.php' ) ) ); ?>">
1088 <?php esc_html_e( 'Credits', 'bbpress' ); ?>
1089 </a>
1090 </h2>
1091
1092 <div class="changelog">
1093 <h3><?php esc_html_e( 'Forum Subscriptions', 'bbpress' ); ?></h3>
1094
1095 <div class="feature-section col two-col">
1096 <div class="last-feature">
1097 <h4><?php esc_html_e( 'Subscribe to Forums', 'bbpress' ); ?></h4>
1098 <p><?php esc_html_e( 'Now your users can subscribe to new topics in specific forums.', 'bbpress' ); ?></p>
1099 </div>
1100
1101 <div>
1102 <h4><?php esc_html_e( 'Manage Subscriptions', 'bbpress' ); ?></h4>
1103 <p><?php esc_html_e( 'Your users can manage all of their subscriptions in one convenient location.', 'bbpress' ); ?></p>
1104 </div>
1105 </div>
1106 </div>
1107
1108 <div class="changelog">
1109 <h3><?php esc_html_e( 'Converters', 'bbpress' ); ?></h3>
1110
1111 <div class="feature-section col one-col">
1112 <div class="last-feature">
1113 <p><?php esc_html_e( 'We&#8217;re all abuzz about the hive of new importers, AEF, Drupal, FluxBB, Kunena Forums for Joomla, MyBB, Phorum, PHPFox, PHPWind, PunBB, SMF, Xenforo and XMB. Existing importers are now sweeter than honey with improved importing stickies, topic tags, forum categories and the sting is now gone if you need to remove imported users.', 'bbpress' ); ?></p>
1114 </div>
1115 </div>
1116
1117 <div class="feature-section col three-col">
1118 <div>
1119 <h4><?php esc_html_e( 'Theme Compatibility', 'bbpress' ); ?></h4>
1120 <p><?php esc_html_e( 'Better handling of styles and scripts in the template stack.', 'bbpress' ); ?></p>
1121 </div>
1122
1123 <div>
1124 <h4><?php esc_html_e( 'Polyglot support', 'bbpress' ); ?></h4>
1125 <p><?php esc_html_e( 'bbPress fully supports automatic translation updates.', 'bbpress' ); ?></p>
1126 </div>
1127
1128 <div class="last-feature">
1129 <h4><?php esc_html_e( 'User capabilities', 'bbpress' ); ?></h4>
1130 <p><?php esc_html_e( 'Roles and capabilities have been swept through, cleaned up, and simplified.', 'bbpress' ); ?></p>
1131 </div>
1132 </div>
1133 </div>
1134
1135 <div class="return-to-dashboard">
1136 <a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bbpress' ), admin_url( 'options-general.php' ) ) ); ?>"><?php esc_html_e( 'Go to Forum Settings', 'bbpress' ); ?></a>
1137 </div>
1138
1139 </div>
1140
1141 <?php
1142 }
1143
1144 /**
1145 * Output the credits screen
1146 *
1147 * @since 2.2.0 bbPress (r4159)
1148 *
1149 * @todo Host this remotely.
1150 */
1151 public function credits_screen() {
1152 ?>
1153
1154 <div class="wrap about-wrap">
1155
1156 <?php $this->screen_header(); ?>
1157
1158 <h2 class="nav-tab-wrapper">
1159 <a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php' ) ) ); ?>" class="nav-tab">
1160 <?php esc_html_e( 'What&#8217;s New', 'bbpress' ); ?>
1161 </a><a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bbp-credits' ), admin_url( 'index.php' ) ) ); ?>" class="nav-tab nav-tab-active">
1162 <?php esc_html_e( 'Credits', 'bbpress' ); ?>
1163 </a>
1164 </h2>
1165
1166 <p class="about-description"><?php esc_html_e( 'bbPress is created by a worldwide swarm of busy, busy bees.', 'bbpress' ); ?></p>
1167
1168 <h3 class="wp-people-group"><?php esc_html_e( 'Project Leaders', 'bbpress' ); ?></h3>
1169 <ul class="wp-people-group " id="wp-people-group-project-leaders">
1170 <li class="wp-person" id="wp-person-matt">
1171 <a href="https://profiles.wordpress.org/matt" class="web"><img src="http://0.gravatar.com/avatar/767fc9c115a1b989744c755db47feb60?s=120" class="gravatar" alt="" />Matt Mullenweg</a>
1172 <span class="title"><?php esc_html_e( 'Founding Developer', 'bbpress' ); ?></span>
1173 </li>
1174 <li class="wp-person" id="wp-person-johnjamesjacoby">
1175 <a href="https://profiles.wordpress.org/johnjamesjacoby" class="web"><img src="http://0.gravatar.com/avatar/7a2644fb53ae2f7bfd7143b504af396c?s=120" class="gravatar" alt="" />John James Jacoby</a>
1176 <span class="title"><?php esc_html_e( 'Lead Developer', 'bbpress' ); ?></span>
1177 </li>
1178 <li class="wp-person" id="wp-person-jmdodd">
1179 <a href="https://profiles.wordpress.org/jmdodd" class="web"><img src="http://0.gravatar.com/avatar/6a7c997edea340616bcc6d0fe03f65dd?s=120" class="gravatar" alt="" />Jennifer M. Dodd</a>
1180 <span class="title"><?php esc_html_e( 'Feature Virtuoso', 'bbpress' ); ?></span>
1181 </li>
1182 <li class="wp-person" id="wp-person-netweb">
1183 <a href="https://profiles.wordpress.org/netweb" class="web"><img src="http://0.gravatar.com/avatar/97e1620b501da675315ba7cfb740e80f?s=120" class="gravatar" alt="" />Stephen Edgar</a>
1184 <span class="title"><?php esc_html_e( 'Tool Maven', 'bbpress' ); ?></span>
1185 </li>
1186 </ul>
1187
1188 <h3 class="wp-people-group"><?php esc_html_e( 'Contributing Developers', 'bbpress' ); ?></h3>
1189 <ul class="wp-people-group " id="wp-people-group-contributing-developers">
1190 <li class="wp-person" id="wp-person-sergeybiryukov">
1191 <a href="https://profiles.wordpress.org/SergeyBiryukov" class="web"><img src="http://0.gravatar.com/avatar/750b7b0fcd855389264c2b1294d61bd6?s=120" class="gravatar" alt="" />Sergey Biryukov</a>
1192 <span class="title"><?php esc_html_e( 'Core Developer', 'bbpress' ); ?></span>
1193 </li>
1194 <li class="wp-person" id="wp-person-thebrandonallen">
1195 <a href="https://profiles.wordpress.org/thebrandonallen" class="web"><img src="http://0.gravatar.com/avatar/6d3f77bf3c9ca94c406dea401b566950?s?s=120" class="gravatar" alt="" />Brandon Allen</a>
1196 <span class="title"><?php esc_html_e( 'Core Developer', 'bbpress' ); ?></span>
1197 </li>
1198 </ul>
1199
1200 <h3 class="wp-people-group"><?php esc_html_e( 'Project Emeriti', 'bbpress' ); ?></h3>
1201 <ul class="wp-people-group " id="wp-people-group-project-emeriti">
1202 <li class="wp-person" id="wp-person-gautamgupta">
1203 <a href="https://profiles.wordpress.org/gautamgupta" class="web"><img src="http://0.gravatar.com/avatar/b0810422cbe6e4eead4def5ae7a90b34?s=120" class="gravatar" alt="" />Gautam Gupta</a>
1204 <span class="title"><?php esc_html_e( 'Feature Developer', 'bbpress' ); ?></span>
1205 </li>
1206 <li class="wp-person" id="wp-person-jaredatch">
1207 <a href="https://profiles.wordpress.org/jaredatch" class="web"><img src="http://0.gravatar.com/avatar/e341eca9e1a85dcae7127044301b4363?s=120" class="gravatar" alt="" />Jared Atchison</a>
1208 <span class="title"><?php esc_html_e( 'Integration Testing', 'bbpress' ); ?></span>
1209 </li>
1210 </ul>
1211
1212 <h3 class="wp-people-group"><?php esc_html_e( 'Contributors to bbPress 2.6', 'bbpress' ); ?></h3>
1213 <p class="wp-credits-list">
1214 <a href="https://profiles.wordpress.org/alex-ye">alex-ye</a>,
1215 <a href="https://profiles.wordpress.org/ankit-k-gupta">ankit-k-gupta</a>,
1216 <a href="https://profiles.wordpress.org/barryhughes-1">barryhughes-1</a>,
1217 <a href="https://profiles.wordpress.org/boonebgorges">boonebgorges</a>,
1218 <a href="https://profiles.wordpress.org/casiepa">casiepa</a>,
1219 <a href="https://profiles.wordpress.org/cfinke">cfinke</a>,
1220 <a href="https://profiles.wordpress.org/danielbachhuber">danielbachhuber</a>,
1221 <a href="https://profiles.wordpress.org/dimitrovadrian">dimitrov.adrian</a>,
1222 <a href="https://profiles.wordpress.org/DJPaul">DJPaul</a>,
1223 <a href="https://profiles.wordpress.org/DrPepper75">DrPepper75</a>,
1224 <a href="https://profiles.wordpress.org/eoigal">eoigal</a>,
1225 <a href="https://profiles.wordpress.org/ericlewis">ericlewis</a>,
1226 <a href="https://profiles.wordpress.org/extendwings">extendwings</a>,
1227 <a href="https://profiles.wordpress.org/Faison">Faison</a>,
1228 <a href="https://profiles.wordpress.org/gautamgupta">gautamgupta</a>,
1229 <a href="https://profiles.wordpress.org/glynwintle">glynwintle</a>,
1230 <a href="https://profiles.wordpress.org/gusrb84">gusrb84</a>,
1231 <a href="https://profiles.wordpress.org/hellofromTonya">hellofromTonya</a>,
1232 <a href="https://profiles.wordpress.org/icu0755">icu0755</a>,
1233 <a href="https://profiles.wordpress.org/imath">imath</a>,
1234 <a href="https://profiles.wordpress.org/jbrinley">jbrinley</a>,
1235 <a href="https://profiles.wordpress.org/jdgrimes">jdgrimes</a>,
1236 <a href="https://profiles.wordpress.org/jmdodd">jmdodd</a>,
1237 <a href="https://profiles.wordpress.org/joedolson">joedolson</a>,
1238 <a href="https://profiles.wordpress.org/johnbillion">johnbillion</a>,
1239 <a href="https://profiles.wordpress.org/johnjamesjacoby">johnjamesjacoby</a>,
1240 <a href="https://profiles.wordpress.org/jorbin">jorbin</a>,
1241 <a href="https://profiles.wordpress.org/jreeve">jreeve</a>,
1242 <a href="https://profiles.wordpress.org/kadamwhite ">kadamwhite</a>,
1243 <a href="https://profiles.wordpress.org/karlgroves">karlgroves</a>,
1244 <a href="https://profiles.wordpress.org/mat-lipe">mat-lipe</a>,
1245 <a href="https://profiles.wordpress.org/mazengamal">mazengamal</a>,
1246 <a href="https://profiles.wordpress.org/melchoyce">melchoyce</a>,
1247 <a href="https://profiles.wordpress.org/mercime">mercime</a>,
1248 <a href="https://profiles.wordpress.org/michaelbeil">michaelbeil</a>,
1249 <a href="https://profiles.wordpress.org/mikelopez">mikelopez</a>,
1250 <a href="https://profiles.wordpress.org/mordauk">mordauk</a>,
1251 <a href="https://profiles.wordpress.org/mspecht">mspecht</a>,
1252 <a href="https://profiles.wordpress.org/MZAWeb">MZAWeb</a>,
1253 <a href="https://profiles.wordpress.org/netweb">netweb</a>,
1254 <a href="https://profiles.wordpress.org/ocean90">ocean90</a>,
1255 <a href="https://profiles.wordpress.org/offereins">offereins</a>,
1256 <a href="https://profiles.wordpress.org/pareshradadiya">pareshradadiya</a>,
1257 <a href="https://profiles.wordpress.org/r-a-y">r-a-y</a>,
1258 <a href="https://profiles.wordpress.org/ramiy">ramiy</a>,
1259 <a href="https://profiles.wordpress.org/robin-w">robin-w</a>,
1260 <a href="https://profiles.wordpress.org/robkk">robkk</a>,
1261 <a href="https://profiles.wordpress.org/ryelle">ryelle</a>,
1262 <a href="https://profiles.wordpress.org/satollo">satollo</a>,
1263 <a href="https://profiles.wordpress.org/SergeyBiryukov">Sergey Biryukov</a>,
1264 <a href="https://profiles.wordpress.org/SGr33n">SGr33n</a>,
1265 <a href="https://profiles.wordpress.org/stephdau">stephdau</a>,
1266 <a href="https://profiles.wordpress.org/tharsheblows">tharsheblows</a>,
1267 <a href="https://profiles.wordpress.org/thebrandonallen">thebrandonallen</a>,
1268 <a href="https://profiles.wordpress.org/tobyhawkins">tobyhawkins</a>,
1269 <a href="https://profiles.wordpress.org/tonyrix">tonyrix</a>,
1270 <a href="https://profiles.wordpress.org/treyhunner">treyhunner</a>,
1271 <a href="https://profiles.wordpress.org/tw2113">tw2113</a>,
1272 <a href="https://profiles.wordpress.org/xknown">xknown</a>
1273 </p>
1274
1275 <div class="return-to-dashboard">
1276 <a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bbpress' ), admin_url( 'options-general.php' ) ) ); ?>"><?php esc_html_e( 'Go to Forum Settings', 'bbpress' ); ?></a>
1277 </div>
1278
1279 </div>
1280
1281 <?php
1282 }
1283
1284 /** Updaters **************************************************************/
1285
1286 /**
1287 * Update all bbPress forums across all sites
1288 *
1289 * @since 2.1.0 bbPress (r3689)
1290 */
1291 public static function update_screen() {
1292
1293 // Get action
1294 $action = isset( $_GET['action'] ) ? $_GET['action'] : ''; ?>
1295
1296 <div class="wrap">
1297 <h1 class="wp-heading-inline"><?php esc_html_e( 'Update Forum', 'bbpress' ); ?></h1>
1298 <hr class="wp-header-end">
1299
1300 <?php
1301
1302 // Taking action
1303 switch ( $action ) {
1304 case 'bbp-update' :
1305
1306 // Run the full updater
1307 bbp_version_updater(); ?>
1308
1309 <p><?php esc_html_e( 'All done!', 'bbpress' ); ?></p>
1310 <a class="button" href="index.php?page=bbp-update"><?php esc_html_e( 'Go Back', 'bbpress' ); ?></a>
1311
1312 <?php
1313
1314 break;
1315
1316 case 'show' :
1317 default : ?>
1318
1319 <p><?php esc_html_e( 'You can update your forum through this page. Hit the link below to update.', 'bbpress' ); ?></p>
1320 <p><a class="button" href="index.php?page=bbp-update&amp;action=bbp-update"><?php esc_html_e( 'Update Forum', 'bbpress' ); ?></a></p>
1321
1322 <?php break;
1323
1324 } ?>
1325
1326 </div><?php
1327 }
1328
1329 /**
1330 * Update all bbPress forums across all sites
1331 *
1332 * @since 2.1.0 bbPress (r3689)
1333 */
1334 public static function network_update_screen() {
1335 $bbp_db = bbp_db();
1336
1337 // Get action
1338 $action = isset( $_GET['action'] ) ? $_GET['action'] : ''; ?>
1339
1340 <div class="wrap">
1341 <h1 class="wp-heading-inline"><?php esc_html_e( 'Update Forums', 'bbpress' ); ?></h1>
1342 <hr class="wp-header-end">
1343
1344 <?php
1345
1346 // Taking action
1347 switch ( $action ) {
1348 case 'bbpress-update' :
1349
1350 // Site counter
1351 $n = isset( $_GET['n'] ) ? intval( $_GET['n'] ) : 0;
1352
1353 // Get blogs 5 at a time
1354 $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 );
1355
1356 // No blogs so all done!
1357 if ( empty( $blogs ) ) : ?>
1358
1359 <p><?php esc_html_e( 'All done!', 'bbpress' ); ?></p>
1360 <a class="button" href="update-core.php?page=bbpress-update"><?php esc_html_e( 'Go Back', 'bbpress' ); ?></a>
1361
1362 <?php
1363
1364 // Still have sites to loop through
1365 else : ?>
1366
1367 <ul>
1368
1369 <?php foreach ( (array) $blogs as $details ) :
1370
1371 // Get site URLs
1372 $site_url = get_site_url( $details['blog_id'] );
1373 $admin_url = get_site_url( $details['blog_id'], 'wp-admin.php', 'admin' );
1374 $remote_url = add_query_arg( array(
1375 'page' => 'bbp-update',
1376 'action' => 'bbp-update'
1377 ), $admin_url ); ?>
1378
1379 <li><?php echo esc_html( $site_url ); ?></li>
1380
1381 <?php
1382
1383 // Get the response of the bbPress update on this site
1384 $response = wp_remote_get(
1385 $remote_url,
1386 array(
1387 'timeout' => 30,
1388 'httpversion' => '1.1'
1389 )
1390 );
1391
1392 // Site errored out, no response?
1393 if ( is_wp_error( $response ) ) {
1394 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>' ) );
1395 }
1396
1397 // Switch to the new site
1398 bbp_switch_to_site( $details[ 'blog_id' ] );
1399
1400 $basename = bbpress()->basename;
1401
1402 // Run the updater on this site
1403 if ( is_plugin_active_for_network( $basename ) || is_plugin_active( $basename ) ) {
1404 bbp_version_updater();
1405 }
1406
1407 // Restore original site
1408 bbp_restore_current_site();
1409
1410 // Do some actions to allow plugins to do things too
1411 do_action( 'after_bbpress_upgrade', $response );
1412 do_action( 'bbp_upgrade_site', $details[ 'blog_id' ] );
1413
1414 endforeach; ?>
1415
1416 </ul>
1417
1418 <p>
1419 <?php esc_html_e( 'If your browser doesn&#8217;t start loading the next page automatically, click this link:', 'bbpress' ); ?>
1420 <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', 'bbpress' ); ?></a>
1421 </p>
1422 <script type='text/javascript'>
1423 <!--
1424 function nextpage() {
1425 location.href = 'update-core.php?page=bbpress-update&action=bbpress-update&n=<?php echo ( $n + 5 ) ?>';
1426 }
1427 setTimeout( 'nextpage()', 250 );
1428 //-->
1429 </script><?php
1430
1431 endif;
1432
1433 break;
1434
1435 case 'show' :
1436 default : ?>
1437
1438 <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>
1439 <p><a class="button" href="update-core.php?page=bbpress-update&amp;action=bbpress-update"><?php esc_html_e( 'Update Forums', 'bbpress' ); ?></a></p>
1440
1441 <?php break;
1442
1443 } ?>
1444
1445 </div><?php
1446 }
1447 }
1448 endif; // class_exists check
1449