ZenphotoCMS 1.6.5

functions-filter.php

Filter functions used by zenphoto

The filter/plugin API is located in this file, which allows for creating filters and hooking functions, and methods. The functions or methods will be run when the filter is called.

Any of the syntaxes explained in the PHP documentation for the 'callback' type are valid.

This API is heavily inspired by the plugin API used in WordPress.

Tags
author

Ozh

since
1.3

Table of Contents

Functions

zp_register_filter()  : mixed
Registers a filtering function Filtering functions are used to post process zenphoto elements or to trigger functions when a filter occur
zp_filter_unique_id()  : string
Build Unique ID for storage and retrieval.
zp_apply_filter()  : mixed
Performs a filtering operation on a zenphoto element or event.
zp_remove_filter()  : bool
Removes a function from a specified filter hook.
zp_has_filter()  : int|bool
Check if any filter has been registered for a hook.
get_filterScript()  : string
returns a list of scripts that have attached to the hook
zp_filter_slot()  : mixed
Returns the position of the function in the hook queue

Functions

zp_register_filter()

Registers a filtering function Filtering functions are used to post process zenphoto elements or to trigger functions when a filter occur

zp_register_filter(string $hook, callable $function_name[, int $priority = NULL ]) : mixed

Typical use:

	zp_register_filter('some_hook', 'function_handler_for_hook');

global array $_zp_filters Storage for all of the filters

Parameters
$hook : string

the name of the zenphoto element to be filtered

$function_name : callable

the name of the function that is to be called.

$priority : int = NULL

optional. Used to specify the order in which the functions associated with a particular action are executed (default=5, higher=earlier execution, and functions with the same priority are executed in the order in which they were added to the filter)

zp_filter_unique_id()

Build Unique ID for storage and retrieval.

zp_filter_unique_id(string $hook, string|array<string|int, mixed> $function, int|bool $priority) : string

Simply using a function name is not enough, as several functions can have the same name when they are enclosed in classes.

global array $_zp_filters storage for all of the filters

Parameters
$hook : string

hook to which the function is attached

$function : string|array<string|int, mixed>

used for creating unique id

$priority : int|bool

used in counting how many hooks were applied. If === false and $function is an object reference, we return the unique id only if it already has one, false otherwise.

Return values
string

unique ID for usage as array key

zp_apply_filter()

Performs a filtering operation on a zenphoto element or event.

zp_apply_filter(string $hook[, mixed $value = '' ]) : mixed

This function is called for each zenphoto element which supports plugin filtering. It is called after any zenphoto specific actions are completed and before the element is used.

Typical use:

	1) Modify a variable if a function is attached to hook 'zp_hook'
	$zp_var = "default value";
	$zp_var = zp_apply_filter( 'zp_hook', $zp_var );

	2) Trigger functions is attached to event 'zp_event'
	zp_apply_filter( 'zp_event' );

Returns an element which may have been filtered by a filter.

global array $_zp_filters storage for all of the filters

Parameters
$hook : string

the name of the zenphoto element

$value : mixed = ''

the value of the element before filtering

zp_remove_filter()

Removes a function from a specified filter hook.

zp_remove_filter(string $hook, callable $function_to_remove[, int $priority = NULL ][, int $accepted_args = 1 ]) : bool

This function removes a function attached to a specified filter hook. This method can be used to remove default functions attached to a specific filter hook and possibly replace them with a substitute.

To be removed the $function_to_remove and $priority arguments must match when the hook was added.

global array $_zp_filters storage for all of the filters

Parameters
$hook : string

The filter hook to which the function to be removed is hooked.

$function_to_remove : callable

The name of the function which should be removed.

$priority : int = NULL

optional. The priority of the function. If not supplied we will get it from zp_has_filter

$accepted_args : int = 1

optional. The number of arguments the function accpets (default: 1).

Return values
bool

Whether the function was registered as a filter before it was removed.

zp_has_filter()

Check if any filter has been registered for a hook.

zp_has_filter(string $hook[, callable $function_to_check = false ]) : int|bool

global array $_zp_filters storage for all of the filters

Parameters
$hook : string

The name of the filter hook.

$function_to_check : callable = false

optional. If specified, return the priority of that function on this hook or false if not attached.

Return values
int|bool

Optionally returns the priority on that hook for the specified function.

get_filterScript()

returns a list of scripts that have attached to the hook

get_filterScript(string $hook) : string
Parameters
$hook : string
Return values
string

zp_filter_slot()

Returns the position of the function in the hook queue

zp_filter_slot( $hook,  $function) : mixed
Parameters
$hook :
$function :

        
On this page

Search results