0

I have a poll, the vote of which must be closed for guests.

<ol class="zf-structure-list zf-quiz_answer zf-text zf-clearfix">
    <?php
    if( isset( $question["answers"] ) ) {
        foreach ($question["answers"] as $answer) {
            ?>
            <li class="zf-answer-item <?php if (isset($_COOKIE["zf_poll_vote_ans_" . $answer["answer_id"]])) echo 'zf-selected'; ?>"
                data-voted="<?php echo isset($poll_results["answers"][$answer["answer_id"]]) ? $poll_results["answers"][$answer["answer_id"]] : 0 ?>"
                data-id="<?php echo $answer["answer_id"]; ?>" data-post-id="<?php the_ID() ?>"
                data-group-id="<?php echo $question["question_id"]; ?>"
                data-voted-group="<?php echo isset($zombify_poll_results["groups"][$question["question_id"]]) ? $zombify_poll_results["groups"][$question["question_id"]] : 0 ?>">
               <div class="zf-answer js-zf-answer">
                   <div class="zf-checkbox-wrp"></div>
                   <div class="zf-poll-stat"></div>
                   <div class="zf-poll-stat_count"></div>
                   <div class="zf-answer_text">
                       <?php echo $answer["answer_text"]; ?>
                   </div>
               </div>
            </li>
        <?php
        }
    } ?>
</ol>

How to make that polls show for the guest, but when you click on the zf-answer-item, nothing happened?

Thanks!

  • How are you implementing polls? I'm guessing based on the data attributes you're using a polls JS library, but you never mention which one, how it's added, how it runs, etc etc. Also where does this data come from? WP doesn't come with polls out of the box, are you using a custom plugin? Where does the $question array come from? How do you determine what a guest is? – Tom J Nowell Jan 2 '19 at 17:55
0

You can check user logged in with is_user_logged_in. This is a simple function to check user logged in or not. Can you try this?

<ol class="zf-structure-list zf-quiz_answer zf-text zf-clearfix">
    <?php
  if(is_user_logged_in()){
    if( isset( $question["answers"] ) ) {
        foreach ($question["answers"] as $answer) {
            ?>
            <li class="zf-answer-item <?php if (isset($_COOKIE["zf_poll_vote_ans_" . $answer["answer_id"]])) echo 'zf-selected'; ?>"
                data-voted="<?php echo isset($poll_results["answers"][$answer["answer_id"]]) ? $poll_results["answers"][$answer["answer_id"]] : 0 ?>"
                data-id="<?php echo $answer["answer_id"]; ?>" data-post-id="<?php the_ID() ?>"
                data-group-id="<?php echo $question["question_id"]; ?>"
                data-voted-group="<?php echo isset($zombify_poll_results["groups"][$question["question_id"]]) ? $zombify_poll_results["groups"][$question["question_id"]] : 0 ?>">
               <div class="zf-answer js-zf-answer">
                   <div class="zf-checkbox-wrp"></div>
                   <div class="zf-poll-stat"></div>
                   <div class="zf-poll-stat_count"></div>
                   <div class="zf-answer_text">
                       <?php echo $answer["answer_text"]; ?>
                   </div>
               </div>
            </li>
        <?php
        }
     }
} else {
 echo 'Please login to show these poll';
}?>
</ol>```

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.