Hooks and Filters

Get Started

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.

Action Hooks

Activity Poll Hooks

bppollsaftersubmitpolls

Fires after a vote is submitted on an activity poll.

do_action( 'bp_polls_after_submit_polls', $user_id, $activity_id );
ParameterTypeDescription
$user_idintID of the user who voted
$activity_idintID 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 );

bpollsaftersavepollactivity

Fires after a poll activity is saved.

do_action( 'bpolls_after_save_poll_activity', $activity_id, $poll_data );

Standalone Poll Hooks

wbpollonvote

Fires when a vote is recorded on a standalone poll.

do_action( 'wbpoll_on_vote', $insertArray, $vote_id, $published );
ParameterTypeDescription
$insertArrayarrayVote data array including pollid, userid, and answer
$vote_idintID of the vote record
$publishedintWhether 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 );

wbpollformvalidation

Fires after vote form validation, before saving the vote.

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

Template Hooks

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

buddypresspollsbeforemaincontent

Fires before the main poll content wrapper in templates.

do_action( 'buddypress_polls_before_main_content' );

buddypresspollsaftermaincontent

Fires after the main poll content wrapper in templates.

do_action( 'buddypress_polls_after_main_content' );

beforesinglebuddypress_polls

Fires before an individual poll is displayed.

do_action( 'before_single_buddypress_polls' );

aftersinglebuddypress_polls

Fires after an individual poll is displayed.

do_action( 'after_single_buddypress_polls' );

Form Hooks

These hooks let you add content around poll answer sections.

wbpollanswerhtml_before

Fires before the poll answer HTML container.

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

wbpollanswerhtmlbeforequestion

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

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

wbpollanswerhtmlafterquestion

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-disclaimer">Your vote is anonymous.</div>';
}, 10, 3 );

wbpollanswerhtml_after

Fires after the poll answer HTML container.

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

Filters

Poll Creation Filters

bpollsusercancreatepoll

Filter whether a user can create activity polls.

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

wbpollusercancreatepoll

Filter whether a user can create standalone polls.

apply_filters( 'wbpoll_user_can_create_poll', $can_create, $allowed_roles );

wbpollenabledpoll_types

Filter which poll types are available.

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 );

wbpollguestcan_create

Filter whether guests can create polls.

apply_filters( 'wbpoll_guest_can_create', $can_create );

Vote Filters

wbpollvotestatus

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 );

wbpollformextra_process

Filter vote data before database insertion.

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

wbpollisuser_voted

Filter the check for whether a user has already voted.

apply_filters( 'wbpoll_is_user_voted', $count );

Display Filters

bpactivitynewpollaction

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 );

bppollsactivityusercanedit

Filter whether a user can edit an activity poll.

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

wbpoll_description

Filter the poll description output.

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

wbpollloginhtml

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="%s" class="btn btn-primary">Sign In to Vote</a>',
        esc_url( $login_url . '?redirect_to=' . $redirect )
    );
}, 10, 3 );

wbpolldefaultavatar

Filter the default avatar URL for anonymous voters.

apply_filters( 'wbpoll_default_avatar', $default_url );

Form HTML Filters

wbpollformhtml

Filter the complete poll form HTML output.

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

wbpollformhtmlbefore / wbpollformhtmlafter

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 );

Template Filters

wbpolllocate_template

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 );

Post Type Filters

wbpollposttype_args

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;
});

Options and Settings Filters

wbpolldisplayoptions

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

apply_filters( 'wbpoll_display_options', $methods );

wbpolldisplayoptions_backend

Filter display options shown in backend settings.

apply_filters( 'wbpoll_display_options_backend', $methods );

wbpolldisplayoptionswidgetresult

Filter display options available in widget results.

apply_filters( 'wbpoll_display_options_widget_result', $methods );

wbpollstatusby_value

Filter the poll status options array.

apply_filters( 'wbpoll_status_by_value', $states );

wbpoll_userroles

Filter the available user roles list used in poll settings.

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

wbpoll_fields

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;
});

Admin Display Filters

wbpolladminlisting_votes

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 );

Form Answer Filters

wbpollformanswer_start

Filter HTML at the start of the answer options section.

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

wbpollformanswer_end

Filter HTML at the end of the answer options section.

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

wbpollregisterhtml

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

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

CSV Export Filters

bpollscsvexport_filename

