Skip to content

Hooks & Filters

Omnalingo exposes WordPress filters and actions for developers, all namespaced under omnalingo/…. Use them with add_filter() and add_action() as usual.

// Add a CSS selector to the translation exclusion list
add_filter('omnalingo/exclusions/selectors', function ($selectors) {
$selectors[] = '.my-widget';
return $selectors;
});
// Translate an HTML string on demand, using Omnalingo's engine
$german = apply_filters('omnalingo/translate/html', $html, 'de');
HookTypeSignaturePurpose
omnalingo/translate/htmlfilter($html, $langCode)Translate a raw HTML string into a language with Omnalingo’s engine; returns the translated HTML.
omnalingo/render/set_target_languageaction($langCode)Set the active render target language (null/'' clears it).
omnalingo/render/target_languagefilter(null)Read the current render target language.
omnalingo/render/enable_gettext_wrappingaction()Enable gettext wrapping for the current render.
omnalingo/render/disable_gettext_wrappingaction()Disable gettext wrapping.
omnalingo/render/wrapping_enabledfilter(false)Read whether gettext wrapping is on.
omnalingo/gettext/skip_wrapfilter(false)Return true to skip wrapping gettext strings this request.
omnalingo/gettext/backtrace_unsafefilter($functions)Adjust the list of calling functions for which gettext wrapping is skipped.
omnalingo/buffer/skipfilter(false)Return true to skip the output-buffer translation pass this request.
HookTypeSignaturePurpose
omnalingo/schema/enabledfilter($enabled)Return false to stop collecting and translating JSON-LD structured data.
HookTypeSignaturePurpose
omnalingo/search/enabledfilter($enabled, $query)Return false to skip translated search for a query — or for the whole site.
omnalingo/search/rest_routesfilter($patterns)Regex patterns for the REST routes translated search may widen. Defaults to WooCommerce’s Store API products route; core’s /wp/v2/ routes are never widened.
HookTypeSignaturePurpose
omnalingo/slug/translate_urlfilter($url, $langCode, $postId, $termId)Return the translated-slug URL for an object in a language. The central slug hook.
omnalingo/slug/resolve_pathfilter($path, $langCode)Map an incoming translated path back to its canonical path.
omnalingo/slug/translationsfilter([], $objectId, $objectType)Per-language slug translations for one object.
omnalingo/slug/mapfilter([], $items)Bulk slug map for a set of content items.
omnalingo/slug/batch_sizefilter(200)Batch size for slug operations.
omnalingo/slug/original_changedaction($id, $type, $newSlug)An object’s original slug changed ($type = post or term).
omnalingo/slug/object_deletedaction($id, $type)An object was deleted.
omnalingo/editor/build_urlfilter($url, $targetUrl)The URL used to load a page in the editor frame.
omnalingo/editor/language_urlsfilter($urls, $baseUrl)Per-language URLs offered in the editor.
omnalingo/editor/title_translatedaction($contentId, $type)A title was translated (e.g. to refresh its slug).
HookTypeSignaturePurpose
omnalingo/sitemap/enabledfilter(true)Enable or disable Omnalingo’s sitemap output.
omnalingo/sitemap/urlfilter('')Provide the sitemap URL (used by SEO-plugin integrations).
omnalingo/sitemap/alternatesfilter([], $entryId, $objectType)hreflang alternates for a sitemap entry.
omnalingo/sitemap/exclude_objectfilter(false, $objectId, $objectType)Exclude an object from the sitemap.
HookTypeSignaturePurpose
omnalingo/content_typesfilter([])Register custom translatable content types (e.g. emails).
omnalingo/content_settings/presetsfilter($presets, $context)Adjust the Sitemap content-type presets.
omnalingo/content_settings/default_selectionsfilter($defaults)Default selected content types.
omnalingo/content_settings/default_presetfilter('wordpress_default')The default content preset slug.
omnalingo/scan/translatable_meta_tagsfilter($metaTags)Which meta tags are extracted for translation.
omnalingo/scan/url_scannedaction($urlId)Fired after a URL is scanned.
omnalingo/scan/gathering_completeaction($trigger)Fired when content gathering finishes.
omnalingo/exclusions/selectorsfilter($selectors)The CSS-selector exclusion list.
omnalingo/auto_translate/new_contentfilter($enabled, $objectId, $objectType, $contentType, $url)Whether newly listed content starts with automatic translation on. See Automatic translation for new content. Since 0.9.4; also runs for archives and added addresses since 0.9.7.
omnalingo/front_page_idfilter($id)The post ID of the site’s front page (0 = latest posts). For themes that choose the front page themselves; Omnalingo’s Enfold integration uses it. Since 0.9.4.

