Poll Maker Shortcodes

Below, you’ll find a detailed guide on how to add the Poll Maker – Best WordPress Poll Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Poll Maker – Best WordPress Poll Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Poll Maker – Best WordPress Poll Plugin and the shortcodes it provides:

Plugin Icon
Poll Maker – Best WordPress Poll Plugin

"Poll Maker is the ultimate WordPress plugin for creating engaging and interactive polls. It's designed to enrich your website's user experience. Try Poll Maker today!"

★★★★✩ (62) Active Installs: 5000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [ays_poll]
  • [ays_poll_all]
  • [ayspoll_results]
  • [ays_display_polls]
  • [ays_poll_passed_users_count]
  • [ays_poll_user_first_name]
  • [ays_poll_user_last_name]
  • [ays_poll_user_display_name]
  • [ays_poll_creation_date]
  • [ays_poll_user_email]
  • [ays_poll_user_passed_polls_count]
  • [ays_poll_user_all_passed_polls_count]
  • [ays_poll_categories_descriptions]
  • [ays_poll_categories_titles]
  • [ays_poll_current_author]
  • [ays_poll_answers_count]

Poll Maker [ays_poll] Shortcode

The Ays Poll shortcode is a function that generates a poll on your WordPress site. It starts by buffering the output, then enqueues necessary styles and scripts. Next, it displays the poll based on the attributes provided. It finalizes by cleaning the output buffer and returning the result, removing any line breaks in the process.

Shortcode: [ays_poll]

Examples and Usage

Basic example – A straightforward usage of the shortcode to display a poll by its ID.

[ays_poll id=1 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ays_poll] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ays_poll', array($this, 'ays_poll_generate_shortcode'));

Shortcode PHP function:

function ays_poll_generate_shortcode( $attr ) {
		ob_start();

		$this->enqueue_styles();
        $this->enqueue_scripts();

		$this->show_poll($attr);

		return str_replace(array("\r\n", "\n", "\r"), '', ob_get_clean());
	}

Code file location:

poll-maker/poll-maker/public/class-poll-maker-ays-public.php

Poll Maker [ays_poll_all] Shortcode

The Ays Poll All shortcode is designed to display all polls on your WordPress site. It fetches all poll IDs from the database and checks their published status. If the ‘display’ attribute is set to ‘all’, it shows all polls, regardless of their status. If it’s set to ‘published’, only active polls are displayed. If no polls are found, it displays a custom message.

Shortcode: [ays_poll_all]

Parameters

Here is a list of all possible ays_poll_all shortcode parameters and attributes:

  • display – determines the type of polls to display, either all polls or only published ones

Examples and Usage

Basic example – Displays all published polls on your page.

[ays_poll_all /]

Advanced examples

Displays all polls regardless of their published status.

[ays_poll_all display="all" /]

Displays only the published polls on your page. If no poll is published, it will display a custom message.

[ays_poll_all display="published" message="No published polls available at the moment." /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ays_poll_all] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ays_poll_all', array($this, 'ays_poll_all_generate_shortcode'));

Shortcode PHP function:

function ays_poll_all_generate_shortcode($attr) {
		ob_start();
		global $wpdb;

		$check_published = "published";
		if(is_array($attr) && !empty($attr)){
			$check_published = isset($attr['display']) && $attr['display'] == "all" ? "all" : "published";
		}

		$poll_table = esc_sql($wpdb->prefix."ayspoll_polls");
		$sql  = "SELECT id FROM ".$poll_table;
		$poll = $wpdb->get_results($sql, 'ARRAY_A');
  
		$this->enqueue_styles();
        $this->enqueue_scripts();
		$checker = array();
		foreach ($poll as $poll_id) {
			$current_id = isset($poll_id['id']) ? $poll_id['id'] : "";
			$check_poll = $this->check_shedule_expired_poll( $current_id );
			$checker[] = $check_poll;
			if($check_published == 'published'){
				if ($check_poll) {
					$this->show_poll($poll_id);
				}
			}
			elseif($check_published == 'all'){
				$this->show_poll($poll_id);
			}
		}

		if(array_sum($checker) == 0){
            $poll_settings   = $this->settings;
            $general_options = ($poll_settings->ays_get_setting('options') !== false) ? json_decode($poll_settings->ays_get_setting('options') , true) : array();
            $message = '';
            if(!empty($general_options)){
                $message = (isset($general_options['all_shortcode_message']) && $general_options['all_shortcode_message'] != '') ? esc_html($general_options['all_shortcode_message']) : '';
            }
            echo '<div class="ays_poll_all_res_none_message">'.$message.'</div>';
        }

		return str_replace(array("\r\n", "\n", "\r"), '', ob_get_clean());
	}

Code file location:

poll-maker/poll-maker/public/class-poll-maker-ays-public.php

Poll Maker [ayspoll_results] Shortcode

