Functions

Retrieve cron info array option.

_get_cron_array() : array
package WordPress
since 2.1.0
access private

Returns

arrayCRON info array.

_get_term_children()

_get_term_children($term_id, $terms, $taxonomy) 
package WordPress

Parameters

$term_id

$terms

$taxonomy

_get_term_hierarchy()

_get_term_hierarchy($taxonomy) 
package WordPress

Parameters

$taxonomy

_pad_term_counts()

_pad_term_counts($terms, $taxonomy) 
package WordPress

Parameters

$terms

$taxonomy

Updates the CRON option with the new CRON array.

_set_cron_array(array $cron) 
package WordPress
since 2.1.0
access private

Parameters

$cron

array

Cron info array from {@link _get_cron_array()}.

Upgrade a Cron info array.

_upgrade_cron_array(array $cron) : array

This function upgrades the Cron info array to version 2.

package WordPress
since 2.1.0
access private

Parameters

$cron

array

Cron info array from {@link _get_cron_array()}.

Returns

arrayAn upgraded Cron info array.

Returns the initialized WP_Http Object

_wp_http_get_object() : \WP_Http
package WordPress
since 2.7.0
access private

Returns

\WP_HttpHTTP Transport object.

Add hook for shortcode tag.

add_shortcode(string $tag, callable $func) 

There can only be one hook for each shortcode. Which means that if another plugin has a similar shortcode, it will override yours or yours will override theirs depending on which order the plugins are included and/or ran.

Simplest example of a shortcode tag using the API:

// [footag foo="bar"] function footag_func($atts) { return "foo = {$atts[foo]}"; } add_shortcode('footag', 'footag_func');

Example with nice attribute defaults:

// [bartag foo="bar"] function bartag_func($atts) { extract(shortcode_atts(array( 'foo' => 'no foo', 'baz' => 'default baz', ), $atts));

return "foo = {$foo}";

} add_shortcode('bartag', 'bartag_func');

Example with enclosed content:

// [baztag]content[/baztag] function baztag_func($atts, $content='') { return "content = $content"; } add_shortcode('baztag', 'baztag_func');

package WordPress
since 2.5
uses

Parameters

$tag

string

Shortcode tag to be searched in post content.

$func

callable

Hook to run when shortcode is found.

check_server_timer()

check_server_timer($local_time) 
package WordPress

Parameters

$local_time

clean_object_term_cache()

clean_object_term_cache($object_ids, $object_type) 
package WordPress

Parameters

$object_ids

$object_type

clean_term_cache()

