PluginProbe
bbPress / 2.6.19
bbPress v2.6.19
2.6.19 2.6.18 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 All 74 releases
bbpress / includes / admin / classes / class-bbp-admin.php

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

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