This page is for developers who want to extend Affiliate Butler Pro or connect it to other tools. You don’t need any of it to use the plugin.
Files
affiliate-butler-pro.php: the main plugin file.src/: the plugin code, in theAffiliateButlerPronamespace: the links and the replacement of the keywords (Links/), the click stats (Stats/), the REST API (Rest/), the admin screens (Admin/) and the licence (Licence/).public/: the short links redirect and the content filters.build/: the compiled scripts and styles of the admin screens, the block editor and the site.languages/: the translations, and theaffiliate-butler-pro.pottemplate to make your own.includes/: the updater, which installs updates from WPRuby when your licence is active.uninstall.php: deletes the plugin’s data when the plugin is deleted and the “Delete all data” setting is on.
Auto links are posts of the lar_link post type, and their categories are terms of the links_category taxonomy. The clicks are in the {prefix}abutler_clicks table. Please edit links through the admin or the REST API, which check and sanitize them.
REST API
Every route is under /wp-json/affiliate-butler/v1 and uses the usual WordPress authentication (cookie and nonce, or application passwords).
| Method | Route | What it does | Capability |
|---|---|---|---|
GET |
/links |
Lists the links. Query: page, per_page, search, status. |
edit_posts |
POST |
/links |
Creates a link. | edit_posts |
GET |
/links/{id} |
Reads a link, with all its fields. | edit_post |
PUT |
/links/{id} |
Updates a link. Fields you leave out keep their value. | edit_post |
DELETE |
/links/{id} |
Moves a link to the Trash, or deletes it with force=true. |
delete_post |
GET |
/links/{id}/occurrences |
The posts that contain the link’s keywords. | edit_post |
GET |
/links/{id}/stats |
The clicks of a link. Query: days. |
manage_options |
POST |
/import |
Imports a JSON or CSV file sent in content. dry_run=true only checks it. |
edit_posts |
GET |
/settings |
Reads the settings. | manage_options |
POST |
/settings |
Changes the settings. | manage_options |
A link is a JSON object with the fields of the link editor. GET /links/{id} shows all of them. For example, to create an external link with a short link:
POST /wp-json/affiliate-butler/v1/links
{
"keywords": [ "web hosting" ],
"type": "external",
"target_url": "https://example.com/?ref=me",
"short_link_enabled": true
}
Invalid fields return a 400 error with a message per field in data.errors.
Filters
| Filter and arguments | Use |
|---|---|
abutler_track_clicks$track, $link_id |
Return false to not record a click, e.g. until the visitor accepts your cookie banner. |
abutler_is_bot$is_bot, $user_agent |
Decide which visitors are bots; their clicks aren’t counted. |
abutler_visitor_country$country |
The visitor’s two-letter country code, when your host passes it in another header. |
abutler_stats_capability$capability |
Who can see the stats, manage_options by default. |
abutler_redirect_status$status, $link_id |
The HTTP status of a short link redirect. |
abutler_forward_params$params, $url |
The query parameters a short link passes on to its URL. |
abutler_rotation_target$url, $rotation, $link_id |
The URL a rotating short link sends the visitor to, e.g. to keep returning visitors on the same one. |
abutler_share_networks$networks, $link_id |
The buttons of the share boxes: name => array( label, share URL ). |
abutler_disable_box_screens$post_types |
The post types that have the “Disable auto links in this post” option. |
abutler_replace_content$html |
The content after the keywords were linked. |
For example, to let editors see the stats:
add_filter( 'abutler_stats_capability', function () {
return 'edit_others_posts';
} );
Actions
abutler_click_recorded( $link_id, $post_id ): after a click is saved.lar_link_redirected( $link_id, $target ): before a short link redirects;$targetis the URL a rotating link picked, empty for the others.
JavaScript event
Every click on an auto link fires an abutler:click event on document, so your own scripts can react to it, for example to send the click to another analytics tool:
document.addEventListener( 'abutler:click', ( event ) => {
const { linkId, postId, url, text } = event.detail;
// e.g. plausible( 'Affiliate click', { props: { url } } );
} );
Translations
The text domain is affiliate-butler-pro. The translations are in the plugin’s languages/ folder: a .po and .mo file per language, and .json files for the admin screens. To translate the plugin into a new language, start from affiliate-butler-pro.pot and send us your file, we’ll ship it in the next update.