Skip to:
Content

bbPress.org


Ignore:
Timestamp:
11/09/2019 07:27:30 AM (7 years ago)
Author:
johnjamesjacoby
Message:

Upgrades: Link to pending upgrades, if there are any.

This commit modifies the "Upgrade Forums" page by adding Statuses to filter by, specifically for pending upgrades. This allows bbPress to link directly to the upgrades that need doing, rather than the generic page itself.

Along with this commit are accompanying styling tweaks and helper functions to make this functionality possible.

Fixes #3244.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/tools/common.php

    r6925 r6926  
    165165            if ( isset( $list[ $item_id ] ) && is_callable( $list[ $item_id ]['callback'] ) ) {
    166166                $messages[] = call_user_func( $list[ $item_id ]['callback'] );
     167
     168                // Remove from pending
     169                bbp_remove_pending_upgrade( $item_id );
    167170            }
    168171        }
     
    508511    $list = bbp_get_admin_repair_tools( $type );
    509512
     513    // Get pending upgrades
     514    $pending = bbp_get_pending_upgrades();
     515
    510516    // Search
    511517    $search = ! empty( $_GET['s'] )
    512518        ? stripslashes( $_GET['s'] )
     519        : '';
     520
     521    // Status
     522    $status = ! empty( $_GET['status'] )
     523        ? sanitize_key( $_GET['status'] )
    513524        : '';
    514525
     
    547558        // Loop through and key by priority for sorting
    548559        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            }
    549567
    550568            // Component filter
     
    815833
    816834    // Filter & return
    817     return apply_filters( 'bbp_get_admin_repair_tool_components', $output, $r, $args );
    818 }
     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 */
     847function 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 */
     859function 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    // Count the tools
     884    $tools = bbp_get_admin_repair_tools( bbp_get_admin_repair_tool_page_id() );
     885
     886    // Get the tools URL
     887    $tools_url = bbp_get_admin_repair_tool_page_url();
     888
     889    // Get pending upgrades
     890    $pending = bbp_get_pending_upgrades();
     891
     892    // Get the current status, if any
     893    $selected = ! empty( $_GET['status'] )
     894        ? sanitize_key( $_GET['status'] )
     895        : '';
     896
     897    // Nothing is current?
     898    $all_current = empty( $selected )
     899        ? 'current'
     900        : '';
     901
     902    // Pending is current?
     903    $pending_current = ( 'pending' === $selected )
     904        ? 'current'
     905        : '';
     906
     907    // Sort
     908    ksort( $pending );
     909
     910    // Build the filter URL
     911    $filter_url = add_query_arg( array(
     912        'status' => 'pending'
     913    ), $tools_url );
     914
     915    // Count HTML
     916    $all_count     = $r['count_before'] . count( $tools   ) . $r['count_after'];
     917    $pending_count = $r['count_before'] . count( $pending ) . $r['count_after'];
     918
     919    // Define links
     920    $links = array(
     921        $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'],
     922        $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']
     923    );
     924
     925    // Surround output with before & after strings
     926    $output = $r['before'] . implode( $r['sep'], $links ) . $r['after'];
     927
     928    // Filter & return
     929    return apply_filters( 'bbp_get_admin_repair_tool_status_filters', $output, $r, $args );
     930}
Note: See TracChangeset for help on using the changeset viewer.