Вход на сайт

Просмотр новости

Найдите то, что Вас интересует

Secure Your Member Map With a Private Geocoding API Key

Дата публикации: 17-09-2026 18:58:38

The Member Directory and Profile Pages Add On uses a single Google Maps API key for two different jobs: rendering the interactive member map in the browser with the Google Maps JavaScript API, and converting member addresses into map coordinates with the Google Geocoding API. Both calls read that same key from Memberships > Settings (more...)

Основное содержимое страницы с новостью.

The Member Directory and Profile Pages Add On uses a single Google Maps API key for two different jobs: rendering the interactive member map in the browser with the Google Maps JavaScript API, and converting member addresses into map coordinates with the Google Geocoding API. Both calls read that same key from Memberships > Settings > Advanced.

That single key forces a tradeoff. Restrict it by HTTP referrer, the way Google recommends for any key exposed in browser JavaScript, and your server-side Geocoding API calls stop working, since Google cannot validate a referrer on a request that never came from a browser. Leave it unrestricted so geocoding keeps working, and you have a public API key anyone can find in your page source and use on their own projects at your expense.

This code recipe shows you how to use the pmpromd_maps_geocoding_api_key filter to give geocoding its own private key. With two keys, you can restrict each one properly: the public key by HTTP referrer, the geocoding key by server IP address, exactly as Google’s documentation recommends.

Member directory map with location pins, one showing a member's profile popup

Do You Need This Recipe?

This recipe is worth adding if any of the following apply to your site:

  • Your Google Maps API key is unrestricted (no HTTP referrer restriction), which means anyone who views your page source can copy it and use it on their own site, and Google bills the usage to your account.
  • You tried restricting the key by HTTP referrer, and your member map’s geocoding stopped working, since referrer restrictions block server-side requests.
  • A security review flagged that your single Maps API key is exposed in public JavaScript with no restrictions.

If your Maps API key is already restricted and your map still works, or you are not concerned about the key being public, this recipe is optional.

Best Practices and Considerations

Google Cloud lets you restrict an API key in one of two ways: by HTTP referrer (for keys used in browser JavaScript) or by IP address (for keys used in server-side calls). You cannot apply both restriction types to the same key. That is the core reason to split the key:

  • Keep your existing key restricted by HTTP referrer for the JavaScript Maps API, since that call always originates from a visitor’s browser.
  • Create a second key restricted by your server’s IP address, and enable it only for the Geocoding API. Use that key with this filter.

Enable the Geocoding API on the new key. When you create the second key in Google Cloud Console, restrict it to the Geocoding API specifically. A key with no API restrictions works, but it defeats the purpose of separating them.

About the Code Recipe

The pmpromd_maps_geocoding_api_key filter runs right before the Member Directory and Profile Pages Add On sends a geocoding request to Google. Internally, the Add On calls apply_filters( 'pmpromd_maps_geocoding_api_key', $map_api_key ), passing in the key currently configured on the Advanced settings page. Your callback receives that value and returns the key you want used instead.

Returning a different string here overrides the key for geocoding calls only. Your Advanced settings page key still handles the front-end JavaScript map, untouched.

Step-by-Step Implementation Guide
  1. In the Google Cloud Console, create a new API key and restrict it to the Geocoding API.
  2. Under Application restrictions, choose IP addresses and add your web server’s outbound IP address (your host can provide it if you don’t know it).
  3. Add the snippet below to a Code Snippets plugin or a site-specific plugin, replacing NEW_KEY_HERE with your new key.
  4. Trigger a geocoding event, such as a member updating their address, and confirm the member’s location still appears correctly on the map.

When you are done, your Credentials page should show two separate API keys, each with its own restriction type.

Google Cloud Credentials page showing two API keys: one restricted by IP addresses for geocoding, one restricted by HTTP referrers for the JavaScript Maps APITwo restricted keys: one for the browser-facing Maps JavaScript API, one for server-side geocoding.The Code RecipeAdding the Recipe to Your Website

You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.

How to Customize This Code Recipe
  • Insert your key (line 19): Replace NEW_KEY_HERE with your restricted geocoding API key.
  • To pull the key from an environment variable or wp-config.php constant instead of hardcoding it in the snippet, swap the assignment for something like $key = defined( 'PMPRO_GEOCODING_API_KEY' ) ? PMPRO_GEOCODING_API_KEY : $key;.

Kim White

Author: Kim White

Kim White is a Technical Support Engineer here at PMPro. She has a great intuition for unraveling information and coming up with a solution. She’s been building and maintaining websites since 1998 and enjoys helping people make the most of their WordPress membership sites. Kim also organizes her local WordPress WordCamp and Meetup.

View more articles by Kim White »

Get Support From Our Team of Experts

Have a question about how to use this feature? Our Support Page outlines three ways to get support.

Our Max plans include hands-on help customizing your membership site and implementing new features. Upgrade to PMPro Max now »

Was this article helpful?

YesNo

Схожие новости

#Наименование новостиТональностьИнформативностьДата публикации
1How to Build a Private Vendor Portal or Gated Catalog with Paid Memberships Pro09.2918-09-2026
2Offer Members a Discounted Rate for Upgrading to a Higher Level06.5316-09-2026
3Import User Meta Fields Stored as an Array via CSV011.8115-09-2026
4Protect an MCP server with an Authorization Server07.3515-06-2026
5Scaling for High Traffic Websites: How to Improve WordPress Site Performance09.2221-09-2026
6Offer Multiple Payment Methods to Increase Conversions07.921-09-2026
7digital tourism and mapping remote places07.303-08-2026
8Integrating Third-Party APIs to Enhance Website Functionality and Business Efficiency #businesstools #programming012.6621-06-2026
9Tourism and Digital Mapping: Documenting Local Places with OpenStreetMap0708-08-2026
10CookieAdmin 1.2.2: Geotargeting2611-07-2026

Классификация: Пресс-релизы. Схожих патентов: 0. Схожих новостей: 10. Тональность: 0. Информативность: 6.33. Источник: www.paidmembershipspro.com.