Hey Demonslay,
We caught that too! Thanks for your help. Release coming soon with the fix.
Awesome, thanks for the quick reply. I look forward for that release. π
I got that error too. Any idea when that fix will be released? Holding up my launch at the moment.
Hey Nimeck – can you reference the fix above?
I tried, but I don’t think I did it write. Here is what I entered:
//loop through registered scripts
foreach ( $wp_scripts->registered as $registered_script ) {
if(is_null($wp_scripts) || is_null($wp_scripts->registered)){
return $multiple_google_maps_api;
}
//find any that have the google script as the source, ensure it's not enqueud by this plugin
if ( strpos( $registered_script->src, 'maps.googleapis.com/maps/api/js' ) !== false && strpos( $registered_script->handle, 'google-maps-builder' ) === false ) {
$multiple_google_maps_api = true;
//ensure we can detect scripts on the frontend from backend; we'll use an option to do this
if ( ! is_admin() ) {
update_option( 'gmb_google_maps_conflict', true );
}
}
}
Yeah that won’t work. Can you email us at support(at) wordimpress.com and we’ll send you the updated file?
nimeck,
My proposed patch would look as follows:
if(is_null($wp_scripts) || is_null($wp_scripts->registered)){
return $multiple_google_maps_api;
}
//loop through registered scripts
foreach ( $wp_scripts->registered as $registered_script ) {
// Loop code...
}
Note that the code I suggested goes before the loop, to prevent the loop from crashing if the variable is NULL unexpectedly.
Thanks guys! I’ve got it working now.
I got the same error….
where exactly i have to pot that code ?….
in what file .php ? function.php ???
please help
Warning: Invalid argument supplied for foreach() in /home/graziano1975/public_html/viveremaiorca.it/wp-content/plugins/google-maps-builder/public/class-wordpress-google-maps.php on line 537
grazianochiappa,
The error actually tells you exactly which file the error occurs in. You can either use FTP and edit the file remotely, or use the WordPress admin panel to edit the file.
The file in question is class-wordpress-google-maps.php, the full path is in the warning itself.
Done, it works
http://www.viveremaiorca.it
now please
like and share ! :-))
thank you
Demonslay335
Thank you so much. I do not know much English so I apologize for spelling errors.
I am a beginner using wordpress and my knowledge of English is not enough, however, intuitively followed your advice and it works !!
Thank you so much again.
I have made the update to this file class-wordpress-google-maps.php in the path given by the warning msg. See http://www.nrfhideout.com. Message text is “Warning: Invalid argument supplied for foreach() in /home1/ambruck/public_html/wp-content/plugins/google-maps-builder/public/class-wordpress-google-maps.php on line 537”. Doesn’t fix the problem. Function is copied in here:
public function check_for_multiple_google_maps_api_calls() {
global $wp_scripts;
$multiple_google_maps_api = false;
if(is_null($wp_scripts) || is_null($wp_scripts->registered)){
return $multiple_google_maps_api;
}
//loop through registered scripts
foreach ( $wp_scripts->registered as $registered_script ) {
//find any that have the google script as the source, ensure it’s not enqueud by this plugin
if ( strpos( $registered_script->src, ‘maps.googleapis.com/maps/api/js’ ) !== false && strpos( $registered_script->handle, ‘google-maps-builder’ ) === false ) {
$multiple_google_maps_api = true;
//ensure we can detect scripts on the frontend from backend; we’ll use an option to do this
if ( ! is_admin() ) {
update_option( ‘gmb_google_maps_conflict’, true );
}
}
}
//Ensure that if user resolved conflict on frontend we remove the option flag
if ( $multiple_google_maps_api === false && ! is_admin() ) {
update_option( ‘gmb_google_maps_conflict’, false );
}
//returns boolean
return $multiple_google_maps_api;
}
ambruck,
Please be sure that you have edited the correct file. It looks like, from the line number, it may have not taken your change properly. The line number for the error stayed the same (537) even with the addition of code, which should have pushed the afflicted line down.
Here is what the whole function should look like.
/**
* Load Google Maps API
*
* @description: Determine if Google Maps API script has already been loaded
* @since : 1.0.3
* @return bool $multiple_google_maps_api
*/
public function check_for_multiple_google_maps_api_calls() {
global $wp_scripts;
$multiple_google_maps_api = false;
/**
* Prevent crashes for guests
* @link https://wordpress.org/support/topic/invalid-argument-25
*/
if(is_null($wp_scripts) || is_null($wp_scripts->registered)){
return $multiple_google_maps_api;
}
//loop through registered scripts
foreach ( $wp_scripts->registered as $registered_script ) {
//find any that have the google script as the source, ensure it's not enqueud by this plugin
if ( strpos( $registered_script->src, 'maps.googleapis.com/maps/api/js' ) !== false && strpos( $registered_script->handle, 'google-maps-builder' ) === false ) {
$multiple_google_maps_api = true;
//ensure we can detect scripts on the frontend from backend; we'll use an option to do this
if ( ! is_admin() ) {
update_option( 'gmb_google_maps_conflict', true );
}
}
}
//Ensure that if user resolved conflict on frontend we remove the option flag
if ( $multiple_google_maps_api === false && ! is_admin() ) {
update_option( 'gmb_google_maps_conflict', false );
}
//returns boolean
return $multiple_google_maps_api;
}
If you continue to have issues, I can send you the file.
Thanks so much, the old pages must still have been cached (I’m using WP Super Cache), because today the message has disappeared!
All seems to work now π