When saving custom meta box inputs, I usually use
get_current_screen() inside the function which hooks to
save_post hook to determine current post’s post type1. However, a realisation comes when I create front end editing screen:
get_current_screen() is only loaded on
is_admin() environment and causes
called undefined function message.
Some workarounds2 toward this:
- Assuming you’re only use the custom meta box on the dashboard screen, checking the existence of the function using
function_exist()and return it if it fails is enough.
- If the custom meta box saving mechanism will be used on both dashboard and front end screen, using
get_post()based on the post ID posted and checking its
$post->post_typewill do the work.