Skip to:
Content

bbPress.org

Changeset 6896


Ignore:
Timestamp:
01/29/2019 03:36:23 AM (6 years ago)
Author:
johnjamesjacoby
Message:

Upgrades: change skipped upgrades to pending upgrade

  • Add functions for managing pending upgrades
  • Use IDs instead of strings for active tools tab
  • Add classes and hr for related H1's
  • Update registered option key name
  • Add skipped upgrades to pending upgrades array
  • Add span to allowed tags in notices

These changes are necessary to bring adimn pages up to speed with WordPress Admin UI mark-up, in relation to the database upgrade notice.

See #3244.

Location:
trunk/src/includes
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/classes/class-bbp-admin.php

    r6819 r6896  
    210210        }
    211211
    212         // Database upgrade skipped?
    213         $skipped = get_option( '_bbp_db_upgrade_skipped', 0 );
    214 
    215         // Database upgrade skipped!
    216         if ( ! empty( $skipped ) && ( $skipped < 260 ) && current_user_can( 'bbp_tools_upgrade_page' ) ) {
     212        // Get page
     213        $page = ! empty( $_GET['page'] )
     214            ? sanitize_key( $_GET['page'] )
     215            : false;
     216
     217        // Pending database upgrades!
     218        if ( ( 'bbp-upgrade' !== $page ) && bbp_get_pending_upgrades() && current_user_can( 'bbp_tools_upgrade_page' ) ) {
    217219
    218220            // Link to upgrade page
    219221            $upgrade_url  = add_query_arg( array( 'page' => 'bbp-upgrade' ), admin_url( 'tools.php' ) );
    220             $dismiss_url  = wp_nonce_url( add_query_arg( array( 'bbp-hide-notice' => 'bbp-skip-upgrade' ) ), 'bbp-hide-notice' );
    221             $upgrade_link = '<a href="' . esc_url( $upgrade_url ) . '">' . esc_html__( 'Go Upgrade',   'bbpress' ) . '</a>';
    222             $dismiss_link = '<a href="' . esc_url( $dismiss_url ) . '">' . esc_html__( 'Hide Forever', 'bbpress' ) . '</a>';
     222            $dismiss_url  = wp_nonce_url( add_query_arg( array( 'bbp-hide-notice' => 'bbp-skip-upgrades' ) ), 'bbp-hide-notice' );
     223            $upgrade_link = '<a href="' . esc_url( $upgrade_url ) . '">' . esc_html__( 'Learn More',   'bbpress' ) . '</a>';
     224            $dismiss_link = '<a href="' . esc_url( $dismiss_url ) . '">' . esc_html__( 'Hide For Now', 'bbpress' ) . '</a>';
    223225            $bbp_dashicon = '<span class="bbpress-logo-icon"></span>';
    224226            $message      = $bbp_dashicon . sprintf(
    225                 esc_html__( 'bbPress requires a manual database upgrade. %s or %s', 'bbpress' ),
     227                esc_html__( 'bbPress requires a manual database upgrade. %s or %s.', 'bbpress' ),
    226228                $upgrade_link,
    227229                $dismiss_link
     
    240242    public function hide_notices() {
    241243
     244        // Hiding a notice?
     245        $hiding_notice = ! empty( $_GET['bbp-hide-notice'] )
     246            ? sanitize_key( $_GET['bbp-hide-notice'] )
     247            : false;
     248
    242249        // Bail if not hiding a notice
    243         if ( empty( $_GET['bbp-hide-notice'] ) ) {
     250        if ( empty( $hiding_notice ) ) {
    244251            return;
    245252        }
     
    254261
    255262        // Maybe delete notices
    256         switch ( $_GET['bbp-hide-notice'] ) {
     263        switch ( $hiding_notice ) {
    257264
    258265            // Skipped upgrade notice
    259             case 'bbp-skip-upgrade' :
    260                 delete_option( '_bbp_db_upgrade_skipped' );
     266            case 'bbp-skip-upgrades' :
     267                bbp_clear_pending_upgrades();
    261268                break;
    262269        }
     
    363370     */
    364371    private function esc_notice( $message = '' ) {
     372
     373        // Get allowed HTML
    365374        $tags = wp_kses_allowed_html();
     375
     376        // Allow spans with classes in notices
     377        $tags['span'] = array(
     378            'class' => 1
     379        );
     380
     381        // Parse the message and remove unsafe tags
    366382        $text = wp_kses( $message, $tags );
    367383
     384        // Return the message text
    368385        return $text;
    369386    }
     
    899916        list( $display_version ) = explode( '-', bbp_get_version() ); ?>
    900917
    901         <h1><?php printf( esc_html__( 'Welcome to bbPress %s', 'bbpress' ), $display_version ); ?></h1>
     918        <h1 class="wp-heading-inline"><?php printf( esc_html__( 'Welcome to bbPress %s', 'bbpress' ), $display_version ); ?></h1>
     919        <hr class="wp-header-end">
    902920        <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>
    903921
     
    11371155
    11381156        <div class="wrap">
    1139             <h1><?php esc_html_e( 'Update Forum', 'bbpress' ); ?></h1>
     1157            <h1 class="wp-heading-inline"><?php esc_html_e( 'Update Forum', 'bbpress' ); ?></h1>
     1158            <hr class="wp-header-end">
    11401159
    11411160        <?php
     
    11801199
    11811200        <div class="wrap">
    1182             <h1><?php esc_html_e( 'Update Forums', 'bbpress' ); ?></h1>
     1201            <h1 class="wp-heading-inline"><?php esc_html_e( 'Update Forums', 'bbpress' ); ?></h1>
     1202            <hr class="wp-header-end">
    11831203
    11841204        <?php
  • trunk/src/includes/admin/settings.php

    r6869 r6896  
    14951495
    14961496    <div class="wrap">
    1497         <h1><?php esc_html_e( 'Forums Settings', 'bbpress' ) ?></h1>
     1497        <h1 class="wp-heading-inline"><?php esc_html_e( 'Forums Settings', 'bbpress' ) ?></h1>
    14981498        <hr class="wp-header-end">
    14991499
     
    17741774
    17751775    <div class="wrap">
    1776         <h1><?php esc_html_e( 'Forum Tools', 'bbpress' ); ?></h1>
     1776        <h1 class="wp-heading-inline"><?php esc_html_e( 'Forum Tools', 'bbpress' ); ?></h1>
    17771777        <hr class="wp-header-end">
    1778         <h2 class="nav-tab-wrapper"><?php bbp_tools_admin_tabs( esc_html__( 'Import Forums', 'bbpress' ) ); ?></h2>
     1778        <h2 class="nav-tab-wrapper"><?php bbp_tools_admin_tabs( 'bbp-converter' ); ?></h2>
    17791779
    17801780        <div class="bbp-converter-wrap">
  • trunk/src/includes/admin/tools.php

    r6892 r6896  
    478478
    479479            // Setup tab HTML
    480             $is_current = (bool) ( $tab['name'] == $active_tab );
     480            $is_current = (bool) ( $tab['page'] === $active_tab );
    481481            $tab_class  = $is_current ? $active_class : $idle_class;
    482482            $tab_url    = add_query_arg( array( 'page' => $tab['page'] ), admin_url( 'tools.php' ) );
  • trunk/src/includes/admin/tools/repair.php

    r6891 r6896  
    2626
    2727    <div class="wrap">
    28         <h1><?php esc_html_e( 'Forum Tools', 'bbpress' ); ?></h1>
    29         <h2 class="nav-tab-wrapper"><?php bbp_tools_admin_tabs( esc_html__( 'Repair Forums', 'bbpress' ) ); ?></h2>
     28        <h1 class="wp-heading-inline"><?php esc_html_e( 'Forum Tools', 'bbpress' ); ?></h1>
     29        <hr class="wp-header-end">
     30        <h2 class="nav-tab-wrapper"><?php bbp_tools_admin_tabs( 'bbp-repair' ); ?></h2>
    3031
    3132        <p><?php esc_html_e( 'bbPress keeps track of relationships between forums, topics, replies, topic-tags, favorites, subscriptions, and users. Occasionally these relationships become out of sync, most often after an import or migration. Use the tools below to manually recalculate these relationships.', 'bbpress' ); ?></p>
  • trunk/src/includes/admin/tools/reset.php

    r6759 r6896  
    2121
    2222    <div class="wrap">
    23         <h1><?php esc_html_e( 'Forum Tools', 'bbpress' ); ?></h1>
    24         <h2 class="nav-tab-wrapper"><?php bbp_tools_admin_tabs( esc_html__( 'Reset Forums', 'bbpress' ) ); ?></h2>
     23        <h1 class="wp-heading-inline"><?php esc_html_e( 'Forum Tools', 'bbpress' ); ?></h1>
     24        <hr class="wp-header-end">
     25        <h2 class="nav-tab-wrapper"><?php bbp_tools_admin_tabs( 'bbp-reset' ); ?></h2>
    2526        <p><?php esc_html_e( 'Revert your forums back to a brand new installation, as if bbPress were never installed. This process cannot be undone.', 'bbpress' ); ?></p>
    2627
  • trunk/src/includes/admin/tools/upgrade.php

    r6895 r6896  
    2323
    2424    <div class="wrap">
    25         <h1><?php esc_html_e( 'Forum Tools', 'bbpress' ); ?></h1>
    26         <h2 class="nav-tab-wrapper"><?php bbp_tools_admin_tabs( esc_html__( 'Upgrade Forums', 'bbpress' ) ); ?></h2>
     25        <h1 class="wp-heading-inline"><?php esc_html_e( 'Forum Tools', 'bbpress' ); ?></h1>
     26        <hr class="wp-header-end">
     27        <h2 class="nav-tab-wrapper"><?php bbp_tools_admin_tabs( 'bbp-upgrade' ); ?></h2>
    2728
    2829        <p><?php esc_html_e( 'As bbPress improves, occasionally database upgrades are required but some forums are too large to upgrade automatically. Use the tools below to manually run upgrade routines.', 'bbpress' ); ?></p>
  • trunk/src/includes/core/options.php

    r6877 r6896  
    3333
    3434            '_bbp_db_version'             => 0,         // Database version
    35             '_bbp_db_upgrade_skipped'     => 0,         // Database upgrade skipped
     35            '_bbp_db_pending_upgrades'    => array(),   // Database upgrades pending
    3636
    3737            /** Flags *************************************************************/
  • trunk/src/includes/core/update.php

    r6876 r6896  
    352352                bbp_admin_upgrade_user_forum_subscriptions();
    353353            } else {
    354                 update_option( '_bbp_db_upgrade_skipped', $raw_db_version );
     354                bbp_add_pending_upgrade( 'bbp-user-favorites-move' );
     355                bbp_add_pending_upgrade( 'bbp-user-topic-subscriptions-move' );
     356                bbp_add_pending_upgrade( 'bbp-user-forum-subscriptions-move' );
    355357
    356358                // Set strategy to pre-2.6 on large network
     
    370372                bbp_admin_upgrade_user_engagements();
    371373            } else {
    372                 update_option( '_bbp_db_upgrade_skipped', $raw_db_version );
     374                bbp_add_pending_upgrade( 'bbp-user-topic-engagements-move' );
    373375
    374376                // Set strategy to pre-2.6 on large network
     
    491493    wp_get_current_user();
    492494}
     495
     496/** Pending Upgrades **********************************************************/
     497
     498/**
     499 * Return the number of pending upgrades
     500 *
     501 * @since 2.6.0 bbPress (r6895)
     502 *
     503 * @return int
     504 */
     505function bbp_get_pending_upgrade_count() {
     506    return count( (array) bbp_get_pending_upgrades() );
     507}
     508
     509/**
     510 * Return an array of pending upgrades
     511 *
     512 * @since 2.6.0 bbPress (r6895)
     513 *
     514 * @return array
     515 */
     516function bbp_get_pending_upgrades() {
     517    return (array) get_option( '_bbp_db_pending_upgrades', array() );
     518}
     519
     520/**
     521 * Add an upgrade ID to pending upgrades array
     522 *
     523 * @since 2.6.0 bbPress (r6895)
     524 *
     525 * @param string $upgrade_id
     526 */
     527function bbp_add_pending_upgrade( $upgrade_id = '' ) {
     528
     529    // Get the pending upgrades option
     530    $pending = bbp_get_pending_upgrades();
     531
     532    // Maybe add upgrade ID to end of pending array
     533    if ( ! isset( $pending[ $upgrade_id ] ) ) {
     534        array_push( $pending, $upgrade_id );
     535    }
     536
     537    // Update and return
     538    return update_option( '_bbp_db_pending_upgrades', $pending );
     539}
     540
     541/**
     542 * Add an upgrade ID to pending upgrades array
     543 *
     544 * @since 2.6.0 bbPress (r6895)
     545 *
     546 * @param string $upgrade_id
     547 */
     548function bbp_remove_pending_upgrade( $upgrade_id = '' ) {
     549
     550    // Get the pending upgrades option
     551    $pending = bbp_get_pending_upgrades();
     552
     553    // Maybe remove upgrade ID from pending array
     554    if ( isset( $pending[ $upgrade_id ] ) ) {
     555        unset( $pending[ $upgrade_id ] );
     556    }
     557
     558    // Update and return
     559    return update_option( '_bbp_db_pending_upgrades', $pending );
     560}
     561
     562/**
     563 * Delete all pending upgrades
     564 *
     565 * @since 2.6.0 bbPress (r6895)
     566 */
     567function bbp_clear_pending_upgrades() {
     568    return delete_option( '_bbp_db_pending_upgrades' );
     569}
Note: See TracChangeset for help on using the changeset viewer.