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.133

Twitter updates

  • ProcessWire 3.0.133 adds a useful new Page::meta() method for a new type of page-specific persistent data storage, adds the ability for users to create their own bookmarks in Lister, and has a handy and time saving update for the asmSelect input type— More
    14 June 2019
  • New post: This week we’ll take a look at 3 different WEBP image strategies that you can use in ProcessWire 3.0.132+. Then we’ll dive into a major update for the Google Client API module, and finish up by outlining some useful new updates in FormBuilder— More
    31 May 2019
  • New post: This week we've added WEBP support in ProcessWire thanks to a GitHub pull request from Horst Nogajski. This enables you to have highly optimized image output in PW and I think you’ll really like the difference it makes— More
    24 May 2019

Latest news

  • ProcessWire Weekly #267
    In the 267th issue of ProcessWire Weekly we're going to cover the latest changes in the development branch of ProcessWire, introduce a new module called MarkupMenu, and highlight a brand new site of the week. Read on!
    Weekly.pw / 22 June 2019
  • ProcessWire 3.0.133 core updates
    ProcessWire 3.0.133 adds a useful new $page->meta() method for a new type of page-specific persistent data storage, adds the ability for users to create their own bookmarks in Lister, and has a handy and time saving update for the asmSelect input type. Read on for all the details, examples and screenshots.
    Blog / 14 June 2019
  • Subscribe to weekly ProcessWire news

“I am currently managing a ProcessWire site with 2 million+ pages. It’s admirably fast, and much, much faster than any other CMS we tested.” —Nickie, Web developer