The ‘ayspoll_results’ shortcode from the Poll-Maker plugin is used to display poll results on a WordPress page. It fetches poll data from the database and generates a results chart. The shortcode utilizes various PHP functions to retrieve and process data. It checks for poll ID, retrieves poll answers, and calculates the percentage of votes for each answer. It then displays the results in various formats like pie chart or column chart based on the settings. The shortcode also handles the display of poll title, answer text, and vote counts. It allows customization of the results display, including font sizes and color schemes. If no poll data is available, it displays a ‘No ratings yet’ message. In summary, this shortcode is a powerful tool for displaying poll results on your WordPress site.

Shortcode: [ayspoll_results]

Parameters

Here is a list of all possible ayspoll_results shortcode parameters and attributes:

  • id – The unique identifier of the poll.
  • recent – If set to ‘true’, it displays the results of the most recent poll.

Examples and Usage

Basic example – Use this shortcode to display the results of a poll by referencing the poll ID.

[ayspoll_results id=1 /]

Advanced examples

Use this shortcode to display the results of the most recent poll. This will ignore the ‘id’ attribute and always display the most recent poll’s results.

[ayspoll_results recent=true /]

Use this shortcode to display the results of a poll by referencing both ID and recent. The poll will first try to load by ID, but if not found, it will try to load the most recent poll’s results.

[ayspoll_results id=1 recent=true /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ayspoll_results] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ayspoll_results', array($this, 'ays_poll_results_generate_shortcode'));

Shortcode PHP function:

