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) 
wireClassNamespace($className)
string arrayGet namespace for given class 
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 
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

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 fallbaack translation values 

API reference based on ProcessWire core version 3.0.155

Twitter updates

  • This post covers a few of the bigger updates in ProcessWire 3.0.154+3.0.155. This includes new live replacement of text in core and modules, a new method for creating canonical URLs, and some major upgrades to our input->urlSegment() method! More
    24 April 2020
  • A brief look at what's new in ProcessWire 3.0.154 in this forum post: More
    17 April 2020
  • This week we’ve got a few new and interesting core updates in progress, though none quite ready to release just yet. So rather than releasing version 3.0.154 today, I thought we'd instead take a brief look at what’s coming over the next few weeks… More
    3 April 2020

Latest news

  • ProcessWire Weekly #310
    The 310th issue of ProcessWire Weekly is going to be short and sweet: in this issue we'll walk you through the latest core updates, introduce a third party module called Twack, and check out a really gorgeous new site of the week. Read on!
    Weekly.pw / 18 April 2020
  • ProcessWire 3.0.154 and 3.0.155 core updates
    This post covers a few of the bigger updates in ProcessWire 3.0.154 and 3.0.155 on the dev branch. This includes a new function for live replacement of text in core and modules, a new method for creating canonical URLs, and some major upgrades to our $input->urlSegment() method that I think you’ll like!
    Blog / 24 April 2020
  • Subscribe to weekly ProcessWire news

“Indeed, if ProcessWire can be considered as a CMS in its own right, it also offers all the advantages of a CMF (Content Management Framework). Unlike other solutions, the programmer is not forced to follow the proposed model and can integrate his/her ways of doing things.” —Guy Verville, Spiria Digital Inc.