Created
January 22, 2017 17:47
-
-
Save chwnam/238b15c453fe5c24b52cf670058e0643 to your computer and use it in GitHub Desktop.
WP_Hook 실험
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: WPHook47 | |
* Description: WP_Hook 을 사용한 4.7 버전과 그 이전의 버전은 이 코드를 실행하면 결과가 다릅니다. | |
*/ | |
add_action( 'wp_footer', function() { | |
error_log( '---------------' ); | |
add_action( 'wph47_test01', 'wph47_test01', 10); | |
wph47_test01_body(); | |
remove_action( 'wph47_test01', 'wph47_test01', 10); | |
add_action( 'wph47_test01', 'wph47_test01', 5); | |
wph47_test01_body(); | |
error_log( '---------------' ); | |
/* | |
이 코드를 4.6 이전 버전에서 실행할 경우 결과는 이렇게 나옵니다. | |
--------------- | |
test begin | |
9 | |
11 | |
12 | |
13 | |
test end | |
test begin | |
9 | |
11 | |
12 | |
13 | |
test end | |
--------------- | |
4.7 버전 이후에서 실행되면 결과는 이렇습니다. 별표는 4.6과의 차이를 나타냅니다. | |
--------------- | |
test begin | |
9 | |
11 | |
12 | |
13 | |
11 * | |
12 * | |
13 * | |
test end | |
test begin | |
9 | |
11 | |
12 | |
13 | |
9 * | |
11 * | |
12 * | |
13 * | |
test end | |
--------------- | |
*/ | |
}); | |
/** | |
* 재귀적인 do_action 호출 | |
*/ | |
function wph47_test01_body() { | |
error_log('test begin'); | |
do_action( 'wph47_test01' ); | |
error_log("test end"); | |
} | |
function wph47_test01() { | |
static $flag = false; if ( $flag ) return; $flag = true; | |
add_action( 'wph47_test01', 'wbh47_cb_9', 9 ); | |
add_action( 'wph47_test01', 'wbh47_cb_11', 11 ); | |
add_action( 'wph47_test01', 'wbh47_cb_12', 12 ); | |
add_action( 'wph47_test01', 'wbh47_cb_13', 13 ); | |
do_action( 'wph47_test01' ); | |
$flag = false; | |
} | |
function wbh47_cb_9() { | |
error_log( '9' ); | |
} | |
function wbh47_cb_10() { | |
error_log( '10' ); | |
} | |
function wbh47_cb_11() { | |
error_log( '11' ); | |
} | |
function wbh47_cb_12() { | |
error_log( '12' ); | |
} | |
function wbh47_cb_13() { | |
error_log( '13' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment