• 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細

このWikiはいつでも誰でも編集できます

「関数リファレンス/add action」の版間の差分

提供: WordPress Codex 日本語版
移動先: 案内検索
({{原文|Function Reference/do_action|76444}}<!-- 21:07, 29 July 2009 Brentes 版 -->)
(相違点なし)

2010年4月15日 (木) 17:22時点における版

Description

Hooks a function on to a specific action.

See Plugin API/Action Reference for a list of hooks for action. Actions are (usually) triggered when the Wordpress core calls do_action().

Usage

%%% <?php add_action( $tag, $function_to_add, $priority, $accepted_args ); ?> %%%

Parameters

$tag
string) (必須) The name of the action you wish to hook onto. (See Plugin API/Action Reference for a list of action hooks)
初期値: なし
$function_to_add
callback) (必須) The name of the function you wish to be called. Note: any of the syntaxes explained in the PHP documentation for the 'callback' type are valid.
初期値: なし
$priority
int) (optional) How important your function is. Alter this to make your function be called before or after other functions. The default is 10, so (for example) setting it to 5 would make it run earlier and setting it to 12 would make it run later.
初期値: 10
$accepted_args
int) (optional) How many arguments your function takes. 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. For example, the action comment_id_not_found will pass any functions that hook onto it the ID of the requested comment.
初期値: 1

Examples

Simple Hook

To email some friends whenever an entry is posted on your blog:

function email_friends($post_ID)  {
   $friends = 'bob@example.org, susie@example.org';
   mail($friends, "sally's blog updated" , 'I just put something on my blog: http://blog.example.com');
   return $post_ID;
}

add_action('publish_post', 'email_friends');

Take Arguments

The hooked function takes one argument from the action. Specifically, the 'echo_comment_id' function, takes the argument $comment_ID. It then echos the value of the received argument.

function echo_comment_id($comment_ID) {
   echo "I just received $comment_ID";
}
add_action('comment_id_not_found','echo_comment_id', 10, 1);

Notes

Change Log

Since: 1.2.0

Source File

add_action() is located in wp-includes/plugin.php.

最新英語版: WordPress Codex » Function Reference/do_action最新版との差分

関連資料

アクション: has_action(), add_action(), do_action(), do_action_ref_array(), did_action(), remove_action(), remove_all_actions()



関数リファレンステンプレートタグ目次もご覧ください。