| 161 | 161 | 5 => array( 'bbp-sync-forum-meta', __( 'Recalculate the parent forum for each post', 'bbpress' ), 'bbp_admin_repair_forum_meta' ), |
| 162 | 162 | 10 => array( 'bbp-sync-forum-visibility', __( 'Recalculate private and hidden forums', 'bbpress' ), 'bbp_admin_repair_forum_visibility' ), |
| 163 | 163 | 15 => array( 'bbp-sync-all-topics-forums', __( 'Recalculate last activity in each topic and forum', 'bbpress' ), 'bbp_admin_repair_freshness' ), |
| 164 | 165 | 20 => array( 'bbp-group-forums', __( 'Repair BuddyPress Group Forum relationships', 'bbpress' ), 'bbp_admin_repair_group_forum_relationship' ), |
| 165 | 166 | 25 => array( 'bbp-forum-topics', __( 'Count topics in each forum', 'bbpress' ), 'bbp_admin_repair_forum_topic_count' ), |
| 166 | 167 | 30 => array( 'bbp-forum-replies', __( 'Count replies in each forum', 'bbpress' ), 'bbp_admin_repair_forum_reply_count' ), |
| | 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 | */ |
| | 848 | function 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 | /** |