e-addons

Share

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on whatsapp
Share on telegram
Share on skype
Share on email

e-addons for Elementor

Text Editor Tokens

What is exactly Text Editor Tokens? Well, just a simple Text Editor but with more dynamic features.
In fact, tokens are placeholders that let you easily insert dynamic data inside your text.
And know what? You won’t need to touch a line of code, we promise!

What is a Token?

A Token is a specially formatted chunk of text that serves as a placeholder for a dynamically generated value.

A string of static text that can be located and replaced with a dynamic value.

In order to avoid having to hard-code a welcome string for every single user of the website, you could use one similar to the following, “Welcome, [ user : first_name ]“.

Code:

Hello [user:first_name], you are using Elementor [option:elementor_version]

Result:

Hello , you are using Elementor 3.0.12

Generic Placeholder Substitution

In many cases, patterns or large chunks of text that contain derived values can be defined by users.

For example, from email messages addressed to a given user, or URL path aliases containing the title of a given post.
Both examples require bits of data that vary each time the text is generated — post titles, user ids, and so on.

Rather than forcing users to embed ugly snippets of PHP, shortcodes or creating elaborate and bizarre UIs for configuring the patterns via the browser, it’s most useful to give users a set of ‘placeholder’ Tokens to place in their text.

The first part

The Token Type are used to group things together into a namespace.

For example, Users can have name, email, and last-login properties. Posts can have title, ID and author properties.

This Token also plays an important role in determining what tokens are available and in what context.

The second part

After the : is the Token itself. This means what value will be substituted into the string containing the Token.

For example :first_name indicates that we want the current First Name of the User Token object.

If the data is an Array or an Object you can access to its subvalue using multiple time the subfield
option:www_user_roles:editor:name

Structure

tokens scheme

1

Token Type

The addon provide access to all basilar object of WP like:

  • Post
  • User
  • Term
  • Option
  • WP_Query
  • Query
  • System
  • Date
  • ACF
  • WooCommerce
  • Query
  • Specific variable

2

Field

Usually here you have to write the name of the Field (or Subfield) of the Token object.

  • Object native fields
  • Meta fields

3

Filter

A filter is a data modifier.
A filter is substantially a function.

You can use all kind of filter like:

  • all WP function
  • PHP native function
  • Custom function provided by plugins, themes of your theme function.php file

4

Fallback

If the Token object field is empty and the Token return no data, then you can define a string as possible Fallback

5

Source

Can be provided a different object as Source of data.

Passing its ID or Unique name the fields will be fetched from this element.

FILTERS

As filter you can use all WP, PHP and Custom function.
Some examples:

  • if the Token returns the string “Hello”, with the filter strtoupper the final result will be “HELLO”;
  • if the Token returns the Post ID, with the filter get_the_post_thumbnail will be printed his Feature Image.
 
How to add your own Custom filter

Add your function In your  function.php file, where the function name will be the filter name.
It has a unique parameter which contain the Token result, it may be a String, an Array, an Object or null.

function my_custom_token_filter($data) {
   // do whatever you want
   return $data;
}
 
Parameter

The Filters may accept also parameters, the Token’s value is automatically passed to the function as first parameter (or last for some function, like explode).

For example
  • substr(0,3) – gets the first 3 character ot the returned string;
  • get_the_post_thumbnail(‘full’) – gets the full image, not the thumb.

 

Multiple
You can add multiple filters, which will be execute in concatenation based on their order.
Write them separated by the “|” pipe:
[ post:title |sanitize_title|strtoupper|trim ]

Some Complete Examples:

