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