我正试图在整个wordpress后端为用户自定义角色挂起一个函数,只是当用户访问编辑帖子页面post.php?post=xxxx0&action=edit
时,该函数不再可用,打印的消息消失。
if ( is_user_logged_in() ) {
echo 'here';
function contributor_posts() {
echo 'here2';
}
add_action( 'admin_init', 'contributor_posts' );
}
echo here
-消失-尽管它不在其他上
echo 'here2
-也消失
admin_init
操作是在登录用户访问管理区域时触发的,这里不需要is_user_logged_in()
检查。
http://codex.wordpress.org/Plugin_API/Action_Reference/admin_init
编辑:
将下面的代码放入functions.php
中,admin_init
操作必须始终在管理区域的每个部分触发。如果不是这样的话,那么我真的不知道问题出在哪里。访问Wordpress Action Reference查看可用的操作挂钩列表和执行顺序。
function contributor_posts() {
echo 'here';
}
add_action( 'admin_init', 'contributor_posts' );