[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/src/includes/admin/classes/ -> class-bbp-admin.php (source)

   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. %s or %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                  // Add the field
 590                  if ( ! empty( $field['callback'] ) && ! empty( $field['title'] ) ) {
 591                      add_settings_field( $field_id, $field['title'], $field['callback'], $page, $section_id, $field['args'] );
 592                  }
 593  
 594                  // Register the setting
 595                  register_setting( $page, $field_id, $field['sanitize_callback'] );
 596              }
 597          }
 598      }
 599  
 600      /**
 601       * Maps settings capabilities
 602       *
 603       * @since 2.2.0 bbPress (r4242)
 604       *
 605       * @param array $caps Capabilities for meta capability
 606       * @param string $cap Capability name
 607       * @param int $user_id User id
 608       * @param array $args Arguments
 609       *
 610       * @return array Actual capabilities for meta capability
 611       */
 612  	public static function map_settings_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) {
 613  
 614          // What capability is being checked?
 615          switch ( $cap ) {
 616  
 617              // Pages
 618              case 'bbp_about_page'            : // About and Credits
 619              case 'bbp_tools_page'            : // Tools Page
 620              case 'bbp_tools_repair_page'     : // Tools - Repair Page
 621              case 'bbp_tools_upgrade_page'    : // Tools - Upgrade Page
 622              case 'bbp_tools_import_page'     : // Tools - Import Page
 623              case 'bbp_tools_reset_page'      : // Tools - Reset Page
 624              case 'bbp_settings_page'         : // Settings Page
 625  
 626              // Converter Sections
 627              case 'bbp_converter_connection'  : // Converter - Connection
 628              case 'bbp_converter_options'     : // Converter - Options
 629  
 630              // Settings Sections
 631              case 'bbp_settings_users'        : // Settings - Users
 632              case 'bbp_settings_features'     : // Settings - Features
 633              case 'bbp_settings_theme_compat' : // Settings - Theme compat
 634              case 'bbp_settings_root_slugs'   : // Settings - Root slugs
 635              case 'bbp_settings_single_slugs' : // Settings - Single slugs
 636              case 'bbp_settings_user_slugs'   : // Settings - User slugs
 637              case 'bbp_settings_per_page'     : // Settings - Per page
 638              case 'bbp_settings_per_rss_page' : // Settings - Per RSS page
 639                  $caps = array( bbp_admin()->minimum_capability );
 640                  break;
 641  
 642              // Extend - BuddyPress
 643              case 'bbp_settings_buddypress' :
 644                  if ( ( is_plugin_active( 'buddypress/bp-loader.php' ) && defined( 'BP_VERSION' ) && bp_is_root_blog() ) && is_super_admin() ) {
 645                      $caps = array( bbp_admin()->minimum_capability );
 646                  } else {
 647                      $caps = array( 'do_not_allow' );
 648                  }
 649  
 650                  break;
 651  
 652              // Extend - Akismet
 653              case 'bbp_settings_akismet' :
 654                  if ( ( is_plugin_active( 'akismet/akismet.php' ) && defined( 'AKISMET_VERSION' ) ) && is_super_admin() ) {
 655                      $caps = array( bbp_admin()->minimum_capability );
 656                  } else {
 657                      $caps = array( 'do_not_allow' );
 658                  }
 659  
 660                  break;
 661          }
 662  
 663          // Filter & return
 664          return (array) apply_filters( 'bbp_map_settings_meta_caps', $caps, $cap, $user_id, $args );
 665      }
 666  
 667      /**
 668       * Register the importers
 669       *
 670       * @since 2.0.0 bbPress (r2737)
 671       */
 672  	public function register_importers() {
 673  
 674          // Leave if we're not in the import section
 675          if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
 676              return;
 677          }
 678  
 679          // Load Importer API
 680          require_once ABSPATH . 'wp-admin/includes/import.php';
 681  
 682          // Load our importers
 683          $importers = apply_filters( 'bbp_importers', array( 'bbpress' ) );
 684  
 685          // Loop through included importers
 686          foreach ( $importers as $importer ) {
 687  
 688              // Allow custom importer directory
 689              $import_dir  = apply_filters( 'bbp_importer_path', $this->admin_dir . 'importers', $importer );
 690  
 691              // Compile the importer path
 692              $import_file = trailingslashit( $import_dir ) . $importer . '.php';
 693  
 694              // If the file exists, include it
 695              if ( file_exists( $import_file ) ) {
 696                  require $import_file;
 697              }
 698          }
 699      }
 700  
 701      /**
 702       * Add Settings link to plugins area
 703       *
 704       * @since 2.0.0 bbPress (r2737)
 705       *
 706       * @param array $links Links array in which we would prepend our link
 707       * @param string $file Current plugin basename
 708       * @return array Processed links
 709       */
 710  	public static function modify_plugin_action_links( $links, $file ) {
 711  
 712          // Return normal links if not bbPress
 713          if ( plugin_basename( bbpress()->basename ) !== $file ) {
 714              return $links;
 715          }
 716  
 717          // New links to merge into existing links
 718          $new_links = array();
 719  
 720          // Settings page link
 721          if ( current_user_can( 'bbp_settings_page' ) ) {
 722              $new_links['settings'] = '<a href="' . esc_url( add_query_arg( array( 'page' => 'bbpress'   ), admin_url( 'options-general.php' ) ) ) . '">' . esc_html__( 'Settings', 'bbpress' ) . '</a>';
 723          }
 724  
 725          // About page link
 726          if ( current_user_can( 'bbp_about_page' ) ) {
 727              $new_links['about']    = '<a href="' . esc_url( add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php'           ) ) ) . '">' . esc_html__( 'About',    'bbpress' ) . '</a>';
 728          }
 729  
 730          // Add a few links to the existing links array
 731          return array_merge( $links, $new_links );
 732      }
 733  
 734      /**
 735       * Enqueue any admin scripts we might need
 736       *
 737       * @since 2.2.0 bbPress (r4260)
 738       */
 739  	public function enqueue_scripts() {
 740  
 741          // Get the current screen
 742          $current_screen = get_current_screen();
 743  
 744          // Enqueue suggest for forum/topic/reply autocompletes
 745          wp_enqueue_script( 'suggest' );
 746  
 747          // Post type checker (only topics and replies)
 748          if ( 'post' === $current_screen->base ) {
 749              switch ( $current_screen->post_type ) {
 750                  case bbp_get_reply_post_type() :
 751                  case bbp_get_topic_post_type() :
 752  
 753                      // Enqueue the common JS
 754                      wp_enqueue_script( 'bbp-admin-common-js' );
 755  
 756                      // Topics admin
 757                      if ( bbp_get_topic_post_type() === $current_screen->post_type ) {
 758                          wp_enqueue_script( 'bbp-admin-topics-js' );
 759  
 760                      // Replies admin
 761                      } elseif ( bbp_get_reply_post_type() === $current_screen->post_type ) {
 762                          wp_enqueue_script( 'bbp-admin-replies-js' );
 763                      }
 764  
 765                      break;
 766              }
 767  
 768          // Enqueue the badge JS
 769          } elseif ( in_array( $current_screen->id, array( 'dashboard_page_bbp-about', 'dashboard_page_bbp-credits' ), true ) ) {
 770              wp_enqueue_script( 'bbp-admin-badge-js' );
 771          }
 772      }
 773  
 774      /**
 775       * Enqueue any admin scripts we might need
 776       *
 777       * @since 2.6.0 bbPress (r5224)
 778       */
 779  	public function enqueue_styles() {
 780          wp_enqueue_style( 'bbp-admin-css' );
 781      }
 782  
 783      /**
 784       * Remove the individual recount and converter menus.
 785       * They are grouped together by h2 tabs
 786       *
 787       * @since 2.0.0 bbPress (r2464)
 788       */
 789  	public function admin_head() {
 790  
 791          // Tools
 792          foreach ( bbp_get_tools_admin_pages() as $tool ) {
 793              remove_submenu_page( 'tools.php', $tool['page'] );
 794          }
 795  
 796          // About
 797          remove_submenu_page( 'index.php', 'bbp-about'   );
 798          remove_submenu_page( 'index.php', 'bbp-credits' );
 799      }
 800  
 801      /**
 802       * Registers the bbPress admin styling and color schemes
 803       *
 804       * Because wp-content can exist outside of the WordPress root, there is no
 805       * way to be certain what the relative path of admin images is.
 806       *
 807       * @since 2.6.0 bbPress (r2521)
 808       */
 809  	public function register_admin_styles() {
 810  
 811          // RTL and/or minified
 812          $suffix  = is_rtl() ? '-rtl' : '';
 813          $suffix .= defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
 814  
 815          // Get the version to use for JS
 816          $version = bbp_get_version();
 817  
 818          // Register admin CSS with dashicons dependency
 819          wp_register_style( 'bbp-admin-css', $this->css_url . 'admin' . $suffix . '.css', array( 'dashicons' ), $version );
 820  
 821          // Color schemes are not available when running out of src
 822          if ( false !== strpos( plugin_basename( bbpress()->file ), 'src' ) ) {
 823              return;
 824          }
 825  
 826          // Mint
 827          wp_admin_css_color(
 828              'bbp-mint',
 829              esc_html_x( 'Mint', 'admin color scheme', 'bbpress' ),
 830              $this->styles_url . 'mint/colors' . $suffix . '.css',
 831              array( '#4f6d59', '#33834e', '#5FB37C', '#81c498' ),
 832              array( 'base' => '#f1f3f2', 'focus' => '#fff', 'current' => '#fff' )
 833          );
 834  
 835          // Evergreen
 836          wp_admin_css_color(
 837              'bbp-evergreen',
 838              esc_html_x( 'Evergreen', 'admin color scheme', 'bbpress' ),
 839              $this->styles_url . 'evergreen/colors' . $suffix . '.css',
 840              array( '#324d3a', '#446950', '#56b274', '#324d3a' ),
 841              array( 'base' => '#f1f3f2', 'focus' => '#fff', 'current' => '#fff' )
 842          );
 843      }
 844  
 845      /**
 846       * Registers the bbPress admin color schemes
 847       *
 848       * Because wp-content can exist outside of the WordPress root there is no
 849       * way to be certain what the relative path of the admin images is.
 850       * We are including the two most common configurations here, just in case.
 851       *
 852       * @since 2.6.0 bbPress (r2521)
 853       */
 854  	public function register_admin_scripts() {
 855  
 856          // Minified
 857          $suffix  = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
 858  
 859          // Get the version to use for JS
 860          $version = bbp_get_version();
 861  
 862          // Header JS
 863          wp_register_script( 'bbp-admin-common-js',  $this->js_url . 'common'    . $suffix . '.js', array( 'jquery', 'suggest'              ), $version );
 864          wp_register_script( 'bbp-admin-topics-js',  $this->js_url . 'topics'    . $suffix . '.js', array( 'jquery'                         ), $version );
 865          wp_register_script( 'bbp-admin-replies-js', $this->js_url . 'replies'   . $suffix . '.js', array( 'jquery', 'suggest'              ), $version );
 866          wp_register_script( 'bbp-converter',        $this->js_url . 'converter' . $suffix . '.js', array( 'jquery', 'postbox', 'dashboard' ), $version );
 867  
 868          // Footer JS
 869          wp_register_script( 'bbp-admin-badge-js',   $this->js_url . 'badge' . $suffix . '.js', array(), $version, true );
 870      }
 871  
 872      /**
 873       * Allow keymaster role to save Forums settings
 874       *
 875       * @since 2.3.0 bbPress (r4678)
 876       *
 877       * @param string $capability
 878       * @return string Return minimum capability
 879       */
 880  	public function option_page_capability_bbpress( $capability = 'manage_options' ) {
 881          $capability = $this->minimum_capability;
 882          return $capability;
 883      }
 884  
 885      /** Ajax ******************************************************************/
 886  
 887      /**
 888       * Ajax action for facilitating the forum auto-suggest
 889       *
 890       * @since 2.2.0 bbPress (r4261)
 891       */
 892  	public function suggest_topic() {
 893  
 894          // Bail early if no request
 895          if ( empty( $_REQUEST['q'] ) ) {
 896              wp_die( '0' );
 897          }
 898  
 899          // Bail if user cannot moderate - only moderators can change hierarchy
 900          if ( ! current_user_can( 'moderate' ) ) {
 901              wp_die( '0' );
 902          }
 903  
 904          // Check the ajax nonce
 905          check_ajax_referer( 'bbp_suggest_topic_nonce' );
 906  
 907          // Try to get some topics
 908          $topics = get_posts( array(
 909              's'         => bbp_db()->esc_like( $_REQUEST['q'] ),
 910              'post_type' => bbp_get_topic_post_type()
 911          ) );
 912  
 913          // If we found some topics, loop through and display them
 914          if ( ! empty( $topics ) ) {
 915              foreach ( (array) $topics as $post ) {
 916                  printf( esc_html__( '%s - %s', 'bbpress' ), bbp_get_topic_id( $post->ID ), bbp_get_topic_title( $post->ID ) . "\n" );
 917              }
 918          }
 919          die();
 920      }
 921  
 922      /**
 923       * Ajax action for facilitating the topic and reply author auto-suggest
 924       *
 925       * @since 2.4.0 bbPress (r5014)
 926       */
 927  	public function suggest_user() {
 928  
 929          // Bail early if no request
 930          if ( empty( $_REQUEST['q'] ) ) {
 931              wp_die( '0' );
 932          }
 933  
 934          // Bail if user cannot moderate - only moderators can change authorship
 935          if ( ! current_user_can( 'moderate' ) ) {
 936              wp_die( '0' );
 937          }
 938  
 939          // Check the ajax nonce
 940          check_ajax_referer( 'bbp_suggest_user_nonce' );
 941  
 942          // Try to get some users
 943          $users_query = new WP_User_Query( array(
 944              'search'         => '*' . bbp_db()->esc_like( $_REQUEST['q'] ) . '*',
 945              'fields'         => array( 'ID', 'user_nicename' ),
 946              'search_columns' => array( 'ID', 'user_nicename', 'user_email' ),
 947              'orderby'        => 'ID'
 948          ) );
 949  
 950          // If we found some users, loop through and display them
 951          if ( ! empty( $users_query->results ) ) {
 952              foreach ( (array) $users_query->results as $user ) {
 953                  printf( esc_html__( '%s - %s', 'bbpress' ), bbp_get_user_id( $user->ID ), bbp_get_user_nicename( $user->ID, array( 'force' => $user->user_nicename ) ) . "\n" );
 954              }
 955          }
 956          die();
 957      }
 958  
 959      /** About *****************************************************************/
 960  
 961      /**
 962       * Output the shared screen header for about_screen() & credits_screen()
 963       *
 964       * Contains title, subtitle, and badge area
 965       *
 966       * @since 2.6.0 bbPress (r6604)
 967       */
 968  	private function screen_header() {
 969          list( $display_version ) = explode( '-', bbp_get_version() ); ?>
 970  
 971          <h1 class="wp-heading-inline"><?php printf( esc_html__( 'Welcome to bbPress %s', 'bbpress' ), $display_version ); ?></h1>
 972          <hr class="wp-header-end">
 973          <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>
 974  
 975          <span class="bbp-hive" id="bbp-hive"></span>
 976          <div class="bbp-badge" id="bbp-badge">
 977              <span class="bbp-bee" id="bbp-bee"></span>
 978          </div>
 979  
 980          <?php
 981      }
 982  
 983      /**
 984       * Output the about screen
 985       *
 986       * @since 2.2.0 bbPress (r4159)
 987       *
 988       * @todo Host this remotely.
 989       */
 990  	public function about_screen() {
 991          ?>
 992  
 993          <div class="wrap about-wrap">
 994  
 995              <?php $this->screen_header(); ?>
 996  
 997              <h2 class="nav-tab-wrapper">
 998                  <a class="nav-tab nav-tab-active" href="<?php echo esc_url( add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php' ) ) ); ?>">
 999                      <?php esc_html_e( 'What&#8217;s New', 'bbpress' ); ?>
1000                  </a><a class="nav-tab" href="<?php echo esc_url( add_query_arg( array( 'page' => 'bbp-credits' ), admin_url( 'index.php' ) ) ); ?>">
1001                      <?php esc_html_e( 'Credits', 'bbpress' ); ?>
1002                  </a>
1003              </h2>
1004  
1005              <div class="changelog">
1006                  <h3><?php esc_html_e( 'Forum Subscriptions', 'bbpress' ); ?></h3>
1007  
1008                  <div class="feature-section col two-col">
1009                      <div class="last-feature">
1010                          <h4><?php esc_html_e( 'Subscribe to Forums', 'bbpress' ); ?></h4>
1011                          <p><?php esc_html_e( 'Now your users can subscribe to new topics in specific forums.', 'bbpress' ); ?></p>
1012                      </div>
1013  
1014                      <div>
1015                          <h4><?php esc_html_e( 'Manage Subscriptions', 'bbpress' ); ?></h4>
1016                          <p><?php esc_html_e( 'Your users can manage all of their subscriptions in one convenient location.', 'bbpress' ); ?></p>
1017                      </div>
1018                  </div>
1019              </div>
1020  
1021              <div class="changelog">
1022                  <h3><?php esc_html_e( 'Converters', 'bbpress' ); ?></h3>
1023  
1024                  <div class="feature-section col one-col">
1025                      <div class="last-feature">
1026                          <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>
1027                      </div>
1028                  </div>
1029  
1030                  <div class="feature-section col three-col">
1031                      <div>
1032                          <h4><?php esc_html_e( 'Theme Compatibility', 'bbpress' ); ?></h4>
1033                          <p><?php esc_html_e( 'Better handling of styles and scripts in the template stack.', 'bbpress' ); ?></p>
1034                      </div>
1035  
1036                      <div>
1037                          <h4><?php esc_html_e( 'Polyglot support', 'bbpress' ); ?></h4>
1038                          <p><?php esc_html_e( 'bbPress fully supports automatic translation updates.', 'bbpress' ); ?></p>
1039                      </div>
1040  
1041                      <div class="last-feature">
1042                          <h4><?php esc_html_e( 'User capabilities', 'bbpress' ); ?></h4>
1043                          <p><?php esc_html_e( 'Roles and capabilities have been swept through, cleaned up, and simplified.', 'bbpress' ); ?></p>
1044                      </div>
1045                  </div>
1046              </div>
1047  
1048              <div class="return-to-dashboard">
1049                  <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>
1050              </div>
1051  
1052          </div>
1053  
1054          <?php
1055      }
1056  
1057      /**
1058       * Output the credits screen
1059       *
1060       * @since 2.2.0 bbPress (r4159)
1061       *
1062       * @todo Host this remotely.
1063       */
1064  	public function credits_screen() {
1065          ?>
1066  
1067          <div class="wrap about-wrap">
1068  
1069              <?php $this->screen_header(); ?>
1070  
1071              <h2 class="nav-tab-wrapper">
1072                  <a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php' ) ) ); ?>" class="nav-tab">
1073                      <?php esc_html_e( 'What&#8217;s New', 'bbpress' ); ?>
1074                  </a><a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bbp-credits' ), admin_url( 'index.php' ) ) ); ?>" class="nav-tab nav-tab-active">
1075                      <?php esc_html_e( 'Credits', 'bbpress' ); ?>
1076                  </a>
1077              </h2>
1078  
1079              <p class="about-description"><?php esc_html_e( 'bbPress is created by a worldwide swarm of busy, busy bees.', 'bbpress' ); ?></p>
1080  
1081              <h3 class="wp-people-group"><?php esc_html_e( 'Project Leaders', 'bbpress' ); ?></h3>
1082              <ul class="wp-people-group " id="wp-people-group-project-leaders">
1083                  <li class="wp-person" id="wp-person-matt">
1084                      <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>
1085                      <span class="title"><?php esc_html_e( 'Founding Developer', 'bbpress' ); ?></span>
1086                  </li>
1087                  <li class="wp-person" id="wp-person-johnjamesjacoby">
1088                      <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>
1089                      <span class="title"><?php esc_html_e( 'Lead Developer', 'bbpress' ); ?></span>
1090                  </li>
1091                  <li class="wp-person" id="wp-person-jmdodd">
1092                      <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>
1093                      <span class="title"><?php esc_html_e( 'Feature Virtuoso', 'bbpress' ); ?></span>
1094                  </li>
1095                  <li class="wp-person" id="wp-person-netweb">
1096                      <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>
1097                      <span class="title"><?php esc_html_e( 'Tool Maven', 'bbpress' ); ?></span>
1098                  </li>
1099              </ul>
1100  
1101              <h3 class="wp-people-group"><?php esc_html_e( 'Contributing Developers', 'bbpress' ); ?></h3>
1102              <ul class="wp-people-group " id="wp-people-group-contributing-developers">
1103                  <li class="wp-person" id="wp-person-sergeybiryukov">
1104                      <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>
1105                      <span class="title"><?php esc_html_e( 'Core Developer', 'bbpress' ); ?></span>
1106                  </li>
1107                  <li class="wp-person" id="wp-person-thebrandonallen">
1108                      <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>
1109                      <span class="title"><?php esc_html_e( 'Core Developer', 'bbpress' ); ?></span>
1110                  </li>
1111              </ul>
1112  
1113              <h3 class="wp-people-group"><?php esc_html_e( 'Project Emeriti', 'bbpress' ); ?></h3>
1114              <ul class="wp-people-group " id="wp-people-group-project-emeriti">
1115                  <li class="wp-person" id="wp-person-gautamgupta">
1116                      <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>
1117                      <span class="title"><?php esc_html_e( 'Feature Developer', 'bbpress' ); ?></span>
1118                  </li>
1119                  <li class="wp-person" id="wp-person-jaredatch">
1120                      <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>
1121                      <span class="title"><?php esc_html_e( 'Integration Testing', 'bbpress' ); ?></span>
1122                  </li>
1123              </ul>
1124  
1125              <h3 class="wp-people-group"><?php esc_html_e( 'Contributors to bbPress 2.6', 'bbpress' ); ?></h3>
1126              <p class="wp-credits-list">
1127                  <a href="https://profiles.wordpress.org/alex-ye">alex-ye</a>,
1128                  <a href="https://profiles.wordpress.org/ankit-k-gupta">ankit-k-gupta</a>,
1129                  <a href="https://profiles.wordpress.org/barryhughes-1">barryhughes-1</a>,
1130                  <a href="https://profiles.wordpress.org/boonebgorges">boonebgorges</a>,
1131                  <a href="https://profiles.wordpress.org/casiepa">casiepa</a>,
1132                  <a href="https://profiles.wordpress.org/cfinke">cfinke</a>,
1133                  <a href="https://profiles.wordpress.org/danielbachhuber">danielbachhuber</a>,
1134                  <a href="https://profiles.wordpress.org/dimitrovadrian">dimitrov.adrian</a>,
1135                  <a href="https://profiles.wordpress.org/DJPaul">DJPaul</a>,
1136                  <a href="https://profiles.wordpress.org/DrPepper75">DrPepper75</a>,
1137                  <a href="https://profiles.wordpress.org/eoigal">eoigal</a>,
1138                  <a href="https://profiles.wordpress.org/ericlewis">ericlewis</a>,
1139                  <a href="https://profiles.wordpress.org/extendwings">extendwings</a>,
1140                  <a href="https://profiles.wordpress.org/Faison">Faison</a>,
1141                  <a href="https://profiles.wordpress.org/gautamgupta">gautamgupta</a>,
1142                  <a href="https://profiles.wordpress.org/glynwintle">glynwintle</a>,
1143                  <a href="https://profiles.wordpress.org/gusrb84">gusrb84</a>,
1144                  <a href="https://profiles.wordpress.org/hellofromTonya">hellofromTonya</a>,
1145                  <a href="https://profiles.wordpress.org/icu0755">icu0755</a>,
1146                  <a href="https://profiles.wordpress.org/imath">imath</a>,
1147                  <a href="https://profiles.wordpress.org/jbrinley">jbrinley</a>,
1148                  <a href="https://profiles.wordpress.org/jdgrimes">jdgrimes</a>,
1149                  <a href="https://profiles.wordpress.org/jmdodd">jmdodd</a>,
1150                  <a href="https://profiles.wordpress.org/joedolson">joedolson</a>,
1151                  <a href="https://profiles.wordpress.org/johnbillion">johnbillion</a>,
1152                  <a href="https://profiles.wordpress.org/johnjamesjacoby">johnjamesjacoby</a>,
1153                  <a href="https://profiles.wordpress.org/jorbin">jorbin</a>,
1154                  <a href="https://profiles.wordpress.org/jreeve">jreeve</a>,
1155                  <a href="https://profiles.wordpress.org/kadamwhite ">kadamwhite</a>,
1156                  <a href="https://profiles.wordpress.org/karlgroves">karlgroves</a>,
1157                  <a href="https://profiles.wordpress.org/mat-lipe">mat-lipe</a>,
1158                  <a href="https://profiles.wordpress.org/mazengamal">mazengamal</a>,
1159                  <a href="https://profiles.wordpress.org/melchoyce">melchoyce</a>,
1160                  <a href="https://profiles.wordpress.org/mercime">mercime</a>,
1161                  <a href="https://profiles.wordpress.org/michaelbeil">michaelbeil</a>,
1162                  <a href="https://profiles.wordpress.org/mikelopez">mikelopez</a>,
1163                  <a href="https://profiles.wordpress.org/mordauk">mordauk</a>,
1164                  <a href="https://profiles.wordpress.org/mspecht">mspecht</a>,
1165                  <a href="https://profiles.wordpress.org/MZAWeb">MZAWeb</a>,
1166                  <a href="https://profiles.wordpress.org/netweb">netweb</a>,
1167                  <a href="https://profiles.wordpress.org/ocean90">ocean90</a>,
1168                  <a href="https://profiles.wordpress.org/offereins">offereins</a>,
1169                  <a href="https://profiles.wordpress.org/pareshradadiya">pareshradadiya</a>,
1170                  <a href="https://profiles.wordpress.org/r-a-y">r-a-y</a>,
1171                  <a href="https://profiles.wordpress.org/ramiy">ramiy</a>,
1172                  <a href="https://profiles.wordpress.org/robin-w">robin-w</a>,
1173                  <a href="https://profiles.wordpress.org/robkk">robkk</a>,
1174                  <a href="https://profiles.wordpress.org/ryelle">ryelle</a>,
1175                  <a href="https://profiles.wordpress.org/satollo">satollo</a>,
1176                  <a href="https://profiles.wordpress.org/SergeyBiryukov">Sergey Biryukov</a>,
1177                  <a href="https://profiles.wordpress.org/SGr33n">SGr33n</a>,
1178                  <a href="https://profiles.wordpress.org/stephdau">stephdau</a>,
1179                  <a href="https://profiles.wordpress.org/tharsheblows">tharsheblows</a>,
1180                  <a href="https://profiles.wordpress.org/thebrandonallen">thebrandonallen</a>,
1181                  <a href="https://profiles.wordpress.org/tobyhawkins">tobyhawkins</a>,
1182                  <a href="https://profiles.wordpress.org/tonyrix">tonyrix</a>,
1183                  <a href="https://profiles.wordpress.org/treyhunner">treyhunner</a>,
1184                  <a href="https://profiles.wordpress.org/tw2113">tw2113</a>,
1185                  <a href="https://profiles.wordpress.org/xknown">xknown</a>
1186              </p>
1187  
1188              <div class="return-to-dashboard">
1189                  <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>
1190              </div>
1191  
1192          </div>
1193  
1194          <?php
1195      }
1196  
1197      /** Updaters **************************************************************/
1198  
1199      /**
1200       * Update all bbPress forums across all sites
1201       *
1202       * @since 2.1.0 bbPress (r3689)
1203       */
1204  	public static function update_screen() {
1205  
1206          // Get action
1207          $action = isset( $_GET['action'] ) ? $_GET['action'] : ''; ?>
1208  
1209          <div class="wrap">
1210              <h1 class="wp-heading-inline"><?php esc_html_e( 'Update Forum', 'bbpress' ); ?></h1>
1211              <hr class="wp-header-end">
1212  
1213          <?php
1214  
1215          // Taking action
1216          switch ( $action ) {
1217              case 'bbp-update' :
1218  
1219                  // Run the full updater
1220                  bbp_version_updater(); ?>
1221  
1222                  <p><?php esc_html_e( 'All done!', 'bbpress' ); ?></p>
1223                  <a class="button" href="index.php?page=bbp-update"><?php esc_html_e( 'Go Back', 'bbpress' ); ?></a>
1224  
1225                  <?php
1226  
1227                  break;
1228  
1229              case 'show' :
1230              default : ?>
1231  
1232                  <p><?php esc_html_e( 'You can update your forum through this page. Hit the link below to update.', 'bbpress' ); ?></p>
1233                  <p><a class="button" href="index.php?page=bbp-update&amp;action=bbp-update"><?php esc_html_e( 'Update Forum', 'bbpress' ); ?></a></p>
1234  
1235              <?php break;
1236  
1237          } ?>
1238  
1239          </div><?php
1240      }
1241  
1242      /**
1243       * Update all bbPress forums across all sites
1244       *
1245       * @since 2.1.0 bbPress (r3689)
1246       */
1247  	public static function network_update_screen() {
1248          $bbp_db = bbp_db();
1249  
1250          // Get action
1251          $action = isset( $_GET['action'] ) ? $_GET['action'] : ''; ?>
1252  
1253          <div class="wrap">
1254              <h1 class="wp-heading-inline"><?php esc_html_e( 'Update Forums', 'bbpress' ); ?></h1>
1255              <hr class="wp-header-end">
1256  
1257          <?php
1258  
1259          // Taking action
1260          switch ( $action ) {
1261              case 'bbpress-update' :
1262  
1263                  // Site counter
1264                  $n = isset( $_GET['n'] ) ? intval( $_GET['n'] ) : 0;
1265  
1266                  // Get blogs 5 at a time
1267                  $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 );
1268  
1269                  // No blogs so all done!
1270                  if ( empty( $blogs ) ) : ?>
1271  
1272                      <p><?php esc_html_e( 'All done!', 'bbpress' ); ?></p>
1273                      <a class="button" href="update-core.php?page=bbpress-update"><?php esc_html_e( 'Go Back', 'bbpress' ); ?></a>
1274  
1275                  <?php
1276  
1277                  // Still have sites to loop through
1278                  else : ?>
1279  
1280                      <ul>
1281  
1282                          <?php foreach ( (array) $blogs as $details ) :
1283  
1284                              // Get site URLs
1285                              $site_url   = get_site_url( $details['blog_id'] );
1286                              $admin_url  = get_site_url( $details['blog_id'], 'wp-admin.php', 'admin' );
1287                              $remote_url = add_query_arg( array(
1288                                  'page'   => 'bbp-update',
1289                                  'action' => 'bbp-update'
1290                              ), $admin_url ); ?>
1291  
1292                              <li><?php echo esc_html( $site_url ); ?></li>
1293  
1294                              <?php
1295  
1296                              // Get the response of the bbPress update on this site
1297                              $response = wp_remote_get(
1298                                  $remote_url,
1299                                  array(
1300                                      'timeout'     => 30,
1301                                      'httpversion' => '1.1'
1302                                  )
1303                              );
1304  
1305                              // Site errored out, no response?
1306                              if ( is_wp_error( $response ) ) {
1307                                  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>' ) );
1308                              }
1309  
1310                              // Switch to the new site
1311                              bbp_switch_to_site( $details[ 'blog_id' ] );
1312  
1313                              $basename = bbpress()->basename;
1314  
1315                              // Run the updater on this site
1316                              if ( is_plugin_active_for_network( $basename ) || is_plugin_active( $basename ) ) {
1317                                  bbp_version_updater();
1318                              }
1319  
1320                              // Restore original site
1321                              bbp_restore_current_site();
1322  
1323                              // Do some actions to allow plugins to do things too
1324                              do_action( 'after_bbpress_upgrade', $response             );
1325                              do_action( 'bbp_upgrade_site',      $details[ 'blog_id' ] );
1326  
1327                          endforeach; ?>
1328  
1329                      </ul>
1330  
1331                      <p>
1332                          <?php esc_html_e( 'If your browser doesn&#8217;t start loading the next page automatically, click this link:', 'bbpress' ); ?>
1333                          <a class="button" href="update-core.php?page=bbpress-update&amp;action=bbpress-update&amp;n=<?php echo ( $n + 5 ); ?>"><?php esc_html_e( 'Next Forums', 'bbpress' ); ?></a>
1334                      </p>
1335                      <script type='text/javascript'>
1336                          <!--
1337  						function nextpage() {
1338                              location.href = 'update-core.php?page=bbpress-update&action=bbpress-update&n=<?php echo ( $n + 5 ) ?>';
1339                          }
1340                          setTimeout( 'nextpage()', 250 );
1341                          //-->
1342                      </script><?php
1343  
1344                  endif;
1345  
1346                  break;
1347  
1348              case 'show' :
1349              default : ?>
1350  
1351                  <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>
1352                  <p><a class="button" href="update-core.php?page=bbpress-update&amp;action=bbpress-update"><?php esc_html_e( 'Update Forums', 'bbpress' ); ?></a></p>
1353  
1354              <?php break;
1355  
1356          } ?>
1357  
1358          </div><?php
1359      }
1360  }
1361  endif; // class_exists check


Generated: Sun Nov 17 01:01:25 2019 Cross-referenced by PHPXref 0.7.1