Actions
do_action
(
$tag
,
$arg
);
$tag
The name of the action hook being executed.
$arg
One or more additional arguments that are passed through to the function called from the
add_action()
function referencing thisdo_action()
function. Say what? Keep reading…
<?
php
add_action
(
'init'
,
'my_user_check'
);
function
my_user_check
()
{
if
(
is_user_logged_in
()
)
{
// do something because a user is logged in
}
}
?>
Note
Filters
apply_filters
(
$tag
,
$value
,
$var
);
$tag
The name of the filter hook.
$value
The value on which the filter can be applied.
$var
Any additional variables, such as a string or an array, passed into the filter function.
add_filter
(
$tag
,
$function
,
$priority
,
$accepted_args
);
$tag
The name of the filter hook you want to filter. This should match the
$tag
parameter of theapply_filters()
function call for which you want to filter the results.$function
The name of the custom function used to actually filter the results.
$priority
This number sets the priority in which your
add_filter()
function will run compared to other places in the code that might be referencing the same filter hook tag. By default, this value is10
.$accepted_args
You can set the number of parameters that your custom function that handles the filtering can accept. The default is
1
, which is the$value
parameter of theapply_filters()
function.
<?
php
add_filter
(
'the_title'
,
'my_filtered_title'
,
10
,
2
);
function
my_filtered_title
(
$value
,
$id
)
{
$value
=
'['
.
$value
.
']'
;
return
$value
;
}
?>