Filter the CSV export filename.

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

bpollscsvexport_settings

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

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

bpollscsvexport_header

Filter the CSV header row.

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

bpollscsvexport_row

Filter each CSV data row.

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

Asset Loading Filter

bpollsenqueueassets_condition

Filter when poll CSS and JavaScript assets should be loaded.

apply_filters( 'bpolls_enqueue_assets_condition', $should_enqueue );
add_filter( 'bpolls_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;
});

Best Practices

Check Plugin Activation

Always verify WB Polls is active before adding hooks:

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

Hook Priority

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

Removing Default Hooks

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

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

AJAX Actions Reference

WB Polls registers these AJAX actions for frontend interactions. All actions use the wpajax prefix and some also register wpajaxnopriv_ variants for guest access.

Activity Poll AJAX Actions

ActionNoncePurposeGuest Access
bpollssavepoll_votebpollsajaxsecuritySubmit a vote on an activity pollNo
bpollssaveimagebpollsajaxsecurityUpload an image to a poll optionNo
bpollssavevideobpollsajaxsecurityUpload a video to a poll optionNo
bpollssaveaudiobpollsajaxsecurityUpload audio to a poll optionNo
bpollsactivityall_votersbpollsajaxsecurityGet full voter list for a poll optionYes
bpollsactivityadduseroptionbpollsajaxsecurityAdd a user-suggested optionNo
bpollsactivitydeleteuseroptionbpollsajaxsecurityDelete a user-suggested optionNo
bpollssetpolltypetruebpollsajaxsecuritySet the poll type flagNo

Standalone Poll AJAX Actions

ActionNoncePurposeGuest Access
wbpolluservotewbpolluservoteSubmit a vote on a standalone pollYes
wbpolladditionalfieldNoneAdd a user-suggested text optionYes
wbpolladditionalfield_imageNoneAdd a user-suggested image optionYes
wbpolladditionalfield_videoNoneAdd a user-suggested video optionYes
wbpolladditionalfield_audioNoneAdd a user-suggested audio optionYes
wbpolladditionalfield_htmlNoneAdd a user-suggested HTML optionYes

Widget AJAX Actions

ActionNoncePurposeGuest Access
bpollswidgetgetactivityresultsbpollswidgetsecurityLoad activity poll results in widgetYes
wbpollwidgetget_resultswbpollwidgetnonceLoad standalone poll results in widgetYes

Admin AJAX Actions

ActionNoncePurpose
wbpollgetanswer_templatewbpollGet answer template for admin poll editor
wbpolllogdeletewbpollDelete a poll log entry

Database Schema

WB Polls creates two custom database tables on activation.

Votes Table ({prefix}wppollvotes)

Stores all votes cast on standalone polls.

ColumnTypeDescription
idmediumint(8)Auto-increment primary key
poll_idint(13)Poll post ID
poll_titletextPoll title at time of vote
user_namevarchar(255)Voter display name
isloggedintinyint(1)Whether voter was logged in
user_cookievarchar(1000)Cookie identifier for duplicate prevention
user_ipvarchar(45)Voter IP address
user_idbigint(20)WordPress user ID (NULL for guests)
user_answertextSelected answer option IDs
answer_titletextSelected answer option text
publishedtinyint(3)Vote published status (default 1)
commentlongtextVote comment
guest_hashvarchar(32)Hash identifier for guest voters
guest_namevarchar(100)Guest voter name
guest_emailvarchar(100)Guest voter email
createdint(20)Unix timestamp of vote

Indexes: pollid, userid, composite polluser (pollid, user_id)

Log Table ({prefix}wppolllog)

Stores poll activity logs for admin review.

ColumnTypeDescription
idmediumint(8)Auto-increment primary key
poll_idint(13)Poll post ID
user_namevarchar(255)User display name
isloggedintinyint(1)Whether user was logged in
user_ipvarchar(45)User IP address
useragenttextBrowser user agent string
user_idbigint(20)WordPress user ID
user_actiontextAction performed
poll_statustextPoll status at time of action
detailstextAction details
createdint(20)Unix timestamp

Indexes: pollid, userid

Duplicate Vote Prevention

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 userip, usercookie, and guest_hash
  3. Cookie tracking: Uses a wbpoll-cookie cookie with a 14-day expiration
Last updated: February 14, 2026