• Resolved AJ Mallory

    (@jasonm4563)


    Writing a plugin to use google maps and I’m trying to figure out how to pass the api key. The end result should look like <script type='text/javascript' src='https://maps.google.com/api/js?key=API_KEY_FROM _PHP_Script&sensor=false'> I can’t seem to figure out how to append the “API_KEY_FROM_PHP_script” part. I think I need to call wp_register_script and such. I’m pretty sure I need this <script> tag in the header section of the eventual resulting page/post.

    Anyone care to point me in the proper direction?
    Much Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • This will depend on how you are going to use your plugin. If it’s only for yourself, then you can hard-code your key into the code there. If you are going to distribute the plugin somewhere you should store the value using
    update_option('gmaps_key', $key);
    and then retrieve it using
    get_option ("gmaps_key");

    Of course, the names that I’ve used there can be changed to suit your own purposes.

    Thread Starter AJ Mallory

    (@jasonm4563)

    Thanks for the response, not quite what I’m looking for. I have all the DB stuff working fine. What I need help with is how to get the variable output to the client browser. I know when I have it figured out I will feel stupid as I’m sure the answer is quite simple and should be obvious, but it’s not…

    Normally using plan PHP I would just write this <script type='text/javascript' src='https://maps.googleapis.com/maps/api/js?key=" . $myarray_options['api_key'] . "&sensor=false'></script> and it would head on its way. How do I get this into the header section using wordpress?

    Thanks again.

    Thread Starter AJ Mallory

    (@jasonm4563)

    Looks like I figured it out. You simply add the needed stuff when you call wp_register_script like this wp_register_script('google_map_ref', 'https://maps.googleapis.com/maps/api/js?key='. $myarray_options["api_key"] .'&sensor=false');

    Hope this will help someone else looking for this info…

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Passing Parameters?’ is closed to new replies.