Documentation for procedural functions available in ProcessWire CMS.
Common
Name | Return | Summary | |
---|---|---|---|
wire() wire() wire(string $name = 'wire') | mixed | Return an API variable, or return current Process | |
wire404() wire404() wire404(string $message = '') | (nothing) | Stop execution with a 404 unless redirect URL available (for front-end use) | |
wireCount() wireCount(mixed $value) wireCount(mixed $value) | int | Return the count of item(s) present in the given value | |
wireDate() wireDate() wireDate($format = '', $ts = null) | string bool | Format a date, using PHP date(), strftime() or other special strings (see arguments). | |
wireEmpty() wireEmpty(mixed $value) wireEmpty(mixed $value) | bool | Is the given value empty according to Process | |
wireInstance() wireInstance() wireInstance($wire = null) | Process | Get or set the current Process | |
wireLen() wireLen($value) wireLen($value) | int | Returns string byte length of any type (string, array, object, bool, int, etc.) | |
wireLength() wireLength($value) wireLength($value, bool $mb = true) | int | Returns string length of any type (string, array, object, bool, int, etc.) | |
wireMail() wireMail() wireMail($to = '', string $from = '', string $subject = '', $body = '', $options = array) | int WireMail | Send an email or get a WireMail object to populate before send |
Markup
Name | Return | Summary | |
---|---|---|---|
wireIconMarkup() wireIconMarkup(string $icon) wireIconMarkup(string $icon, string $class = '') | string | Render markup for a system icon | |
wireIconMarkupFile() wireIconMarkupFile(string $filename) wireIconMarkupFile(string $filename, $class = '') | string | Get the markup or class name for an icon that can represent the given filename |
Strings
Name | Return | Summary | |
---|---|---|---|
wireBytesStr() wireBytesStr(int $bytes) wireBytesStr(int $bytes, $small = false, $options = array) | string | Given a quantity of bytes (int), return readable string that refers to quantity in bytes, kB, MB, GB and TB | |
wireDate() wireDate() wireDate($format = '', $ts = null) | string bool | Format a date, using PHP date(), strftime() or other special strings (see arguments). | |
wirePopulateStringTags() wirePopulateStringTags(string $str, $vars) wirePopulateStringTags(string $str, $vars, array $options = array) | string | Given a string ($str) and values ($vars), replace “{tags}” in the string with the values | |
wireRelativeTimeStr() wireRelativeTimeStr($ts) wireRelativeTimeStr($ts, $abbreviate = false, bool $useTense = true) | string | Given a unix timestamp (or date string), returns a formatted string indicating the time relative to now |
Arrays
These shortcuts for creating WireArray types are available in Process
Name | Return | Summary | |
---|---|---|---|
PageArray() PageArray() PageArray($items = array) | PageArray | Create new PageArray, add given $items (pages) to it, and return it | |
WireArray() WireArray() WireArray($items = array) | WireArray | Create new WireArray, add given $items to it, and return it | |
WireData() WireData() WireData($data = array) | WireData | Create a new WireData instance and optionally add given associative array of data to it |
Functions API
Provides an alternative to the API variables by providing functions of the same name, with these benefits:
- They are always in scope whether inside a function or outside of it.
- They are self documenting with your IDE, unlike API $variables.
- They cannot be accidentally overwritten the way variables can be.
- They provider greater contrast between what are API-calls and variables.
- In some cases it makes for shorter API calls.
- Some of the functions provide arguments for useful shortcuts.
These functions always refer to the current Process If these functions are not working for you, you can enable them by setting
Regardless of whether the Functions API is enabled or not, you can also access
any of these functions by prefixing the word $config->useFunctionsAPI=true;
in your /site/config.php file. wire
to them and using the format
wireFunction()
i.e. wirePages()
, wireUser()
, etc. Or, if you do not
Name | Return | Summary | |
---|---|---|---|
cache() cache() cache(string $name = '', $expire = null, $func = null) | WireCache string array PageArray null | Get and save caches ($cache API variable as a function) | |
config() config() config(string $key = '', null $value = null) | Config mixed | Access a Process | |
database() database() database() | WireDatabasePDO | Create and execute PDO database queries ($database API variable as a function) | |
datetime() datetime() datetime(string $format = '', $value = '') | WireDateTime string int | Access date and time related tools ($datetime API variable as a function) | |
fields() fields() fields(string $name = '') | Fields Field null | Get or save fields independent of templates ($fields API variable as as function) | |
files() files() files() | WireFileTools | Access tools for working on the file system ($files API variable as a function) | |
input() input() input(string $type = '', string $key = '', string $sanitizer = null, $fallback = null) | WireInput WireInputData array string int null | Access GET, POST or COOKIE input variables and more ($input API variable as a function) | |
languages() languages() languages($name = '') | Languages Language NullPage null | Access all installed languages in multi-language environment ($languages API variable as a function) | |
modules() modules() modules(string $name = '') | Modules Module ConfigurableModule null | Get a module, get module information, and much more ($modules API variable as a function) | |
page() page() page(string $key = '', null $value = null) | Page mixed | Returns the current Page being viewed ($page API variable as a function) | |
pageId() pageId($value) pageId($value) | int false | Return id for given page or false if it’s not a page | |
pages() pages() pages($selector = '') | Pages PageArray Page NullPage | Retrieve or save pages ($pages API variable as a function) | |
paths() paths() paths(string $key = '') | null Paths string | Get one of any named server disk paths (shortcut to the $config API variable “paths” property) | |
permissions() permissions() permissions($selector = '') | Permissions Permission PageArray null NullPage | Get, find or save permissions ($permissions API variable as a function) | |
region() region() region(string $key = '', $value = null) | string null bool array | Get or set an output region (primarily for front-end output usage) | |
roles() roles() roles($selector = '') | Roles Role PageArray null NullPage | Get, find or save roles ($roles API variable as a function) | |
sanitizer() sanitizer() sanitizer(string $name = '', string $value = '') | Sanitizer string int array null mixed | Sanitize variables and related string functions ($sanitizer API variable as a function) | |
session() session() session(string $key = '', null $value = null) | Session null string array int float | Get or set values in the current user session ($session API variable as a function) | |
setting() setting() setting($name = '', $value = null) | array string int bool mixed null | Get or set a runtime site setting | |
templates() templates() templates(string $name = '') | Templates Template null | Get or save templates ($templates API variable as a function) | |
urls() urls() urls(string $key = '') | null Paths string | Get one of any named system URLs (shortcut to the $config API variable “urls” property) | |
user() user() user(string $key = '', null $value = null) | User mixed | Get the currently logged in user ($user API variable as a function) | |
users() users() users($selector = '') | Users PageArray User mixed | Get, find or save users ($users API variable as a function) | |
wire() wire() wire(string $name = 'wire') | mixed | Return an API variable, or return current Process |
Files
These file system functions are procedural versions of some of those provided by the $files
API variable.
Class helpers
Translation
Provides GetText-like language translation functions to Process
Name | Return | Summary | |
---|---|---|---|
__() __($text) __($text, $textdomain = null, $context = '') | string array | Perform a language translation | |
_n() _n(string $textSingular, string $textPlural, int $count) _n(string $textSingular, string $textPlural, int $count, string $textdomain = null) | string | Perform a language translation with singular and plural versions | |
_x() _x(string $text, string $context) _x(string $text, string $context, string $textdomain = null) | string | Perform a language translation in a specific context | |
wireLangEntityEncode() wireLangEntityEncode() wireLangEntityEncode($value = '') | bool int string null | Set entity encoding state for language translation function calls | |
wireLangReplacements() wireLangReplacements(array $values) wireLangReplacements(array $values) | array string | Set global translation replacement values | |
wireLangTranslations() wireLangTranslations() wireLangTranslations(array $values = array) | array | Set predefined fallback translation values |
API reference based on Process