3
函数之前或之后的add_action(),add_filter()
浏览WordPress片段/教程/插件时,我经常看到add_action()和add_filter()放置在函数声明之前: add_action( 'publish_post', 'email_friends' ); 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; } 从逻辑的角度来看,这对我来说毫无意义。为什么在代码中调用了函数之后又放置它呢?通常,这就是我处理相同情况的方式: function email_friends( $post_ID ) { $friends = 'bob@example.org, susie@example.org'; mail( $friends, "sally's blog updated" , 'I just …