Skip to content

Instantly share code, notes, and snippets.

@jreviews
Created November 8, 2019 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jreviews/9f05ff56bbb648e1a3351c57b82b1c05 to your computer and use it in GitHub Desktop.
Save jreviews/9f05ff56bbb648e1a3351c57b82b1c05 to your computer and use it in GitHub Desktop.
JReviews Developer Filter: Limit loading of Google Maps API in front-end to the listing form
<?php
defined('MVC_FRAMEWORK') or die;
/**
* In front-end, load Google Maps API only while using the listing form
* if either the map service or geocoding service is set to Google
*/
function google_api_listing_form_only($load, $params)
{
if ( $params['in_admin'] )
{
return $load;
}
elseif (
in_array($params['route'], ['listings.create','listings.edit'])
&&
($params['maps_service'] == 'google' || $params['geocoding_service_front'] == 'google')
) {
return true;
}
return false;
}
Clickfwd\Hook\Filter::add('maps_load_google_api', 'google_api_listing_form_only', 10);
@jreviews
Copy link
Author

jreviews commented Nov 8, 2019

To use this filter:

  1. Upload the above file to jreviews_overrides/filters
  2. Add the line below to jreviews_overrides/filter_functions.php, if you are not using filters yet, read the documentation on Getting Started with JReviews developer filters

require_once "google_api_listing_form_only.php";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment