AriLinks developer reference

The AriLinks shortcode, filters, actions, REST route and link markup, with their parameters exactly as they are in the plugin code.

  • Reference
  • AriLinks
  • 3 min read
  • Updated

AriLinks has one shortcode, six filters, two actions and one REST route. It has no blocks, widgets or WP-CLI commands.

Shortcode

ShortcodeAttributesWhat it does
[arilinks_skip]…[/arilinks_skip]NoneKeeps the enclosed content free of automatic links. Shortcodes inside it are still run. The link report respects it too.

Filters

FilterParametersWhat it does
arilinks_is_allowedbool $allowed, WP_Post $postLast word on whether a post gets automatic links in the current request. Runs after the built-in checks (single view of the main post, not in the admin or feeds, not password protected).
arilinks_pre_filterstring|null $pre, string $content, WP_Post $postReturn a string to use as the linked HTML and skip processing. Return null to let AriLinks process the content.
arilinks_rule_appliesbool $applies, array $rule, WP_Post|null $postDecide whether one rule applies to a post. Runs after the rule's own content type, page and self-link checks.
arilinks_link_attributesarray $attrs, array $rule, WP_Post|null $postChange the attributes of an automatic link (name => value). href is escaped with esc_url(), the others with esc_attr().
arilinks_editor_keywords_capstring $capCapability needed to use Keywords that link here in the editor. Default edit_others_posts.
arilinks_rule_conditionsarray $conditions, array $inputFor add-ons: extra conditions to store with a rule when it is saved from the Add link form. Only used when a callback is attached. The result is stored as JSON in the rule's conditions field.

The $rule array holds the rule's columns: id, keyword, variants (one per line), url, target_post, post_types, nofollow, new_tab, case_sensitive, max_per_post, only_posts and conditions, plus _url, the resolved target address.

add_filter( 'arilinks_is_allowed', function ( $allowed, $post ) {
	return $allowed && ! has_category( 'news', $post );
}, 10, 2 );
add_filter( 'arilinks_link_attributes', function ( $attrs, $rule, $post ) {
	$attrs['title'] = $rule['keyword'];
	return $attrs;
}, 10, 3 );

Actions

ActionParametersWhen it runs
arilinks_after_processWP_Post $post, string $content, string $outAfter AriLinks has linked a post's content, with the original and the linked HTML. Not run when arilinks_pre_filter returned a string.
arilinks_rule_form_fieldsarray|null $ruleInside the Add link form table, after Only on these pages. Print extra <tr> rows here. $rule is null for a new link.

PHP helper

AriLinks_Frontend::link_html( $html, $post = null ) adds automatic links to HTML that belongs to the post being viewed on its single page, using the same rules and checks as the post content. It does not run arilinks_pre_filter or arilinks_after_process. With no $post, it uses the current post. It returns the HTML unchanged when the post is not allowed to get links.

REST route

RouteMethodParametersResponse
/wp-json/arilinks/v1/clickPOSTid (required, integer): the rule ID{"ok":true} with status 200; {"ok":false} with status 400 when id is 0 or click tracking is off.

The route is public. The front-end script calls it when a visitor clicks an automatic link with the left or middle mouse button. Requests with an empty user agent or one that looks like a bot return 200 without counting. Each visitor and link is counted at most once every 20 seconds; the rate-limit key is a hash of the IP address and rule ID made with the site's salt, and expires after 20 seconds.

An automatic link looks like this:

<a href="https://example.com/running-shoes/" class="arilink" data-arilink="12" target="_blank" rel="nofollow noopener">running shoes</a>
  • class is the CSS class setting, left out when it is empty.
  • data-arilink holds the rule ID and is only added while click tracking is on. The click script is only loaded on pages that contain such a link.
  • target="_blank" and rel="noopener" come from Open in a new tab; rel="nofollow" from Add rel="nofollow".

Data stored

WhereNameWhat it holds
Tables{prefix}arilinks_rulesLink rules and their click totals.
Tables{prefix}arilinks_statsClicks per rule per day.
Tables{prefix}arilinks_index, {prefix}arilinks_edgesThe link report: counts per page and which page links to which.
Optionsarilinks_settings, arilinks_db_version, arilinks_rules_version, arilinks_index_versionSettings and version markers.
Transientarilinks_active_rulesCached active rules with their target addresses, for up to a day.
Transientarilinks_c_{hash}Click rate limit per visitor and link, for 20 seconds.
Post meta_arilinks_offSet when Do not add automatic links on this page is ticked.

With Uninstall ticked in Settings, deleting the plugin removes all of these. On multisite, each site follows its own setting.

Still stuck?

Our helpdesk answers on working days, Norwegian time. Include your WordPress version, PHP version and the page address.

Submit a ticketor email info@arihub.com