topic_query->post; } if ( $this_post_type == $reply_post_type ) { $post = bbpress()->reply_query->post; } } // Do we have a post? if ( ! empty( $post ) ) { $post_id = $post->ID; // Since we're using a filter on the author link, avoid duplicates // if($bbp_voting_last_author_link_post_id === $post_id) { // Duplicate // return $author_link; // } else { // New, continue, but set the global variable // $bbp_voting_last_author_link_post_id = $post_id; // } if ( $current_action === 'bbp_voting_cpt' ) { $post_setting = true; $broad_disable = false; } else { switch ( $this_post_type ) { case $topic_post_type: $forum_id = bbp_get_topic_forum_id( $post_id ); $post_setting = get_post_meta( $forum_id, 'bbp_voting_forum_enable_topics', true ); $broad_disable = $opt['is_voting_disabled_topics'] ?? 0; break; case $reply_post_type: $forum_id = bbp_get_reply_forum_id( $post_id ); $post_setting = get_post_meta( $forum_id, 'bbp_voting_forum_enable_replies', true ); $broad_disable = $opt['is_voting_disabled_replies'] ?? 0; break; } // Filter Hook: 'bbp_voting_allowed_on_forum' if ( ! apply_filters( 'bbp_voting_allowed_on_forum', true, $forum_id ) ) { return; } } if ( ! empty( $post_setting ) ) { // Forum-specific override is set (not Default) if ( $post_setting === 'false' ) { return; } } else { // Use broad disable settings if ( $broad_disable === '0' ) { return; } } // Done with "allowed" checks... let's do this $score = (int) get_post_meta( $post_id, 'bbp_voting_score', true ); $ups = (int) get_post_meta( $post_id, 'bbp_voting_ups', true ); $downs = (int) get_post_meta( $post_id, 'bbp_voting_downs', true ); // Check for, and correct, discrepancies $calc_score = $ups + $downs; if ( $score > $calc_score ) { $diff = $score - $calc_score; $ups += $diff; update_post_meta( $post_id, 'bbp_voting_ups', $ups ); } // Get the weighted score // $weighted_score = get_post_meta($post_id, 'bbp_voting_weighted_score', true); // Get user's vote by ID or IP $voting_log = get_post_meta( $post_id, 'bbp_voting_log', true ); $voting_log = is_array( $voting_log ) ? $voting_log : []; // Set up new array $client_ip = $_SERVER['REMOTE_ADDR']; $identifier = is_user_logged_in() ? get_current_user_id() : $client_ip; $existing_vote = array_key_exists( $identifier, $voting_log ) ? $voting_log[ $identifier ] : 0; // Admin bypass? $is_admin_can_vote_unlimited = $opt['is_admin_can_vote_unlimited'] ?? false; $admin_bypass = current_user_can( 'administrator' ) && $is_admin_can_vote_unlimited; // View only score? // View only for visitors option $is_disabled_voting_non_logged = $opt['is_disabled_voting_for_non_logged_users'] ?? false; $view_only = ! is_user_logged_in() && $is_disabled_voting_non_logged; if ( ! $view_only ) { // View only for closed topic option. if ( $current_action !== 'bbp_voting_cpt' ) { $topic_id = $this_post_type == $topic_post_type ? $post_id : bbp_get_reply_topic_id( $post_id ); $topic_status = get_post_status( $topic_id ); $is_diabled_closed_topics = $opt['is_disabled_voting_closed_topics'] ?? false; $view_only = ( 'closed' == $topic_status && $is_diabled_closed_topics ) ? true : false; } if ( ! $view_only ) { // View only for author of post. $is_disabled_own_topic_reply = $opt['is_disabled_voting_own_topic_reply'] ?? false; $view_only = ( $is_disabled_own_topic_reply && $post->post_author == get_current_user_ID() ) ? true : false; } } // Show labels? // Disable down votes? $disable_down = $opt['is_down_votes_disabled'] ?? 0; $vote_number_display = $opt['vote_numbers_display'] ?? 'hover'; // How to display vote numbers? $display_vote_nums = 'num-' . $vote_number_display; // Start HTML $html = ''; $float = in_array( current_action(), [ 'bbp_theme_before_reply_content', 'bbp_theme_before_topic_content', 'bbp_voting_cpt' ] ); $html .= '