clean_term_cache($ids, $taxonomy = ''
package WordPress

Parameters

$ids

$taxonomy

Search content for shortcodes and filter shortcodes through their hooks.

do_shortcode(string $content) : string

If there are no shortcode tags defined, then the content will be returned without any filtering. This might cause issues when plugins are disabled but the shortcode will still show up in the post or content.

package WordPress
since 2.5
uses
uses Gets the search pattern for searching shortcodes.

Parameters

$content

string

Content to search for shortcodes

Returns

stringContent with shortcodes filtered out.

Regular Expression callable for do_shortcode() for calling shortcode hook.

do_shortcode_tag(array $m) : mixed
package WordPress
see for details of the match array contents.
since 2.5
access private
uses

Parameters

$m

array

Regular expression match array

Returns

mixedFalse on failure.

get_object_taxonomies()

get_object_taxonomies($object_type) 
package WordPress

Parameters

$object_type

get_object_term_cache()

get_object_term_cache($id, $taxonomy) 
package WordPress

Parameters

$id

$taxonomy

get_objects_in_term()

get_objects_in_term($terms, $taxonomies, $args = array()
package WordPress

Parameters

$terms

$taxonomies

$args

Retrieve the shortcode regular expression for searching.

get_shortcode_regex() : string

The regular expression combines the shortcode tags in the regular expression in a regex class.

The regular expresion contains 6 different sub matches to help with parsing.

1/6 - An extra [ or ] to allow for escaping shortcodes with double [[]] 2 - The shortcode name 3 - The shortcode argument list 4 - The self closing / 5 - The content of a shortcode when it wraps some content.

package WordPress
since 2.5
uses

Returns

stringThe shortcode search regular expression

get_taxonomy()

get_taxonomy($taxonomy) 
package WordPress

Parameters

$taxonomy

get_term()

get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw'
package WordPress

Parameters

$term

$taxonomy

$output

$filter

get_term_by()

get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw'
package WordPress

Parameters

$field

$value

$taxonomy

$output

$filter

get_term_children()

get_term_children($term, $taxonomy) 
package WordPress

Parameters

$term

$taxonomy

get_term_field()

get_term_field($field, $term, $taxonomy, $context = 'display'
package WordPress

Parameters

$field

$term

$taxonomy

$context

get_term_to_edit()

get_term_to_edit($id, $taxonomy) 
package WordPress

Parameters

$id

$taxonomy

get_terms()

get_terms($taxonomies, $args = ''
package WordPress

Parameters

$taxonomies

$args

is_object_in_term()

is_object_in_term($object_id, $taxonomy, $terms = null
package WordPress

Parameters

$object_id

$taxonomy

$terms

is_taxonomy()

is_taxonomy($taxonomy) 
package WordPress

Parameters

$taxonomy

is_taxonomy_hierarchical()

is_taxonomy_hierarchical($taxonomy) 
package WordPress

Parameters

$taxonomy

is_term()

is_term($term, $taxonomy = ''
package WordPress

Parameters

$term

$taxonomy

register_taxonomy()

register_taxonomy($taxonomy, $object_type, $args = array()
package WordPress

Parameters

$taxonomy

$object_type

$args

Set the uninstallation hook for a plugin.

register_uninstall_hook(string $file, callback $callback) 

Registers the uninstall hook that will be called when the user clicks on the uninstall link that calls for the plugin to uninstall itself. The link won't be active unless the plugin hooks into the action.

The plugin should not run arbitrary code outside of functions, when registering the uninstall hook. In order to run using the hook, the plugin will have to be included, which means that any code laying outside of a function will be run during the uninstall process. The plugin should not hinder the uninstall process.

If the plugin can not be written without running code within the plugin, then the plugin should create a file named 'uninstall.php' in the base plugin folder. This file will be called, if it exists, during the uninstall process bypassing the uninstall hook. The plugin, when using the 'uninstall.php' should always check for the 'WP_UNINSTALL_PLUGIN' constant, before executing.

package WordPress
since 2.7

Parameters

$file

string

$callback

callback

The callback to run when the hook is called.

Remove all of the hooks from an action.

remove_all_actions(string $tag, integer $priority = false) : boolean
package WordPress
since 2.7

Parameters

$tag

string

The action to remove hooks from.

$priority

integer

The priority number to remove them from.

Returns

booleanTrue when finished.

Remove all of the hooks from a filter.

remove_all_filters(string $tag, integer $priority = false) : boolean
package WordPress
since 2.7

Parameters

$tag

string

The filter to remove hooks from.

$priority

integer

The priority number to remove.

Returns

booleanTrue when finished.

Clear all shortcodes.

remove_all_shortcodes() 

This function is simple, it clears all of the shortcode tags by replacing the shortcodes global by a empty array. This is actually a very efficient method for removing all shortcodes.

package WordPress
since 2.5
uses

Removes hook for shortcode.

remove_shortcode(string $tag) 
package WordPress
since 2.5
uses

Parameters

$tag

string

shortcode tag to remove hook for.

sanitize_term()

sanitize_term($term, $taxonomy, $context = 'display'
package WordPress

Parameters

$term

$taxonomy

$context

sanitize_term_field()

sanitize_term_field($field, $value, $term_id, $taxonomy, $context) 
package WordPress

Parameters

$field

$value

$term_id

$taxonomy

$context

Combine user attributes with known attributes and fill in defaults when needed.

shortcode_atts(array $pairs, array $atts) : array

The pairs should be considered to be all of the attributes which are supported by the caller and given as a list. The returned attributes will only contain the attributes in the $pairs list.

If the $atts list has unsupported attributes, then they will be ignored and removed from the final returned list.

package WordPress
since 2.5

Parameters

$pairs

array

Entire list of supported attributes and their defaults.

$atts

array

User defined attributes in shortcode tag.

Returns

arrayCombined and filtered attribute list.

Retrieve all attributes from the shortcodes tag.

shortcode_parse_atts(string $text) : array

The attributes list has the attribute name as the key and the value of the attribute as the value in the key/value pair. This allows for easier retrieval of the attributes, since all attributes have to be known.

package WordPress
since 2.5

Parameters

$text

string

Returns

arrayList of attributes and their value.

Send request to run cron through HTTP request that doesn't halt page loading.

spawn_cron($local_time = 0) : null
package WordPress
since 2.1.0

Parameters

$local_time

Returns

nullCron could not be spawned, because it is not needed to run.

Remove all shortcode tags from the given content.

strip_shortcodes(string $content) : string
package WordPress
since 2.5
uses

Parameters

$content

string

Content to remove shortcode tags.

Returns

stringContent without shortcode tags.

update_object_term_cache()

update_object_term_cache($object_ids, $object_type) 
package WordPress

Parameters

$object_ids

$object_type

update_term_cache()

update_term_cache($terms, $taxonomy = ''
package WordPress

Parameters

$terms

$taxonomy

Adds data to the cache, if the cache key doesn't aleady exist.

wp_cache_add(integer|string $key, mixed $data, string $flag = '', integer $expire = 0) : \unknown
package WordPress
since 2.0.0
uses Object Cache Class
see

Parameters

$key

integerstring

The cache ID to use for retrieval later

$data

mixed

The data to add to the cache store

$flag

string

The group to add the cache to

$expire

integer

When the cache data should be expired

Returns

\unknown

Adds a group or set of groups to the list of global groups.

wp_cache_add_global_groups(string|array $groups) 
package WordPress
since 2.6.0

Parameters

$groups

stringarray

A group or an array of groups to add

Adds a group or set of groups to the list of non-persistent groups.

wp_cache_add_non_persistent_groups(string|array $groups) 
package WordPress
since 2.6.0

Parameters

$groups

stringarray

A group or an array of groups to add

Closes the cache.

wp_cache_close() : boolean

This function has ceased to do anything since WordPress 2.5. The functionality was removed along with the rest of the persistent cache. This does not mean that plugins can't implement this function when they need to make sure that the cache is cleaned up after WordPress no longer needs it.

package WordPress
since 2.0.0

Returns

booleanAlways returns True

Removes the cache contents matching ID and flag.

wp_cache_delete(integer|string $id, string $flag = '') : boolean
package WordPress
since 2.0.0
uses Object Cache Class
see

Parameters

$id

integerstring

What the contents in the cache are called

$flag

string

Where the cache contents are grouped

Returns

booleanTrue on successful removal, false on failure

Removes all cache items.

wp_cache_flush($group = null) : boolean
package WordPress
since 2.0.0
uses Object Cache Class
see

Parameters

$group

Returns

booleanAlways returns true

Retrieves the cache contents from the cache by ID and flag.

wp_cache_get(integer|string $id, string $flag = '') : boolean | mixed
package WordPress
since 2.0.0
uses Object Cache Class
see

Parameters

$id

integerstring

What the contents in the cache are called

$flag

string

Where the cache contents are grouped

Returns

booleanmixedFalse on failure to retrieve contents or the cache contents on success

Sets up Object Cache Global and assigns it.

wp_cache_init() 
package WordPress
since 2.0.0
global WP_Object_Cache $wp_object_cache WordPress Object Cache

Replaces the contents of the cache with new data.

wp_cache_replace($key, mixed $data, string $flag = '', integer $expire = 0) : boolean
package WordPress
since 2.0.0
uses Object Cache Class
see

Parameters

$key

$data

mixed

The contents to store in the cache

$flag

string

Where to group the cache contents

$expire

integer

When to expire the cache contents

Returns

booleanFalse if cache ID and group already exists, true on success

Saves the data to the cache.

wp_cache_set($key, mixed $data, string $flag = '', integer $expire = 0) : boolean
package WordPress
since 2.0
uses Object Cache Class
see

Parameters

$key

$data

mixed

The contents to store in the cache

$flag

string

Where to group the cache contents

$expire

integer

When to expire the cache contents

Returns

booleanFalse if cache ID and group already exists, true on success

Unschedule all cron jobs attached to a specific hook.

wp_clear_scheduled_hook(string $hook, array $args = array()
package WordPress
since 2.1.0

Parameters

$hook

string

Action hook, the execution of which will be unscheduled.

$args

array

Optional. Arguments that were to be pass to the hook's callback function.

wp_count_terms()

wp_count_terms($taxonomy, $args = array()
package WordPress

Parameters

$taxonomy

$args

Run scheduled callbacks or spawn cron for all scheduled events.

wp_cron() : null
package WordPress
since 2.1.0

Returns

nullWhen doesn't need to run Cron.

wp_defer_term_counting()

wp_defer_term_counting($defer = NULL
package WordPress

Parameters

$defer

wp_delete_object_term_relationships()

wp_delete_object_term_relationships($object_id, $taxonomies) 
package WordPress

Parameters

$object_id

$taxonomies

wp_delete_term()

wp_delete_term($term, $taxonomy, $args = array()
package WordPress

Parameters

$term

$taxonomy

$args

wp_get_object_terms()

wp_get_object_terms($object_ids, $taxonomies, $args = array()
package WordPress

Parameters

$object_ids

$taxonomies

$args

Retrieve Cron schedule for hook with arguments.

wp_get_schedule(string $hook, array $args = array()) : string | boolean
package WordPress
since 2.1.0

Parameters

$hook

string

Action hook to execute when cron is run.

$args

array

Optional. Arguments to pass to the hook's callback function.

Returns

stringbooleanFalse, if no schedule. Schedule on success.

Retrieve supported and filtered Cron recurrences.

wp_get_schedules() : array

The supported recurrences are 'hourly' and 'daily'. A plugin may add more by hooking into the 'cron_schedules' filter. The filter accepts an array of arrays. The outer array has a key that is the name of the schedule or for example 'weekly'. The value is an array with two keys, one is 'interval' and the other is 'display'.

The 'interval' is a number in seconds of when the cron job should run. So for 'hourly', the time is 3600 or 6060. For weekly, the value would be 6060247 or 604800. The value of 'interval' would then be 604800.

The 'display' is the description. For the 'weekly' key, the 'display' would be __('Once Weekly').

For your plugin, you will be passed an array. you can easily add your schedule by doing the following. // filter parameter variable name is 'array' $array['weekly'] = array( 'interval' => 604800, 'display' => __('Once Weekly') );

package WordPress
since 2.1.0

Returns

array

wp_insert_term()

wp_insert_term($term, $taxonomy, $args = array()
package WordPress

Parameters

$term

$taxonomy

$args

Retrieve the next timestamp for a cron event.

wp_next_scheduled(string $hook, array $args = array()) : boolean | integer
package WordPress
since 2.1.0

Parameters

$hook

string

Action hook to execute when cron is run.

$args

array

Optional. Arguments to pass to the hook's callback function.

Returns

booleanintegerThe UNIX timestamp of the next time the scheduled event will occur.

Retrieve the raw response from the HTTP request using the GET method.

wp_remote_get(string $url, array $args = array()) : \WP_Error | array
package WordPress
see For more information on the response array format.
since 2.7.0

Parameters

$url

string

Site URL to retrieve.

$args

array

Optional. Override the defaults.

Returns

\WP_ErrorarrayThe response or WP_Error on failure.

Retrieve the raw response from the HTTP request using the HEAD method.

wp_remote_head(string $url, array $args = array()) : \WP_Error | array
package WordPress
see For more information on the response array format.
since 2.7.0

Parameters

$url

string

Site URL to retrieve.

$args

array

Optional. Override the defaults.

Returns

\WP_ErrorarrayThe response or WP_Error on failure.

Retrieve the raw response from the HTTP request using the POST method.

wp_remote_post(string $url, array $args = array()) : \WP_Error | array
package WordPress
see For more information on the response array format.
since 2.7.0

Parameters

$url

string

Site URL to retrieve.

$args

array

Optional. Override the defaults.

Returns

\WP_ErrorarrayThe response or WP_Error on failure.

Retrieve the raw response from the HTTP request.

wp_remote_request(string $url, array $args = array()) : \WP_Error | array

The array structure is a little complex.

$res = array( 'headers' => array(), 'response' => array('code' => int, 'message' => string) );

All of the headers in $res['headers'] are with the name as the key and the value as the value. So to get the User-Agent, you would do the following.

$user_agent = $res['headers']['user-agent'];

The body is the raw response content and can be retrieved from $res['body'].

This function is called first to make the request and there are other API functions to abstract out the above convoluted setup.

package WordPress
since 2.7.0

Parameters

$url

string

Site URL to retrieve.

$args

array

Optional. Override the defaults.

Returns

\WP_ErrorarrayThe response or WP_Error on failure.

Retrieve only the body from the raw response.

wp_remote_retrieve_body(array $response) : string
package WordPress
since 2.7.0

Parameters

$response

array

HTTP response.

Returns

stringThe body of the response. Empty string if no body or incorrect parameter given.

Retrieve a single header by name from the raw response.

wp_remote_retrieve_header(array $response, string $header) : string
package WordPress
since 2.7.0

Parameters

$response

array

$header

string

Header name to retrieve value from.

Returns

stringThe header value. Empty string on if incorrect parameter given, or if the header doesnt exist.

Retrieve only the headers from the raw response.

wp_remote_retrieve_headers(array $response) : array
package WordPress
since 2.7.0

Parameters

$response

array

HTTP response.

Returns

arrayThe headers of the response. Empty array if incorrect parameter given.

Retrieve only the response code from the raw response.

wp_remote_retrieve_response_code(array $response) : string

Will return an empty array if incorrect parameter value is given.

package WordPress
since 2.7.0

Parameters

$response

array

HTTP response.

Returns

stringthe response code. Empty string on incorrect parameter given.

Retrieve only the response message from the raw response.

wp_remote_retrieve_response_message(array $response) : string

Will return an empty array if incorrect parameter value is given.

package WordPress
since 2.7.0

Parameters

$response

array

HTTP response.

Returns

stringThe response message. Empty string on incorrect parameter given.

Reschedule a recurring event.

wp_reschedule_event(integer $timestamp, string $recurrence, string $hook, array $args = array()) : boolean | null
package WordPress
since 2.1.0

Parameters

$timestamp

integer

Timestamp for when to run the event.

$recurrence

string

How often the event should recur.

$hook

string

Action hook to execute when cron is run.

$args

array

Optional. Arguments to pass to the hook's callback function.

Returns

booleannullFalse on failure. Null when event is rescheduled.

Schedule a periodic event.

wp_schedule_event(integer $timestamp, string $recurrence, string $hook, array $args = array()) : boolean | null

Schedules a hook which will be executed by the WordPress actions core on a specific interval, specified by you. The action will trigger when someone visits your WordPress site, if the scheduled time has passed.

Valid values for the recurrence are hourly, daily and twicedaily. These can be extended using the cron_schedules filter in wp_get_schedules().

package WordPress
since 2.1.0

Parameters

$timestamp

integer

Timestamp for when to run the event.

$recurrence

string

How often the event should recur.

$hook

string

Action hook to execute when cron is run.

$args

array

Optional. Arguments to pass to the hook's callback function.

Returns

booleannullFalse on failure, null when complete with scheduling event.

Schedules a hook to run only once.

wp_schedule_single_event(integer $timestamp, string $hook, array $args = array()

Schedules a hook which will be executed once by the WordPress actions core at a time which you specify. The action will fire off when someone visits your WordPress site, if the schedule time has passed.

package WordPress
since 2.1.0
link http://codex.wordpress.org/Function_Reference/wp_schedule_single_event

Parameters

$timestamp

integer

Timestamp for when to run the event.

$hook

string

Action hook to execute when cron is run.

$args

array

Optional. Arguments to pass to the hook's callback function.

wp_set_object_terms()

wp_set_object_terms($object_id, $terms, $taxonomy, $append = false
package WordPress

Parameters

$object_id

$terms

$taxonomy

$append

wp_unique_term_slug()

wp_unique_term_slug($slug, $term) 
package WordPress

Parameters

$slug

$term

Unschedule a previously scheduled cron job.

wp_unschedule_event(integer $timestamp, string $hook, array $args = array()

The $timestamp and $hook parameters are required, so that the event can be identified.

package WordPress
since 2.1.0

Parameters

$timestamp

integer

Timestamp for when to run the event.

$hook

string

Action hook, the execution of which will be unscheduled.

$args

array

Arguments to pass to the hook's callback function. Although not passed to a callback function, these arguments are used to uniquely identify the scheduled event, so they should be the same as those used when originally scheduling the event.

wp_update_term()

wp_update_term($term, $taxonomy, $args = array()
package WordPress

Parameters

$term

$taxonomy

$args

wp_update_term_count()

wp_update_term_count($terms, $taxonomy, $do_deferred = false
package WordPress

Parameters

$terms

$taxonomy

$do_deferred

wp_update_term_count_now()

wp_update_term_count_now($terms, $taxonomy) 
package WordPress

Parameters

$terms

$taxonomy

Classes, interfaces, and traits

WP_Ajax_Response

Send XML response back to AJAX request.

« More »

WP_Error

WordPress Error class.

« More »

WP_HTTP_IXR_Client

WP_HTTP_IXR_Client

« More »

WP_HTTP_Proxy

Adds Proxy support to the WordPress HTTP API.

« More »

WP_Taxonomy

WordPress Taxonomy based off of WordPress revision 8782.

« More »

Classes, interfaces, and traits

WP_Object_Cache

WordPress Object Cache

« More »

Classes, interfaces, and traits

WP_Http

WordPress HTTP Class for managing HTTP Transports and making HTTP requests.

« More »

WP_Http_Curl

HTTP request method uses Curl extension to retrieve the url.

« More »

WP_Http_Encoding

Implementation for deflate and gzip transfer encodings.

« More »

WP_Http_ExtHTTP

HTTP request method uses HTTP extension to retrieve the url.

« More »

WP_Http_Fopen

HTTP request method uses fopen function to retrieve the url.

« More »

WP_Http_Fsockopen

HTTP request method uses fsockopen function to retrieve the url.

« More »

WP_Http_Streams

HTTP request method uses Streams to retrieve the url.

« More »

Functions

Calls the 'all' hook, which will process the functions hooked into it.

_wp_call_all_hook(array $args) 

The 'all' hook passes all of the arguments or parameters that were used for the hook, which this function was called for.

This function is used internally for apply_filters(), do_action(), and do_action_ref_array() and is not meant to be used from outside those functions. This function does not check for the existence of the all hook, so it will fail unless the all hook exists prior to this function call.

package WordPress
package WordPress
subpackage Plugin
since 2.5
access private
uses Used to process all of the functions in the 'all' hook

Parameters

$args

array

The collected parameters from the hook that was called.

Build Unique ID for storage and retrieval.

_wp_filter_build_unique_id(string $tag, callback $function, integer|boolean $priority) : string | boolean

The old way to serialize the callback caused issues and this function is the solution. It works by checking for objects and creating an a new property in the class to keep track of the object and new objects of the same class that need to be added.

It also allows for the removal of actions and filters for objects after they change class properties. It is possible to include the property $wp_filter_id in your class and set it to "null" or a number to bypass the workaround. However this will prevent you from adding new classes and any new classes will overwrite the previous hook by the same class.

Functions and static method callbacks are just returned as strings and shouldn't have any speed penalty.

package WordPress
package WordPress
subpackage Plugin
access private
since 2.2.3
link http://trac.wordpress.org/ticket/3875
global array $wp_filter Storage for all of the filters and actions

Parameters

$tag

string

Used in counting how many hooks were applied

$function

callback

Used for creating unique id

$priority

integerboolean

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.

Returns

stringbooleanUnique ID for usage as array key or false if $priority === false and $function is an object reference, and it does not already have a uniqe id.

Hooks a function on to a specific action.

add_action(string $tag, callback $function_to_add, integer $priority = 10, integer $accepted_args = 1

Actions are the hooks that the WordPress core launches at specific points during execution, or when specific events occur. Plugins can specify that one or more of its PHP functions are executed at these points, using the Action API.

package WordPress
package WordPress
uses Adds an action. Parameter list and functionality are the same.
subpackage Plugin
since 1.2

Parameters

$tag

string

The name of the action to which the $function_to_add is hooked.

$function_to_add

callback

The name of the function you wish to be called.

$priority

integer

optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.

$accepted_args

integer

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

Hooks a function or method to a specific filter action.

add_filter(string $tag, callback $function_to_add, integer $priority = 10, integer $accepted_args = 1) : boolean

Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen. Plugins can specify that one or more of its PHP functions is executed to modify specific types of text at these times, using the Filter API.

To use the API, the following code should be used to bind a callback to the filter.

function example_hook($example) { echo $example; } add_filter('example_filter', 'example_hook');

In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching do_action() or apply_filters() call is run. The $accepted_args allow for calling functions only when the number of args match. Hooked functions can take extra arguments that are set when the matching do_action() or apply_filters() call is run. For example, the action comment_id_not_found will pass any functions that hook onto it the ID of the requested comment.

Note: the function will return true no matter if the function was hooked fails or not. There are no checks for whether the function exists beforehand and no checks to whether the $function_to_add is even a string. It is up to you to take care and this is done for optimization purposes, so everything is as quick as possible.

package WordPress
package WordPress
subpackage Plugin
since 0.71
global array $wp_filter Stores all of the filters added in the form of wp_filter['tag']['array of priorities']['array of functions serialized']['array of ['array (functions, accepted_args)']']
global array $merged_filters Tracks the tags that need to be merged for later. If the hook is added, it doesn't need to run through that process.

Parameters

$tag

string

The name of the filter to hook the $function_to_add to.

$function_to_add

callback

The name of the function to be called when the filter is applied.

$priority

integer

optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.

$accepted_args

integer

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

Returns

booleantrue

Call the functions added to a filter hook.

apply_filters(string $tag, mixed $value) : mixed

The callback functions attached to filter hook $tag are invoked by calling this function. This function can be used to create a new filter hook by simply calling this function with the name of the new hook specified using the $tag parameter.

The function allows for additional arguments to be added and passed to hooks. function example_hook($string, $arg1, $arg2) { //Do stuff return $string; } $value = apply_filters('example_filter', 'filter me', 'arg1', 'arg2');

package WordPress
package WordPress
subpackage Plugin
since 0.71
global array $wp_filter Stores all of the filters
global array $merged_filters Merges the filter hooks using this function.
global array $wp_current_filter stores the list of current filters with the current one last

Parameters

$tag

string

The name of the filter hook.

$value

mixed

The value on which the filters hooked to $tag are applied on.

Returns

mixedThe filtered value after all hooked functions are applied to it.

Execute functions hooked on a specific filter hook, specifying arguments in an array.

apply_filters_ref_array(string $tag, array $args) : mixed
package WordPress
package WordPress
see This function is identical, but the arguments passed to the functions hooked to $tag are supplied using an array.
subpackage Plugin
since 3.0.0
global array $wp_filter Stores all of the filters
global array $merged_filters Merges the filter hooks using this function.
global array $wp_current_filter stores the list of current filters with the current one last

Parameters

$tag

string

The name of the filter hook.

$args

array

The arguments supplied to the functions hooked to $tag

Returns

mixedThe filtered value after all hooked functions are applied to it.

Retrieve the name of the current filter or action.

current_filter() : string
package WordPress
package WordPress
subpackage Plugin
since 2.5

Returns

stringHook name of the current filter or action.

Retrieve the number times an action is fired.

did_action(string $tag) : integer
package WordPress
package WordPress
subpackage Plugin
since 2.1
global array $wp_actions Increments the amount of times action was triggered.

Parameters

$tag

string

The name of the action hook.

Returns

integerThe number of times action hook $tag is fired

Execute functions hooked on a specific action hook.

do_action(string $tag, $arg = '') : null

This function invokes all functions attached to action hook $tag. It is possible to create new action hooks by simply calling this function, specifying the name of the new hook using the $tag parameter.

You can pass extra arguments to the hooks, much like you can with apply_filters().

package WordPress
package WordPress
see This function works similar with the exception that nothing is returned and only the functions or methods are called.
subpackage Plugin
since 1.2
global array $wp_filter Stores all of the filters
global array $wp_actions Increments the amount of times action was triggered.

Parameters

$tag

string

The name of the action to be executed.

$arg

Returns

nullWill return null if $tag does not exist in $wp_filter array

Execute functions hooked on a specific action hook, specifying arguments in an array.

do_action_ref_array(string $tag, array $args) : null
package WordPress
package WordPress
see This function is identical, but the arguments passed to the functions hooked to $tag are supplied using an array.
subpackage Plugin
since 2.1
global array $wp_filter Stores all of the filters
global array $wp_actions Increments the amount of times action was triggered.

Parameters

$tag

string

The name of the action to be executed.

$args

array

The arguments supplied to the functions hooked to $tag

Returns

nullWill return null if $tag does not exist in $wp_filter array

Check if any action has been registered for a hook.

has_action(string $tag, callback $function_to_check = false) : integer | boolean
package WordPress
package WordPress
subpackage Plugin
since 2.5
see has_action() is an alias of has_filter().

Parameters

$tag

string

The name of the action hook.

$function_to_check

callback

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

Returns

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

Check if any filter has been registered for a hook.

has_filter(string $tag, callback $function_to_check = false) : integer | boolean
package WordPress
package WordPress
subpackage Plugin
since 2.5
global array $wp_filter Stores all of the filters

Parameters

$tag

string

The name of the filter hook.

$function_to_check

callback

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

Returns

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

Gets the basename of a plugin.

plugin_basename(string $file) : string

This method extracts the name of a plugin from its filename.

package WordPress
package WordPress
subpackage Plugin
since 1.5
access private
uses

Parameters

$file

string

The filename of plugin.

Returns

stringThe name of a plugin.

Gets the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in

plugin_dir_path(string $file) : string
package WordPress
package WordPress
subpackage Plugin
since 2.8

Parameters

$file

string

The filename of the plugin (FILE)

Returns

stringthe filesystem path of the directory that contains the plugin

Gets the URL directory path (with trailing slash) for the plugin __FILE__ passed in

plugin_dir_url(string $file) : string
package WordPress
package WordPress
subpackage Plugin
since 2.8

Parameters

$file

string

The filename of the plugin (FILE)

Returns

stringthe URL path of the directory that contains the plugin

Set the activation hook for a plugin.

register_activation_hook(string $file, callback $function) 

When a plugin is activated, the action 'activate_PLUGINNAME' hook is activated. In the name of this hook, PLUGINNAME is replaced with the name of the plugin, including the optional subdirectory. For example, when the plugin is located in wp-content/plugin/sampleplugin/sample.php, then the name of this hook will become 'activate_sampleplugin/sample.php'. When the plugin consists of only one file and is (as by default) located at wp-content/plugin/sample.php the name of this hook will be 'activate_sample.php'.

package WordPress
package WordPress
subpackage Plugin
since 2.0

Parameters

$file

string

The filename of the plugin including the path.

$function

callback

the function hooked to the 'activate_PLUGIN' action.

Set the deactivation hook for a plugin.

register_deactivation_hook(string $file, callback $function) 

When a plugin is deactivated, the action 'deactivate_PLUGINNAME' hook is deactivated. In the name of this hook, PLUGINNAME is replaced with the name of the plugin, including the optional subdirectory. For example, when the plugin is located in wp-content/plugin/sampleplugin/sample.php, then the name of this hook will become 'activate_sampleplugin/sample.php'.

When the plugin consists of only one file and is (as by default) located at wp-content/plugin/sample.php the name of this hook will be 'activate_sample.php'.

package WordPress
package WordPress
subpackage Plugin
since 2.0

Parameters

$file

string

The filename of the plugin including the path.

$function

callback

the function hooked to the 'activate_PLUGIN' action.

Removes a function from a specified action hook.

remove_action(string $tag, callback $function_to_remove, integer $priority = 10, integer $accepted_args = 1) : boolean

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

package WordPress
package WordPress
subpackage Plugin
since 1.2

Parameters

$tag

string

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

$function_to_remove

callback

The name of the function which should be removed.

$priority

integer

optional The priority of the function (default: 10).

$accepted_args

integer

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

Returns

booleanWhether the function is removed.

Removes a function from a specified filter hook.

remove_filter(string $tag, callback $function_to_remove, integer $priority = 10, integer $accepted_args = 1) : boolean

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 remove a hook, the $function_to_remove and $priority arguments must match when the hook was added. This goes for both filters and actions. No warning will be given on removal failure.

package WordPress
package WordPress
subpackage Plugin
since 1.2

Parameters

$tag

string

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

$function_to_remove

callback

The name of the function which should be removed.

$priority

integer

optional. The priority of the function (default: 10).

$accepted_args

integer

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

Returns

booleanWhether the function existed before it was removed.

Functions

Retrieve original referer that was posted, if it exists.

wp_get_original_referer() : string | boolean
package WordPress
package WordPress
subpackage Security
since 2.0.4

Returns

stringbooleanFalse if no original referer or original referer if set.

Retrieve referer from '_wp_http_referer', HTTP referer, or current page respectively.

wp_get_referer() : string | boolean
package WordPress
package WordPress
subpackage Security
since 2.0.4

Returns

stringbooleanFalse on failure. Referer URL on success.

Retrieve or display original referer hidden field for forms.

wp_original_referer_field(boolean $echo = true, string $jump_back_to = 'current') : string

The input name is '_wp_original_http_referer' and will be either the same value of wp_referer_field(), if that was posted already or it will be the current page, if it doesn't exist.

package WordPress
package WordPress
subpackage Security
since 2.0.4

Parameters

$echo

boolean

Whether to echo the original http referer

$jump_back_to

string

Optional, default is 'current'. Can be 'previous' or page you want to jump back to.

Returns

stringOriginal referer field.

Retrieve or display referer hidden field for forms.

wp_referer_field(boolean $echo = true) : string

The referer link is the current Request URI from the server super global. The input name is '_wp_http_referer', in case you wanted to check manually.

package WordPress
package WordPress
subpackage Security
since 2.0.4

Parameters

$echo

boolean

Whether to echo or return the referer field.

Returns

stringReferer field.