PDF for GravityView Hooks – gfpdf_gv_static_map_url_signature
Description
Provides a URL signing secret so Static Maps requests are signed. There's no setting for the secret, so this filter is the only way to supply it.
Depending on your project's usage and settings, Google can require every Static Maps request to be signed. When it does, unsigned requests are refused and the maps in your PDFs don't appear.
Return your URL signing secret from the Google Cloud Console (Google Maps Platform > Credentials), exactly as Google shows it. PDF for GravityView uses it to sign each map request. Only the signature is added to the request, never the secret.
If maps still don't appear, check you copied the whole secret. A secret that can't be decoded is ignored and requests are sent unsigned.
Version
This hook was introduced in PDF for GravityView 2.0.
Arguments
The following arguments are passed to functions that use this hook:
$secret | string
- Your URL signing secret, in the URL-safe base64 form Google provides (letters, numbers,
-and_, often ending in=). - Return
''to send requests unsigned. - The default value is
''.
Usage
Use a secret defined in wp-config.php, so it stays out of the database. For example, define( 'MY_STATIC_MAPS_SIGNING_SECRET', 'your-url-signing-secret' );:
add_filter( 'gfpdf_gv_static_map_url_signature', function( $secret ) {
return defined( 'MY_STATIC_MAPS_SIGNING_SECRET' ) ? MY_STATIC_MAPS_SIGNING_SECRET : $secret;
} );
Treat the signing secret like a password. Anyone with it and your API key can sign requests that Google bills to you. Don't commit it to a public repository, and generate a new one in the Google Cloud Console if it's exposed.
The Check Key button in the Static Maps Key setting sends an unsigned test request. It may report a problem with a key that works once this filter supplies the secret. Generate a PDF with a map to confirm signing works.
To supply the API key itself from code, see gfpdf_gv_static_map_api_key.
Source Code
This filter is located in src/Pdf/Maps/StaticMapRenderer.php of the PDF for GravityView extension.