| @@ -3,13 +3,19 @@ | ||
| 3 | 3 | while ( $children->have_posts() ) : |
| 4 | 4 | $children->the_post(); |
| 5 | 5 | $current_topic_id = get_the_ID(); |
| 6 | 6 | |
| 7 | - // Batched in admin_ui.php via forumax_admin_reply_stats(). | |
| 8 | - $total_replies = (int) ( $reply_stats['total'][ $current_topic_id ] ?? 0 ); | |
| 9 | - $pending_replies = $reply_stats['pending'][ $current_topic_id ] ?? []; | |
| 7 | + $replies = new WP_Query( | |
| 8 | + [ | |
| 9 | + 'post_parent' => $current_topic_id, | |
| 10 | + 'post_type' => bbp_get_reply_post_type(), | |
| 11 | + 'post_status' => [ 'publish', 'draft', 'pending' ], | |
| 12 | + ] | |
| 13 | + ); | |
| 10 | 14 | |
| 11 | - $no_reply = 0 === $total_replies ? 'no-reply' : ''; | |
| 15 | + $pending_replies = []; | |
| 16 | + | |
| 17 | + $no_reply = 0 == $replies->found_posts ? 'no-reply' : ''; | |
| 12 | 18 | $is_solved = isset($GLOBALS['forumax_solve_topic']) && $GLOBALS['forumax_solve_topic']->is_solved( $current_topic_id ) ? ' solved' : ' unsolved'; |
| 13 | 19 | $is_open = bbp_is_topic_closed( $current_topic_id ) ? ' closed-topics' : ' open-topics'; |
| 14 | 20 | $is_hidden = bbp_is_topic_spam( $current_topic_id ) || bbp_is_topic_pending( $current_topic_id ) ? ' hidden-topics' : ''; |
| 15 | 21 | $approve_btn = ''; |
| @@ -50,9 +56,9 @@ | ||
| 50 | 56 | ?> |
| 51 | 57 | </span> |
| 52 | 58 | <h4> |
| 53 | 59 | <a href="<?php echo esc_attr( $edit_link ); ?>" target="<?php echo esc_attr( $target ); ?>"> |
| 54 | - <?php echo esc_html( get_the_title( $current_topic_id ) ); ?> | |
| 60 | + <?php the_title(); ?> | |
| 55 | 61 | </a> |
| 56 | 62 | </h4> |
| 57 | 63 | <!-- Topic Author --> |
| 58 | 64 | <span class="bbpc-author-name"> |
| @@ -61,9 +67,9 @@ | ||
| 61 | 67 | |
| 62 | 68 | echo wp_kses_post( |
| 63 | 69 | bbp_get_topic_author_link( |
| 64 | 70 | array( |
| 65 | - 'post_id' => $current_topic_id, | |
| 71 | + 'post_id' => get_the_ID(), | |
| 66 | 72 | 'type' => 'name', |
| 67 | 73 | ) |
| 68 | 74 | ) |
| 69 | 75 | ); |
| @@ -84,10 +90,21 @@ | ||
| 84 | 90 | ]; |
| 85 | 91 | |
| 86 | 92 | echo wp_kses( $approve_btn, $allowed_html ); |
| 87 | 93 | |
| 94 | + while ( $replies->have_posts() ) : | |
| 95 | + $replies->the_post(); | |
| 96 | + $reply_id = get_the_ID(); | |
| 97 | + | |
| 98 | + if ( bbp_is_reply_pending( $reply_id ) ) { | |
| 99 | + $pending_replies[] = $reply_id; | |
| 100 | + } | |
| 101 | + | |
| 102 | + endwhile; | |
| 103 | + wp_reset_postdata(); | |
| 104 | + | |
| 88 | 105 | $pending_replies_count = count( $pending_replies ); |
| 89 | - $reply_count = $total_replies - $pending_replies_count; | |
| 106 | + $reply_count = $replies->found_posts - $pending_replies_count; | |
| 90 | 107 | ?> |
| 91 | 108 | <div |
| 92 | 109 | title="<?php echo esc_attr( sprintf( |
| 93 | 110 | /* translators: %d: Number of published replies */ |
| @@ -125,9 +142,9 @@ | ||
| 125 | 142 | </li> |
| 126 | 143 | |
| 127 | 144 | <?php if ( current_user_can( 'editor' ) || current_user_can( 'administrator' ) ) : ?> |
| 128 | 145 | <li class="delete"> |
| 129 | - <a href="javascript:void(0)" bbp_topic_ID="<?php echo esc_attr( $current_topic_id ); ?>" class="section-delete" title="<?php esc_attr_e( 'Move this topic to the Trash', 'forumax' ); ?>"> | |
| 146 | + <a href="javascript:void(0)" bbp_topic_ID="<?php the_ID(); ?>" class="section-delete" title="<?php esc_attr_e( 'Move this topic to the Trash', 'forumax' ); ?>"> | |
| 130 | 147 | <span class="dashicons dashicons-trash"></span> |
| 131 | 148 | </a> |
| 132 | 149 | </li> |
| 133 | 150 | <?php endif; ?> |
| @@ -135,9 +152,9 @@ | ||
| 135 | 152 | </div> |
| 136 | 153 | <div class="right-content"> |
| 137 | 154 | <!-- Topic Refresh Time --> |
| 138 | 155 | <span class="progress-text"> |
| 139 | - <?php bbp_topic_freshness_link( $current_topic_id ); ?> | |
| 156 | + <?php bbp_topic_freshness_link() ?> | |
| 140 | 157 | </span> |
| 141 | 158 | <!-- ./Topic Refresh Time --> |
| 142 | 159 | </div> |
| 143 | 160 | </div> |
| @@ -146,14 +163,15 @@ | ||
| 146 | 163 | <?php if ( ! empty( $pending_replies_count ) ) : ?> |
| 147 | 164 | <ul class="bbpc-nested-replies" reply-target=<?php echo esc_attr( $current_topic_id ); ?>> |
| 148 | 165 | <?php |
| 149 | 166 | foreach ( $pending_replies as $p_reply ) { |
| 167 | + setup_postdata( $p_reply ); | |
| 150 | 168 | ?> |
| 151 | - <li reply-id="<?php echo esc_attr( $p_reply ); ?>" class="bbpc-reply-wrap"> | |
| 169 | + <li reply-id="<?php the_ID(); ?>" class="bbpc-reply-wrap"> | |
| 152 | 170 | <?php |
| 153 | - echo esc_html( wp_trim_words( get_post_field( 'post_content', $p_reply ), 10, '...' ) ); | |
| 171 | + echo esc_html( wp_trim_words( get_the_content(), 10, '...' ) ); | |
| 154 | 172 | echo ' - '; |
| 155 | - echo esc_html( bbp_get_reply_author_display_name( $p_reply ) ); | |
| 173 | + the_author(); | |
| 156 | 174 | ?> |
| 157 | 175 | <?php |
| 158 | 176 | if ( bbp_is_reply_pending( $p_reply ) ) { |
| 159 | 177 | $url = wp_nonce_url( admin_url( 'admin.php?bbpc_approve_reply_id=' . $p_reply ), 'bbpc_approve_reply_' . $p_reply ); |
| @@ -176,8 +194,10 @@ | ||
| 176 | 194 | ?> |
| 177 | 195 | </li> |
| 178 | 196 | <?php |
| 179 | 197 | } |
| 198 | + | |
| 199 | + wp_reset_postdata(); | |
| 180 | 200 | ?> |
| 181 | 201 | </ul> |
| 182 | 202 | <?php endif; ?> |
| 183 | 203 | </div> |