[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/src/includes/admin/tools/ -> common.php (source)

   1  <?php
   2  
   3  /**
   4   * bbPress Admin Tools Common
   5   *
   6   * @package bbPress
   7   * @subpackage Administration
   8   */
   9  
  10  // Exit if accessed directly
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Return the current admin repair tool page
  15   *
  16   * @since 2.6.0 bbPress (r6894)
  17   *
  18   * @return string
  19   */
  20  function bbp_get_admin_repair_tool_page() {
  21      return sanitize_key( $_GET['page'] );
  22  }
  23  
  24  /**
  25   * Return the current admin repair tool page ID
  26   *
  27   * @since 2.6.0 bbPress (r6894)
  28   *
  29   * @return string
  30   */
  31  function bbp_get_admin_repair_tool_page_id() {
  32  
  33      // Get the page
  34      $page = bbp_get_admin_repair_tool_page();
  35  
  36      // Maybe trim prefix off of page
  37      if ( ! empty( $page ) && ( 0 === strpos( $page, 'bbp-' ) ) ) {
  38          $page = str_replace( 'bbp-', '', $page );
  39      } else {
  40          $page = '';
  41      }
  42  
  43      return $page;
  44  }
  45  
  46  /**
  47   * Return a URL to the repair tool page
  48   *
  49   * @since 2.6.0 bbPress (r6894)
  50   *
  51   * @param array $args
  52   *
  53   * @return string
  54   */
  55  function bbp_get_admin_repair_tool_page_url( $args = array() ) {
  56  
  57      // Parse arguments
  58      $r = wp_parse_args( $args, array(
  59          'page' => bbp_get_admin_repair_tool_page()
  60      ) );
  61  
  62      return add_query_arg( $r, admin_url( 'tools.php' ) );
  63  }
  64  
  65  /**
  66   * Output the URL to run a specific repair tool
  67   *
  68   * @since 2.6.0 bbPress (r5885)
  69   *
  70   * @param string $component
  71   */
  72  function bbp_admin_repair_tool_run_url( $component = array() ) {
  73      echo esc_url( bbp_get_admin_repair_tool_run_url( $component ) );
  74  }
  75  
  76      /**
  77       * Return the URL to run a specific repair tool
  78       *
  79       * @since 2.6.0 bbPress (r5885)
  80       *
  81       * @param string $component
  82       */
  83  	function bbp_get_admin_repair_tool_run_url( $component = array() ) {
  84  
  85          // Page
  86          $page = ( 'repair' === $component['type'] )
  87              ? 'bbp-repair'
  88              : 'bbp-upgrade';
  89  
  90          // Arguments
  91          $args = array(
  92              'page'    => $page,
  93              'action'  => 'run',
  94              'checked' => array( $component['id'] )
  95          );
  96  
  97          // Url
  98          $nonced = wp_nonce_url( bbp_get_admin_repair_tool_page_url( $args ), 'bbpress-do-counts' );
  99  
 100          // Filter & return
 101          return apply_filters( 'bbp_get_admin_repair_tool_run_url', $nonced, $component );
 102      }
 103  
 104  /**
 105   * Assemble the admin notices
 106   *
 107   * @since 2.0.0 bbPress (r2613)
 108   *
 109   * @param string|WP_Error $message        A message to be displayed or {@link WP_Error}
 110   * @param string          $class          Optional. A class to be added to the message div
 111   * @param bool            $is_dismissible Optional. True to dismiss, false to persist
 112   *
 113   * @return string The message HTML
 114   */
 115  function bbp_admin_tools_feedback( $message, $class = false, $is_dismissible = true ) {
 116      return bbp_admin()->add_notice( $message, $class, $is_dismissible );
 117  }
 118  
 119  /**
 120   * Handle the processing and feedback of the admin tools page
 121   *
 122   * @since 2.0.0 bbPress (r2613)
 123   *
 124   */
 125  function bbp_admin_repair_handler() {
 126  
 127      // Bail if not an actionable request
 128      if ( ! bbp_is_get_request() ) {
 129          return;
 130      }
 131  
 132      // Get the current action or bail
 133      if ( ! empty( $_GET['action'] ) ) {
 134          $action = sanitize_key( $_GET['action'] );
 135      } elseif ( ! empty( $_GET['action2'] ) ) {
 136          $action = sanitize_key( $_GET['action2'] );
 137      } else {
 138          return;
 139      }
 140  
 141      // Bail if not running an action
 142      if ( 'run' !== $action ) {
 143          return;
 144      }
 145  
 146      check_admin_referer( 'bbpress-do-counts' );
 147  
 148      // Parse list of checked repairs
 149      $checked = ! empty( $_GET['checked'] )
 150          ? array_map( 'sanitize_key', $_GET['checked'] )
 151          : array();
 152  
 153      // Flush all caches before running tools
 154      wp_cache_flush();
 155  
 156      // Get the list
 157      $list = bbp_get_admin_repair_tools();
 158  
 159      // Stores messages
 160      $messages = array();
 161  
 162      // Run through checked repair tools
 163      if ( count( $checked ) ) {
 164          foreach ( $checked as $item_id ) {
 165              if ( isset( $list[ $item_id ] ) && is_callable( $list[ $item_id ]['callback'] ) ) {
 166                  $messages[] = call_user_func( $list[ $item_id ]['callback'] );
 167  
 168                  // Remove from pending
 169                  bbp_remove_pending_upgrade( $item_id );
 170              }
 171          }
 172      }
 173  
 174      // Feedback
 175      if ( count( $messages ) ) {
 176          foreach ( $messages as $message ) {
 177              bbp_admin_tools_feedback( $message[1] );
 178          }
 179      }
 180  
 181      // Flush all caches after running tools
 182      wp_cache_flush();
 183  }
 184  
 185  /**
 186   * Get the array of available repair tools
 187   *
 188   * @since 2.6.0 bbPress (r5885)
 189   *
 190   * @param string $type repair|upgrade The type of tools to get. Default empty for all tools.
 191   * @return array
 192   */
 193  function bbp_get_admin_repair_tools( $type = '' ) {
 194  
 195      // Get tools array
 196      $tools = ! empty( bbp_admin()->tools )
 197          ? bbp_admin()->tools
 198          : array();
 199  
 200      // Maybe limit to type (otherwise return all tools)
 201      if ( ! empty( $type ) ) {
 202          $tools = wp_list_filter( bbp_admin()->tools, array( 'type' => $type ) );
 203      }
 204  
 205      // Filter & return
 206      return (array) apply_filters( 'bbp_get_admin_repair_tools', $tools, $type );
 207  }
 208  
 209  /**
 210   * Return array of components from the array of registered tools
 211   *
 212   * @since 2.5.0 bbPress (r5885)
 213   *
 214   * @return array
 215   */
 216  function bbp_get_admin_repair_tool_registered_components() {
 217  
 218      // Default return value
 219      $retval = array();
 220  
 221      // Get tools
 222      $tools = bbp_get_admin_repair_tools( bbp_get_admin_repair_tool_page_id() );
 223  
 224      // Loop through tools
 225      if ( ! empty( $tools ) ) {
 226          $plucked = wp_list_pluck( $tools, 'components' );
 227  
 228          // Loop through components
 229          if ( count( $plucked ) ) {
 230              foreach ( $plucked as $components ) {
 231                  foreach ( $components as $component ) {
 232  
 233                      // Skip if already in array
 234                      if ( in_array( $component, $retval, true ) ) {
 235                          continue;
 236                      }
 237  
 238                      // Add component to the array
 239                      $retval[] = $component;
 240                  }
 241              }
 242          }
 243      }
 244  
 245      // Filter & return
 246      return (array) apply_filters( 'bbp_get_admin_repair_tool_registered_components', $retval );
 247  }
 248  
 249  /**
 250   * Output the repair list search form
 251   *
 252   * @since 2.6.0 bbPress (r5885)
 253   */
 254  function bbp_admin_repair_list_search_form() {
 255      ?>
 256  
 257      <p class="search-box">
 258          <label class="screen-reader-text" for="bbp-repair-search-input"><?php esc_html_e( 'Search Tools:', 'bbpress' ); ?></label>
 259          <input type="search" id="bbp-repair-search-input" name="s" value="<?php _admin_search_query(); ?>">
 260          <input type="submit" id="search-submit" class="button" value="<?php esc_html_e( 'Search Tools', 'bbpress' ); ?>">
 261      </p>
 262  
 263      <?php
 264  }
 265  
 266  /**
 267   * Output a select drop-down of components to filter by
 268   *
 269   * @since 2.5.0 bbPress (r5885)
 270   */
 271  function bbp_admin_repair_list_components_filter() {
 272  
 273      // Sanitize component value, if exists
 274      $selected = ! empty( $_GET['components'] )
 275          ? sanitize_key( $_GET['components'] )
 276          : '';
 277  
 278      // Get registered components
 279      $components = bbp_get_admin_repair_tool_registered_components();
 280  
 281      // Bail if no components
 282      if ( empty( $components ) ) {
 283          return;
 284      } ?>
 285  
 286      <label class="screen-reader-text" for="components"><?php esc_html_e( 'Filter by Component', 'bbpress' ); ?></label>
 287      <select name="components" id="components" class="postform">
 288          <option value="" <?php selected( $selected, false ); ?>><?php esc_html_e( 'All Components', 'bbpress' ); ?></option>
 289  
 290          <?php foreach ( $components as $component ) : ?>
 291  
 292              <option class="level-0" value="<?php echo esc_attr( $component ); ?>" <?php selected( $selected, $component ); ?>><?php echo esc_html( bbp_admin_repair_tool_translate_component( $component ) ); ?></option>
 293  
 294          <?php endforeach; ?>
 295  
 296      </select>
 297  
 298      <?php
 299  }
 300  
 301  /**
 302   * Return array of versions from the array of registered tools
 303   *
 304   * @since 2.6.0 bbPress (r6894)
 305   *
 306   * @return array
 307   */
 308  function bbp_get_admin_repair_tool_registered_versions() {
 309  
 310      // Default return value
 311      $retval = array();
 312  
 313      // Get tools
 314      $tools = bbp_get_admin_repair_tools( bbp_get_admin_repair_tool_page_id() );
 315  
 316      // Loop through tools
 317      if ( ! empty( $tools ) ) {
 318          $plucked = wp_list_pluck( $tools, 'version' );
 319  
 320          // Loop through components
 321          if ( count( $plucked ) ) {
 322              foreach ( $plucked as $versions ) {
 323  
 324                  // Skip if empty
 325                  if ( empty( $versions ) ) {
 326                      continue;
 327  
 328                  // Cast to array if string
 329                  } elseif ( is_string( $versions ) ) {
 330                      $versions = (array) $versions;
 331                  }
 332  
 333                  // Loop through versions
 334                  foreach ( $versions as $version ) {
 335  
 336                      // Skip if already in array
 337                      if ( in_array( $version, $retval, true ) ) {
 338                          continue;
 339                      }
 340  
 341                      // Add component to the array
 342                      $retval[] = $version;
 343                  }
 344              }
 345          }
 346      }
 347  
 348      // Filter & return
 349      return (array) apply_filters( 'bbp_get_admin_repair_tool_registered_versions', $retval );
 350  }
 351  
 352  /**
 353   * Output a select drop-down of versions to filter by
 354   *
 355   * @since 2.5.0 bbPress (r6894)
 356   */
 357  function bbp_admin_repair_list_versions_filter() {
 358  
 359      // Sanitize component value, if exists
 360      $selected = ! empty( $_GET['version'] )
 361          ? sanitize_text_field( $_GET['version'] )
 362          : '';
 363  
 364      // Get registered components
 365      $versions = bbp_get_admin_repair_tool_registered_versions();
 366  
 367      // Bail if no components
 368      if ( empty( $versions ) ) {
 369          return;
 370      } ?>
 371  
 372      <label class="screen-reader-text" for="version"><?php esc_html_e( 'Filter by Version', 'bbpress' ); ?></label>
 373      <select name="version" id="version" class="postform">
 374          <option value="" <?php selected( $selected, false ); ?>><?php esc_html_e( 'All Versions', 'bbpress' ); ?></option>
 375  
 376          <?php foreach ( $versions as $version ) : ?>
 377  
 378              <option class="level-0" value="<?php echo esc_attr( $version ); ?>" <?php selected( $selected, $version ); ?>><?php echo esc_html( bbp_admin_repair_tool_translate_version( $version ) ); ?></option>
 379  
 380          <?php endforeach; ?>
 381  
 382      </select>
 383  
 384      <?php
 385  }
 386  
 387  /** Translations **************************************************************/
 388  
 389  /**
 390   * Maybe translate a repair tool overhead name
 391   *
 392   * @since 2.6.0 bbPress (r6177)
 393   *
 394   * @param string $overhead
 395   * @return string
 396   */
 397  function bbp_admin_repair_tool_translate_overhead( $overhead = '' ) {
 398  
 399      // Get the name of the component
 400      switch ( $overhead ) {
 401          case 'low' :
 402              $name = esc_html__( 'Low', 'bbpress' );
 403              break;
 404          case 'medium' :
 405              $name = esc_html__( 'Medium', 'bbpress' );
 406              break;
 407          case 'high' :
 408              $name = esc_html__( 'High', 'bbpress' );
 409              break;
 410          default :
 411              $name = ucwords( $overhead );
 412              break;
 413      }
 414  
 415      return $name;
 416  }
 417  
 418  /**
 419   * Maybe translate a repair tool component name
 420   *
 421   * @since 2.6.0 bbPress (r5885)
 422   *
 423   * @param string $component
 424   * @return string
 425   */
 426  function bbp_admin_repair_tool_translate_component( $component = '' ) {
 427  
 428      // Get the name of the component
 429      switch ( $component ) {
 430          case 'bbp_user' :
 431              $name = esc_html__( 'Users', 'bbpress' );
 432              break;
 433          case bbp_get_forum_post_type() :
 434              $name = esc_html__( 'Forums', 'bbpress' );
 435              break;
 436          case bbp_get_topic_post_type() :
 437              $name = esc_html__( 'Topics', 'bbpress' );
 438              break;
 439          case bbp_get_reply_post_type() :
 440              $name = esc_html__( 'Replies', 'bbpress' );
 441              break;
 442          case bbp_get_topic_tag_tax_id() :
 443              $name = esc_html__( 'Topic Tags', 'bbpress' );
 444              break;
 445          case bbp_get_user_rewrite_id() :
 446              $name = esc_html__( 'Users', 'bbpress' );
 447              break;
 448          case bbp_get_user_favorites_rewrite_id() :
 449              $name = esc_html__( 'Favorites', 'bbpress' );
 450              break;
 451          case bbp_get_user_subscriptions_rewrite_id() :
 452              $name = esc_html__( 'Subscriptions', 'bbpress' );
 453              break;
 454          case bbp_get_user_engagements_rewrite_id() :
 455              $name = esc_html__( 'Engagements', 'bbpress' );
 456              break;
 457          default :
 458              $name = ucwords( $component );
 459              break;
 460      }
 461  
 462      return $name;
 463  }
 464  
 465  /**
 466   * Maybe translate a repair tool overhead name
 467   *
 468   * @since 2.6.0 bbPress (r6894)
 469   *
 470   * @param string $version
 471   * @return string
 472   */
 473  function bbp_admin_repair_tool_translate_version( $version = '' ) {
 474  
 475      // Get the version
 476      switch ( $version ) {
 477          case '2.5' :
 478          case '2.5.0' :
 479              $name = esc_html__( '2.5.0', 'bbpress' );
 480              break;
 481          case '2.6' :
 482          case '2.6.0' :
 483              $name = esc_html__( '2.6.0', 'bbpress' );
 484              break;
 485          default :
 486              $name = sanitize_text_field( $version );
 487              break;
 488      }
 489  
 490      return $name;
 491  }
 492  
 493  /** Lists *********************************************************************/
 494  
 495  /**
 496   * Get the array of the repairs to show in a list table.
 497   *
 498   * Uses known filters to reduce the registered results down to the most finite
 499   * set of tools.
 500   *
 501   * @since 2.0.0 bbPress (r2613)
 502   *
 503   * @return array Repair list of options
 504   */
 505  function bbp_admin_repair_list( $type = 'repair' ) {
 506  
 507      // Define empty array
 508      $repair_list = array();
 509  
 510      // Get the available tools
 511      $list = bbp_get_admin_repair_tools( $type );
 512  
 513      // Get pending upgrades
 514      $pending = bbp_get_pending_upgrades();
 515  
 516      // Search
 517      $search = ! empty( $_GET['s'] )
 518          ? stripslashes( $_GET['s'] )
 519          : '';
 520  
 521      // Status
 522      $status = ! empty( $_GET['status'] )
 523          ? sanitize_key( $_GET['status'] )
 524          : '';
 525  
 526      // Overhead
 527      $overhead = ! empty( $_GET['overhead'] )
 528          ? sanitize_key( $_GET['overhead'] )
 529          : '';
 530  
 531      // Component
 532      $component = ! empty( $_GET['components'] )
 533          ? sanitize_key( $_GET['components'] )
 534          : '';
 535  
 536      // Version
 537      $version = ! empty( $_GET['version'] )
 538          ? sanitize_text_field( $_GET['version'] )
 539          : '';
 540  
 541      // Orderby
 542      $orderby = ! empty( $_GET['orderby'] )
 543          ? sanitize_key( $_GET['orderby'] )
 544          : 'priority';
 545  
 546      // Order
 547      $order = ! empty( $_GET['order'] ) && in_array( strtolower( $_GET['order'] ), array( 'asc', 'desc' ), true )
 548          ? strtolower( $_GET['order'] )
 549          : 'asc';
 550  
 551      // Overhead filter
 552      if ( ! empty( $overhead ) ) {
 553          $list = wp_list_filter( $list, array( 'overhead' => $overhead ) );
 554      }
 555  
 556      if ( count( $list ) ) {
 557  
 558          // Loop through and key by priority for sorting
 559          foreach ( $list as $id => $tool ) {
 560  
 561              // Status filter
 562              if ( ! empty( $status ) && ( 'pending' === $status ) ) {
 563                  if ( ! in_array( $id, (array) $pending, true ) ) {
 564                      continue;
 565                  }
 566              }
 567  
 568              // Component filter
 569              if ( ! empty( $component ) ) {
 570                  if ( ! in_array( $component, (array) $tool['components'], true ) ) {
 571                      continue;
 572                  }
 573              }
 574  
 575              // Version filter
 576              if ( ! empty( $version ) ) {
 577                  if ( ! in_array( $version, (array) $tool['version'], true ) ) {
 578                      continue;
 579                  }
 580              }
 581  
 582              // Search
 583              if ( ! empty( $search ) ) {
 584                  if ( ! strstr( strtolower( $tool['title'] ), strtolower( $search ) ) ) {
 585                      continue;
 586                  }
 587              }
 588  
 589              // Add to repair list
 590              $repair_list[ $tool['priority'] ] = array(
 591                  'id'          => sanitize_key( $id ),
 592                  'type'        => $tool['type'],
 593                  'title'       => $tool['title'],
 594                  'priority'    => $tool['priority'],
 595                  'description' => $tool['description'],
 596                  'callback'    => $tool['callback'],
 597                  'overhead'    => $tool['overhead'],
 598                  'version'     => $tool['version'],
 599                  'components'  => $tool['components']
 600              );
 601          }
 602      }
 603  
 604      // Sort
 605      $retval = wp_list_sort( $repair_list, $orderby, $order, true );
 606  
 607      // Filter & return
 608      return (array) apply_filters( 'bbp_repair_list', $retval );
 609  }
 610  
 611  /**
 612   * Get filter links for components for a specific admin repair tool
 613   *
 614   * @since 2.6.0 bbPress (r5885)
 615   *
 616   * @param array $item
 617   * @return array
 618   */
 619  function bbp_get_admin_repair_tool_components( $item = array() ) {
 620  
 621      // Get the tools URL
 622      $tools_url = bbp_get_admin_repair_tool_page_url();
 623  
 624      // Define links array
 625      $links      = array();
 626      $components = ! empty( $item['components'] )
 627          ? (array) $item['components']
 628          : array();
 629  
 630      // Loop through tool components and build links
 631      if ( count( $components ) ) {
 632          foreach ( $components as $component ) {
 633              $args       = array( 'components' => $component );
 634              $filter_url = add_query_arg( $args, $tools_url );
 635              $name       = bbp_admin_repair_tool_translate_component( $component );
 636              $links[]    = '<a href="' . esc_url( $filter_url ) . '">' . esc_html( $name ) . '</a>';
 637          }
 638  
 639      // No components, so return a dash
 640      } else {
 641          $links[] = '&mdash;';
 642      }
 643  
 644      // Filter & return
 645      return (array) apply_filters( 'bbp_get_admin_repair_tool_components', $links, $item );
 646  }
 647  
 648  /**
 649   * Get filter links for versions for a specific admin repair tool
 650   *
 651   * @since 2.6.0 bbPress (r6894)
 652   *
 653   * @param array $item
 654   * @return array
 655   */
 656  function bbp_get_admin_repair_tool_version( $item = array() ) {
 657  
 658      // Get the tools URL
 659      $tools_url = bbp_get_admin_repair_tool_page_url();
 660  
 661      // Define links array
 662      $links    = array();
 663      $versions = ! empty( $item['version'] )
 664          ? (array) $item['version']
 665          : array();
 666  
 667      // Loop through tool versions and build links
 668      if ( count( $versions ) ) {
 669          foreach ( $versions as $version ) {
 670              $args       = array( 'version' => $version );
 671              $filter_url = add_query_arg( $args, $tools_url );
 672              $name       = bbp_admin_repair_tool_translate_version( $version );
 673              $links[]    = '<a href="' . esc_url( $filter_url ) . '">' . esc_html( $name ) . '</a>';
 674          }
 675  
 676      // No versions, so return a dash
 677      } else {
 678          $links[] = '&mdash;';
 679      }
 680  
 681      // Filter & return
 682      return (array) apply_filters( 'bbp_get_admin_repair_tool_version', $links, $item );
 683  }
 684  
 685  /**
 686   * Get filter links for overhead for a specific admin repair tool
 687   *
 688   * @since 2.6.0 bbPress (r5885)
 689   *
 690   * @param array $item
 691   * @return array
 692   */
 693  function bbp_get_admin_repair_tool_overhead( $item = array() ) {
 694  
 695      // Get the tools URL
 696      $tools_url = bbp_get_admin_repair_tool_page_url();
 697  
 698      // Define links array
 699      $links     = array();
 700      $overheads = ! empty( $item['overhead'] )
 701          ? (array) $item['overhead']
 702          : array();
 703  
 704      // Loop through tool overhead and build links
 705      if ( count( $overheads ) ) {
 706          foreach ( $overheads as $overhead ) {
 707              $args       = array( 'overhead' => $overhead );
 708              $filter_url = add_query_arg( $args, $tools_url );
 709              $name       = bbp_admin_repair_tool_translate_overhead( $overhead );
 710              $links[]    = '<a href="' . esc_url( $filter_url ) . '">' . esc_html( $name ) . '</a>';
 711          }
 712  
 713      // No overhead, so return a single dash
 714      } else {
 715          $links[] = '&mdash;';
 716      }
 717  
 718      // Filter & return
 719      return (array) apply_filters( 'bbp_get_admin_repair_tool_overhead', $links, $item );
 720  }
 721  
 722  /** Overhead ******************************************************************/
 723  
 724  /**
 725   * Output filter links for overheads for a specific admin repair tool
 726   *
 727   * @since 2.6.0 bbPress (r5885)
 728   *
 729   * @param array $args
 730   */
 731  function bbp_admin_repair_tool_overhead_filters( $args = array() ) {
 732      echo bbp_get_admin_repair_tool_overhead_filters( $args );
 733  }
 734  
 735  /**
 736   * Get filter links for overheads for a specific admin repair tool
 737   *
 738   * @since 2.6.0 bbPress (r5885)
 739   *
 740   * @param array $args
 741   * @return array
 742   */
 743  function bbp_get_admin_repair_tool_overhead_filters( $args = array() ) {
 744  
 745      // Parse args
 746      $r = bbp_parse_args( $args, array(
 747          'before'       => '<ul class="subsubsub">',
 748          'after'        => '</ul>',
 749          'link_before'  => '<li>',
 750          'link_after'   => '</li>',
 751          'count_before' => ' <span class="count">(',
 752          'count_after'  => ')</span>',
 753          'sep'          => ' | ',
 754  
 755          // Retired, use 'sep' instead
 756          'separator'    => false
 757      ), 'get_admin_repair_tool_overhead_filters' );
 758  
 759      /**
 760       * Necessary for backwards compatibility
 761       * @see https://bbpress.trac.wordpress.org/ticket/2900
 762       */
 763      if ( ! empty( $r['separator'] ) ) {
 764          $r['sep'] = $r['separator'];
 765      }
 766  
 767      // Count the tools
 768      $tools = bbp_get_admin_repair_tools( bbp_get_admin_repair_tool_page_id() );
 769  
 770      // Get the tools URL
 771      $tools_url = bbp_get_admin_repair_tool_page_url();
 772  
 773      // Define arrays
 774      $overheads = $links = array();
 775  
 776      // Loop through tools and count overheads
 777      if ( count( $tools ) ) {
 778          foreach ( $tools as $tool ) {
 779  
 780              // Get the overhead level
 781              $overhead = $tool['overhead'];
 782  
 783              // Set an empty count
 784              if ( empty( $overheads[ $overhead ] ) ) {
 785                  $overheads[ $overhead ] = 0;
 786              }
 787  
 788              // Bump the overhead count
 789              $overheads[ $overhead ]++;
 790          }
 791      }
 792  
 793      // Get the current overhead, if any
 794      $selected = ! empty( $_GET['overhead'] )
 795          ? sanitize_key( $_GET['overhead'] )
 796          : '';
 797  
 798      // Create the "All" link
 799      $current = empty( $selected ) ? 'current' : '';
 800      $links[] = $r['link_before'] . '<a href="' . esc_url( $tools_url ) . '" class="' . esc_attr( $current ) . '">' . sprintf( esc_html__( 'All %s', 'bbpress' ), $r['count_before'] . count( $tools ) . $r['count_after'] ) . '</a>' . $r['link_after'];
 801  
 802      // Loop through overheads and created links
 803      if ( count( $overheads ) ) {
 804  
 805          // Sort
 806          ksort( $overheads );
 807  
 808          // Loop through overheads and build filter
 809          foreach ( $overheads as $overhead => $count ) {
 810  
 811              // Build the filter URL
 812              $key        = sanitize_key( $overhead );
 813              $args       = array( 'overhead' => $key );
 814              $filter_url = add_query_arg( $args, $tools_url );
 815  
 816              // Figure out separator and active class
 817              $current  = ( $selected === $key )
 818                  ? 'current'
 819                  : '';
 820  
 821              // Counts to show
 822              if ( ! empty( $count ) ) {
 823                  $overhead_count = $r['count_before'] . $count . $r['count_after'];
 824              }
 825  
 826              // Build the link
 827              $links[] = $r['link_before'] . '<a href="' . esc_url( $filter_url ) . '" class="' . esc_attr( $current ) . '">' . bbp_admin_repair_tool_translate_overhead( $overhead ) . $overhead_count . '</a>' . $r['link_after'];
 828          }
 829      }
 830  
 831      // Surround output with before & after strings
 832      $output = $r['before'] . implode( $r['sep'], $links ) . $r['after'];
 833  
 834      // Filter & return
 835      return apply_filters( 'bbp_get_admin_repair_tool_overhead_filters', $output, $r, $args );
 836  }
 837  
 838  /** Pending ******************************************************************/
 839  
 840  /**
 841   * Output filter links for statuses
 842   *
 843   * @since 2.6.0 bbPress (r6925)
 844   *
 845   * @param array $args
 846   */
 847  function bbp_admin_repair_tool_status_filters( $args = array() ) {
 848      echo bbp_get_admin_repair_tool_status_filters( $args );
 849  }
 850  
 851  /**
 852   * Get filter links for statuses
 853   *
 854   * @since 2.6.0 bbPress (r5885)
 855   *
 856   * @param array $args
 857   * @return array
 858   */
 859  function bbp_get_admin_repair_tool_status_filters( $args = array() ) {
 860  
 861      // Parse args
 862      $r = bbp_parse_args( $args, array(
 863          'before'       => '<ul class="subsubsub">',
 864          'after'        => '</ul>',
 865          'link_before'  => '<li>',
 866          'link_after'   => '</li>',
 867          'count_before' => ' <span class="count">(',
 868          'count_after'  => ')</span>',
 869          'sep'          => ' | ',
 870  
 871          // Retired, use 'sep' instead
 872          'separator'    => false
 873      ), 'get_admin_repair_tool_status_filters' );
 874  
 875      /**
 876       * Necessary for backwards compatibility
 877       * @see https://bbpress.trac.wordpress.org/ticket/2900
 878       */
 879      if ( ! empty( $r['separator'] ) ) {
 880          $r['sep'] = $r['separator'];
 881      }
 882  
 883      // Get the type of tool
 884      $type = bbp_get_admin_repair_tool_page_id();
 885  
 886      // Count the tools
 887      $tools = bbp_get_admin_repair_tools( $type );
 888  
 889      // Get the tools URL
 890      $tools_url = bbp_get_admin_repair_tool_page_url();
 891  
 892      // Get pending upgrades
 893      $pending = bbp_get_pending_upgrades( $type );
 894  
 895      // Get the current status, if any
 896      $selected = ! empty( $_GET['status'] )
 897          ? sanitize_key( $_GET['status'] )
 898          : '';
 899  
 900      // Nothing is current?
 901      $all_current = empty( $selected )
 902          ? 'current'
 903          : '';
 904  
 905      // Pending is current?
 906      $pending_current = ( 'pending' === $selected )
 907          ? 'current'
 908          : '';
 909  
 910      // Sort
 911      ksort( $pending );
 912  
 913      // Build the filter URL
 914      $filter_url = add_query_arg( array(
 915          'status' => 'pending'
 916      ), $tools_url );
 917  
 918      // Count HTML
 919      $all_count     = $r['count_before'] . count( $tools   ) . $r['count_after'];
 920      $pending_count = $r['count_before'] . count( $pending ) . $r['count_after'];
 921  
 922      // Define links
 923      $links = array(
 924          $r['link_before'] . '<a href="' . esc_url( $tools_url  ) . '" class="' . esc_attr( $all_current     ) . '">' . sprintf( esc_html__( 'All %s',     'bbpress' ), $all_count     ) . '</a>' . $r['link_after'],
 925          $r['link_before'] . '<a href="' . esc_url( $filter_url ) . '" class="' . esc_attr( $pending_current ) . '">' . sprintf( esc_html__( 'Pending %s', 'bbpress' ), $pending_count ) . '</a>' . $r['link_after']
 926      );
 927  
 928      // Surround output with before & after strings
 929      $output = $r['before'] . implode( $r['sep'], $links ) . $r['after'];
 930  
 931      // Filter & return
 932      return apply_filters( 'bbp_get_admin_repair_tool_status_filters', $output, $r, $args );
 933  }


Generated: Sat Apr 20 01:00:52 2024 Cross-referenced by PHPXref 0.7.1