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


Generated: Sat Sep 21 01:01:35 2019 Cross-referenced by PHPXref 0.7.1