">Doc

Introduction

In some parts of the plugin such as in the template or in the calculated fields it is possible to insert custom code through a template engine.
This is divided into two main concepts: variables and functions.

You can otherwise execute the template engine instructions via the adfo_tmpl shortcode. Add a shortcode block from the editor and type:

[adfo_tmpl]2*2 = [^MATH 2 * 2] [/adfo_tmpl]

In lists, for example, the extracted data is saved in the variable [%data]. All variables are called with shortcodes starting with%. On the other hand, functions with shortcodes starting with ^ and always behave the same way in every part of the code.

[%data.post_title]
It will print the title of a post in a list where posts are extracted. To retrieve the properties of an object via shortcodes, a period is used.

STATEMENTS AND FLOW CONTROL

[^MATH]

[^MATH 3 + 1 + .5] [// 4.5 //]
[^MATH 3+2 * 2] [// 7 //]
[^MATH (3+2) * 2] [// 10 //]
[^MATH 2^3] [// 8 (2*2*2) //]
[^MATH 9^.5] [// 3 (square root) //]
Relation operators can be used > >= < <= != o <> in, not in, !
[^MATH 2 > 1 ] [// 1 //]
[^MATH 2 <> 1 ] [// 1 //]
[^MATH 2 in ["1","3","4"] ] [// 0 //]
[^MATH 2 not in ["1","3","4"] ] [// 1 //]
In math you can also use the logical operators: AND && OR || It will return 1 if true 0 if false
 [^MATH 4 > 5 OR (3 == 3 AND 2 == 2) ] [// 1 //]

[^IF] ... [^ELSE] ... [^ENDIF]

Conditional statement. If the condition is met, the code between [^IF] and [^ELSE] is executed, otherwise the code between [^ELSE] and [^ENDIF] is executed.

[^SET a=3]
[^IF [%a]*2 == 6] YES [^ENDIF]

[^FOR] ... [^ENDFOR]

Cycle the data.

Attributes:

  • EACH= sets the array to cycle. It also sets the name of the variable to which to pass the values automatically starting from the first word encountered.
  • VAL= The name of the variable to pass the data to.
  • KEY= If it is an associative array, the name of the array key.
<ul>
    [^FOR EACH=[%data] KEY=mykey VAL=myItem]
        <li>[%mykey] = [%myItem]</li>
    [^ENDFOR]
</ul>
[// Or if you don't use KEY and VAL //]

<ul>
    [^FOR EACH=[%data]]
        <li>[%key] = [%item]</li>
    [^ENDFOR]
</ul>

Generate a list of linkable post titles. The break statement can be used to break a loop.

<ul>
    [^FOR EACH=[^POST TYPE=post]]
        <li>[%item.title_link]</li>
    [^ENDFOR]
</ul>
<ul>
    [^FOR EACH=["foo","bar","pippo"] VAL=var]
    [^break [%var] == "bar"]
    <li>[%var]</li>
    [^ENDFOR]
</ul>
The above example will output::
• foo

[^WHILE] ... [^ENDWHILE]

It loops until the condition is met. For more information on the conditions you can see MATH

[^WHILE [%var set+=1] < 10]
    [^SET ris.[]=[%var]]
    [^BREAK [%var]>=5]
[^ENDWHILE]
[^RETURN [%ris SEP=;]]
The above example will output::
1 , 2 , 3 , 4 , 5

[^BREAK]

Stops execution of a FOR or WHILE loop or the block being executed.

Break is executed if a condition is met. If no conditions are entered then it always blocks execution

[^IF 3==3]
    Lorem ipsum dolor sit amet,
    [^BREAK]
    consectetur adipiscing
[^ENDIF]
Donec et accumsan nulla, at tempus metus
        

It does not print "consectetur adipiscing" because it is after the break, but it prints "Donec ..." because it is outside the if block. In fact, Break interrupts the execution of a block or a loop.

The above example will output::
Lorem ipsum dolor sit amet, Donec et accumsan nulla, at tempus metus

[// COMMENT //]

Comments are not printed on the page

[// commento //]

[^BLOCK] ... [^ENDBLOCK]

Capture the code inside the tag and set it in a variable without executing it. The code will then be executed when the variable is called. That's the closest thing to a function there is.

FUNCTIONS

[^USER]

Upload a wordpress user and his metadata. If no data is passed, it returns the current user
The parameters that can be passed are:
id | slug | email | login for single user upload.
If you do not pass any parameters then it is uploaded the user who logged in

La funzione ritorna

  • id: int
  • login: string
  • email: string
  • reoles: array
  • registered: string
  • nickname: string
  • wpx_capabilities: array
  • wpx_user_level: int
  • meta_*: other metadata
[^user]
{"login":"admin","email":"admin^admin.it","roles":["administrator"],"registered":"2020-01-08 13:31:57","nickname":"admin"}
[^IF [^user]==""]
    you are not logged in
[^else]
    You are logged in
[^endif]
Runs a different code whether you are logged in or not.

[^NOW]

Today's date returns

[^now]
[^now date-format="d-m-Y" date-modify="+2 days"]
[^now timestamp] 

[^POST]

Retrieves post data given a post ID or other search parameters .

The attributes are

To check out a single article

id = find the post with a certain id. If it's an array of ids, find all posts with those arrays

To check out more articles

type = The post_type (post, page etc ...) By default it is post. If you want to upload images see the [^ POST] alias
cat = Find posts from a certain category or group of categories. Accept id, slug or array of ids
!cat = Find posts that are not in a particular category or group of categories. Accept the slug id or an array of ids
author = find posts for a particular author. If it is a number use the id otherwise the user_nicename (NOT THE NAME)
slug = Search for the slug.
tag = Certain a post that has at least one of the tags selected. you can write them in an object or in a string.
parent_id = The id of the parent post.
limit = Limit the number of articles to display. By default 10. put -1 to have them all.
offset = Display articles starting with
order = The field to order on
ASC Ascending order
DESC Descending order
Show associated articles over a certain period of time.
year = The articles of a specific year (eg 2020)
month = The articles of a particular month (1-12)
week = The articles of a specific week (week)
day = The articles of a certain day (day)
first = Show first articles posted. By default 5. Replaces order, asc, desc, limit
last = Shows the last articles posted. By default 5. Replaces order, asc, desc, limit

Search in postMeta:

You can search postmetas by entering the filter type in the meta_query attribute. If you want to search for more parameters, these can be added divided by spaces. They will automatically be connected as AND. If you want to add OR and AND within the search, they are inserted as functions. The conditions within the function are linked by the inserted logical conjunction.

meta_query=[: 
    AND(a>=b
    OR (
        b<=var c!=ccc L IN (3,2,5,3,52,34) ) .c LIKE ("% ") 
        .d=" [%foo]" param=)
    c> 2 
:]

Other parameters:

read_more = The text to put in the link_read_more variable. If not present it adds .... If light_load is present the tag is unusable

image_size = The size of the opening image: thumbnail, medium, large, full. If not set, upload post-thumbnail

light_load Excludes post_meta and other added data from loading to simplify post management. Passing 0 or 1 is optional

The function returns

  • id: int
  • author: text
  • *author_id: int
  • *author_name: text
  • *author_roles: array
  • *author_email: text
  • *author_link
  • date: date
  • content: text
  • title: text
  • *title_link: link
  • *permalink: link
  • guid: link
  • excerpt: text
  • status: text
  • comment_status: text
  • name: text
  • modified: date
  • parent: int
  • menu_order: int
  • type: text
  • mime_type: text
  • comment_count: int
  • filter: text
  • *read_more_link: link
  • *image: html
  • *image_link: text
  • *image_id: int
  • *[postmeta]

If the light_load attribute is present this data is not loaded. If the post type is attachment and mime_type is image, permalink, image and image_link are still loaded.
To these are added all the post meta.

Examples

[^POSt id=XX for=[:
    [%item for=[:<p><b>[%key]</b>: [%item trim_words] </p>:]]
:]]
[^POST get={"id":"id","Titolo":"title_link", "Autore"=>"author_name"} type=post tmpl=table]

[^IMAGE]

Get the image data from the attached ID

Params

The attributes are the same as [^POST]. In particular you can use:

id = find the image with a certain id. If it's an array of ids, find all images with those arrays

: image_size = The size of the opening image: thumbnail, medium, large, full, fit, winfit. If not set, upload post-thumbnail. fit: enlarge the image to the maximum size of its container (width = 100%). winfit: resizes the image in proportion to the screen. See tutorial 2 for more information.

Added:

post_id = Find all images linked to a single post

light_load = is set to 0 (in posts it is set to 1). If you want to load everything you have to enter light_load = 0

The function returns

Returns the same parameters as POST

  • image: html
  • title: text
  • *title_link: link
  • *permalink: link
  • url: string
  • original_url: string
  • image_link: text
  • image_id: int
  • *attachment_width: int
  • *attachment_height: int
  • *attachment_file: int
  • *attachment_sizes: Array
  • *attachment_image_meta: Array
  • id: int
  • author: text
  • *author_id: int
  • *author_name: text
  • *author_roles: array
  • *author_email: text
  • *author_link
  • date: date
  • content: text
  • guid: link
  • excerpt: text
  • status: text
  • comment_status: text
  • name: text
  • modified: date
  • parent: int
  • menu_order: int
  • type: text
  • mime_type: text
  • comment_count: int
  • filter: text
  • *read_more_link: link
  • *[postmeta]

* If light_load = 0 is entered this data is not loaded. Otherwise they will not be loaded.

To these are added all the post meta.

Examples

[^IMAGE.image id=[%data.image_id] class=my_gallery attr={"id":"myGallery"} sep=" " ]

[^CURRENT_POST]

Return the post you are viewing

[^LINK]

The equivalent of get_permalink()

Parameters

Link as the name implies is used to generate a link to the site.
For the choice of the pagethe parameter to be inserted is page_id. For a post it is post_id. If page_id or post_id are not inserted, the generated link will be to the current page. all other parameters that you enter are registered as a new url element

Examples

<a href="[^LINK id=xxx filter=yyy action=zzz]">link</a>
<a href="[^LINK id=[%post.ID]]">[%post.post_title]</a>

If you link to posts with custom post_type, remember to register the post_type on function.php of your template

add_action( 'init', 'register_my_post_type' );
function register_my_post_type() {
    register_post_type(
    'my_post_type',
    array (
        'public'             => true,
        'rewrite'            => array('slug' => 'my_post_type'),
        'show_in_menu'      => false,
        'show_in_nav_menus' => false,
        'show_in_rest' 		=> false
    )
    );
}

[^ADMIN_URL]

Create a link to an administrative list. You can pass additional parameters to filter past data

Parameters

  • id
    (integer) The id of the list
  • some_other_params
    (string) You can add other parameters that will be passed in the url

Example: In a list it shows the data of another filtered list and the button to go to edit the data.
1. Create a list linked to posts with a post_id column.
2. Add some records linked to posts.
3. Create a second list where you extract wordpress posts
4. On the new form open List view formatting and click add row at the bottom

[^GET_LIST ID=xx post_id=[%data.ID]]
        <a href="[^ADMIN_URL id=xx post_id=[%data.ID]]">Edit</a>

[^SET]

Define new variables

[^SET variable=value var2=val2]

To set the content of several variables, you can write:

[^SET myvar="FOO" mynewvar="bar"]
[%myvar set="FOO"]

The difference between the two writes is that in the first case the [^ SET ...] function sets one or more variables without printing them, while in the second example the variable is set and printed

Shortcodes can also work with content not set in variables:

[%"Here is my text"] [// print the text //]
    [%[1,2,3,4,5,6,7,8,9] ] [// print the json of the array //]
[^SET 
   a="Foo | part1 | part2.3" 
   b=[%a split=|] 
   c=[%b.2 split=.]
]
[^RETURN [%c.1]] [// output 3 //]

you can insert instructions both in the values and in the names of the variables as long as you respect the rule of not putting spaces

[^SET ser='a:3:{s:1:"a";i:1;s:1:"b";i:2;s:1:"c";i:3;}' unser={"d":4,"e":5,"f":6}]
[^SET nu=[%ser unserialize]]
[%nu.c] | [%unser.d]

The example sets an array (unser) and a serialize string (ser). Then a new variable nu is set with the array extracted from ser, finally unser is cycled and its values are inserted into the variable nu.

[^COUNTER]

Each time it is called it returns a new number in a number sequence

The optional attributes are

name = The name of the counter that wants to be called

start = The number you want the counter to start from

step = the number of units to increase or decrease the counter each time it is called

[^GET_THE_ID]

Torna l'id di un post, identico a get_the_id di wordpress

[^RETURN]

Delete all the text up to that point and print only the return value. This function is very useful if you are writing code that consists of multiple lines to prevent them from being printed

It won't print "My result", just the value of my_var.

 My result: [^ RETURN [%my_var]] 

[^IS_USER_LOGGED_IN]

Return 1 if the user is logged in otherwise 0

[^IS_ADMIN]

Return 1 if is admin page

is_*

[^IS_PAGE_AUTHOR], [^IS_PAGE_ARCHIVE], [^IS_PAGE_TAG], [^IS_PAGE_DATE], [^IS_PAGE_TAX]

Return 1 if it is the requested page, 0 otherwise

[^GET_TAG] or [^GET_CAT]

Returns the data of the tag or category

Attributes

  • id or term_id
  • slug
  • name

Return

  • id
  • term_id
  • name
  • slug
  • term_group
  • taxonomy
  • parent
  • link
  • html
[^GET_TAG.html id=2]

[^GET_POST_TAGS] or [^GET_POST_CATS]

Returns the tag or category data of a post

Attributes

  • post_id

Return

  • id
  • term_id
  • name
  • slug
  • term_group
  • taxonomy
  • parent
  • link
  • html
[^GET_POST_CATS.html post_id=2]

List specific functions

[^LINK_DETAIL]

Params item=[%data], dbp_id=xx, action=""

Create link to show page detail

Examples

<a href="[^LINK_DETAIL]" class="js-dbp-popup">popup detail</a>

[^UNIQ_CHARS_ID]

Params item=[%data], dbp_id=xx

Generate a unique string to retrieve the record.
This solves the problem that, if the query is composed of multiple tables, to extract a specific row you have to pass the ids of all the tables.

Examples

1. In list view formatting create a custom code and add this code:

<a href="?k=[^uniq_chars_id]">[^uniq_chars_id]</a>

2. In functions.php add the following code by replacing {the_list_id} with the id of the list you are working on.

if (isset($_REQUEST['k'])) {
	var_dump(admin_form\ADFO::get_detail({the_list_id}, $_REQUEST['k']));
    die;
}

[^GET_LIST id=""]

Print a specific list.

[^GET_SINGLE id=""]

Prints the results of a single record.

[^GET_DETAIL dpb_id="" id=""]

Extracts data from a specific record

[^GET_TOTAL dpb_id="" ]

[^GET_LIST_DATA list_id=""]

Extract data from a specific list

[^GET_LIST_DATA id=xxx tmpl=[:
    <h3>[%item.title]</h3>
    <p>[%item.description]</p>
:]]

[^BTN_EXPORT id="" format=csv|sql title="" class=""]

Create the button to download a list.

VARIABLES

You can add variables or jsons as attribute values

[%myvar set=[^POST last]] 
[%myvar set=["foo","bar"]]
[%myvar set={"a":"foo","b":"bar"}]

You can't put variables in place of attribute names

[%myvar [%var]="foo"] [// NOT CORRECT //] 

This is only allowed inside the [^ SET] function as long as there are no spaces

[^SET [%var]="foo"] [// CORRECT //] 
[^SET mypost.[%var]="foo"] [// CORRECT //] 

You can call the parameters of an object via the .*

[%post.title] 
[%post.0.title] 

This will return a string if there is only one post, otherwise an array of titles.

Attributes

Attributes modify a variable or function. They can have an associated value.

You CANNOT put the space next to the = symbol.

[%"string" uppercase]
[%"1602288000" date-format="Y-m-d"]

default=

If the value or object is empty, it returns the default

[%novar default="foo"]

*=[::]

Attribute values must not have spaces.

If you have to put a space you have to insert the text in quotation marks or the symbols [::]. Quotation marks within already quoted text must be added with a backslash

[%myvar default=foobar] [// CORRECT //]
[%myvar default=foo bar] [// NOT CORRECT //]
[%myvar default=[:foo bar:]] [// CORRECT //]
[%myvar default="foo bar"] [// CORRECT //]
[%myvar default='foo bar'] [//  CORRECT //]

Check if it is

is_string

Check if the variable is a string

is_date

Check if a variable is a valid date

is_object

Checks if a variable is an array or an object

Attributes of texts

val

In the results extracted from a list, the unmodified value is returned. For example in a select field where the values are replaced by label it returns the value or in a media library field it returns the id of the image.

[data.column val]

upper - (Synonyms: uppercase strtoupper)

Transform a string to all uppercase

[%"foo" upper]
FOO

lower - (Synonyms: strtolower lowercase)

Make a string all lowercase

[%"MY FOO" lower]
my foo

ucfirst - (Synonyms: capitalize)

Capitalize the first character of a string

[%"my foo" ucfirst]
My foo

strip-comment - (Synonyms: strip_comment stripcomment)

Remove comments <!-- --> o // o /* */

[^SET myvar=" <div>testo</div>  <!-- a comment --> <i>testo</i>"]
[%myvar htmlentities]<br>
[%myvar strip-comment htmlentities]
<div>testo</div> <!-- a comment --> <i>testo</i>
<div>testo</div> <i>testo</i>
[^SET myvar="<script> a =\"foo\"; 
/* other comment 
* multiline
*/
alert(a);
</script>"]
[%myvar htmlentities nl2br]<br><hr>
[%myvar strip-comment htmlentities nl2br]

strip-tags - (Synonyms: strip_tags striptags)

Remove all html tags from text

nl2br

Transform the accapi into br

htmlentities

Transform special characters into html entities

        <textarea>[%"</textarea><b>fff</b>" htmlentities]</textarea>
        

The example shows how through the htmlentities attribute it is possible to write html tags inside a textarea

left=

Accept a numeric parameter.
Takes the first n characters of the text. Accept a second "more" attribute to add text if left has actually cut the string

    [%"A1B2C3D4E5F6G7H8I9" left=5 more=" ..."]
A1B2C ...

If the text is cut, you can add text at the end of the line using the more attribute

        [%"Hello George" left=5 more=" ..."]
        [%"good afternoon" left=25 more=" ..."]
        

In the first case it cuts the text and then puts the text of the more attribute, in the second case it doesn't cut the text so it doesn't put the text of the more

Hello ... good afternoon

right=

Accept a numeric parameter.
Takes the first n characters of the text

[%"Hello George" right=6]
George

trim_words=

Accept a numeric parameter.
Takes the first n words of the text

if the text is cut it is possible to add a text at the end of the line using the more attribute

[%"Hello George how are you?" trim_words=2 more=" [^link id=2 text="..."]"]
Hello George ...

sanitize

Executes the function wordpress sanitize_text_field

esc_url

Executes the function wordpress esc_url

trim

Removes spaces before and after in text or all fields in an array

split=

Divide a text into an array

[^SET a=[%"Hello | World" split="|"]][%a.1] [// World //]

Search=

Returns 1 if it finds the substring or 0 if it doesn't.

[%"Nel mezzo del cammin di nostra vita" search="nostra" ]
1

If instead passed, the replace parameter replaces the string

[%"Nel mezzo del cammin di notra vita" search="notra" replace="<b>nostra</b>" ]
Nel mezzo del cammin di nostra vita

if=

Show the field if the condition is met. The condition can be placed in quotation marks or in square brackets with a colon [: ... :]

            [^POST type=post if=[: [%item.id]>30 :] length]
        

Count the number of articles with id > 30

set=

Imposta il valore di una variabile

[%myvar set="foo"]
foo

set+= o set-= to add or subtract the passed variable

zero= - (Synonyms: empty)

Print alternate text if variable is 0 or empty.

one= - (Synonyms: singular)

Print alternate text if variable is 1.

[^SET a=["foo"] ]
[%a count] [%a singular="Item" plural="Items"]

plural=

Print alternate text if variable is greater than 1.

[^SET a=["3","23","65"] ]
[%a count] [%a singular="Item" plural="Items"]

negative=

Print alternate text if variable is negative

decode_ids

On the detail page, the array of the record ids is returned.

[^SET ids=[%request.dbp_ids decode_ids]] [%ids]

json

Converts a string formatted as a json to an array

[%my_json_var json tmpl[:<p>[%key]=[%item.title]</p>:]]]

unserialize

Converts a string formatted as a php serialize to an array

[%my_serialize_var json tmpl[:<p>[%key]=[%item.title]</p>:]]]

Attributes for numbers

set+= set-=

To add or subtract the passed variable.

decimal=

Sets the number of values after the comma to show. It accepts two more parameters dec_point and thousands_sep

[%"1203.23" decimal=1]<br>
[%"1203.23" decimal=1 dec_point=, thousands_sep=.]
1203.2 1.203,2

euro

Format a number as euro currency

floor

Rounds down the value of a number

round

Round the value by a number

ceil

Rounds up the value of a number

Attributes for dates

date-format=

Accept a text parameter.
Change the date format

            [%"2020-10-10" date-format='Y']
            
2020

It accepts either dates, timestamps or strings year month day all attached or even timed

[%"1602288000" date-format="Y-m-d"]
2020-10-10

The following example takes an item.post_date variable in text day/month/year format, converts it to year-month-day and prints Y-m-d H:i:S

[^SET date=[:[%item.post_date left=10 right=4]-[%item.post_date left=5 right=2]-[%item.post_date left=2]:]][%date date-format="Y-m-d H:is"]

date-modify=

Accept a text parameter.
Change a date

[%"2020-10-10" date-modify="+2 days"]
2020-10-12

last-day

It takes a date and sets the last day of the month

[%"2020-10-10" last-day]
2020-10-31

timestamp

It takes a date and converts it to a timestamp

[%"2020-10-10" timestamp]
1602288000

datediff-year=

Returns the difference in years between two dates.

datediff-month=

Returns the difference in months between two dates.

datediff-day=

Returns the difference in days between two dates.

They have passed: [%a set='2001-10-04 10:20:10' datediff-day='2001-09-02 10:30:00']

datediff-hour=

Returns the difference in hours between two dates.

datediff-minute=

Returns the difference in minutes between two dates.

timenum-to-timestr

Time fields are saved in seconds in the database. This attribute transforms seconds into time format hh:mm.

timestr-to-timenum

Time fields are saved in seconds in the database. This attribute transforms the value from the format time hh:mm into seconds.

time-to-hour

This attribute calculates the number of hours from a time field, ie in seconds, or from a time value in the format hh:mm.

Attributi negli array

Tmpl= - (Synonyms: for, print)

Print data within a template. This can be in a variable *, an external php template or written inside the attribute value. The data inside the template is looped into the variable [%item] and [%key] for the name or number of the passed variable.

* The variables are transformed, but the code inside them is not executed due to performance problems ... you have to put [::] then the code inside if it is a single variable is reworked!

[^POST post_type=post tmpl=[:<p>[%key]=[%item.title]</p>:]]
        
[%["1","2","3","4","5"] for=[: 
    <h2>ID=[%item]</h2>
    [^POST id=[%item] tmpl=[:
        <p>[%key]=[%item.title]</p>
    :]]
:]]

.(variable_name)=

You can add values to an array simply by adding dot-preceded attributes

sep=

Accept a text parameter.
merges the values of an array into separate text from the specified text. Synonym for implode in php

qsep=

Same as sep but joins the text with quotation marks

if=

Show the field if the condition is met. The condition can be inserted in quotation marks or in square brackets with a colon [: ... :]

[^POST type=post if=[: [%item.id]>30 :] length]

Count the number of articles with id> 30

[^POST type=post if=[:[%item.author_name] == 'admin':] ]

Only extracts articles with author = 2

sum

Adds a vector.

mean

It does the mathematical average

count - (Synonyms: length)

If it is an array it counts the number of rows. If it is a string it counts the number of characters

[%["bar","foo"] length]<br>
    [%"foo" length]
2 // is an array of two elements 3 // the number of characters in the string

get= - (Synonyms: show, fields)

Returns only some certain fields of an array. If the array is associative it replaces the field name with the new key

[^post id=3 fields={"post_title":"title"}]
array (size=1) 'post_title' => string '...' (length=14)
[^post type=page fields=["id","author","title"]]
0 => array (size=3) 'ID' => int 1 'author' => string '1' (length=1) 'title' => string '...' (length=9) 1 => array (size=3) 'ID' => int 2 'author' => string '1' (length=1) 'title' => string '...' (length=15)
[^post type=page fields=id]
array (size=2) 0 => int 1 1 => int 2
[^post type=page fields={"id":"id", "author":"author"} tmpl=table]

Print a table whose titles are id and author.