Skip to content

WB Polls provides action hooks and filters for developers to extend and customize polling functionality. This reference covers the most commonly used hooks organized by feature area.

Fires after a vote is submitted on an activity poll.

do_action( 'bp_polls_after_submit_polls', $user_id, $activity_id );
Parameter Type Description
$user_id int ID of the user who voted
$activity_id int ID of the activity containing the poll
add_action( 'bp_polls_after_submit_polls', function( $user_id, $activity_id ) {
// Award points for voting
mycred_add( 'poll_vote', $user_id, 5, 'Voted on a poll', $activity_id );
}, 10, 2 );

Fires when a vote is recorded on a standalone poll.

do_action( 'wbpoll_on_vote', $insertArray, $vote_id, $published );
Parameter Type Description
$insertArray array Vote data array including poll_id, user_id, and answer
$vote_id int ID of the vote record
$published int Whether the vote is published
add_action( 'wbpoll_on_vote', function( $data, $vote_id, $published ) {
// Log vote to external analytics
wp_remote_post( 'https://api.example.com/votes', [
'body' => [
'poll_id' => $data['poll_id'],
'user_id' => $data['user_id'],
'answer' => $data['answer']
]
]);
}, 10, 3 );

Fires after vote form validation, before saving the vote.

do_action( 'wbpoll_form_validation', $poll_result, $poll_id );

These hooks let you inject custom content around poll templates without overriding entire template files.

Fires before the main poll content wrapper in templates.

do_action( 'buddypress_polls_before_main_content' );

Fires after the main poll content wrapper in templates.

do_action( 'buddypress_polls_after_main_content' );

Fires before an individual poll is displayed.

do_action( 'before_single_buddypress_polls' );

Fires after an individual poll is displayed.

do_action( 'after_single_buddypress_polls' );

These hooks let you add content around poll answer sections.

Fires before the poll answer HTML container.

do_action( 'wbpoll_answer_html_before', $poll_id, $reference, $poll_result );

Fires before the question/options section within the answer HTML.

do_action( 'wbpoll_answer_html_before_question', $poll_id, $reference, $poll_result );

Fires after the question/options section within the answer HTML.

do_action( 'wbpoll_answer_html_after_question', $poll_id, $reference, $poll_result );
add_action( 'wbpoll_answer_html_after_question', function( $poll_id, $ref, $result ) {
echo '<div class="poll-note">Results update as soon as you vote.</div>';
}, 10, 3 );

Fires after the poll answer HTML container.

do_action( 'wbpoll_answer_html_after', $poll_id, $reference, $poll_result );

There is no filter for the activity poll creator check. WBPollHelper::current_user_can_create_activity_poll() reads the Activity Polls setting limit_poll_activity (everyone, user_role or member_type) with the poll_user_role and poll_member_type lists, and administrators always pass. The composer, the save path and the media upload route all call it. To change who can create activity polls, change that setting. The old bpolls_user_can_create_poll filter is not applied anywhere and was removed from this reference.

Filter whether a user can create standalone polls. The default comes from the Who Can Create Polls setting (wppolls_create_poll, empty means every logged-in user). It runs for the dashboard, the create form and the REST POST /wbpoll/v1/postpoll route.

apply_filters( 'wbpoll_user_can_create_poll', $can_create, $allowed_roles );
add_filter( 'wbpoll_user_can_create_poll', function( $can_create, $allowed_roles ) {
// Restrict to users with 100+ posts
return $can_create && count_user_posts( get_current_user_id() ) >= 100;
}, 10, 2 );

Filter which poll types are available.

$enabled_types holds text (always true) and one boolean per other type. A type other than text is true only when its Polls > Poll Types switch is saved on; a switch that was never saved is off, the same as the settings page shows.

apply_filters( 'wbpoll_enabled_poll_types', $enabled_types, $settings );
add_filter( 'wbpoll_enabled_poll_types', function( $types, $settings ) {
// Disable audio polls programmatically
unset( $types['audio'] );
return $types;
}, 10, 2 );

Filter whether guests can create polls.

apply_filters( 'wbpoll_guest_can_create', $can_create );

Filter the vote status before saving.

apply_filters( 'wbpoll_vote_status', $status, $poll_id );
add_filter( 'wbpoll_vote_status', function( $status, $poll_id ) {
// Moderate votes from users registered less than 7 days ago
$user = get_userdata( get_current_user_id() );
if ( strtotime( $user->user_registered ) > strtotime( '-7 days' ) ) {
return 0; // Set to pending
}
return $status;
}, 10, 2 );

Filter vote data before database insertion.

apply_filters( 'wbpoll_form_extra_process', $insertArray, $poll_id );

Filter the check for whether a user has already voted.

apply_filters( 'wbpoll_is_user_voted', $count );

Filter the activity action text for polls.

apply_filters( 'bp_activity_new_poll_action', $action, $activity );
add_filter( 'bp_activity_new_poll_action', function( $action, $activity ) {
return sprintf(
'%s created a poll - vote now!',
bp_core_get_userlink( $activity->user_id )
);
}, 10, 2 );

Filter whether a user can edit an activity poll.

apply_filters( 'bppolls_activity_user_can_edit', $can_edit, $activity );

Filter the poll description output.

apply_filters( 'wbpoll_description', $poll_content, $post_id );

Filter the login link HTML shown to guests.

apply_filters( 'wbpoll_login_html', $html, $login_url, $redirect_url );
add_filter( 'wbpoll_login_html', function( $html, $login_url, $redirect ) {
return sprintf(
'<a href="/bp-family/buddypress-polls/developer-guide/%s/" class="btn btn-primary">Sign In to Vote</a>',
esc_url( $login_url . '?redirect_to=' . $redirect )
);
}, 10, 3 );

Filter the default avatar URL for guest voters.

apply_filters( 'wbpoll_default_avatar', $default_url );

Filter the complete poll form HTML output.

apply_filters( 'wbpoll_form_html', $poll_form_html, $post_id );

wbpoll_form_html_before / wbpoll_form_html_after

Section titled “wbpoll_form_html_before / wbpoll_form_html_after”

Filter HTML before or after the poll form.

apply_filters( 'wbpoll_form_html_before', $html, $post_id );
apply_filters( 'wbpoll_form_html_after', $html, $post_id );

Filter the template file location for theme overrides.

apply_filters( 'wb_poll_locate_template', $template_part, $file_name );
add_filter( 'wb_poll_locate_template', function( $template, $file ) {
$custom = get_template_directory() . '/polls/' . $file;
if ( file_exists( $custom ) ) {
return $custom;
}
return $template;
}, 10, 2 );

Filter the wbpoll custom post type registration arguments.

apply_filters( 'wbpoll_post_type_args', $args );
add_filter( 'wbpoll_post_type_args', function( $args ) {
$args['rewrite'] = [ 'slug' => 'surveys', 'with_front' => false ];
return $args;
});

Filter available poll display options (text, bar, pie).

apply_filters( 'wbpoll_display_options', $methods );

Filter display options shown in backend settings.

apply_filters( 'wbpoll_display_options_backend', $methods );

Filter display options available in widget results.

apply_filters( 'wbpoll_display_options_widget_result', $methods );

Filter the poll status options array.

apply_filters( 'wbpoll_status_by_value', $states );

Filter the available user roles list used in poll settings.

apply_filters( 'wbpoll_userroles', $userRoles, $plain, $include_guest );

Filter the poll meta fields array. Use this to add custom meta fields to polls.

apply_filters( 'wbpoll_fields', $post_meta_fields );
add_filter( 'wbpoll_fields', function( $fields ) {
$fields['_wbpoll_custom_field'] = [
'label' => 'Custom Field',
'type' => 'text'
];
return $fields;
});

Filter the vote count display in admin poll listings.

apply_filters( 'wbpoll_admin_listing_votes', $total_votes, $post_id );
add_filter( 'wbpoll_admin_listing_votes', function( $votes, $post_id ) {
return number_format( $votes );
}, 10, 2 );

Filter HTML at the start of the answer options section.

apply_filters( 'wbpoll_form_answer_start', $html, $post_id );

Filter HTML at the end of the answer options section.

apply_filters( 'wbpoll_form_answer_end', $html, $post_id );

Filter the registration link HTML shown to guests who need to register.

apply_filters( 'wbpoll_register_html', $html, $redirect_url );

