Adrian
Adrian

Reputation: 2291

Hook a function on the entire backend in wordpress

I am trying to hook a function on the entire wordpress backend for a user custom role, just that when the user is accessing the edit posts page post.php?post=xxxx0&action=edit, the function is no more available, printed message disappears.

if ( is_user_logged_in() ) {
    echo 'here';
    function contributor_posts() {
      echo 'here2';
    }
    add_action( 'admin_init', 'contributor_posts' );
}

echo here - disappears - though it doesn't go on the else

echo 'here2- disappears also

Upvotes: 0

Views: 466

Answers (1)

Danijel
Danijel

Reputation: 12709

admin_init action is triggered when a logged in user access the admin area, there is no need for is_user_logged_in() check here.

http://codex.wordpress.org/Plugin_API/Action_Reference/admin_init

edit:

Put the code below inside functions.php, admin_init action must be triggered always in every part of the admin area. If that is not the case then i really do not know where the problem is. Visit Wordpress Action Reference to see the list of action hooks available and the order of execution.

function contributor_posts() {
    echo 'here';
}
add_action( 'admin_init', 'contributor_posts' );

Upvotes: 4

Related Questions