Post

  • post:title – print current Post Title, native field of this object (you can also write it without the repetitive post_)
  • post:_yoast_wpseo_metadesc – print current Post Meta Description, a post meta field created by 3rd part plugin (like ACF, PODS, …)
  • post:_thumbnail_id|wp_get_attachment_url – print the current Post Feature Image url
  • post:_thumbnail_id|wp_get_attachment_image_src(thumbnail)|reset – print the Featured Image thumbnail URL of current Post
  • post:ID|get_the_post_thumbnail(full) – print current Post Featured Image trough a core WP function with parameters or a placeholder image if post hasn’t got the Featured Image
  • post:date|strtotime|date_i18n("j F Y") – print the current Post Date in custom format
  • [post:date|strtotime|sum(86400)|date_i18n("Y-m-d H:i:s") – print the Post Date plus one day in default time format
  • post:type:labels:singular_name – print the Type Singular Label of current Post
  • post:permalink – print the unique url of Current Post, use post:guid may be an alternative

User

  • user:first_name – print logged User first name, or nothing if the page is viewed from a non authenticated visitor;
  • user:last_name|concat('Mr ',true) – print logged User last name with a prefix;
  • user:email|explode(@)|reset – print only username of current User Email (for example support@e-addons.com);
  • user:nicename|trim?Anonimous!23 – print trimmed User Nicename from user with ID 23, otherwise if user has no nicename or user not exist will print “Anonymous”;
  • user:roles – print logged in User Role, separated by a comma if multiple Roles.

Author (User alias)

  • author:display_name – print the name of Author of Current Post.
  • author:ID:count_user_posts – print the number of Posts written by current Author, it accept as parameter the CPT name

Term

  • term:name – print Term name of Current Term or First Term of Current Post;
  • term:description|wpautop – print Term description with automatic paragraph;
  • term:description!123 – print Term description of the Term with ID 123;
  • term:count!123 – print Post count related to Term with ID 123;
  • term:link|last – print the url to Term Archive of the last term of current post;
  • term:txtarea|artist – print the value of an ACF field (like a Textarea) stored in Term of custom “artist” Taxonomy related to current Post;
  • term:term_id|category|posts|reset|get_the_title – print the Title of last published Post in same Taxonomy (Category);
  • term:term_id|posts|options!123 – return all Posts related to Term 123 as Options for Elementor PRO Form;
  • term:thumbnail_id|wp_get_attachment_url(full) – return the url of the Media in Term Meta field which contain his ID.

Option

  • option:elementor_version – print current version of the installed Elementor’s plugin from WP system options;
  • option:www_user_roles:editor:name|strtoupper – print uppercased name of Editor Role;
  • option:home|wp_logout_url – return to the direct Logout url and return to the Homepage.

Date

  • date:+1 month – print the date of a month from today in WordPress default format;
  • date|Y m d – print the date of today in custom format;
  • date:user:registered – print the current User registration date in default WordPress format;
  • date:post:date:+2 days|Y-m-d H:i:s – print the current Post publish date + 2 days (optional) in standard datetime format.

System

  • system:get:my_query_var – print the variable stored inside $_GET, also compatible with POST, SESSION, COOKIE and SERVER systems vars;
  • system:cookie:my_favorite – print the value stored inside a Cookie, also used for Add to Favorite Widget;
  • system:server:REMOTE_ADDR – print the IP of the current visitor;
  • system:MY_CONSTANT – print the value of a constant previously declared in code.

Query

  • query:user – print the list of all Users (Display Names);
  • query:user:email – print the list of all Users email;
  • query:user:editor – print the list of Editor Users (or any other Role);
  • query:user:customer|options("Guest") – create a Customer list in the Options setting of a Select Form Field with also an empty value “Guest”;
  • query:user:administrator:email – generate the list of all administrator emails, could be useful to fill the To recipient of a Form Email Action;
  • query:term – print the list of Terms (by default the Categories);
  • query:term:post_tag – print the list of Tags Terms (or any other Taxonomy);
  • query:post – print the list of the Posts (Titles);
  • query:post|count – print the number of published Posts;
  • query:post:uncategorized – print the list of the Posts without Category (or related to any other Term);
  • query:page – print the list of the Page (or any other Custom Post Type);
  • query:product|options – create the option list of all Products of your shop in a Select Form Field;
  • query:post:_thumbnail_id – print the list of the Featured Image Media ID of the Posts (or any other Meta Field);
  • query:attachment:guid|rand – print a random Media url.

WP_Query

  • wp_query:posts – print the id (or ids) of posts in the displayed page (like in archive);
  • wp_query:query_vars:paged – print the current pagination page number (return 0 on first page).

Expression

  • expr:5+(8*2)/3 – execute a mathematic expression;
  • expr: [ post:my_num_val ] *2 – execute a mathematic expression with dynamic values (nested Tokens);
  • expr: [ post:my_num_val ] + [ post:my_num_val ] * [ acf:coeff|123 ] – execute a mathematic expression with multiple dynamic values.

Variable

  • ROW:var_1|trim – print the variable ROW inside widgets with your own html structure.

Examples on 3rd part plugins:

ACF

  • acf:my_acf_field – print the value of ACF Field, where “my_acf_field” is the name of the field in ACF settings, it works also for subfield in rows of ACF Repeater;
  • acf:my_acf_field!123 – print the value of ACF Field of the Post with ID 123;
  • acf:my_file:filesize|size_format(2) – print the Human readable size (with 2 optional decimal) of a ACF File Field;
  • acf:my_acf_field:title – print the label of ACF Field set in his configuration;
  • acf:my_select_field:settings:choices:red – print the label of a ACF Field Option set in his configuration;
  • acf:my_acf_field:settings:choices|options – use the choices of ACF Field Select set in his configuration as options in a Select Field of Elementor PRO Form.

WOOCOMMERCE

All WooCommerce tokens are available only if the Wocommerce plugin is enabled . All the previous Post Tokens are also compatible with Products.
  • product:_price – print current Product base Price;
  • product:_sku – print current Product SKU;
  • product:_price|Woo-tshirt-logo – print Product base Price of Product with a specific SKU.
dis textEditorTokens