title: How to make wp_insert_post_data and sessions work together properly?
body: <p>I'm trying to process the post content before saving it to database and inform user if there was any error. I'm using wp_insert_post_data filter, sessions and admin_notices, since it seems to be the only simple solution to throw the error message to edit screen in admin panel after publishing. However, I ran into strange problem - the code seems to run twice, so when I have:</p>
  
  <pre><code>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'] .= '&lt;div class="updated"&gt;&lt;p&gt;Everything is ok&lt;/p&gt;&lt;/div&gt;';
  return $data;
  } else {
  $_SESSION['notices'] .= '&lt;div class="error"&gt;&lt;p&gt;Something went wrong&lt;/p&gt;&lt;/div&gt;';
  return $data;}
  </code></pre>
  
  <p>I receive two messages. I've made some tests and it seems that first is for content that is to be saved in database and second for the "old" content (already saved). For example: if previous content was "wrong" and the one to be saved is "ok", the first message is "ok" and second "error" and so on. However, all messages are generated on the same time (so this is not some kind of caching problem, I suppose).
  What is even more strange for me, is that if I use this simple code:</p>
  
  <pre><code>add_filter ('wp_insert_post_data', 'filterthis', '99', 2);
  function filterthis($data){
  $date = date('H:i:s');
  $_SESSION['my_admin_notices'] .= '&lt;div class="updated"&gt;&lt;p&gt;This is a message from '.$date.'&lt;/p&gt;&lt;/div&gt;';
  $data['post_content'] .= $date;
  return $data;
  }
  </code></pre>
  
  <p>I get also two messages, but only one piece of timing data appended to post content - identical to the one delivered by the first message. So it seems like the code runs twice, but only for the first time it saves the content to database... I'm totally confused after seven hours of googling and reading Codex. Maybe the solution is trivial, but I'm not really a PHP programmer, just learning it for a while, so I would be very glad if someone here could help me.</p>