script src="my domain.com/path/to/polls-admin-js.js
but it isn’t working.
Anyone got ant ideas?
The code I am using is here:
<?php
/**
* Template Name: Add Poll
*
* @package WordPress
* @subpackage WP Poll
*/
get_header();
?>
<script src="https://outrankd.com/wp-content/plugins/wp-polls/polls-admin-js.js"></script>
<?php
### Check Whether User Can Manage Polls
/*
if(!current_user_can('manage_polls')) {
die('Access Denied');
}*/
### Poll Manager
$base_name = plugin_basename('wp-polls/polls-manager.php');
$base_page = 'admin.php?page='.$base_name;
### Form Processing
if(!empty($_POST['do'])) {
// Decide What To Do
switch($_POST['do']) {
// Add Poll
case __('Add Poll', 'wp-polls'):
check_admin_referer('wp-polls_add-poll');
// Poll Question
$pollq_question = wp_kses_post( trim( $_POST['pollq_question'] ) );
if( ! empty( $pollq_question ) ) {
// Poll Start Date
$timestamp_sql = '';
$pollq_timestamp_day = intval($_POST['pollq_timestamp_day']);
$pollq_timestamp_month = intval($_POST['pollq_timestamp_month']);
$pollq_timestamp_year = intval($_POST['pollq_timestamp_year']);
$pollq_timestamp_hour = intval($_POST['pollq_timestamp_hour']);
$pollq_timestamp_minute = intval($_POST['pollq_timestamp_minute']);
$pollq_timestamp_second = intval($_POST['pollq_timestamp_second']);
$pollq_timestamp = gmmktime($pollq_timestamp_hour, $pollq_timestamp_minute, $pollq_timestamp_second, $pollq_timestamp_month, $pollq_timestamp_day, $pollq_timestamp_year);
if ($pollq_timestamp > current_time('timestamp')) {
$pollq_active = -1;
} else {
$pollq_active = 1;
}
// Poll End Date
$pollq_expiry_no = isset( $_POST['pollq_expiry_no'] ) ? intval($_POST['pollq_expiry_no']) : 0;
if ($pollq_expiry_no == 1) {
$pollq_expiry = '';
} else {
$pollq_expiry_day = intval($_POST['pollq_expiry_day']);
$pollq_expiry_month = intval($_POST['pollq_expiry_month']);
$pollq_expiry_year = intval($_POST['pollq_expiry_year']);
$pollq_expiry_hour = intval($_POST['pollq_expiry_hour']);
$pollq_expiry_minute = intval($_POST['pollq_expiry_minute']);
$pollq_expiry_second = intval($_POST['pollq_expiry_second']);
$pollq_expiry = gmmktime($pollq_expiry_hour, $pollq_expiry_minute, $pollq_expiry_second, $pollq_expiry_month, $pollq_expiry_day, $pollq_expiry_year);
if ($pollq_expiry <= current_time('timestamp')) {
$pollq_active = 0;
}
}
// Mutilple Poll
$pollq_multiple_yes = intval($_POST['pollq_multiple_yes']);
$pollq_multiple = 0;
if ($pollq_multiple_yes == 1) {
$pollq_multiple = intval($_POST['pollq_multiple']);
} else {
$pollq_multiple = 0;
}
// Insert Poll
$add_poll_question = $wpdb->insert(
$wpdb->pollsq,
array(
'pollq_question' => $pollq_question,
'pollq_timestamp' => $pollq_timestamp,
'pollq_totalvotes' => 0,
'pollq_active' => $pollq_active,
'pollq_expiry' => $pollq_expiry,
'pollq_multiple' => $pollq_multiple,
'pollq_totalvoters' => 0
),
array(
'%s',
'%s',
'%d',
'%d',
'%s',
'%d',
'%d'
)
);
if ( ! $add_poll_question ) {
$text .= '<p style="color: red;">' . sprintf(__('Error In Adding Poll \'%s\'.', 'wp-polls'), $pollq_question) . '</p>';
}
// Add Poll Answers
$polla_answers = $_POST['polla_answers'];
$polla_qid = intval( $wpdb->insert_id );
foreach ($polla_answers as $polla_answer) {
$polla_answer = wp_kses_post( trim( $polla_answer ) );
if( ! empty( $polla_answer ) ) {
$add_poll_answers = $wpdb->insert(
$wpdb->pollsa,
array(
'polla_qid' => $polla_qid,
'polla_answers' => $polla_answer,
'polla_votes' => 0
),
array(
'%d',
'%s',
'%d'
)
);
if ( ! $add_poll_answers ) {
$text .= '<p style="color: red;">' . sprintf(__('Error In Adding Poll\'s Answer \'%s\'.', 'wp-polls'), $polla_answer) . '</p>';
}
} else {
$text .= '<p style="color: red;">' . __( 'Poll\'s Answer is empty.', 'wp-polls' ) . '</p>';
}
}
// Update Lastest Poll ID To Poll Options
$latest_pollid = polls_latest_id();
$update_latestpoll = update_option('poll_latestpoll', $latest_pollid);
// If poll starts in the future use the correct poll ID
$latest_pollid = ( $latest_pollid < $polla_qid ) ? $polla_qid : $latest_pollid;
if ( empty( $text ) ) {
$text = '<p style="color: green;">' . sprintf( __( 'Poll \'%s\' (ID: %s) added successfully. Embed this poll with the shortcode: %s or go back to <a href="%s">Manage Polls</a>', 'wp-polls' ), $pollq_question, $latest_pollid, '<input type="text" value=\'[poll id="' . $latest_pollid . '"]\' readonly="readonly" size="10" />', $base_page ) . '</p>';
programmatically_create_post();
} else {
if( $add_poll_question ) {
$text .= '<p style="color: green;">' . sprintf( __( 'Poll \'%s\' (ID: %s) (Shortcode: %s) added successfully, but there are some errors with the Poll\'s Answers. Embed this poll with the shortcode: %s or go back to <a href="%s">Manage Polls</a>', 'wp-polls' ), $pollq_question, $latest_pollid, '<input type="text" value=\'[poll id="' . $latest_pollid . '"]\' readonly="readonly" size="10" />' ) .'</p>';
}
}
do_action( 'wp_polls_add_poll', $latest_pollid );
cron_polls_place();
} else {
$text .= '<p style="color: red;">' . __( 'Poll Question is empty.', 'wp-polls' ) . '</p>';
}
break;
}
}
### Add Poll Form
$poll_noquestion = 2;
$count = 0;
?>
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade">'.stripslashes($text).'</div>'; } ?>
<form method="post" action="https://outrankd.com/wp-admin/admin.php?page=wp-polls/polls-add.php">
<?php wp_nonce_field('wp-polls_add-poll'); ?>
<div class="container">
<div class="wrap">
<h2><?php _e('Create a Poll', 'wp-polls'); ?></h2>
<!-- Poll Question -->
<h3><?php _e('Basic Info', 'wp-polls'); ?></h3>
<table class="form-table">
<tr>
<th width="20%" scope="row" valign="top"><?php _e('Question/Post Title', 'wp-polls') ?></th>
<td width="80%"><input type="text" size="70" name="pollq_question" value="" /></td>
</tr>
<tr>
<th width="20%" scope="row" valign="top">Description<div id="characters-left"></div></th>
<td width="80%"><textarea id="text-area" style="width: 48%" name="poll-description" value="" maxlength="200"></textarea></td>
</tr>
</table>
<!-- Poll Answers -->
<h3><?php _e('Poll Answers', 'wp-polls'); ?></h3>
<table class="form-table">
<tfoot>
<tr>
<td width="20%"> </td>
<td width="80%"><input type="button" value="<?php _e('Add Answer', 'wp-polls') ?>" onclick="add_poll_answer_add();" class="button" /></td>
</tr>
</tfoot>
<tbody id="poll_answers">
<?php
for($i = 1; $i <= $poll_noquestion; $i++) {
echo "<tr id=\"poll-answer-$i\">\n";
echo "<th width=\"20%\" scope=\"row\" valign=\"top\">".sprintf(__('Answer %s', 'wp-polls'), number_format_i18n($i))."</th>\n";
echo "<td width=\"80%\"><input type=\"text\" size=\"50\" maxlength=\"200\" name=\"polla_answers[]\" /> <input type=\"button\" value=\"".__('Remove', 'wp-polls')."\" onclick=\"remove_poll_answer_add(".$i.");\" class=\"button\" /></td>\n";
echo "</tr>\n";
$count++;
}
?>
</tbody>
</table>
<!-- Poll Multiple Answers -->
<h3><?php _e('Poll Multiple Answers', 'wp-polls') ?></h3>
<table class="form-table">
<tr>
<th width="40%" scope="row" valign="top"><?php _e('Allows Users To Select More Than One Answer?', 'wp-polls'); ?></th>
<td width="60%">
<select name="pollq_multiple_yes" id="pollq_multiple_yes" size="1" onchange="check_pollq_multiple();">
<option value="0"><?php _e('No', 'wp-polls'); ?></option>
<option value="1"><?php _e('Yes', 'wp-polls'); ?></option>
</select>
</td>
</tr>
<tr>
<th width="40%" scope="row" valign="top"><?php _e('Maximum Number Of Selected Answers Allowed?', 'wp-polls') ?></th>
<td width="60%">
<select name="pollq_multiple" id="pollq_multiple" size="1" disabled="disabled">
<?php
for($i = 1; $i <= $poll_noquestion; $i++) {
echo "<option value=\"$i\">".number_format_i18n($i)."</option>\n";
}
?>
</select>
</td>
</tr>
</table>
<!-- Poll Start/End Date -->
<h3 id="date-time-heading"><?php _e('Poll Start/End Date', 'wp-polls'); ?></h3>
<table class="form-table date-time">
<tr>
<th width="20%" scope="row" valign="top"><?php _e('Start Date/Time', 'wp-polls') ?></th>
<td width="80%"><?php poll_timestamp(current_time('timestamp')); ?></td>
</tr>
<tr>
<th width="20%" scope="row" valign="top"><?php _e('End Date/Time', 'wp-polls') ?></th>
<td width="80%"><input type="checkbox" name="pollq_expiry_no" id="pollq_expiry_no" value="1" checked="checked" onclick="check_pollexpiry();" /> <label for="pollq_expiry_no"><?php _e('Do NOT Expire This Poll', 'wp-polls'); ?></label><?php poll_timestamp(current_time('timestamp'), 'pollq_expiry', 'none'); ?></td>
</tr>
</table>
<?php echo'
<style>
#date-time-heading {display: none;}
.date-time {visibility: hidden;}
</style>' ?>
<p style="text-align: center;"><input type="submit" name="do" value="<?php _e('Add Poll', 'wp-polls'); ?>" class="button-primary" /> <input type="button" name="cancel" value="<?php _e('Cancel', 'wp-polls'); ?>" class="button" onclick="javascript:history.go(-1)" /></p>
</div>
</div>
</form>
<script>
var textarea = document.getElementById('text-area');
window.onload = textareaLengthCheck();
function textareaLengthCheck() {
var textArea = textarea.value.length;
var charactersLeft = 200 - textArea;
var count = document.getElementById('characters-left');
count.style.fontWeight = "normal";
count.innerHTML = "Characters left: " + charactersLeft;
}
textarea.addEventListener('keyup', textareaLengthCheck, false);
textarea.addEventListener('keydown', textareaLengthCheck, false);
</script>
<?php
function programmatically_create_post() {
// Initialize the page ID to -1. This indicates no action has been taken.
$post_id = -1;
$author_id = 1;
$slug = 'poll';
$latest_pollid = polls_latest_id();
global $current_user;
//$text = '<p style="color: green;">' . sprintf( __( 'Poll \'%s\' (ID: %s) added successfully. Embed this poll with the shortcode: %s or go back to <a href="%s">Manage Polls</a>', 'wp-polls' ), $pollq_question, $latest_pollid, '<input type="text" value=\'[poll id="' . $latest_pollid . '"]\' readonly="readonly" size="10" />', $base_page ) . '</p>';
// If the page doesn't already exist, then create it
if( null == get_page_by_title( $title ) ) {
// Set the post ID so that we know the post was created successfully
$pollq_question = wp_kses_post( trim( $_POST['pollq_question'] ) );
$post_id = wp_insert_post(
array(
'comment_status' => 'open',
'ping_status' => 'closed',
'post_author' => $current_user->ID,
'post_name' => $slug,
'post_title' => $pollq_question,
'post_status' => 'publish',
'post_type' => 'post',
'post_content' => $_POST['poll-description'] . '[poll id=' . $latest_pollid . ']'
)
);
// Otherwise, we'll stop
} else {
// Arbitrarily use -2 to indicate that the page with the title already exists
$post_id = -2;
} // end if
} // end programmatically_create_post
?>
https://www.ads-software.com/plugins/wp-polls/
]]>Fatal error: Call to undefined function add_action() in /.../wp-content/plugins/wp-polls/wp-polls.php on line 33
In my theme there is:
ajax_url: "https://www.domain.com/wp-content/plugins/wp-polls/wp-polls.php
If I call the wp-polls.php directly, the same error.
Earlier versions worked fine. Google shows that many other websites have the same error, too.
Anyone a solution?
https://www.ads-software.com/extend/plugins/wp-polls/
]]>display_pollvote
in wp-polls.php will generate an error notice everytime $poll_question
is used in the lines below.
When using the custom code or wp-polls as a widget there should be a default action if no active polls exist. A choice could be not to show anything or give a message that there are no polls.
https://www.ads-software.com/extend/plugins/wp-polls/
]]>I just hit this error with the 2.63 version of wp-polls:
PHP Fatal error: Call to undefined function add_action() in /*/wp-content/plugins/wp-polls/wp-polls.php on line 31
Trying to vote, never works for that. Chrome says there was an error 500 on wp-polls.php
After digging for a while, i realize that 2.63 it’s called directly by this code:
<script type='text/javascript'>
/* <![CDATA[ */
var pollsL10n = {
ajax_url: "https://www.cdf.cl/wp-content/plugins/wp-polls/wp-polls.php",
text_wait: "Tu ultima solicitud esta siendo procesada, por favor espera...",
text_valid: "Por favor selecciona una respuesta valida.",
text_multiple: "Numero maximo de respuestas permitidas: ",
show_loading: "1",
show_fading: "1"
};
/* ]]> */
</script>
Then, doing a comparison of both version, 2.63 and 2.62 or 2.61, i realize you don’t include this on top of wp-polls.php file:
### Load WP-Config File If This File Is Called Directly
if (!function_exists('add_action')) {
$wp_root = '../../..';
if (file_exists($wp_root.'/wp-load.php')) {
require_once($wp_root.'/wp-load.php');
} else {
require_once($wp_root.'/wp-config.php');
}
}
So i add those lines myself, reupload wp-polls.php, and… it works again.
Hopefully this can be fixed soon
Great plugin
https://www.ads-software.com/extend/plugins/wp-polls/
]]>https://www.lesterchan.net/wordpress/tutorials/integrating/
]]>