function ays_poll_results_generate_shortcode($attr) {
		ob_start();

		$this->enqueue_styles();
        $this->enqueue_scripts();

		global $wpdb;
		$answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
		$rep_table = esc_sql($wpdb->prefix."ayspoll_reports");
		$polls_table = esc_sql($wpdb->prefix."ayspoll_polls");

		if(isset($attr['recent']) && $attr['recent'] === 'true'){						
			$id = $this->ays_poll_get_recent_poll_id();
		}else{
			$id = isset($attr['id']) && $attr['id'] !== 0 ? absint(intval($attr['id'])) : "";
		}

		$ans_sql  = "SELECT * FROM ".$answ_table." WHERE poll_id =%d ORDER BY votes DESC";
		$poll_answers = $wpdb->get_results(
			   	  	$wpdb->prepare( $ans_sql, $id),
			   	  	'ARRAY_A'
				  );

		$poll_sql  = "SELECT * FROM ".$polls_table." WHERE id =%d";
		$polls = $wpdb->get_row(
			   	  	$wpdb->prepare( $poll_sql, $id),
			   	  	'ARRAY_A'
				  );

		$settings_options = $this->settings->ays_get_setting('options');
        $result_options_res = ($settings_options === false) ? json_encode(array()) : $settings_options;
        $result_option_res = json_decode($result_options_res, true);

		$chart_style = false;
		if (isset( $result_option_res['show_result_view']) && ( $result_option_res['show_result_view'] == 'pie_chart' ||  $result_option_res['show_result_view'] == 'column_chart' )) {
			$this->show_chart_js();
			// $this->show_column_chart_js();
			$chart_style = true;
		}

		if ($polls == null) {
			$content = '<p style="text-align:center;">No ratings yet</p>';
		}else{
			$show_title = isset($polls['show_title']) && $polls['show_title'] == 0 ? false : true;
			$poll_title = isset($polls['title']) ? $polls['title'] : '';
			$votes_count = $this->get_poll_results_count_by_id($id);
			$poll = $this->get_poll_by_id($id);
			$polls_options = $poll['styles'];
	        if (intval($votes_count['res_count']) > 0) {
				$one_percent = 100/intval($votes_count['res_count']);
	        }else{
	        	$one_percent = 1;
	        }
			$poll_border_color_res = isset($polls_options['border_color']) && $polls_options['border_color'] != "" ? esc_attr($polls_options['border_color']) : '';

			// Poll question font size
			$poll_question_font_size_pc     = isset($polls_options['poll_question_size_pc']) && $polls_options['poll_question_size_pc'] != "" ? esc_attr($polls_options['poll_question_size_pc']) : "16"; 
			$poll_question_font_size_mobile = isset($polls_options['poll_question_size_mobile']) && $polls_options['poll_question_size_mobile'] != "" ? esc_attr($polls_options['poll_question_size_mobile']) : "16";
			$content = "";
			$content .= "<style>
				.ays-poll-main .ays_question p{
					font-size: ".$poll_question_font_size_pc."px;
				}
				
				@media only screen and (max-width: 768px){
					.ays-poll-main .ays_question p{
						font-size: ".$poll_question_font_size_mobile."px;
					}
				}
			</style>";
			$content .= '<div class="ays-poll-main" style="margin-bottom: 1rem; border:2px solid '.$poll_border_color_res.'; background-color: '.$polls_options['bg_color'].';color: '.$polls_options['main_color'].';" id="ays-poll-container-'.htmlentities($id).'">';

			if($show_title){
				$content .= '<div class="apm-title-box">
								<h5 style="text-align:center;">'.stripslashes($poll_title).'</h5>
							</div>';
			}
							
			$content .= '<div class="ays_question">
							<p>'.stripslashes($polls['question']).'</p>
						 </div>';
			$content .=	"<input type='hidden' name='ays_poll_curent_page_link' class='ays-poll-curent-page-link'/>";
			if ($votes_count['res_count'] == 0) {
				$content .= '<p style="text-align:center; margin: 0;">No ratings yet</p>';	 	
			}
			if($chart_style){
				$content .= '<div class="results-apm" id="pollAllResultId'.$id.'" style="height:400px;display: flex;justify-content: center;">';
				$aysChartData = array(['','']);
				foreach ($poll_answers as $key => $c_value) {
					$all_votes_chart = 0;
					$real_votes = isset($c_value['votes']) ? intval($c_value['votes']) : 0;
					$all_votes_chart += $real_votes;
					if(isset($poll["type"]) && $poll["type"] == "voting"){
						$c_value['answer'] = $c_value['answer'] == 1 ? "Like" : "Dislike";
					}
					$arr = [$c_value['answer'] , $all_votes_chart];
						array_push($aysChartData,$arr);
				}
				$show_result_view = isset($result_option_res['show_result_view']) && $result_option_res['show_result_view'] != '' ? $result_option_res['show_result_view'] : 'standart';
			}
			else{
				$content .= '<div class="results-apm">';
			}

			$poll_answers_count = count($poll_answers);
			$chart_font_size = "fontSize:12";
			if(isset($poll["type"]) && ($poll["type"] == "voting" || $poll["type"] == "rating" )){
				$chart_font_size = "fontSize:18";
			}

			$title_bg_color = isset($polls_options['main_color']) ? $polls_options['main_color'] : '#fff';
			if($chart_style && $show_result_view == 'pie_chart'){
				$content .=  '
				<script> 
					(function ($) {
						"use strict";    
						$(document).ready(function () {
						
						var aysChartData = '. json_encode($aysChartData).';
							google.charts.load("current", {packages:["corechart"]});
							google.charts.setOnLoadCallback(drawChart);
	
							function drawChart() {
								var dataGoogle = google.visualization.arrayToDataTable(aysChartData);
	
								var options = {
									legend: {position: "right",},
									pieSliceText: "label",
									chartArea:{"left":"100","width":"100%"},
									width: 500,
									height: 400,
									'.$chart_font_size.',
									legend: {textStyle :{color:"'.$title_bg_color.'"}},
									backgroundColor: { fill:"transparent" },
								};
	
								var chart = new google.visualization.PieChart(pollAllResultId'.$id.');
								chart.draw(dataGoogle, options);
							}
						});
					})(jQuery);
				</script>';
			}
			elseif($chart_style && $show_result_view  == 'column_chart'){
				$content .=  '
				<script> 
					(function ($) {
						"use strict";
						$(document).ready(function () {
							var aysChartData = '. json_encode($aysChartData).';
							google.charts.load("current", {"packages":["bar"]});
							google.charts.setOnLoadCallback(drawStuff);
	
							function drawStuff() {
								var dataColumnChart = new google.visualization.arrayToDataTable(aysChartData);
	
								var options = {
									width: 500,
									maxWidth: "100%",
									height: 400,
									legend: { position: "none" },
									axes: {
									x: {
									  0: { side: "bottom"} 
									}
								  },
								  bar: { groupWidth: "90%" }
								};
	
								var chart = new google.charts.Bar(pollAllResultId'.$id.');
							
								chart.draw(dataColumnChart, google.charts.Bar.convertOptions(options));
							}
						});
					})(jQuery);
				</script>';
			}
			else{
				foreach ($poll_answers as $ans_key => $ans_val) {
					$percent = round($one_percent*intval($ans_val['votes']));
					if ($percent == 0) {
						$perc_cont = '';
					}else{
						$perc_cont = $percent.' %';
					}
					switch ($polls['type']) {
						case 'choosing':
							$content .= '<div class="answer-title flex-apm">
											<span class="answer-text">'.stripslashes($ans_val['answer']).'</span>
											<span class="answer-votes">'.$ans_val['votes'].'</span>
										</div>
										<div class="answer-percent" style="width: '.$percent.'%; background-color: '.$polls_options['main_color'].'; color: '.$polls_options['bg_color'].';">'.$perc_cont.'</div>';
							break;

						case 'rating':
							switch ($polls['view_type']) {
								case 'star':
									$star_type  = '';
									for ($i=0; $i < intval($ans_val['answer']); $i++) { 
										$star_type .= '<i class="ays_poll_far ays_poll_fa-star far"></i>';
									}
									$content .= '<div class="answer-title flex-apm">
													<span class="answer-text">'.$star_type.'</span>
													<span class="answer-votes">'.$ans_val['votes'].'</span>
												</div>
												<div class="answer-percent" style="width: '.$percent.'%; background-color: '.$polls_options['main_color'].'; color: '.$polls_options['bg_color'].';">'.$perc_cont.'</div>';
									break;
								
								case 'emoji':
									$emojy_type  = '';
									if ($poll_answers_count == 3) {
										switch (intval($ans_val['answer'])) {
											case 1:
												$emojy_type .= '<i class="ays_poll_far ays_poll_fa-frown far"></i>';
												break;
											case 2:
												$emojy_type .= '<i class="ays_poll_far ays_poll_fa-meh far"></i>';
												break;
											case 3:
												$emojy_type .= '<i class="ays_poll_far ays_poll_fa-smile far"></i>';
												break;
											default:
												break;
										}
									}else{
										switch (intval($ans_val['answer'])) {
											case 1:
												$emojy_type .= '<i class="ays_poll_far ays_poll_fa-tired far"></i>';
												break;
											case 2:
												$emojy_type .= '<i class="ays_poll_far ays_poll_fa-frown far"></i>';
												break;
											case 3:
												$emojy_type .= '<i class="ays_poll_far ays_poll_fa-meh far"></i>';
												break;
											case 4:
												$emojy_type .= '<i class="ays_poll_far ays_poll_fa-smile far"></i>';
												break;
											case 5:
												$emojy_type .= '<i class="ays_poll_far ays_poll_fa-dizzy far"></i>';
												break;
											default:
												break;
										}
									}

									$content .= '<div class="answer-title flex-apm">
													<span class="answer-text">'.$emojy_type.'</span>
													<span class="answer-votes">'.$ans_val['votes'].'</span>
												</div>
												<div class="answer-percent" style="width: '.$percent.'%; background-color: '.$polls_options['main_color'].'; color: '.$polls_options['bg_color'].';">'.$perc_cont.'</div>';

									break;
								default:										
									break;
							}
							break;
						case 'voting':
							switch ($polls['view_type']) {
								case 'hand':
									$hand_type  = '';
									if (intval($ans_val['answer'] == 1)) {
										$hand_type = '<i class="ays_poll_far ays_poll_fa-thumbs-up far"></i>';
									}else{
										$hand_type = '<i class="ays_poll_far ays_poll_fa-thumbs-down far"></i>';
									}
									$content .= '<div class="answer-title flex-apm">
													<span class="answer-text">'.$hand_type.'</span>
													<span class="answer-votes">'.$ans_val['votes'].'</span>
												</div>
												<div class="answer-percent" style="width: '.$percent.'%; background-color: '.$polls_options['main_color'].'; color: '.$polls_options['bg_color'].';">'.$perc_cont.'</div>';
									break;
								case 'emoji':
									$emojy_type  = '';
									if (intval($ans_val['answer'] == 1)) { 
										$emojy_type = '<i class="ays_poll_far ays_poll_fa-smile far"></i>';
									}else{
										$emojy_type = '<i class="ays_poll_far ays_poll_fa-frown far"></i>';
									}
									$content .= '<div class="answer-title flex-apm">
													<span class="answer-text">'.$emojy_type.'</span>
													<span class="answer-votes">'.$ans_val['votes'].'</span>
												</div>
												<div class="answer-percent" style="width: '.$percent.'%; background-color: '.$polls_options['main_color'].'; color: '.$polls_options['bg_color'].';">'.$perc_cont.'</div>';

									break;
								default:										
									break;
							}
							break;
						default:										
							break;
					}
					
				}
			}

			$content .= '</div>
						</div>';
		}

        echo $content;

		return str_replace(array("\r\n", "\n", "\r"), '', ob_get_clean());
	}

