lesterchan / wp-polls

Adds an AJAX poll system to your WordPress blog. You can also easily add a poll into your WordPress's blog post/page.
https://wordpress.org/plugins/wp-polls/
93 stars 78 forks source link

Cleaning nested if statements #82

Closed ghost closed 7 years ago

ghost commented 7 years ago

I added a switch statement to handle the errors. I also moved some variables around to make it run cleaner. This was tested on my own local instance of WordPress, and it worked without any problems. If this isn't what you were looking for, it's cool.

lesterchan commented 7 years ago

I will probably do something like:

if( $is_real <= 0 ) {
    printf(__('Invalid Answer to Poll ID #%s', 'wp-polls'), $poll_id);
    die();
}

if( $poll_id <= 0 || empty($poll_aid_array) || ! check_allowtovote()) {
    printf(__('Invalid Poll ID. Poll ID #%s', 'wp-polls'), $poll_id);
    die();
}

if ( $is_poll_open <= 0 ) {
    printf( __( 'Poll ID #%s is closed', 'wp-polls' ), $poll_id );
    die();
}

if ($check_voted > 0) {
    printf(__('You Had Already Voted For This Poll. Poll ID #%s', 'wp-polls'), $poll_id);
    die();
}

// Rate The Poll