Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // add_action() で登録されたアクションフックを実行します。
- // この関数が記述されているところがアクションフックを実行している箇所ともいえる
- <?php
- // $tag 必須 実行したいアクションフック名
- // $arg 任意 第一引数で実行するアクションフックにわたすパラメタ 省略すると空が渡る
- function do_action( $tag, $arg = '' ) {
- // グローバル変数
- // $wp_filter フィルターとアクションをすべて格納
- // $wp_actions アクションが呼び出された回数
- // $wp_current_filter 現在呼び出されているフィルターフックまたはアクションフックの名前を取得
- global $wp_filter, $wp_actions, $wp_current_filter;
- // $wp_actions に登録されているかを確認
- // $tag 必須 整数|オブジェクト
- if ( ! isset( $wp_actions[ $tag ] ) ) {
- $wp_actions[ $tag ] = 1;
- } else {
- ++$wp_actions[ $tag ];
- }
- // Do 'all' actions first
- // 実行順序について記載されている
- if ( isset( $wp_filter['all'] ) ) {
- $wp_current_filter[] = $tag;
- $all_args = func_get_args();
- _wp_call_all_hook( $all_args );
- }
- // アクションフックがなければ、allが含まれているアクションを呼び出す
- if ( ! isset( $wp_filter[ $tag ] ) ) {
- if ( isset( $wp_filter['all'] ) ) {
- array_pop( $wp_current_filter );
- }
- return;
- }
- // なければ現在の呼び出し関数を実行
- if ( ! isset( $wp_filter['all'] ) ) {
- $wp_current_filter[] = $tag;
- }
- // 関数の引数のチェック処理
- $args = array();
- if ( is_array( $arg ) && 1 == count( $arg ) && isset( $arg[0] ) && is_object( $arg[0] ) ) { // array(&$this)
- $args[] =& $arg[0];
- } else {
- $args[] = $arg;
- }
- for ( $a = 2, $num = func_num_args(); $a < $num; $a++ ) {
- $args[] = func_get_arg( $a );
- }
- $wp_filter[ $tag ]->do_action( $args );
- array_pop( $wp_current_filter );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement