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 
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). 
wireInstance()
ProcessWireGet or set the current ProcessWire instance 
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, etc. 
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) 
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 

Class helpers

NameReturnSummary 
wireClassExists(string $className)
boolDoes the given class name exist? 
wireClassImplements($className)
arrayGet an array of all the interfaces that the given class implements 
wireClassName($className)
string nullNormalize a class name with or without namespace, or get namespace of class 
wireClassParents($className)
arrayReturn array of all parent classes for given class/object 
wireInstanceOf($instance, $className)
bool stringDoes given instance (or class) represent an instance of the given className (or class names)? 
wireIsCallable($var)
arrayIs the given $var callable as a function? 
wireMethodExists(string $className, string $method)
boolDoes the given class have the given method? 

Translation

Provides GetText-like language translation functions to ProcessWire.

API reference based on ProcessWire core version 3.0.137

Twitter updates

  • ProcessWire 3.0.146 on the dev branch contains about 22 commits with a combination of useful upgrades and issue report resolutions, more details in this forum post: More
    22 November 2019
  • ProcessWire 3.0.144 and 3.0.145 add improved field template context override settings and include a new Inputfields API, along with numerous other issue fixes, optimizations and improvements to the core. More
    8 November 2019
  • ProcessWire 3.0.144 core updates: Upgraded overrides section in the field editor, a new Inputfields JS API, and more— More
    1 November 2019

Latest news

  • ProcessWire Weekly #291
    In the 291st issue of ProcessWire Weekly we're going to take a closer look at the latest core updates, check out a brand new third party module called ProcessHelpVideos, and introduce a new site of the week. Read on!
    Weekly.pw / 8 December 2019
  • New User Activity module
    Blog / 29 November 2019
  • Subscribe to weekly ProcessWire news

“The end client and designer love the ease at which they can update the website. Training beyond how to log in wasn’t even necessary since ProcessWire’s default interface is straightforward.” —Jonathan Lahijani