Code file location:

poll-maker/poll-maker/public/class-poll-maker-ays-public.php

Poll Maker [ays_display_polls] Shortcode

The ‘ays_display_polls’ shortcode from the Poll Maker plugin generates a list of recent polls. It fetches the recent poll IDs, creates a shortcode for each, and displays them in a div section.

Shortcode: [ays_display_polls]

Parameters

Here is a list of all possible ays_display_polls shortcode parameters and attributes:

  • id – The unique identifier of a specific poll

Examples and Usage

Basic example – The shortcode displays the poll by referencing its ID.

[ays_display_polls id=1 /]

Advanced examples

Using the shortcode to display multiple polls by referencing their IDs. The polls will load by ID in the order they are listed.

[ays_display_polls id="1,2,3" /]

Using the shortcode to display a poll by referencing its ID and specifying a custom class. The custom class can be used to apply specific styles to the poll.

[ays_display_polls id="1" class="custom-class" /]

Using the shortcode to display a poll by referencing its ID and specifying the number of polls to display. The number parameter can be used to limit the number of polls displayed.

[ays_display_polls id="1" number="5" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ays_display_polls] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ays_display_polls', array($this, 'ays_generate_display_polls_method'));

Shortcode PHP function:

function ays_generate_display_polls_method($attr){
		$recent_poll_ids = $this->ays_recent_poll_ids($attr);
		$content = '<div class="ays_poll_recent_polls">';
		$polls = array();
        foreach ($recent_poll_ids as $key => $last_poll_id) {
            $poll_id = (isset($last_poll_id['id']) && intval($last_poll_id['id']) != '') ? intval($last_poll_id['id']) : '';
            $shortcode = '[ays_poll id="'.$poll_id.'"]';
            $polls[] = do_shortcode( $shortcode );
        }
        $content .= implode( '', $polls );
		$content .= '</div>';
		return str_replace(array("\r\n", "\n", "\r"), "\n", $content);
	}

