Remove published post notification while handling errors

im creating an error handler for a custom post type.

add_filter( 'wp_insert_post_data' , 'filter_post_data' , '99', 2 );
function filter_post_data( $data , $postarr )
{
    //error handling
    if($data['post_type'] == 'post_annunci')
    {
        if($postarr['annuncio_prezzo'] == '' || !is_numeric($postarr['annuncio_prezzo']))
        {
            $errors .= 'Annuncio non salvato, devi inserire un prezzo con valori numerici.</br>prezzo = '.$postarr['annuncio_prezzo'];
            update_option('my_admin_errors', $errors);

            $data['post_status'] = 'draft';
        }
    }
    return $data;

}

add_action( 'admin_notices', 'admin_error_handler_annunci' );
function admin_error_handler_annunci() {

    $errors = get_option('my_admin_errors');

    if($errors) 
        echo '<div class="error"><p>' . $errors . '</p></div>';
}
// Clear any errors
add_action( 'admin_footer', 'clear_error_handler_annunci' );
function clear_error_handler_annunci() {

    update_option('my_admin_errors', false);
}

      

This works fine, but I get a "posted message" notification that I want to delete.

Is there a way to get rid of this message? I've seen some kind of notification remover like the script but only works for update notifications.

function hideUpdateNag() {
    remove_action( 'admin_notices', 'update_nag', 3 );
}
add_action('admin_menu','hideUpdateNag');

      

+2


source to share


1 answer


Yes. This is possible with a filter . post_updated_messages

add_filter( 'post_updated_messages', 'remove_all_messages_so_16015959' );

function remove_all_messages_so_16015959( $messages )
{
    return array();
}

      



This example returns an empty array. As a result, there are no messages.
This can be fine-tuned with the sample values ​​below, which are the content $messages

before the filter.

Array
(
    [post] => Array
        (
            [0] => 
            [1] => Post updated. View post
            [2] => Custom field updated.
            [3] => Custom field deleted.
            [4] => Post updated.
            [5] => 
            [6] => Post published. View post
            [7] => Post saved.
            [8] => Post submitted. Preview post
            [9] => Post scheduled for: Jan 12, 2013 @ 19:03. Preview post
            [10] => Post draft updated. Preview post
        )

    [page] => Array
        (
            [0] => 
            [1] => Page updated. View page
            [2] => Custom field updated.
            [3] => Custom field deleted.
            [4] => Page updated.
            [5] => 
            [6] => Page published. View page
            [7] => Page saved.
            [8] => Page submitted. Preview page
            [9] => Page scheduled for: Jan 12, 2013 @ 19:03. Preview page
            [10] => Page draft updated. Preview page
        )

    [attachment] => Array
        (
            [1] => Media attachment updated.
            [2] => Media attachment updated.
            [3] => Media attachment updated.
            [4] => Media attachment updated.
            [5] => Media attachment updated.
            [6] => Media attachment updated.
            [7] => Media attachment updated.
            [8] => Media attachment updated.
            [9] => Media attachment updated.
            [10] => Media attachment updated.
        )

)

      

+2


source







All Articles