Created
November 8, 2019 11:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use this filter:
require_once "google_api_listing_form_only.php";