Code file location:

poll-maker/poll-maker/public/class-poll-maker-ays-public.php

Poll Maker [ays_poll_passed_users_count] Shortcode

The AYS Poll Passed Users Count shortcode is used to display the number of users who have completed a specific poll. This shortcode takes an ‘id’ attribute, which is the poll’s ID. If the ‘id’ is not set or is zero, it will display an error message. It generates a unique ID, combines it with the poll’s ID, and then calls the ‘ays_poll_passed_users_count_html’ function to create the HTML output.

Shortcode: [ays_poll_passed_users_count]

Parameters

Here is a list of all possible ays_poll_passed_users_count shortcode parameters and attributes:

  • id – The unique number that identifies the specific poll

Examples and Usage

Basic example – A shortcode that displays the count of users who passed a specific poll by referencing the poll’s ID.

[ays_poll_passed_users_count id=1 /]

Advanced examples

A shortcode that displays the count of users who passed a specific poll by referencing the poll’s ID. If the ID is not found or incorrect, it will display a custom error message.

[ays_poll_passed_users_count id=1 /]

Another advanced usage of the shortcode can be to display the count of users who passed a specific poll by referencing the poll’s ID, and also assigning a unique identifier to each shortcode instance. This can be useful if you want to use the shortcode multiple times on the same page.

[ays_poll_passed_users_count id=1 unique_id=123 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ays_poll_passed_users_count] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ays_poll_passed_users_count', array($this, 'ays_generate_passed_users_count_method'));

Shortcode PHP function:

function ays_generate_passed_users_count_method( $attr ){

        $id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;

        if (is_null($id) || $id == 0 ) {
            $passed_users_count_html = "<p class='wrong_shortcode_text' style='color:red;'>" . __('Wrong shortcode initialized', $this->plugin_name) . "</p>";
            return str_replace(array("\r\n", "\n", "\r"), "\n", $passed_users_count_html);
        }

        $unique_id = uniqid();
        $this->unique_id = $unique_id;
        $this->unique_id_in_class = $id . "-" . $unique_id;


        $passed_users_count_html = $this->ays_poll_passed_users_count_html( $id );
        return str_replace(array("\r\n", "\n", "\r"), "\n", $passed_users_count_html);
    }

Code file location:

poll-maker/poll-maker/public/partials/class-poll-maker-extra-shortcode.php

Poll Maker [ays_poll_user_first_name] Shortcode

The ‘ays_poll_user_first_name’ shortcode is used to generate the first name of the logged-in user. This function creates a unique ID, checks if a user is logged in, and if so, generates the HTML for the user’s first name. It then returns this HTML, replacing all line breaks with a newline character.

Shortcode: [ays_poll_user_first_name]

Examples and Usage

Basic example – A simple usage of the shortcode to generate the logged-in user’s first name.

[ays_poll_user_first_name]

PHP Function Code

In case you have difficulties debugging what causing issues with [ays_poll_user_first_name] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ays_poll_user_first_name', array($this, 'ays_generate_user_first_name_method'));

Shortcode PHP function:

function ays_generate_user_first_name_method(){

        $unique_id = uniqid();
        $this->unique_id = $unique_id;
        $this->unique_id_in_class = $unique_id;

        $user_first_name_html = "";
        if(is_user_logged_in()){
            $user_first_name_html = $this->ays_generate_users_html('first');
        }
        return str_replace(array("\r\n", "\n", "\r"), "\n", $user_first_name_html);
    }

Code file location:

poll-maker/poll-maker/public/partials/class-poll-maker-extra-shortcode.php

Poll Maker [ays_poll_user_last_name] Shortcode

The Ays Poll User Last Name shortcode is designed to generate the last name of the currently logged in user. This shortcode utilizes the uniqid() function to create a unique identifier, which is then assigned to the user. If the user is logged in, the shortcode generates HTML to display the user’s last name. It also ensures the output is formatted correctly by replacing any carriage returns and line breaks with a single line break.

Shortcode: [ays_poll_user_last_name]

Examples and Usage

Basic Example – Show the logged-in user’s last name using the shortcode.

[ays_poll_user_last_name /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ays_poll_user_last_name] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ays_poll_user_last_name', array($this, 'ays_generate_user_last_name_method'));

Shortcode PHP function:

function ays_generate_user_last_name_method(){

        $unique_id = uniqid();
        $this->unique_id = $unique_id;
        $this->unique_id_in_class = $unique_id;

        $user_last_name_html = "";
        if(is_user_logged_in()){
            $user_last_name_html = $this->ays_generate_users_html('last');
        }
        return str_replace(array("\r\n", "\n", "\r"), "\n", $user_last_name_html);
    }

Code file location:

poll-maker/poll-maker/public/partials/class-poll-maker-extra-shortcode.php

Poll Maker [ays_poll_user_display_name] Shortcode

