I'm trying to write a custom bulk importer for store locations but I am struggling with which action hook to use.

I have written it and tested it on a clean WordPress installation and it works fine there but when I try to use it alongside WooCommerce I get an error on every admin page.

I've traced the fault back and I think it is being caused by the filter hook I am trying to use.


My import method looks like this:

public function importLocations($newvalue,$option,$oldvalue){
    if('stockist_settings'==$option && !empty($newvalue['fileimport'])){



            $prefix = $this->getAttributes()['slug']."_";
            foreach($locations as $location){

                // Checks that the longitude and latitude are filled out
                if(empty($location['Lat']) || empty($location['Lng'])){
                    $geocoder=new Geocoder();
                    $lnglat = $geocoder->geocodePostcode($location['Postcode']);


                $v = new Valitron\Validator($location);
                if($v->validate()) {

                        'post_title'    =>  $location['CompanyName'],
                        'post_type'     =>  $this->getAttributes()['slug'],
                        'post_status'   =>  'publish',
                        'meta_input'    =>  [
                            $prefix.'address1'      =>  $location['Address1'],
                            $prefix.'address2'      =>  $location['Address2'],
                            $prefix.'address3'      =>  $location['Address3'],
                            $prefix.'city'          =>  $location['City'],
                            $prefix.'postcode'      =>  $location['Postcode'],
                            $prefix.'phonenumber'   =>  $location['PhoneNumber'],
                            $prefix.'website'       =>  $location['Website'],
                            $prefix.'email'         =>  $location['Email'],
                            $prefix.'longitude'     =>  $location['Lng'],
                            $prefix.'latitude'      =>  $location['Lat'],


                } else {
                    // Errors


Is there a better filter hook this I should use or am I approaching the bulk import from the wrong direction entirely?

  • 1
    I don't think it's a good idea to redirect via that hook (which is a filter hook). Secondly, your function would be applied when updating any options, so you should always return $newvalue; at the end of your function.
    – Sally CJ
    Commented Oct 16, 2019 at 1:54
  • @SallyCJ That is the crux of my question, is there a better filter or action to use?
    – Burgi
    Commented Oct 16, 2019 at 8:20
  • If you need to run the import process every time the option stockist_settings is being updated (either via a form submission or programatically), then you can use the pre_update_option hook, but don't redirect and be sure to return the $newvalue. Or if you're not actually modifying the $newvalue and just reading the file path, then it's better to use an action hook like update_option or updated_option. But even so, redirection should still be avoided.
    – Sally CJ
    Commented Oct 16, 2019 at 14:19


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.