WP ULike
Get Pro

Front-End AJAX API

How the voting script submits likes without the Pro REST API — endpoints, payloads, and responses.

The default like button uses WordPress admin-ajax.php, not the Pro REST API. This is how votes work on most sites out of the box.

The Pro REST API is optional — for headless apps and server integrations. See REST API.


Global JavaScript object

The front-end script exposes:

wp_ulike_params.ajax_url       // admin-ajax.php URL
wp_ulike_params.notifications  // whether toasts are enabled
wp_ulike_params.ajax_error     // default connection error message

Instantiate buttons with the WordpressUlike class (done automatically on .wp_ulike_general_class elements).


Vote endpoint

PropertyValue
URL
{site}/wp-admin/admin-ajax.php
Action
wp_ulike_process
Method
POST
Auth
Logged-in and guest (nopriv hook registered)

POST parameters

ParamRequiredDescription
action
yes
Must be wp_ulike_process
id
yes
Item ID (post, comment, activity, topic)
type
yes
Content type slug: post, comment, activity, topic
nonce
yes
{type}{id} nonce from button data-ulike-nonce
factor
no
up or down — like vs dislike button
template
no
Template slug (default wpulike-default)
displayLikers
no
Whether to return likers HTML
likersTemplate
no
popover, inline, etc.

Filter incoming data: wp_ulike_listener_data.


Vote response (JSON)

Success response shape:

{
  "message": "Thanks! You liked this.",
  "btnText": "Unlike",
  "messageType": "success",
  "status": 3,
  "data": "42",
  "likers": { "template": "..." },
  "hasToast": true
}

Status codes (status)

CodeMeaning
1
Vote registered (not liked → liked path)
2
Unlike registered
3
Already liked state
4
No-limit vote, or login required when response includes requireLogin: true
5
Permission denied (blacklist, validation)

Error responses include message, messageType: "error", and hasToast.

Modify responses: wp_ulike_ajax_respond filter.

Status-specific counter filters: wp_ulike_respond_for_liked_data, wp_ulike_respond_for_unliked_data, wp_ulike_respond_for_not_liked_data, wp_ulike_respond_for_no_limit_data.


Likers endpoint

PropertyValue
Action
wp_ulike_get_likers
Method
POST

Fetches likers box HTML for popover and modal layouts. Used when the likers box is enabled.


Button data attributes

Each vote button exposes:

AttributePurpose
data-ulike-id
Item ID
data-ulike-type
Content type
data-ulike-nonce
CSRF nonce
data-ulike-template
Active template slug
data-ulike-factor
up or down

CSS classes during interaction:

  • wp_ulike_is_loading — AJAX in progress
  • wp_ulike_btn_is_active — user has voted
  • wp_ulike_put_image — image button variant

PHP vote lifecycle

AJAX vote flow hooks (in order):

  1. wp_ulike_before_process$data array with id, type, nonce, template, IP
  2. Vote validation and DB write
  3. wp_ulike_data_inserted or wp_ulike_data_updated
  4. wp_ulike_after_process — action attributes array (id, key, user_id, status, has_log, slug, table, is_distinct)
  5. wp_ulike_ajax_respond — modify JSON before output

Block invalid votes: wp_ulike_permission_status filter.


When to use REST instead

Use the Pro REST API when you need:

  • Server-to-server vote writes with Bearer tokens
  • Paginated log export (GET /vote)
  • Stats datasets for external dashboards
  • Headless front ends without admin-ajax

Enable under Tools → REST API. Configuration exports with settings backup; keys do not.

Related: JavaScript Events · Hooks & Filters

Continue with these guides