WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Passing Parameters? (4 posts)

  1. AJ Mallory
    Member
    Posted 1 year ago #

    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='http://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!

  2. michael.mariart
    Member
    Posted 1 year ago #

    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.

  3. AJ Mallory
    Member
    Posted 1 year ago #

    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='http://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.

  4. AJ Mallory
    Member
    Posted 1 year ago #

    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', 'http://maps.googleapis.com/maps/api/js?key='. $myarray_options["api_key"] .'&sensor=false');

    Hope this will help someone else looking for this info...

Topic Closed

This topic has been closed to new replies.

About this Topic