Undefined index: at_nonce in custom post metabox

These are your problem lines:

if ( $_POST && !wp_verify_nonce($_POST['at_nonce'], __FILE__) ) {
    return;
}

You check to see that $_POST is set, but you don’t check $_POST['at_nonce']. If $_POST is set but that key is not then you will get a Notice. It is a simple fix:

if ( isset($_POST['at_nonce']) && !wp_verify_nonce($_POST['at_nonce'], __FILE__) ) {
    return;
}

When that Notice prints, content is sent to the browser. Since that content is being sent before the proper headers are sent, when those proper headers are sent you get the “Cannot modify header information” warning.

Leave a Comment