The ‘ays_poll_user_display_name’ shortcode is a user-friendly tool that generates a unique display name for each user. It is designed for use when a user is logged in. The PHP function ‘ays_generate_user_display_name_method’ creates a unique ID for each user and generates a display name. It replaces any line breaks in the display name with a new line character.

Shortcode: [ays_poll_user_display_name]

Examples and Usage

Basic example – The shortcode ‘ays_poll_user_display_name’ is used to generate and display the logged in user’s name.

[ays_poll_user_display_name /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ays_poll_user_display_name] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ays_poll_user_display_name', array($this, 'ays_generate_user_display_name_method'));

Shortcode PHP function:

function ays_generate_user_display_name_method(){

        $unique_id = uniqid();
        $this->unique_id = $unique_id;
        $this->unique_id_in_class = $unique_id;

        $user_display_name_html = "";
        if(is_user_logged_in()){
            $user_display_name_html = $this->ays_generate_users_html('display');
        }
        return str_replace(array("\r\n", "\n", "\r"), "\n", $user_display_name_html);
    }

Code file location:

poll-maker/poll-maker/public/partials/class-poll-maker-extra-shortcode.php

Poll Maker [ays_poll_creation_date] Shortcode

The ‘ays_poll_creation_date’ shortcode is used to generate the creation date of a specific poll. It takes an ‘id’ as an attribute, which is sanitized and checked for validity. If the provided ‘id’ is invalid, it returns an error message. The shortcode also generates a unique id that is used to create a unique class. The function ‘ays_poll_creation_date_html’ is then called with the ‘id’ as an argument to generate the HTML for the poll creation date.

Shortcode: [ays_poll_creation_date]

Parameters

Here is a list of all possible ays_poll_creation_date shortcode parameters and attributes:

  • id – The unique identifier for the specific poll.

Examples and Usage

Basic example – A shortcode that displays the creation date of a poll by referencing its ID.

[ays_poll_creation_date id=1 /]

Advanced examples

Display the creation date of a poll by referencing its ID, and if the ID is not found or incorrect, it will display a warning message.

[ays_poll_creation_date id=0 /]

Display the creation date of a poll by referencing its ID. In this case, the ID is not specified, so it will display a warning message.

[ays_poll_creation_date /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ays_poll_creation_date] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ays_poll_creation_date', array($this, 'ays_generate_creation_date_method'));

Shortcode PHP function:

function ays_generate_creation_date_method( $attr ){

        $id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;

        if (is_null($id) || $id == 0 ) {
            $poll_creation_date_html = "<p class='wrong_shortcode_text' style='color:red;'>" . __('Wrong shortcode initialized', $this->plugin_name) . "</p>";
            return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_creation_date_html);
        }

        $unique_id = uniqid();
        $this->unique_id = $unique_id;
        $this->unique_id_in_class = $id . "-" . $unique_id;


        $poll_creation_date_html = $this->ays_poll_creation_date_html( $id );
        return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_creation_date_html);
    }

Code file location:

poll-maker/poll-maker/public/partials/class-poll-maker-extra-shortcode.php

Poll Maker [ays_poll_user_email] Shortcode

The Ays Poll User Email shortcode is designed to generate a unique ID for logged-in users and display their email. The PHP function associated with this shortcode creates a unique ID, checks if a user is logged in, and if true, generates the user’s email in HTML format. It then returns this HTML, replacing any line breaks with a new line character.

Shortcode: [ays_poll_user_email]

Examples and Usage

Basic example – A simple shortcode usage that generates a unique ID and returns the logged-in user’s email.

[ays_poll_user_email /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ays_poll_user_email] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ays_poll_user_email', array($this, 'ays_generate_user_email_method'));

Shortcode PHP function:

function ays_generate_user_email_method(){

        $unique_id = uniqid();
        $this->unique_id = $unique_id;
        $this->unique_id_in_class = $unique_id;

        $user_email_html = "";
        if(is_user_logged_in()){
            $user_email_html = $this->ays_generate_users_html('email');
        }
        return str_replace(array("\r\n", "\n", "\r"), "\n", $user_email_html);
    }

Code file location:

poll-maker/poll-maker/public/partials/class-poll-maker-extra-shortcode.php

Poll Maker [ays_poll_user_passed_polls_count] Shortcode

The ‘ays_poll_user_passed_polls_count’ shortcode is from the Poll-Maker plugin. This shortcode generates the count of polls passed by a logged-in user. It starts by creating a unique ID. If the user is logged in, it generates HTML for the passed polls count. The output is then returned after replacing any type of line breaks with a newline.

Shortcode: [ays_poll_user_passed_polls_count]

Examples and Usage

Basic example – Showcases the usage of the shortcode without any additional parameters. The shortcode will generate the count of passed polls for the logged-in user.

[ays_poll_user_passed_polls_count]

PHP Function Code

In case you have difficulties debugging what causing issues with [ays_poll_user_passed_polls_count] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ays_poll_user_passed_polls_count', array($this, 'ays_generate_user_passed_polls_count_method'));

