Skip to:
Content

bbPress.org

Changeset 4104


Ignore:
Timestamp:
07/22/2012 10:09:36 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Forum Visibility:

  • Prevent forum metaboxes from saving forum revisions as private/hidden.
  • Add repair function for private/hidden forums to Tools.
  • Add updater for 2.1.1, and run the visibility repair function.
  • Fixes #1891.
  • For 2.1 branch.
Location:
branches/2.1
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/2.1/bbp-admin/bbp-forums.php

    r4079 r4104  
    303303            return $forum_id;
    304304
     305        // Only save for forum post-types
     306        if ( ! bbp_is_forum( $forum_id ) )
     307            return $forum_id;
     308
    305309        // Bail if current user cannot edit this forum
    306310        if ( !current_user_can( 'edit_forum', $forum_id ) )
  • branches/2.1/bbp-admin/bbp-tools.php

    r3966 r4104  
    160160        0  => array( 'bbp-sync-topic-meta',        __( 'Recalculate the parent topic for each post',          'bbpress' ), 'bbp_admin_repair_topic_meta'               ),
    161161        5  => array( 'bbp-sync-forum-meta',        __( 'Recalculate the parent forum for each post',          'bbpress' ), 'bbp_admin_repair_forum_meta'               ),
    162         10 => array( 'bbp-forum-topics',           __( 'Count topics in each forum',                          'bbpress' ), 'bbp_admin_repair_forum_topic_count'        ),
    163         15 => array( 'bbp-forum-replies',          __( 'Count replies in each forum',                         'bbpress' ), 'bbp_admin_repair_forum_reply_count'        ),
    164         20 => array( 'bbp-topic-replies',          __( 'Count replies in each topic',                         'bbpress' ), 'bbp_admin_repair_topic_reply_count'        ),
    165         25 => array( 'bbp-topic-voices',           __( 'Count voices in each topic',                          'bbpress' ), 'bbp_admin_repair_topic_voice_count'        ),
    166         30 => array( 'bbp-topic-hidden-replies',   __( 'Count spammed & trashed replies in each topic',       'bbpress' ), 'bbp_admin_repair_topic_hidden_reply_count' ),
    167         35 => array( 'bbp-user-replies',           __( 'Count topics for each user',                          'bbpress' ), 'bbp_admin_repair_user_topic_count'         ),
    168         35 => array( 'bbp-user-topics',            __( 'Count replies for each user',                         'bbpress' ), 'bbp_admin_repair_user_reply_count'         ),
    169         40 => array( 'bbp-user-favorites',         __( 'Remove trashed topics from user favorites',           'bbpress' ), 'bbp_admin_repair_user_favorites'           ),
    170         45 => array( 'bbp-user-subscriptions',     __( 'Remove trashed topics from user subscriptions',       'bbpress' ), 'bbp_admin_repair_user_subscriptions'       ),
    171         50 => array( 'bbp-sync-all-topics-forums', __( 'Recalculate last activity in each topic and forum',   'bbpress' ), 'bbp_admin_repair_freshness'                )
     162        10 => array( 'bbp-sync-forum-visibility',  __( 'Recalculate private and hidden forums',               'bbpress' ), 'bbp_admin_repair_forum_visibility'         ),
     163        15 => array( 'bbp-forum-topics',           __( 'Count topics in each forum',                          'bbpress' ), 'bbp_admin_repair_forum_topic_count'        ),
     164        20 => array( 'bbp-forum-replies',          __( 'Count replies in each forum',                         'bbpress' ), 'bbp_admin_repair_forum_reply_count'        ),
     165        25 => array( 'bbp-topic-replies',          __( 'Count replies in each topic',                         'bbpress' ), 'bbp_admin_repair_topic_reply_count'        ),
     166        30 => array( 'bbp-topic-voices',           __( 'Count voices in each topic',                          'bbpress' ), 'bbp_admin_repair_topic_voice_count'        ),
     167        35 => array( 'bbp-topic-hidden-replies',   __( 'Count spammed & trashed replies in each topic',       'bbpress' ), 'bbp_admin_repair_topic_hidden_reply_count' ),
     168        40 => array( 'bbp-user-replies',           __( 'Count topics for each user',                          'bbpress' ), 'bbp_admin_repair_user_topic_count'         ),
     169        45 => array( 'bbp-user-topics',            __( 'Count replies for each user',                         'bbpress' ), 'bbp_admin_repair_user_reply_count'         ),
     170        50 => array( 'bbp-user-favorites',         __( 'Remove trashed topics from user favorites',           'bbpress' ), 'bbp_admin_repair_user_favorites'           ),
     171        55 => array( 'bbp-user-subscriptions',     __( 'Remove trashed topics from user subscriptions',       'bbpress' ), 'bbp_admin_repair_user_subscriptions'       ),
     172        60 => array( 'bbp-sync-all-topics-forums', __( 'Recalculate last activity in each topic and forum',   'bbpress' ), 'bbp_admin_repair_freshness'                )
    172173    );
    173174    ksort( $repair_list );
     
    679680    }
    680681   
     682    // Complete results
     683    $result = __( 'Complete!', 'bbpress' );
     684    return array( 0, sprintf( $statement, $result ) );
     685}
     686
     687/**
     688 * Recaches the private and hidden forums
     689 *
     690 * @since bbPress (r4104)
     691 *
     692 * @uses delete_option() to delete private and hidden forum pointers
     693 * @uses WP_Query() To query post IDs
     694 * @uses is_wp_error() To return if error occurred
     695 * @uses update_option() To update the private and hidden post ID pointers
     696 * @return array An array of the status code and the message
     697 */
     698function bbp_admin_repair_forum_visibility() {
     699
     700    $statement = __( 'Recalculating forum visibility … %s', 'bbpress' );
     701    $result    = __( 'Failed!', 'bbpress' );
     702
     703    // First, delete everything.
     704    delete_option( '_bbp_private_forums' );
     705    delete_option( '_bbp_hidden_forums'  );
     706
     707    // Next, get all the private and hidden forums
     708    $private_forums = new WP_Query( array(
     709        'suppress_filters' => true,
     710        'nopaging'         => true,
     711        'post_type'        => bbp_get_forum_post_type(),
     712        'post_status'      => bbp_get_private_status_id(),
     713        'fields'           => 'ids'
     714    ) );
     715    $hidden_forums = new WP_Query( array(
     716        'suppress_filters' => true,
     717        'nopaging'         => true,
     718        'post_type'        => bbp_get_forum_post_type(),
     719        'post_status'      => bbp_get_hidden_status_id(),
     720        'fields'           => 'ids'
     721    ) );
     722
     723    // Bail if queries returned errors
     724    if ( is_wp_error( $private_forums ) || is_wp_error( $hidden_forums ) )
     725        return array( 2, sprintf( $statement, $result ) );
     726
     727    update_option( '_bbp_private_forums', $private_forums->posts ); // Private forums
     728    update_option( '_bbp_hidden_forums',  $hidden_forums->posts  ); // Hidden forums
     729
    681730    // Complete results
    682731    $result = __( 'Complete!', 'bbpress' );
  • branches/2.1/bbp-includes/bbp-core-update.php

    r3964 r4104  
    140140    // Are we running an outdated version of bbPress?
    141141    if ( bbp_is_update() ) {
     142
     143        // Call the automated updater
     144        bbp_version_updater();
    142145
    143146        // Bump the version
     
    210213    );
    211214}
     215
     216/**
     217 * bbPress's version updater looks at what the current database version is, and
     218 * runs whatever other code is needed.
     219 *
     220 * This is most-often used when the data schema changes, but should also be used
     221 * to correct issues with bbPress meta-data silently on software update.
     222 *
     223 * @since bbPress (r4104)
     224 */
     225function bbp_version_updater() {
     226
     227    // Get the raw database version
     228    $raw_db_version = (int) bbp_get_db_version_raw();
     229
     230    // Bail if no database version exists
     231    if ( empty( $raw_db_version ) )
     232        return;
     233
     234    /** 2.0 Branch ************************************************************/
     235
     236    // 2.0, 2.0.1, 2.0.2, 2.0.3
     237    if ( $raw_db_version < 200 ) {
     238        // Do nothing
     239    }
     240
     241    /** 2.1 Branch ************************************************************/
     242
     243    // 2.1, 2.1.1
     244    if ( $raw_db_version < 211 ) {
     245
     246        /**
     247         * Repair private and hidden forum data
     248         *
     249         * @link http://bbpress.trac.wordpress.org/ticket/1891
     250         */
     251        bbp_admin_repair_forum_visibility();
     252    }
     253
     254    /** 2.2 Branch ************************************************************/
     255
     256    // 2.2
     257    if ( $raw_db_version < 220 ) {
     258        // No changes yet
     259    }
     260}
  • branches/2.1/bbp-includes/bbp-forum-functions.php

    r4071 r4104  
    612612
    613613    // Bail if forum ID is empty
    614     if ( empty( $forum_id ) )
     614    if ( empty( $forum_id ) || ! bbp_is_forum( $forum_id ) )
    615615        return;
    616616
  • branches/2.1/bbpress.php

    r4073 r4104  
    175175
    176176        $this->version    = '2.1'; // bbPress version
    177         $this->db_version = '210'; // bbPress DB version
     177        $this->db_version = '211'; // bbPress DB version
    178178
    179179        /** Paths *************************************************************/
Note: See TracChangeset for help on using the changeset viewer.