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.142 has a lot of updates but the biggest is the addition of custom fields support for file and image fields. In this post, we take a closer look at that, and also outline all of the new features in the just-released FormBuilder v40— More
    11 October 2019
  • This week’s dev branch version brings you improvements to ProcessWire’s input->cookie API variable, plus it adds the ability to modify system URLs and paths at runtime. This post also includes some examples to demonstrate just how useful this can be— More
    20 September 2019
  • New post: This week we’ll take a look at a new version of FormBuilder that's on the way (with a screencast), as well as the latest version of the core: ProcessWire 3.0.140— More
    6 September 2019

Latest news

  • ProcessWire Weekly #283
    The 283rd issue of ProcessWire Weekly introduces ProcessWire 3.0.142 and FormBuilder v40, highlights some conference content, and features a new weekly poll continuing with the #processwireworks theme. Read on!
    Weekly.pw / 12 October 2019
  • ProcessWire 3.0.142 core updates
    This latest version of the core on the dev branch has a lot of updates, bnd the biggest is the addition of custom fields support for file and image fields. In this post, we take a closer look and also outline all of the new features in the just-released FormBuilder v40.
    Blog / 11 October 2019
  • Subscribe to weekly ProcessWire news

I just love the easy and intuitive ProcessWire API. ProcessWire rocks!” —Jens Martsch, Web developer