Filter the CSV export filename.

apply_filters( 'bpolls_csv_export_filename', $file, $activity_id, $poll_name );

Filter CSV export settings including delimiter, enclosure, and date format.

apply_filters( 'bpolls_csv_export_settings', $csv_settings, $activity_id );

Filter the CSV header row.

apply_filters( 'bpolls_csv_export_header', $csv_header, $activity_meta, $activity_id );

Filter each CSV data row.

apply_filters( 'bpolls_csv_export_row', $fields, $user, $activity_meta, $activity_id );

Filter when poll CSS and JavaScript assets should be loaded.

apply_filters( 'bppolls_enqueue_assets_condition', $should_enqueue );
add_filter( 'bppolls_enqueue_assets_condition', function( $should_enqueue ) {
// Always load poll assets on a custom page
if ( is_page( 'my-polls-page' ) ) {
return true;
}
return $should_enqueue;
});
Filter Arguments Purpose
wbpoll_creation_settings $creation_settings, $settings Consolidated standalone poll creation settings (types, roles, limits)
wbpoll_cannot_vote_message $message, $post_id, $is_logged_in Message shown when a viewer cannot vote
wbpoll_form_html_before_question / wbpoll_form_html_after_question $html, $post_id HTML before or after the question block
wbpoll_answer_extra_fields (action) $index, $answers_extra, $is_voted, $poll_postid Add markup inside each answer row
wbpolladmin_add_answertype (action) $poll_postid, $new_index Add fields to each answer type in the poll editor
buddypress_polls_dashboard_per_page $per_page (default 12) Polls per page on the member dashboard
wbp_admin_tabs $tabs Tabs on the plugin admin hub
wbsurvey_admin_notification_subject / _message $text, $survey, $response Survey email to the admin
wbsurvey_respondent_notification_subject / _message $text, $survey, $response Survey email to the respondent
wbsurvey_email_headers $headers Survey email headers
wb_polls_booted (action) $plugin Plugin finished booting
wb_polls_before_vote (action) $insert_array, $poll_id Before a standalone poll vote is saved
wb_polls_after_vote (action) $vote_id, $poll_id, $insert_array After a standalone poll vote is saved
wb_polls_before_activity_vote (action) $activity_id, $user_id, $activity_meta Before an activity poll vote is saved
wb_polls_after_activity_vote (action) $activity_id, $user_id, $user_vote After an activity poll vote is saved ($user_vote holds the chosen option keys)
wb_polls_poll_saved (action) $poll_id, $is_update, $request A poll was created or updated through the REST API
wb_polls_poll_paused / wb_polls_poll_unpublished / wb_polls_poll_published / wb_polls_poll_deleted (actions) $poll_id, $request A REST poll action ran
wb_polls_rest_prepare_poll $item, $post, $request Change the data the poll list API returns for a poll
wb_polls_survey_response_started (action) $response_id, $survey_id, $response A survey response was started
wb_polls_survey_answer_saved (action) $survey_id, $poll_id, $answer, $response A survey answer was saved
wb_polls_survey_response_completed (action) $response_id, $survey_id, $response A survey response was completed
wb_polls_survey_response_deleted (action) $response_id, $survey_id A survey response was deleted
wb_polls_survey_lead_captured (action) $survey_id, $email, $consent An email was captured at the lead gate
wb_polls_rest_prepare_survey $data, $survey, $include_details Change the data the survey API returns
wb_polls_rate_limit_max $max, $action Change the per-minute request ceiling for public vote, lead and survey actions
wb_polls_trust_proxy_headers $trusted Trust forwarded client-IP headers. Defaults to the WB_POLLS_TRUSTED_PROXIES constant
wbpoll_email_placeholders / wbsurvey_email_placeholders $placeholders, plus poll or survey data Add placeholders to poll and survey emails

WB Polls saves every date in UTC and shows it in one timezone, the site timezone by default. This filter changes that timezone, for example to show each member dates in their own timezone. It applies to poll start and end dates, activity poll closing dates, survey expiry, response dates, exports and emails.

