Skip to main content
Version: 0.0.3-alpha

Basic Syntax

Expression Lab uses the Symfony Expression Language component as the foundational engine for evaluating expressions. It provides a declarative Domain-Specific Language designed for querying, transforming data, and interacting with WordPress services without writing raw PHP scripts.

Want to learn more?

See the Symfony's The Expression Syntax official documentation for further reference.


Language Engine Overview​

The Symfony Expression Language component compiles expressions into Abstract Syntax Tree (AST) structures. While expression-oriented (evaluating to a single result without imperative loops like while or for), Expression Lab extends the base language with a declarative functional scripting layer (prog[...], set[...], fn[...], map[...]).

This enables multi-step execution pipelines, expression state management, and lambda transformations while restricting execution to registered operators and functions.


Literals & Primitive Types​

Expression Lab supports standard data primitives:

TypeSyntax ExamplesDescription
Numbers42, 3.14, -10, 1e3Integers and floating-point values.
Strings'hello', "WordPress", "Value with \"quotes\""Single or double-quoted strings.
Booleanstrue, falseCase-insensitive boolean literals.
NullnullRepresents an empty or null value.

String Escaping​

Strings can be enclosed in single quotes ('...') or double quotes ("..."). When you need to include quote marks or backslashes within a string, follow standard escape rules:

  • Single quotes ('...'): Escape internal single quotes with a backslash (\'), e.g., 'It\'s a test'.
  • Double quotes ("..."): Escape internal double quotes with a backslash (\"), e.g., "He said \"Hello\"".
  • Literal backslashes: Escape backslashes with a double backslash (\\), e.g., 'C:\\Windows' or "path\\to\\file".
  • Pro Tip: You can alternate quote delimiters to avoid escaping entirely:
    • Use double quotes to enclose single quotes: "It's a test"
    • Use single quotes to enclose double quotes: 'He said "Hello"'

Collections & Data Structures​

Arrays (Lists)​

Arrays are comma-separated values enclosed in square brackets [...]:

[1, 2, 3, "four", true]

Elements are accessed via zero-based numeric indexing:

users[0]

Maps (Key-Value Objects)​

Key-value maps are enclosed in curly braces {...}:

{ id: 1, title: 'Sample Post', published: true }

Property access can be performed using either dot notation or bracket notation:

post.title
post['title']

Operators​

Expression Lab provides a comprehensive set of operators for arithmetic, comparison, logical evaluation, and string manipulation.

Arithmetic Operators​

OperatorSyntaxDescription
+10 + 5Addition (returns 15)
-10 - 5Subtraction (returns 5)
*10 * 5Multiplication (returns 50)
/10 / 5Division (returns 2)
%10 % 3Modulo (returns 1)
**2 ** 3Exponentiation (returns 8)

String Concatenation​

Use the ~ (tilde) operator to concatenate strings:

'Hello, ' ~ Users.current.data.display_name ~ '!'

Comparison Operators​

OperatorSyntaxDescription
==status == 'publish'Loose equality
===user_id === 1Strict equality
!=post_type != 'revision'Loose inequality
!==role !== 'subscriber'Strict inequality
<, >count > 10Less than, greater than
<=, >=memory <= 50Less than or equal, greater than or equal

Logical Operators​

OperatorSyntaxDescription
and / &&is_admin and has_accessLogical AND
or / ||is_editor or is_adminLogical OR
not / !not is_draftLogical NOT

Advanced Operators​

Ternary Operator (condition ? true_val : false_val)​

user.is_admin ? 'Administrator' : 'Standard User'

Null Coalescing Operator (??)​

Returns the first operand if it exists and is not null, otherwise returns the second:

post.meta['subtitle'] ?? 'No subtitle available'

Membership Operators (in, not in)​

Check whether an element is present in an array or string:

'administrator' in Users.current.roles
'draft' not in ['publish', 'future', 'private']

Regular Expression Matching (matches)​

Test strings against regular expressions:

Users.current.data.user_email matches '/^[a-zA-Z0-9._%+-]+@example\\.com$/'

Method Calls & Object Access​

You can invoke methods on any exposed service or model object:

Options.get('active_plugins')

Methods can be chained fluidly:

Posts.where('post_status','publish').get()

Next Steps​