A modern, accessible polling block that lets visitors vote on questions about your content, with beautiful card-style options and optional AI suggestions.
Engage your audience by asking them to vote on aspects of the page they're reading. AI analyzes your content and suggests relevant polling questions, or create your own. Visitors vote once anonymously, then see real-time results with visual progress bars.
Perfect for: Blog posts, product pages, documentation, news articles, tutorials, reviews β any content where you want to gauge reader opinions or preferences.
- Card-Style Interface: Modern, clickable option cards with radio button indicators (no traditional buttons)
- Ordered Options: Automatic A, B, C, D labeling for clarity
- Anonymous & Secure: Cookie-based deduplication with SHA-256 hashing
- One Vote Per Visitor: Secure token prevents duplicate voting
- Visual Results: Progress bars with percentages and vote counts
- Theme Adaptive: Automatically matches your WordPress theme colors
- Persistent Selection: Returning voters see their previously selected option checked
AI reads your page content and generates contextually relevant poll questions:
- Heuristic (Default) - Built-in keyword extraction from your content, no API required. Use it for tests and basic suggestions.
- OpenAI - GPT models analyze your content for smart suggestions
- Azure OpenAI - Enterprise Azure OpenAI Service
- Anthropic Claude - Claude 3.5 Sonnet analyzes content context
- Google Gemini - Gemini 1.5 Flash (free tier available)
- Ollama - Self-hosted local models process content privately
Example: On a blog post about photography tips, AI might suggest: "Which photography technique interests you most?" with options like "Composition", "Lighting", "Editing", "Equipment".
- Settings Page: Configure AI provider, API keys, and models at Settings β ContentPoll AI
- Flexible Options: Choose 2-6 voting options per block
- Lock on First Vote: Options become immutable after the first vote to preserve data integrity
- Debug Mode: Test reset functionality when WP_DEBUG is enabled
- Model Validation: Real-time API testing when saving AI settings
- REST API: Complete endpoints for voting, results, and suggestions
- Modern Stack: Built with @wordpress/scripts, React hooks, and webpack
- CSP Compliant: No inline scripts, data attributes for i18n
- Accessibility: ARIA labels, keyboard navigation, semantic HTML
- Internationalization: Translation-ready with
.potfile
- Download
content-poll.zip - Upload via
Plugins β Add New β Upload Plugin - Activate via
WordPress Admin β Plugins
Configuration (Optional)
- Go to
Settings β ContentPoll AI - Choose an AI provider for suggestions
- Enter your API key or endpoint details
- Click Save Settings (plugin tests API connection automatically)
See AI Provider Integration Guide for detailed setup instructions for each AI provider.
Updates
- Plugin updates are handled automatically via GitHub. No need to manually download and install updates.
# Install via Composer
composer require soderlind/content-poll
# Install dependencies
composer install
npm install
# Build assets
npm run build
# Or watch for changes
npm run start- Add Block: In the editor, insert the "ContentPoll AI" block (display name may appear as ContentPoll) into your post/page
- Set Question: Enter a question about your content (or use AI to generate one)
- Configure Options: Add 2-6 answer options related to your content
- Publish: Visitors reading that page can now vote on your question and see results
- Go to Settings β ContentPoll AI
- Select an AI provider (OpenAI, Anthropic, Gemini, Ollama, or Azure)
- Enter your API key/endpoint
- Write your post content first (AI needs content to analyze)
- Add the ContentPoll AI block
- Click Generate Suggestions - AI reads the page content and suggests a relevant question
- Review and adjust the AI-generated question and options
After voting, visitors see:
- Their selected option marked with a checkmark
- Vote counts for each option (e.g., "3 votes")
- Visual progress bars showing percentages
- Clean card layout with A, B, C, D labels
- No Buttons: Uses semantic
<li>elements styled as interactive cards - Radio Indicators: Visual radio button circles that fill when selected
- Hover Effects: Cards lift and shadow on hover with smooth transitions
- Pointer Cursor: Clear visual feedback that options are clickable
- Theme Colors: Uses WordPress CSS custom properties (
--wp--preset--color--*) - Responsive: Works beautifully on all screen sizes
- Box Sizing: Proper containment prevents overflow issues
npm run build # Production build (minified)
npm run start # Development mode with watch
npm test # Run all tests (JS + PHP linting)
npm run test:js # Vitest unit tests
npm run lint:js # ESLint JavaScript files
composer test # PHPUnit tests- JavaScript: Vitest for helper functions and logic
- PHP: PHPUnit for storage, aggregation, and API validation
- Linting: WordPress coding standards via @wordpress/scripts
- Database Safety: Tests include safeguards to prevent accidental data loss
Run Tests Safely:
# JavaScript tests (safe - no database changes)
npm test
# PHP tests with production database protection
composer test
# PHP tests with separate test database (recommended)
WP_TESTS_DB_PREFIX=test_ composer testSee tests/README.md for detailed testing documentation and database safety configuration.
content-poll/
βββ src/
β βββ block/vote-block/ # Gutenberg block (JS + CSS)
β βββ php/ # Backend logic
β βββ Admin/ # Settings page
β βββ Blocks/ # Block registration
β βββ REST/ # API endpoints
β βββ Security/ # Nonce & token handling
β βββ Services/ # Vote storage & AI
βββ build/ # Compiled assets (webpack)
βββ tests/ # PHPUnit tests
βββ languages/ # Translation files
βββ docs/ # Documentation
- Block ID: UUID for each vote instance
- Option Index: Which option was selected (0-5)
- Hashed Token: SHA-256 hash of cookie + AUTH_KEY
- β IP addresses
- β User agents
- β Email addresses
- β Personal information
- Anonymous voting only
- No personally identifiable information
- Uninstall script removes all data
- Cookie notice: Site owners should inform users about voting cookies
POST /wp-json/content-poll/v1/block/{blockId}/vote
Headers: X-WP-Nonce
Body: { "optionIndex": 0, "postId": 123 }
GET /wp-json/content-poll/v1/block/{blockId}/results
Response: {
"blockId": "...",
"totalVotes": 42,
"counts": { "0": 15, "1": 12, "2": 10, "3": 5 },
"percentages": { "0": 35.71, "1": 28.57, "2": 23.81, "3": 11.90 },
"userVote": 1 // If user has voted
}
GET /wp-json/content-poll/v1/suggest?postId=123
Response: {
"question": "What aspect interests you most?",
"options": ["Option A", "Option B", "Option C", "Option D"]
}
- Admin dashboard with vote analytics
- Export votes to CSV
- Transient caching for high-traffic sites
- Custom result templates
- Vote scheduling (start/end dates)
- Multiple votes per user (optional)
- Integration with popular form plugins
GPL-2.0-or-later
Built with modern WordPress tools and best practices. Uses @wordpress/scripts for building, WordPress design system for styling, and follows WordPress coding standards.