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