Put simply, I'm trying to redirect the user after clicking a 'Save Changes' button. The plugin uses custom capabilities, and so I want to check the current user has the correct capabilities before progressing with the save and redirect afterwards.

However, bit of a dilemma. I have tried loading the function that carries out what is mentioned above using 'admin_init' and 'admin_menu'.

Using 'admin_init', throws an undefined function error for the 'current_user_can' function, which makes sense since it hasn't been loaded yet (and is well documented in other help topics). The redirect works fine (using wp_safe_redirect).

On the other hand, using 'admin_menu' allows the 'current_user_can' function to work, but the redirect doesn't. This is because the headers have already been sent.

Is there a way to have both functions working in either actions 'admin_init' or 'admin_menu'?

Thanks in advance.


You should be able to use current_user_can inside the admin_init hooked callback. See the Codex examples.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.