PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.5.1
Forumax – AI Powered Advanced Community Forum Plugin v2.5.1
2.5.1 2.5.0 2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 All 31 releases
← All changes | includes/features/bbp_voting/frontend.php +16 -25 2.5.0 → 2.5.1 View file →
@@ -92,11 +92,20 @@
92 92 }
93 93
94 94 $voting_log = get_post_meta( $post_id, 'bbp_voting_log', true );
95 95 $voting_log = is_array( $voting_log ) ? $voting_log : [];
96 - $client_ip = $_SERVER['REMOTE_ADDR'];
97 - $identifier = is_user_logged_in() ? get_current_user_id() : $client_ip;
98 - $existing_vote = $voting_log[ $identifier ] ?? 0;
96 + // Match the identifier the AJAX handler stores (hashed IP for visitors),
97 + // falling back to legacy raw-IP entries saved before 2.3.1.
98 + $existing_vote = 0;
99 + if ( is_user_logged_in() ) {
100 + $existing_vote = $voting_log[ get_current_user_id() ] ?? 0;
101 + } elseif ( ! empty( $voting_log ) ) {
102 + $existing_vote = $voting_log[ forumax_get_hashed_ip() ] ?? 0;
103 + if ( ! $existing_vote ) {
104 + $raw_ip = forumax_get_raw_ip();
105 + $existing_vote = $raw_ip ? ( $voting_log[ $raw_ip ] ?? 0 ) : 0;
106 + }
107 + }
99 108
100 109 // Check if admin can bypass voting restrictions
101 110 $admin_bypass = current_user_can( 'administrator' ) &&
102 111 forumax_get_opt( 'is_admin_can_vote_unlimited', false );
@@ -296,30 +305,12 @@
296 305
297 306 // Get the meta key to sort by
298 307 $sort_meta_key = apply_filters( 'bbp_voting_sort_meta_key', 'bbp_voting_score' );
299 308
300 - // Find and fill any posts missing the sort meta key
301 - $cache_key = 'frmx_vote_backfill_' . md5( serialize( $args ) );
302 - if ( false === get_transient( $cache_key ) ) {
303 - $missing_meta_query = [
304 - 'meta_query' => [
305 - [
306 - 'key' => $sort_meta_key,
307 - 'compare' => 'NOT EXISTS',
308 - 'value' => '',
309 - ],
310 - ],
311 - 'fields' => 'ids',
312 - ];
313 -
314 - $query = new WP_Query( array_merge( $args, $missing_meta_query ) );
315 - foreach ( $query->posts as $post_id ) {
316 - $default_value = apply_filters( 'bbp_voting_sort_meta_key_default_value', '0', $post_id );
317 - update_post_meta( $post_id, $sort_meta_key, $default_value );
318 - }
319 -
320 - // Cache for 24 hours to skip subsequent checks
321 - set_transient( $cache_key, 'done', DAY_IN_SECONDS );
309 + // The default key is backfilled once site-wide and on save (see
310 + // forumax_backfill_voting_score_meta_once()), not per page view.
311 + if ( 'bbp_voting_score' !== $sort_meta_key ) {
312 + forumax_backfill_voting_sort_meta( $sort_meta_key, $args );
322 313 }
323 314
324 315 // Clear existing sort parameters
325 316 $args = array_diff_key( $args, array_flip( ['meta_key', 'meta_type', 'orderby', 'order'] ) );