| @@ -11,16 +11,10 @@ | ||
| 11 | 11 | // Verify nonce for security |
| 12 | 12 | check_ajax_referer( 'forumax-nonce', 'nonce' ); |
| 13 | 13 | |
| 14 | 14 | header( 'Content-type: application/json' ); |
| 15 | - $post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0; | |
| 15 | + $post_id = (int) $_POST['post_id']; | |
| 16 | 16 | |
| 17 | - // Only published/closed topics and replies can be voted on. | |
| 18 | - $post_type = get_post_type( $post_id ); | |
| 19 | - if ( ! $post_id || ! in_array( $post_type, [ bbp_get_topic_post_type(), bbp_get_reply_post_type() ], true ) || ! in_array( get_post_status( $post_id ), [ 'publish', 'closed' ], true ) ) { | |
| 20 | - die( json_encode( [ 'error' => 'Invalid post.' ] ) ); | |
| 21 | - } | |
| 22 | - | |
| 23 | 17 | // View only for visitors. |
| 24 | 18 | if ( ! is_user_logged_in() && forumax_get_opt( 'is_disabled_voting_for_non_logged_users', false ) ) { |
| 25 | 19 | die( json_encode( [ 'error' => 'Voting is disabled for visitors.' ] ) ); |
| 26 | 20 | } |
| @@ -35,9 +29,9 @@ | ||
| 35 | 29 | if ( is_user_logged_in() && forumax_get_opt( 'is_disabled_voting_own_topic_reply', false ) && get_post_field( 'post_author', $post_id ) == get_current_user_ID() ) { |
| 36 | 30 | die( json_encode( [ 'error' => 'Voting is disabled on for the author.' ] ) ); |
| 37 | 31 | } |
| 38 | 32 | // Direction |
| 39 | - $direction = isset( $_POST['direction'] ) ? (int) $_POST['direction'] : 0; | |
| 33 | + $direction = (int) $_POST['direction']; | |
| 40 | 34 | $direction = in_array( $direction, [ 1, -1 ] ) ? $direction : 0; // Enforce 1 or -1 |
| 41 | 35 | |
| 42 | 36 | // Check if down votes are disabled |
| 43 | 37 | if ( $direction === -1 && forumax_get_opt( 'is_down_votes_disabled', 0 ) != 1 ) { |