Shortcode PHP function:

function ays_generate_user_passed_polls_count_method(){

        $unique_id = uniqid();
        $this->unique_id = $unique_id;
        $this->unique_id_in_class = $unique_id;

        $passed_polls_count_html = "";
        if(is_user_logged_in()){
            $passed_polls_count_html = $this->ays_generate_user_passed_polls_count_html();
        }
        return str_replace(array("\r\n", "\n", "\r"), "\n", $passed_polls_count_html);
    }

Code file location:

poll-maker/poll-maker/public/partials/class-poll-maker-extra-shortcode.php

Poll Maker [ays_poll_user_all_passed_polls_count] Shortcode

The ‘ays_poll_user_all_passed_polls_count’ shortcode is designed to generate a unique count of all polls a user has passed. This shortcode checks if a user is logged in and then generates a count of all passed polls. It returns this count in a clean HTML format, replacing any carriage return characters with a newline.

Shortcode: [ays_poll_user_all_passed_polls_count]

Examples and Usage

Basic example – A simple usage of the shortcode to display the count of all passed polls by the logged-in user.

[ays_poll_user_all_passed_polls_count /]

For more advanced usage, you can use additional parameters with the shortcode. However, please note that the shortcode provided does not accept any parameters. Hence, in this scenario, an advanced usage example cannot be provided.

Advanced example – Unfortunately, the given shortcode does not support any additional parameters. Thus, an advanced usage example cannot be provided for this specific shortcode.

PHP Function Code

In case you have difficulties debugging what causing issues with [ays_poll_user_all_passed_polls_count] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ays_poll_user_all_passed_polls_count', array($this, 'ays_generate_user_all_passed_polls_count_method'));

Shortcode PHP function:

function ays_generate_user_all_passed_polls_count_method(){

        $unique_id = uniqid();
        $this->unique_id = $unique_id;
        $this->unique_id_in_class = $unique_id;

        $all_passed_polls_count_html = "";
        if(is_user_logged_in()){
            $all_passed_polls_count_html = $this->ays_generate_user_all_passed_polls_count_html();
        }
        return str_replace(array("\r\n", "\n", "\r"), "\n", $all_passed_polls_count_html);
    }

Code file location:

poll-maker/poll-maker/public/partials/class-poll-maker-extra-shortcode.php

Poll Maker [ays_poll_categories_descriptions] Shortcode

The ‘ays_poll_categories_descriptions’ shortcode is a function in the poll-maker plugin that generates category descriptions. It sanitizes and verifies the ID, then produces a unique ID for each instance. . The shortcode replaces line breaks in the description with a newline character, ensuring the text displays correctly. It returns an empty string if the ID is invalid or not provided.

Shortcode: [ays_poll_categories_descriptions]

Parameters

Here is a list of all possible ays_poll_categories_descriptions shortcode parameters and attributes:

  • id – It is the unique identifier for the poll category. If it’s not provided or zero, the function will return an empty description.

Examples and Usage

Basic example – Utilize the shortcode to generate a category description based on the given ID.

[ays_poll_categories_descriptions id=1 /]

Advanced examples

Use the shortcode to generate a category description, and if the ID is not found or not valid, it will return an empty description.

[ays_poll_categories_descriptions id=100 /]

Another advanced usage of the shortcode could involve using a variable ID, dynamically set in your PHP code. This could be useful if you’re using the shortcode within a loop, for example.

<?php $id = get_the_ID(); echo do_shortcode("[ays_poll_categories_descriptions id={$id} /]"); ?>

PHP Function Code

In case you have difficulties debugging what causing issues with [ays_poll_categories_descriptions] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ays_poll_categories_descriptions', array($this, 'ays_generate_category_description_method'));

Shortcode PHP function:

function ays_generate_category_description_method( $attr ) {
        $id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;

        if (is_null($id) || $id == 0 ) {
            $poll_category_description = "";
            return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_category_description);
        }

        $unique_id = uniqid();
        $this->unique_id = $unique_id;
        $this->unique_id_in_class = $unique_id;

        $poll_category_description = $this->ays_generate_category_description_html( $id );

        return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_category_description);
    }

Code file location:

poll-maker/poll-maker/public/partials/class-poll-maker-extra-shortcode.php

Poll Maker [ays_poll_categories_titles] Shortcode

The Ays Poll Categories Titles shortcode is a dynamic code snippet that generates a unique title for each poll category. This shortcode takes a category ID as an attribute, sanitizes it, and checks if it’s valid. If the ID is null or zero, it returns an empty string. If valid, it generates a unique ID and uses it to create a unique title for the poll category.

Shortcode: [ays_poll_categories_titles]

Parameters

Here is a list of all possible ays_poll_categories_titles shortcode parameters and attributes:

  • id – Specifies the unique identifier of the poll category

Examples and Usage

Basic example – A simple usage of the shortcode that generates the title of a poll category based on its ID

[ays_poll_categories_titles id=1 /]

For advanced examples:

Advanced example – An instance where the shortcode is used without specifying any ID. In this case, the shortcode will return an empty string.