apply_filters( 'wb_polls_display_timezone', $timezone, $user_id );
Parameter Type Description
$timezone DateTimeZone The site timezone (wp_timezone())
$user_id int The member the date is shown to, or 0 for the current visitor
add_filter( 'wb_polls_display_timezone', function( $timezone, $user_id ) {
$zone = get_user_meta( $user_id ?: get_current_user_id(), 'my_timezone', true );
return $zone ? new DateTimeZone( $zone ) : $timezone;
}, 10, 2 );

Always verify WB Polls is active before adding hooks:

if ( class_exists( 'Buddypress_Polls' ) ) {
add_filter( 'wbpoll_user_can_create_poll', 'my_custom_check', 10, 2 );
}

Use priority values to control execution order:

add_action( 'wbpoll_on_vote', 'early_function', 5, 3 ); // Runs first
add_action( 'wbpoll_on_vote', 'normal_function', 10, 3 ); // Default
add_action( 'wbpoll_on_vote', 'late_function', 20, 3 ); // Runs last

Remove existing hook callbacks when you need to replace default behavior:

remove_filter( 'wbpoll_login_html', 'default_login_html_function', 10 );

Since 5.0 the frontend does not use admin-ajax.php. Every public action is a REST route that wraps the original handler, so the nonce and the JSON response shape are unchanged. Each handler still enforces its own login, nonce and poll rules. The old wp_ajax_bpolls_* and wp_ajax_wbpoll_* frontend actions no longer exist.

Route Nonce Purpose
/save-vote bpolls_ajax_security Submit a vote on an activity poll
/save-image bpolls_ajax_security Upload an image to a poll option
/save-video bpolls_ajax_security Upload a video to a poll option
/save-audio bpolls_ajax_security Upload audio to a poll option
/activity-voters bpolls_ajax_security One page (20) of a poll option’s voters; send page for the next page
/activity-add-option bpolls_ajax_security Add a user-suggested option
/activity-delete-option bpolls_ajax_security Delete a user-suggested option
/set-poll-type bpolls_ajax_security No-op since 5.0.3, kept for cached scripts; the poll type comes from the options posted with the update
/widget-activity-results bpolls_widget_security Load activity poll results in the widget
Route Nonce Purpose
/vote wbpolluservote Submit a vote on a standalone poll
/lead wbpoll_lead_nonce Lead capture after voting
/additional-field wbpoll_additional_field_nonce Add a user-suggested option (text, image, video, audio or HTML, one route)
/widget-results wbpoll_widget_nonce Load standalone poll results in the widget
Action Nonce Purpose
wbpoll_get_answer_template wbpoll Get answer template for admin poll editor
wbpoll_log_delete wbpoll Delete a poll log entry

WB Polls creates two custom database tables on activation.

Stores all votes cast on standalone polls.

Column Type Description
id mediumint(8) Auto-increment primary key
poll_id int(13) Poll post ID
poll_title text Poll title at time of vote
user_name varchar(255) Voter display name
is_logged_in tinyint(1) Whether voter was logged in
user_cookie varchar(1000) Cookie identifier for duplicate prevention
user_ip varchar(45) Voter IP address
user_id bigint(20) WordPress user ID (NULL for guests)
user_answer text Selected answer option IDs
answer_title text Selected answer option text
published tinyint(3) Vote published status (default 1)
comment longtext Vote comment
guest_hash varchar(32) Hash identifier for guest voters
guest_name varchar(100) Guest voter name
guest_email varchar(100) Guest voter email
created int(20) Unix timestamp of vote

Indexes: poll_id, user_id, composite poll_user (poll_id, user_id)

Stores poll activity logs for admin review.

Column Type Description
id mediumint(8) Auto-increment primary key
poll_id int(13) Poll post ID
user_name varchar(255) User display name
is_logged_in tinyint(1) Whether user was logged in
user_ip varchar(45) User IP address
useragent text Browser user agent string
user_id bigint(20) WordPress user ID
user_action text Action performed
poll_status text Poll status at time of action
details text Action details
created int(20) Unix timestamp

Indexes: poll_id, user_id

The votes table supports multiple methods of duplicate vote detection:

  1. Logged-in users: Checked by user_id
  2. Guest voters: Checked by combination of user_ip, user_cookie, and guest_hash
  3. Cookie tracking: Uses a wbpoll-cookie cookie with a 14-day expiration