ProcessWire functions

Documentation for procedural functions available in ProcessWire CMS.

Show args?        

Common

NameReturnSummary 
wire()
mixedReturn an API variable, or return current ProcessWire instance if given no arguments 
wire404()
(nothing)Stop execution with a 404 unless redirect URL available (for front-end use) 
wireCount(mixed $value)
intReturn the count of item(s) present in the given value 
wireDate()
string boolFormat a date, using PHP date(), strftime() or other special strings (see arguments). 
wireEmpty(mixed $value)
boolIs the given value empty according to ProcessWire standards? 
wireInstance()
ProcessWireGet or set the current ProcessWire instance 
wireLen($value)
intReturns string byte length of any type (string, array, object, bool, int, etc.) 
wireLength($value)
intReturns string length of any type (string, array, object, bool, int, etc.) 
wireMail()
int WireMailSend an email or get a WireMail object to populate before send 

Markup

NameReturnSummary 
wireIconMarkup(string $icon)
stringRender markup for a system icon 
wireIconMarkupFile(string $filename)
stringGet the markup or class name for an icon that can represent the given filename 

Strings

NameReturnSummary 
wireBytesStr(int $bytes)
stringGiven a quantity of bytes (int), return readable string that refers to quantity in bytes, kB, MB, GB and TB 
wireDate()
string boolFormat a date, using PHP date(), strftime() or other special strings (see arguments). 
wirePopulateStringTags(string $str, $vars)
stringGiven a string ($str) and values ($vars), replace “{tags}” in the string with the values 
wireRelativeTimeStr($ts)
stringGiven 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 ProcessWire 3.0.123 and newer.

NameReturnSummary 
PageArray()
PageArrayCreate new PageArray, add given $items (pages) to it, and return it 
WireArray()
WireArrayCreate new WireArray, add given $items to it, and return it 
WireData()
WireDataCreate 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 ProcessWire instance, so are intended primarily for front-end usage in template files (not for modules).

If these functions are not working for you, you can enable them by setting $config->useFunctionsAPI=true; in your /site/config.php file.

Regardless of whether the Functions API is enabled or not, you can also access any of these functions by prefixing the word wire to them and using the format wireFunction() i.e. wirePages(), wireUser(), etc. Or, if you do not

NameReturnSummary 
cache()
WireCache string array PageArray nullGet and save caches ($cache API variable as a function) 
config()
Config mixedAccess a ProcessWire configuration setting ($config API variable as a function) 
database()
WireDatabasePDOCreate and execute PDO database queries ($database API variable as a function) 
datetime()
WireDateTime string intAccess date and time related tools ($datetime API variable as a function) 
fields()
Fields Field nullGet or save fields independent of templates ($fields API variable as as function) 
files()
WireFileToolsAccess tools for working on the file system ($files API variable as a function) 
input()
WireInput WireInputData array string int nullAccess GET, POST or COOKIE input variables and more ($input API variable as a function) 
languages()
Languages Language NullPage nullAccess all installed languages in multi-language environment ($languages API variable as a function) 
modules()
Modules Module ConfigurableModule nullGet a module, get module information, and much more ($modules API variable as a function) 
page()
Page mixedReturns the current Page being viewed ($page API variable as a function) 
pageId($value)
int falseReturn id for given page or false if it’s not a page 
pages()
Pages PageArray Page NullPageRetrieve or save pages ($pages API variable as a function) 
paths()
null Paths stringGet one of any named server disk paths (shortcut to the $config API variable “paths” property) 
permissions()
Permissions Permission PageArray null NullPageGet, find or save permissions ($permissions API variable as a function) 
region()
string null bool arrayGet or set an output region (primarily for front-end output usage) 
roles()
Roles Role PageArray null NullPageGet, find or save roles ($roles API variable as a function) 
sanitizer()
Sanitizer string int array null mixedSanitize variables and related string functions ($sanitizer API variable as a function) 
session()
Session null string array int floatGet or set values in the current user session ($session API variable as a function) 
setting()
array string int bool mixed nullGet or set a runtime site setting 
templates()
Templates Template nullGet or save templates ($templates API variable as a function) 
urls()
null Paths stringGet one of any named system URLs (shortcut to the $config API variable “urls” property) 
user()
User mixedGet the currently logged in user ($user API variable as a function) 
users()
Users PageArray User mixedGet, find or save users ($users API variable as a function) 
wire()
mixedReturn an API variable, or return current ProcessWire instance if given no arguments 

Files

These file system functions are procedural versions of some of those provided by the $files API variable.

NameReturnSummary 
wireChmod(string $path)
boolChange the mode of a file or directory (optionally recursive) 
wireCopy(string $src, string $dst)
boolCopy all files recursively from one directory to another 
wireIconMarkupFile(string $filename)
stringGet the markup or class name for an icon that can represent the given filename 
wireIncludeFile(string $filename)
boolInclude a PHP file passing it all API variables and optionally your own specified variables 
wireMkdir(string $path)
boolCreate a directory (optionally recursively) that is writable to ProcessWire and uses the $config chmod settings 
wireRenderFile(string $filename)
string boolGiven a filename, render it as a ProcessWire template file 
wireRmdir(string $path)
boolRemove a directory (optionally recursively) 
wireSendFile(string $filename, array $headers)
(nothing)Send the contents of the given filename via http 
wireTempDir($name)
WireTempDirReturn a new temporary directory/path ready to use for files 
wireUnzipFile(string $file, string $dst)
arrayUnzips the given ZIP file to the destination directory 
wireZipFile(string $zipfile, $files)
arrayCreate a ZIP file from given files 

Translation

Provides GetText-like language translation functions to ProcessWire.

NameReturnSummary 
__($text)
string arrayPerform a language translation 
_n(string $textSingular, string $textPlural, int $count)
stringPerform a language translation with singular and plural versions 
_x(string $text, string $context)
stringPerform a language translation in a specific context 
wireLangEntityEncode()
bool int string nullSet entity encoding state for language translation function calls 
wireLangReplacements(array $values)
array stringSet global translation replacement values 
wireLangTranslations()
arraySet predefined fallback translation values 

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #514
    In the 514th issue of ProcessWire Weekly we'll check out the latest blog post from Ryan, introduce two new third party modules — Page List Versions Counter and Fieldtype Fieldset Panel — and more. Read on!
    Weekly.pw / 16 March 2024
  • Invoices Site Profile
    The new invoices site profile is a free invoicing application developed in ProcessWire. It enables you to create invoices, record payments to them, email invoices to clients, print invoices, and more. This post covers all the details.
    Blog / 15 March 2024
  • Subscribe to weekly ProcessWire news

“Yesterday I sent the client a short documentation for their ProcessWire-powered website. Today all features already used with no questions. #cmsdoneright—Marc Hinse, Web designer/developer