title: Wordpress plugin admin redirect and returning errors
body: <p>Apologies, but I did ask this at the wordpress site but it doesn't seem to get viewed yet alone answered! Hope I'm not breaking any rules by reposting here.</p>
  
  <p>I've been developing a wordpress plugin that has an admin section with a form to add and edit various things. Now after an admin submits the form I wanted to redirect if successful (to show updated values) or show the various error messages if not. I got the header errors from trying wp_redirect and after looking through SO I started to use the add_action method so I could redirect without header error messages. The problem I have now though is that my array of errors is now always null, even if the form wasn't submitted correctly. I have defined the errors variable before add_action and in the function in add_action I have </p>
  
  <pre><code>   global $errors;
  </code></pre>
  
  <p>If I do a var_dump of $errors in the function that handles the submit it is populated, but then on my actual page it is always empty. My guess is that I'm not familiar with the order the pages get called in WP and I'm missing something, but how does anyone else handle this?</p>
  
  <pre><code>  //the index.php for pluging
    //require necessary files
    $errors = null;
    include('plugin_file.php');
    //Tie into wordpress hooks
    add_action('widgets_init', 'plugin::register_func');
    add_action('admin_menu', 'plugin::add_menu_item');
    add_action('admin_init', 'plugin::check_form_submission');
  </code></pre>
  
  <p>Then the form submission is similar to</p>
  
  <pre><code>  //THE Class file for my plugin
    static function check_form_submission(){
    global $errors;
          if(empty($_POST['some_field'])){
                        $errors['some-error'] = 'some error';
          }
    if(!$errors){
      //handle and redirect here
     }else{
    var_dump($errors); // does have values
    }
    }
  </code></pre>
  
  <p>In the actual admin page that shows the form</p>
  
  <pre><code>  //actual admin page that shows in WP
    var_dump($errors); // returns NULL
  </code></pre>
  
  <p>will always be null even if it has values above. Anyone got any advice how to handle this? I'm new to WP plugin development so not sure what the best practice is.</p>