Modifying the “Comprehensive Google Maps Plugin” to load scripts only on own admin pages – preventing interference with ThemeStarta

Thanks to the Members who reported the issue with using the “Comprehensive Google Maps Plugin” at the same time as ThemeStarta.

This maps plugin depends on a few scripts, each of which are loaded into the admin area of WordPress. However, as long as the plugin is active those scripts are loaded everywhere in the admin area, including in the ThemeStarta interface, and unfortunately the scripts interfere with the functionality of ThemeStarta.

However, with a small modification to the ”Comprehensive Google Maps Plugin” the scripts that cause this issue can be restricted to loading in that plugin’s own admin pages only. By doing this the scripts will no longer load in the ThemeStarta interface, and hence will no longer interfere with any of the functionality.

Here’s how to make this change.

In the root folder of your ”Comprehensive Google Maps Plugin”, named comprehensive-google-map-plugin, find and open the head.php file for editing.

In that file on lines 34 to 47 locate the following function, which is responsible for loading the scripts described above:

34
35
36
37
38
39
40
41
42
43
44
45
46
47
if ( !function_exists('cgmp_google_map_admin_add_script') ):
		function cgmp_google_map_admin_add_script()  {
 
				$whitelist = array('localhost', '127.0.0.1', 'initbinder.com');
 
				wp_enqueue_script('cgmp-jquery-tools-tooltip', CGMP_PLUGIN_JS .'/jquery.tools.tooltip.min.js', array('jquery'), '1.2.5.a', true);
				$minified = ".min";
				if (in_array($_SERVER['HTTP_HOST'], $whitelist)) {
					$minified = "";
				}
				wp_enqueue_script('cgmp-jquery-tokeninput', CGMP_PLUGIN_JS. '/cgmp.tokeninput'.$minified.'.js', array('jquery'), CGMP_VERSION, true);
				wp_enqueue_script('comprehensive-google-map-plugin', CGMP_PLUGIN_JS. '/cgmp.admin'.$minified.'.js', array('jquery'), CGMP_VERSION, true);
		}
endif;

More specifically within that function, locate lines 39 to 46, which is the section we want to run only when in the plugin’s own admin pages:

39
40
41
42
43
44
45
wp_enqueue_script('cgmp-jquery-tools-tooltip', CGMP_PLUGIN_JS .'/jquery.tools.tooltip.min.js', array('jquery'), '1.2.5.a', true);
$minified = ".min";
if (in_array($_SERVER['HTTP_HOST'], $whitelist)) {
	$minified = "";
}
wp_enqueue_script('cgmp-jquery-tokeninput', CGMP_PLUGIN_JS. '/cgmp.tokeninput'.$minified.'.js', array('jquery'), CGMP_VERSION, true);
wp_enqueue_script('comprehensive-google-map-plugin', CGMP_PLUGIN_JS. '/cgmp.admin'.$minified.'.js', array('jquery'), CGMP_VERSION, true);

What we are going to do is wrap this code with a check to determine if we are on one of the plugin’s admin pages before allowing the scripts to be loaded.

Above the code add the following lines:

39
40
41
$thisadminpage = $_REQUEST['page'];
 
if($thisadminpage=="cgmp-documentation"||$thisadminpage=="cgmp-shortcodebuilder"||$thisadminpage=="cgmp-settings"){

And below it add this closing curly bracket:

49
}

The end result should look like this:

39
40
41
42
43
44
45
46
47
48
49
$thisadminpage = $_REQUEST['page'];
 
if($thisadminpage=="cgmp-documentation"||$thisadminpage=="cgmp-shortcodebuilder"||$thisadminpage=="cgmp-settings"){
wp_enqueue_script('cgmp-jquery-tools-tooltip', CGMP_PLUGIN_JS .'/jquery.tools.tooltip.min.js', array('jquery'), '1.2.5.a', true);
$minified = ".min";
if (in_array($_SERVER['HTTP_HOST'], $whitelist)) {
	$minified = "";
}
wp_enqueue_script('cgmp-jquery-tokeninput', CGMP_PLUGIN_JS. '/cgmp.tokeninput'.$minified.'.js', array('jquery'), CGMP_VERSION, true);
wp_enqueue_script('comprehensive-google-map-plugin', CGMP_PLUGIN_JS. '/cgmp.admin'.$minified.'.js', array('jquery'), CGMP_VERSION, true);
}

And the entire function should now look like this:

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
if ( !function_exists('cgmp_google_map_admin_add_script') ):
		function cgmp_google_map_admin_add_script()  {
 
				$whitelist = array('localhost', '127.0.0.1', 'initbinder.com');
 
				$thisadminpage = $_REQUEST['page'];
 
              	if($thisadminpage=="cgmp-documentation"||$thisadminpage=="cgmp-shortcodebuilder"||$thisadminpage=="cgmp-settings"){
				wp_enqueue_script('cgmp-jquery-tools-tooltip', CGMP_PLUGIN_JS .'/jquery.tools.tooltip.min.js', array('jquery'), '1.2.5.a', true);
				$minified = ".min";
				if (in_array($_SERVER['HTTP_HOST'], $whitelist)) {
					$minified = "";
				}
				wp_enqueue_script('cgmp-jquery-tokeninput', CGMP_PLUGIN_JS. '/cgmp.tokeninput'.$minified.'.js', array('jquery'), CGMP_VERSION, true);
				wp_enqueue_script('comprehensive-google-map-plugin', CGMP_PLUGIN_JS. '/cgmp.admin'.$minified.'.js', array('jquery'), CGMP_VERSION, true);
				}
		}
endif;

With this change in place the plugin will now check to make sure you are on one of its three admin pages before loading its scripts. As a result, the scripts will no longer load in the ThemeStarta section and you’ll be able to happily use both plugins together.

Bear in mind that if / when you update the CGMP plugin to a future version it will overwrite this change, so you will have to make the adjustments again.