Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6685845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:06:15+00:00 2026-05-26T05:06:15+00:00

Apologies, but I did ask this at the wordpress site but it doesn’t seem

  • 0

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.

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

   global $errors;

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?

  //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');

Then the form submission is similar to

  //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
  }
  }

In the actual admin page that shows the form

  //actual admin page that shows in WP
  var_dump($errors); // returns NULL

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:06:16+00:00Added an answer on May 26, 2026 at 5:06 am

    well it looks like I worked this out.

    On the actual admin page I need to declare my $errors array as global as well

    global $errors;
    

    I guess wordpress must somehow box the admin page into a function and so the $errors array was not referencing the global var.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies if this has been answered already but I have yet been unable to
Apologies if this is somewhat of a duplicate question, I did see others but
Apologies if this is answered, but I waded through a bunch of articles before
Apologies for this question but I am a bit of a noob with Delphi.
Apologies if this was already asked but, I have had a look and can't
Apologies if this is a dumb question but I'm trying to format a currency
Apologies for the long post, but I wonder if I could get some more
Apologies for the open endedness of this question, but I really don't know what
Apologies if this is a slightly noob question, but looking to clarify my thoughts
Apologies if I missed this question already, but I searched and couldn't find it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.