PluginProbe
bbPress / 2.6.17
bbPress v2.6.17
2.6.17 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 All 72 releases
bbpress / includes / admin / classes / class-bbp-admin.php

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

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