[ays_poll_categories_titles /]

Another advanced example would be using the shortcode to generate a poll category title with a non-numeric ID. This will also return an empty string as the ID is sanitized and converted to an integer. Any non-numeric value will be converted to zero and the shortcode function will return an empty string.

[ays_poll_categories_titles id='non-numeric-value' /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ays_poll_categories_titles] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ays_poll_categories_titles', array($this, 'ays_generate_category_title_method'));

Shortcode PHP function:

function ays_generate_category_title_method( $attr ) {
        $id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;

        if (is_null($id) || $id == 0 ) {
            $poll_category_title = "";
            return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_category_title);
        }

        $unique_id = uniqid();
        $this->unique_id = $unique_id;
        $this->unique_id_in_class = $unique_id;

        $poll_category_title = $this->ays_generate_category_title_html( $id );

        return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_category_title);
    }

Code file location:

poll-maker/poll-maker/public/partials/class-poll-maker-extra-shortcode.php

Poll Maker [ays_poll_current_author] Shortcode

The ‘ays_poll_current_author’ shortcode from the Poll Maker plugin is designed to generate the current poll author’s details. It checks if the user is logged in and if so, it retrieves the author’s information. .

Shortcode: [ays_poll_current_author]

Parameters

Here is a list of all possible ays_poll_current_author shortcode parameters and attributes:

  • id – The unique identification number of the specific poll

Examples and Usage

Basic example – Displays the author of the current poll, if the user is logged in.

[ays_poll_current_author id=1 /]

Advanced examples

Display the author of the poll with the given ID, if the user is logged in. If the poll with the given ID does not exist, or if the user is not logged in, no output will be generated.

[ays_poll_current_author id=2 /]

Display the author of the poll with the given ID, if the user is logged in. If the poll with the given ID does not exist, or if the user is not logged in, no output will be generated. This example uses a larger ID, showing that the shortcode can handle polls with IDs in the hundreds or thousands.

[ays_poll_current_author id=1000 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ays_poll_current_author] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ays_poll_current_author', array($this, 'ays_generate_current_poll_author_method'));

Shortcode PHP function:

function ays_generate_current_poll_author_method( $attr ) {

        $id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;

        if (is_null($id) || $id == 0 ) {
            $poll_author = "";
            return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_author);
        }

        $unique_id = uniqid();
        $this->unique_id = $unique_id;
        $this->unique_id_in_class = $unique_id;

        $poll_author = "";
        if(is_user_logged_in()){
            $poll_author = $this->ays_generate_current_poll_author_html( $id );
        }
        return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_author);
    }

Code file location:

poll-maker/poll-maker/public/partials/class-poll-maker-extra-shortcode.php

Poll Maker [ays_poll_answers_count] Shortcode

The Ays Poll Answers Count shortcode is a function in PHP that counts the answers in a poll. It checks if an ID is set and valid, else it returns an empty string. It then generates a unique ID for each instance of the shortcode. The function ays_generate_poll_answers_count_html is called to count the poll answers. The result is then returned.

Shortcode: [ays_poll_answers_count]

Parameters

Here is a list of all possible ays_poll_answers_count shortcode parameters and attributes:

  • id – Unique identifier of the poll to show the answers count.

Examples and Usage

Basic example – A basic usage of the shortcode ‘ays_poll_answers_count’ to display the count of answers for a specific poll. The poll is identified by its ID.

[ays_poll_answers_count id=1 /]

Advanced examples

Using the shortcode ‘ays_poll_answers_count’ with a non-existing ID. If the given ID does not correspond to any poll, the shortcode will return an empty string.

[ays_poll_answers_count id=0 /]

Using the shortcode ‘ays_poll_answers_count’ without specifying an ID. If the ‘id’ attribute is not set, the shortcode will return an empty string.

[ays_poll_answers_count /]

Please note that the actual output of the shortcode ‘ays_poll_answers_count’ depends on the method ‘ays_generate_poll_answers_count_html’, which is not provided in the given PHP code. The method ‘ays_generate_poll_answers_count_html’ is expected to generate the HTML output based on the poll ID. The shortcode ‘ays_poll_answers_count’ simply calls this method with the given ID and returns its output.

PHP Function Code

In case you have difficulties debugging what causing issues with [ays_poll_answers_count] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ays_poll_answers_count', array($this, 'ays_generate_poll_answers_count_method'));

Shortcode PHP function:

function ays_generate_poll_answers_count_method( $attr ){

        $id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;

        if (is_null($id) || $id == 0 ) {
            $poll_answers_count = "";
            return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_answers_count);
        }

        $unique_id = uniqid();
        $this->unique_id = $unique_id;
        $this->unique_id_in_class = $unique_id;

        $poll_answers_count = $this->ays_generate_poll_answers_count_html( $id );

        return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_answers_count);
    }

Code file location:

poll-maker/poll-maker/public/partials/class-poll-maker-extra-shortcode.php

Conclusion

Now that you’ve learned how to embed the Poll Maker – Best WordPress Poll Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *