Server IP : 66.29.132.124 / Your IP : 3.140.195.8 Web Server : LiteSpeed System : Linux business141.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : wavevlvu ( 1524) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/wavevlvu/misswavenigeria.com/wp-content/plugins/totalpoll-lite/src/Shortcodes/ |
Upload File : |
<?php namespace TotalPoll\Shortcodes; use TotalPoll\Poll\Model; use TotalPollVendors\TotalCore\Form\Page; use TotalPollVendors\TotalCore\Shortcodes\Shortcode; use WP_Error; /** * Poll Shortcode. * @package TotalPoll\Shortcode * @since 1.0.0 */ class RandomPoll extends Shortcode { /** * Render shortcode. * * @return mixed|string */ public function handle() { /** * @var Model|null $poll */ $poll = TotalPoll( 'polls.repository' )->getRandomly(); if ( ! $poll ): return ''; endif; $screen = $this->getAttribute( 'screen', 'vote' ); if ( $screen ): // Override screen when rendering add_filter( 'totalpoll/filters/render/screen', function ( $currentScreen, $renderedPoll ) use ( $poll, $screen ) { if ( $renderedPoll->getId() === $poll->getId() ) : if ( $screen === Model::VOTE_SCREEN && $poll->hasVoted() ) { $poll->setError( new WP_Error( 'voted_before', esc_html__( 'You cannot vote again.', 'totalpoll' ) ) ); } else { $poll->setError( null ); } return $screen; endif; return $currentScreen; }, 10, 2 ); // Hide fields when vote is not allowed add_filter( 'totalpoll/filters/form/pages', function ( $pages, $renderedPoll ) use ( $screen, $poll ) { if ( $renderedPoll->getId() === $poll->getId() && $screen === Model::VOTE_SCREEN && ! $poll->isAcceptingVotes() ) : $pages['fields'] = new Page(); endif; return $pages; }, 10, 2 ); // Override results visibility add_filter( 'totalpoll/filters/poll/results-hidden', function ( $hidden, $renderedPoll ) use ( $poll ) { if ( $renderedPoll->getId() === $poll->getId() ) : return false; endif; return $hidden; }, 10, 2 ); // Hide buttons add_filter( 'totalpoll/filters/form/buttons', function ( $buttons, $renderedPoll ) use ( $screen, $poll ) { if ( $renderedPoll->getId() === $poll->getId() && ( $screen !== Model::VOTE_SCREEN || ! $poll->isAcceptingVotes() ) ) : return []; endif; return $buttons; }, 10, 2 ); endif; return $poll->render(); } }