I am attempting to process the publish content before saving it to database and inform user if there is any error. I am using wordpress_place_publish_data filter, periods and admin_notices, because it appears to be the sole simple means to fix toss the error message to edit screen in admin panel after posting. However, I went into strange problem - the code appears to operate two times, then when I've:

function notices(){
if(!empty($_SESSION['notices'])) print  $_SESSION['notices'];
unset ($_SESSION['notices']);}
add_action( 'admin_notices', 'notices' );

add_filter('wp_insert_post_data', 'processdata', '99', 2);
function processdata($data) {
$processed_content = filterthis($data['post_content']);
if($processed_content!='error') {
$data['post_content'] = $processed_content;
$_SESSION['notices'] .= '<div class="updated"><p>Everything is ok</p></div>';
return $data;
} else {
$_SESSION['notices'] .= '<div class="error"><p>Something went wrong</p></div>';
return $data;}

I receive two messages. I have made some tests also it appears that first is perfect for content that's to become held in database and 2nd for that "old" content (already saved). For instance: if previous content was "wrong" and also the someone to be saved is "ok", the very first message is "ok" and 2nd "error" and so forth. However, all messages are produced on a single time (making this not some type of caching problem, I guess). What's much more strange for me personally, is when I personally use this straightforward code:

add_filter ('wp_insert_post_data', 'filterthis', '99', 2);
function filterthis($data){
$date = date('H:i:s');
$_SESSION['my_admin_notices'] .= '<div class="updated"><p>This is a message from '.$date.'</p></div>';
$data['post_content'] .= $date;
return $data;
}

I recieve also two messages, only one bit of timing data appended to publish content - just like the main one shipped through the first message. Therefore it appears such as the code runs two times, only the very first time it saves this content to database... I am totally confused after seven hrs of searching and reading through Codex. Maybe the answer is trivial, but I am not just a PHP programmer, just learning it for some time, and so i could be very glad if a person here may help me.