Helpers

The ConveyThis plugin provides a set of methods that can be called within your WordPress code to retrieve specific information.



ConveyThisHelper::getApiKey()
ConveyThisHelper::getApiKey()

Returns a string of the private API key in the format pub_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.


ConveyThisHelper::getSourceLanguage()
ConveyThisHelper::getSourceLanguage()

Returns the source language key as a 2-letter ISO 639-1 code. For example, es for Spanish.


ConveyThisHelper::getTargetLanguages()
ConveyThisHelper::getTargetLanguages()

Returns an array of all target language keys as 2-letter ISO 639-1 codes. For example, array('es', 'de') for Spanish and German.


ConveyThisHelper::getDefaultLanguage()
ConveyThisHelper::getDefaultLanguage()

Returns the default language key as a 2-letter ISO 639-1 code. For example, es for Spanish.


ConveyThisHelper::getCurrentLanguage()
ConveyThisHelper::getCurrentLanguage()

Returns the current language key as a 2-letter ISO 639-1 code. For example, es for Spanish.


ConveyThisHelper::getExclusions()
ConveyThisHelper::getExclusions()

Returns an array of all excluded pages based on various rules:

  • 'end': Matches URLs that end with a specific string (e.g., 'end' => 'end-url').
  • 'start': Matches URLs that start with a specific string (e.g., 'start' => '/start-url').
  • 'contain': Matches URLs that contain a specific string (e.g., 'contain' => 'contained-in-url').
  • 'equal': Matches URLs that exactly match a specific URL (e.g., 'equal' => 'https://example.com/exluded-page.php').

Example:

array (
  0 => array (
    0 => 'end',
    1 => 'about-us',
  ),
  1 => array (
    0 => 'start',
    1 => '/blog/',
  ),
  2 => array (
    0 => 'contain',
    1 => 'product',
  ),
  3 => array (
    0 => 'equal',
    1 => 'https://example.com/exluded-page.php',
  ),
)


ConveyThisHelper::getLanguages()
ConveyThisHelper::getLanguages()

Returns an array of all available languages for translation. Each language is represented as an associative array with the following keys:

  • 'title_en': English name of the language.
  • 'title_native': Native name of the language.
  • 'code2': 2-letter ISO 639-1 language code.
  • 'code3': 3-letter ISO 639-2 language code. Example:
array (
  0 => array (
    'title_en' => 'Afrikaans',
    'title_native' => 'Afrikaans',
    'code2' => 'af',
    'code3' => 'afr',
  ),
  1 => array (
    'title_en' => 'Albanian',
    'title_native' => 'Shqip',
    'code2' => 'sq',
    'code3' => 'sqi',
  ),
  2 => array (
    'title_en' => 'Amharic',
    'title_native' => 'አማርኛ',
    'code2' => 'am',
    'code3' => 'amh',
  ),
  // ... more languages
)


ConveyThisHelper::getBaseUrl()
ConveyThisHelper::getBaseUrl()

Returns a string of the base URL without the language key.


ConveyThisHelper::getWpPatterns()
ConveyThisHelper::getWpPatterns()

Returns an array of regular expression patterns used to identify and exclude common WordPress core files and directories.

This helps to prevent unnecessary translation attempts on files that are not typically user-facing or translatable.

Example:

array (
  0 => '/\\/sitemap\\b/',
  1 => '/\\/roboto\\b/',
  2 => '/\\/wp-admin\\b/',
  3 => '/\\/wp-content\\b/',
  4 => '/\\/wp-includes\\b/',
  5 => '/\\/wp-json\\b/',
  6 => '/wp-login\\.php\\b/',
  7 => '/wp-cron\\.php\\b/',
  8 => '/wp-signup\\.php\\b/',
  9 => '/wp-activate\\.php\\b/',
  10 => '/wp-mail\\.php\\b/',
  11 => '/wp-load\\.php\\b/',
  12 => '/wp-blog-header\\.php\\b/',
  13 => '/wp-links-opml\\.php\\b/',
  14 => '/wp-trackback\\.php\\b/',
  15 => '/wp-comments-post\\.php\\b/',
  16 => '/\\.(zip|tar\\.gz|tar\\.bz2|\\.xml|\\.txt)\\b/',
)

This page was last edited on 2024-12-23 19:46

Powered by Wiki|Docs

This page was last edited on 2024-12-23 19:46

Conveythis.com
Copyright © All rights reserved

Powered by Wiki|Docs