Every page in Omnalingo’s list has its own Auto-translate switch. A page gets its switch when Omnalingo first lists it, usually the moment it is published, and it starts with the site-wide default. The Enable Auto translate for all button above the content list in Translate sets that default to on (and switches every listed page on); Turn off for all in the same button’s menu sets it to off.

omnalingo/auto_translate/new_content lets you decide per page instead. Return true to start the page with automatic translation on, false to start it off, or $enabled to keep the site-wide default.

ArgumentExampleMeaning
$enabledfalseThe site-wide default for new content.
$objectId2915Post ID, or term ID for categories and tags. For archives: 202611 (year and month) for a monthly archive, the author’s user ID for an author archive, a number derived from the post type for a post-type archive. 0 for an address added by hand or from the live editor.
$objectType'post''post', 'term', 'archive' (since 0.9.7) or 'custom' (an added address, since 0.9.7).
$contentType'ex_team'Post type or taxonomy, such as 'page', 'product' or 'product_cat'. For archives 'date_archive', 'author_archive' or 'cpt_archive'; 'custom' for added addresses.

Check $objectType before you use $objectId: for an archive it is not a post ID, and an author’s user ID can match an unrelated post. | $url | '/member/maria-papadopoulou/' | The address in the site’s main language, relative to the site root. |

Example: leave the site-wide default off, and translate new author biographies (the ex_team post type, or anything under /member/) automatically:

add_filter('omnalingo/auto_translate/new_content', function ($enabled, $objectId, $objectType, $contentType, $url) {
if ($contentType === 'ex_team' || strpos($url, '/member/') === 0) {
return true;
}
return $enabled;
}, 10, 5);

Good to know:

  • It runs once per page, when Omnalingo first lists it. Later saves don’t run it again, so a switch you change by hand on the page keeps your choice.
  • Pages already in the list are not touched. To switch existing pages on, select them in the Translate list and turn Auto-translate on there.
  • Later edits are covered. A page with Auto-translate on is read again after each save, and new or changed text is translated automatically.
  • What it does not cover. The 404 and search-results entries and shop email previews always start off; Omnalingo creates them by itself. A draft or private post added from the live editor starts off too.
  • The content type must be tracked. Omnalingo only lists the content types selected in its content settings; make sure the post type (here ex_team) is one of them.
  • Return a real boolean. Any other value is converted with PHP’s (bool).
HookTypeSignaturePurpose
omnalingo/settings/tabsfilter([])Register extra settings tabs.
omnalingo/settings/groupsfilter($groups)Per-tab settings group definitions.
omnalingo/admin/hydration_datafilter($data)The data object passed to the admin interface.
HookTypeSignaturePurpose
omnalingo/db/table_prefixfilter($prefix)The table prefix for Omnalingo’s tables.
omnalingo/db/resetaction()Fired on factory reset.
omnalingo/client/refreshedaction($clientData)Fired when plan/client data is refreshed.
omnalingo/fixture/capturedaction($name, $dir, $mode)Fired when a support fixture is captured.
omnalingo/containerfilter(null)Returns the plugin’s dependency-injection container — advanced; lets you reach internal services.

These cover the shop-email and XLIFF features, and use the shared hooks above:

HookTypeSignaturePurpose
omnalingo/email/providersfilter([])Register e-commerce email providers for translation.
omnalingo/email/preview_capabilityfilter('edit_posts')Capability required to use the email preview.
omnalingo/xliff/importedaction($langCode, $languageData)Fired after an XLIFF file is imported for a language.