Skip to:
Content

bbPress.org

Ticket #2157: bbpress-admin-tools-sticky.patch

File bbpress-admin-tools-sticky.patch, 3.2 KB (added by gawain, 13 years ago)
  • includes/admin/tools.php

    diff --git a/includes/admin/tools.php b/includes/admin/tools.php
    index 16f13f2..3553f56 100644
    a b  
    161161                5  => array( 'bbp-sync-forum-meta',        __( 'Recalculate the parent forum for each post',          'bbpress' ), 'bbp_admin_repair_forum_meta'               ),
    162162                10 => array( 'bbp-sync-forum-visibility',  __( 'Recalculate private and hidden forums',               'bbpress' ), 'bbp_admin_repair_forum_visibility'         ),
    163163                15 => array( 'bbp-sync-all-topics-forums', __( 'Recalculate last activity in each topic and forum',   'bbpress' ), 'bbp_admin_repair_freshness'                ),
     164                16 => array( 'bbp-sync-all-topics-sticky', __( 'Recalculate the sticky replationship of each topic',  'bbpress' ), 'bbp_admin_repair_sticky'                   ),
    164165                20 => array( 'bbp-group-forums',           __( 'Repair BuddyPress Group Forum relationships',         'bbpress' ), 'bbp_admin_repair_group_forum_relationship' ),
    165166                25 => array( 'bbp-forum-topics',           __( 'Count topics in each forum',                          'bbpress' ), 'bbp_admin_repair_forum_topic_count'        ),
    166167                30 => array( 'bbp-forum-replies',          __( 'Count replies in each forum',                         'bbpress' ), 'bbp_admin_repair_forum_reply_count'        ),
     
    704705
    705706                // If no role map exists, give the default forum role (bbp-participant)
    706707                $new_role = isset( $role_map[$role] ) ? $role_map[$role] : $default_role;
    707                        
     708
    708709                // Get users of this site, limited to 1000
    709710                while ( $users = get_users( array(
    710711                                'role'   => $role,
     
    836837}
    837838
    838839/**
     840 * Repairing the relationship of forums sticky posts topics to the actual parent
     841 *
     842 * @since bbPress ()
     843 *
     844 * @uses wpdb::get_col() To run our recount sql queries
     845 * @uses is_wp_error() To check if the executed query returned {@link WP_Error}
     846 * @return array An array of the status code and the message
     847 */
     848function bbp_admin_repair_sticky() {
     849        global $wpdb;
     850
     851        $statement = __( 'Repairing the relationship of forums sticky posts topics to the actual parent… %s', 'bbpress' );
     852        $result    = __( 'Failed!', 'bbpress' );
     853
     854
     855        $forums = $wpdb->get_col( "SELECT ID FROM `$wpdb->posts` WHERE `post_type` = 'forum' AND ( `post_status` = 'publish' OR `post_status` = 'private' );" );
     856
     857        if ( is_wp_error( $forums ) )
     858                return array( 1, sprintf( $statement, $result ) );
     859
     860        foreach( $forums as $forum )
     861                        $forum_stickies[$forum] = get_post_meta( $forum, '_bbp_sticky_topics', true );
     862
     863        foreach( $forum_stickies as $forum => $stickies )
     864        {
     865                if ( ! empty( $stickies ) )
     866                {
     867                        foreach ( $stickies as $id=> $topic_id )
     868                        {
     869                                // Make sure topic is not super sticky and the parent forum matches this one
     870                                if ( ! bbp_is_topic_super_sticky( $topic_id ) && $forum != bbp_get_topic_forum_id( $topic_id ) )
     871                                        unset( $forum_stickies[$forum][$id] );
     872                        }
     873                        $stuck = ( empty( $forum_stickies[$forum] ) ? '' : array_values( $forum_stickies[$forum] ) );
     874                        update_post_meta( $forum, '_bbp_sticky_topics', $stuck );
     875                }
     876        }
     877
     878        return array( 0, sprintf( $statement, __( 'Complete!', 'bbpress' ) ) );
     879}
     880
     881/**
    839882 * Recaches the private and hidden forums
    840883 *
    841884 * @since bbPress (r4104)