Joel’s PostPoll
This plugin enables you to write an individual poll (voting form) that is displayed with every post on a Wordpress Blog. This allows you to have multiple polls running simultaneously, which I don’t think any other plugin currently provides. For anonymous users (guests) that just walk in off the street, their voting history is tracked by a cookie, while for registered users, their history is stored against their user name, and they are able to delete or modify their votes and their voting history reported back (e.g., on their user page).
Key Features
- Display a custom poll on every post
- Polls easily created through custom fields
- Cookies remember a guest’s votes, so results are automatically displayed instead of voting forms once you’ve voted
- For logged in users/subscribers, votes are stored against their user name
- Votes may be deleted or changed (via deleting and re-voting)
- A user’s voting history may be displayed (e.g., on a user page)
- Colours and layout may be controlled, to some extent, through CSS
How do I use it?
To use this plugin, first download postpoll.txt , rename it to “postpoll.php” and place it in your wp-content/plugins directory. Then activated by the Plugin control panel.
To add a poll to a post, you need to add a custom field called “postpoll”. In this field, you put one line for each poll option you would like. Each line, then, has the form “ID:Option text:Description”. So, for instance, the poll on this page would be:
1:This is a great poll:I think Joel’s PostPoll is a great plugin
2:This is an awesome poll:I think Joel’s PostPoll is an awesome plugin
3:Joel is a god:I think Joel is a God
Here, we have uniquely identified each poll option by the numbers 1,2 and 3. This is to allow reordering of the options and/or changing of the poll text later. The second part is the text that will be displayed with each option. The third is the description of that choice that will be printed out if you look up a user’s history.
Now, simply save your post, and view it - you’ll see the poll appear at the bottom of your post.
Using the poll
Select the radio button corresponding to your choice, hit “Vote!” and you’ll see the current results in place of the voting form. You’ll see some friendly text displayed at the bottom of the poll reminding you of your choice. Alternatively, simply hit “Just view results” to see the current votes. It will also remind you that you haven’t voted yet. The “Vote anonymously” checkbox on the voting form (displayed for registered users) means that your vote won’t be displayed in your voting history. Additionally, it won’t display your choice on the screen (good for nosey neighbours!)
If you’re logged in, you’ll see the option to “Delete Vote” from the results page. Clicking it will warn you what you’re about to do, then with your permission it will remove your vote, and allow you to vote again. This option is only available to registered users, to prevent abuse.
To display the votes for a user, you need to call
<?php postpoll_displayvotes(for_user) ? >
where
for_user
is the user_id of the user you’re interested in. Drop me a comment if you want a specific application of this.
If you’re feeling mildly adventurous, check out the source code to see the CSS fields that are used for each field - define those somewhere, and you can customize until your heart’s content.
This plugin is released under the GPL license, so you’re welcome to use it as you see fit. My only humble request is to put a comment here, perhaps wtih a link to your site, so I can get some idea of how much use it gets. If you’d really like to say thanks, why not visit my site The Dividing Line, and vote your opinions on a couple of dilemmas - it warms my heart. Even more so if you find it worthy enough of a link!
To do
There are several things I would like to do to this poll when I get time.
- Write an options panel which would include a few customization options:
- Allow the text displayed when you’ve voted,etc to be a custom value (perhaps with %yourvote% style tags for customization). At present, you need to edit the php file manually - just search for the text, and replace it. It’s hard to break anything, except you need to escape your inverted commas, e.g. you’re.
- Template CSS code that would be inserted into the header (see also below)?
- Neaten up the CSS code a bit - the field names are a bit dodgy.
- Hook into the header to insert some custom CSS code
- Write a function which displays a user’s vote as part of their comments to that post
I’m also open (and keen) for any suggestions or requests - please comment below. I don’t have huge quantities of time at present, but at the very least bug fixes will be done promptly.
A little history
I needed this functionality for my dilemmas website, The Dividing Line, where every day we pose a dilemma and ask people what to do. I wanted the polls to be persistent, so that people could still vote months down the track, rather than just when the poll was “active”, and tied to a post with additional text.
This plugin was developed from the since-abandoned padd_poll plugin developed by aktivcoder, which implemented the basic functionality - gathering the votes, displaying the poll bars and storing a cookie with each visitor. However, it was buggy (it broke commenting, couldn’t display properly on main page, etc) and was abandoned before they could be repaired. I took it up, fixed the bugs, and added registered user support, CSS, printing voter history, etc.