Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. // add_action() で登録されたアクションフックを実行します。
  2. // この関数が記述されているところがアクションフックを実行している箇所ともいえる
  3. <?php
  4. // $tag 必須 実行したいアクションフック名
  5. // $arg 任意 第一引数で実行するアクションフックにわたすパラメタ 省略すると空が渡る
  6. function do_action( $tag, $arg = '' ) {
  7. // グローバル変数
  8. // $wp_filter フィルターとアクションをすべて格納
  9. // $wp_actions アクションが呼び出された回数
  10. // $wp_current_filter 現在呼び出されているフィルターフックまたはアクションフックの名前を取得
  11. global $wp_filter, $wp_actions, $wp_current_filter;
  12. // $wp_actions に登録されているかを確認
  13. // $tag 必須 整数|オブジェクト
  14. if ( ! isset( $wp_actions[ $tag ] ) ) {
  15. $wp_actions[ $tag ] = 1;
  16. } else {
  17. ++$wp_actions[ $tag ];
  18. }
  19.  
  20. // Do 'all' actions first
  21. // 実行順序について記載されている
  22. if ( isset( $wp_filter['all'] ) ) {
  23. $wp_current_filter[] = $tag;
  24. $all_args = func_get_args();
  25. _wp_call_all_hook( $all_args );
  26. }
  27.  
  28. // アクションフックがなければ、allが含まれているアクションを呼び出す
  29. if ( ! isset( $wp_filter[ $tag ] ) ) {
  30. if ( isset( $wp_filter['all'] ) ) {
  31. array_pop( $wp_current_filter );
  32. }
  33. return;
  34. }
  35. // なければ現在の呼び出し関数を実行
  36. if ( ! isset( $wp_filter['all'] ) ) {
  37. $wp_current_filter[] = $tag;
  38. }
  39.  
  40. // 関数の引数のチェック処理
  41. $args = array();
  42. if ( is_array( $arg ) && 1 == count( $arg ) && isset( $arg[0] ) && is_object( $arg[0] ) ) { // array(&$this)
  43. $args[] =& $arg[0];
  44. } else {
  45. $args[] = $arg;
  46. }
  47. for ( $a = 2, $num = func_num_args(); $a < $num; $a++ ) {
  48. $args[] = func_get_arg( $a );
  49. }
  50.  
  51. $wp_filter[ $tag ]->do_action( $args );
  52.  
  53. array_pop( $wp_current_filter );
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement