0

I have a Settings API field for an address. The address is stored this form: "Address, City, Country".

Is there any way of creating / generating other options based on the one above? When I save the option I want it to generate and save latitude and longitude variables because I need them in order to display the address on the front-end (Google Map)?

Any ideas how to resolve that? I could do that on front-end but then I will have to request the data for every user, not only once and I don't want to do that (performance & there's 25k/monthly limit of requests). I don't want to create additional Settings API fields neither.

1

I believe you should be able to use the update_option_{$option} hook:

do_action( "update_option_{$option}", $oldvalue, $_newvalue );

Something like:

add_action( 
  "update_option_youroptionname", 
  function ($oldvalue, $_newvalue) {
    // process your option value and update/insert options as needed
    // var_dump($oldvalue, $_newvalue);  // debug
    // wp_die(); // debug
  },
  1,2
);

Be sure to replace "youroptionname" with the appropriate value.

  • I'm going to try it right away, but how to store my options then? Is there any easy way of saving variables in functions.php so I could use them on the front-end? Or do I have to use theme options / settings? – Wordpressor Sep 4 '13 at 12:14
  • Alright, I think I'm going to use update_option(), though your hook doesn't seem to work at all, maybe that's because I have an array of Settings API and I'm updating mysettings['something']. – Wordpressor Sep 4 '13 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.