[Google Maps] Error in Google Maps Pro widget in Elementor

The error is "Uncaught Error: Class 'AgmDependencies' not found in /var/www/html/wp-content/plugins/wpmu_dev_maps_plugin/inc/class-agm-maps-widget.php:166".

It happens not when displaying the page, but when trying to edit with Elementor. The page itself displays the map correctly.
Most pages are custom post types, rendered using a custom Elementor single-post template. Those pages are referring to the map in the template rather than the post content. The template displays the "associated map" for the page
But a separate stand-alone page (no template) does the same thing using the shortcode directly (via Shortcode widget instead of Google Maps widget).
It's not completely consistent: If I deactivate the plugin so I can get into Elementor, I sometimes can then reactivate it and add maps back. But then it goes back to error again on later edits.

  • Adam Czajczyk

    Hello Kenn

    I hope you're well today and thank you for your question!

    I'm not sure if I correctly understand the case so I'd like to ask you some questions first to get a better picture of the case:

    1. In a "typical case" you would be adding a map shortcode in Elementor to its text widget. That renders the shortcode itself when in Elmentor editor but displays map properly on front-end. The same should be happening if using "shortcode" Elementor widget. You mentioned that it doesn't display map in Elementor editor - do you add and see shortcode there or is it some different way?

    2. You mentioned "map added via template", could you please elaborate on this a bit more?

    3. Are you using Elementor or Elementor Pro?

    Let me know, please, and it would also be great if I could take a closer look at your site so would you enable support access to it for me? To do so, please go to the "WPMU DEV -> Support" page in your site's back-end, click on "Grant support access" button there and let me know here once it's done.

    Let me also know on which page(s) I can see and test this behavior.

    Kind regards,

  • Kenn

    Thanks for your reply. Here are the answers to your questions:

    1. I used the shortcode widget in Elementor. As you said, it showed the shortcode in the editor but displays the map when the page is rendered. The issue is that I can't go BACK into the editor. It spits out the error when I try. I have to deactivate the plugin in order to get back in. Then, I see the shortcode as expected.

    2. "Via template" is where the map widget is not in the post content itself. It is in the custom "single post" template that is displaying that post. I want the maps for all posts of this custom type to display consistently, so I am having the template control the location of the widget. All posts have an associated map for the template to find.

    3. I am using Elementor Pro.

    I will try to get the support access for you later today. Thanks!

  • Kenn

    You have the Support Access now.

    If it's a clue, this behavior seems inconsistent. Sometimes I can deactivate the plugin, remove the map, reactivate the plugin, re-add the map, and it seems to work correctly...for a while. But I come back into the same page later, and the editor won't open. Sometimes the template (using the widget) seems broken while the About Us page (using the shortcode) is OK...then sometimes it's the reverse. I *think* it is staying OK until *something* sets it off, then it won't correct while the plugin is active. But I haven't been able to pin down the exact sequence to recreate the problem consistently.

    For your testing, the About Us page and the House-for-Sale template (associated with Home for Sale CPT) are good examples. Just now when I tried, the page worked and the template did not. Both are showing the maps correctly on the site. I will avoid working on those areas so they are stable for you to test.

  • Adam Czajczyk

    HI Kenn

    Thank you for getting back to me with additional explanations. However, I must say I'm still not sure what might be happening there.

    I accessed your site and tried to edit these templates and "about us" page and even one of the Houses for Sale (I didn't make any changes there, just tried to use Elementor) and didn't encounter any issues. I watched browser console while doing that to check for possible errors but there was none either. I wasn't able to trigger any issue on my test setup as well.

    I'm wondering though about that "random factor" - as you explained this is "sometimes working, sometimes not" and while one template might be working at the moment, the other might be breaking and opposite. This suggests something additional involved but to start with the simplest (even though that seems strange) things: did you try that with different browsers and if you do have any browser add-ons enabled, did you try to disable them?

    I'm just trying to rule out possible options... :wink:

    Best regards,

  • Kenn

    That gave me an idea: I cleared cookies for that site and tried again. (I've had cookies crumble before :slight_smile: by keeping browsers going in several of the .kmde.us sites at once.)

    After that, all three pages/templates opened in Elementor correctly, for a few seconds. I exited with no changes between the three tests. Then I went back into About Us, faked a change (added a space to the text box, then removed it), hit Update. So far, so good, but... THEN I tried to edit the Houses template again, and it blew up.

    Why would saving the About Us page cause the Houses template to break? The Neighborhood template is still working. So is About Us.

    I wanted to repeat the test so I cleared cookies again. This time, it stayed broken. I cleared cache also, no difference.

    If you repeat the sequence of a fake change to About Us, does it make a difference in your environment?

  • Adam Czajczyk

    Hi Kenn

    Thanks for that testing.

    I checked your site again and... I was able to see the issue finally. Furthermore, I think I might have made a mistake when testing before because I assumed that all the templates are using the map in the same way. Although, we both missed something as well: apparently the map is not used the same way everywhere :slight_smile:

    The "About Us" page has a shortcode explicitly added via Elementor's "shortcode" widget. The "Neighborhood" template as well. The same is with "Neighborhood - Houses for Sale" but not with "House for Sale" template.

    That last one is using a GoogleMap widget. There's an Elementor native "Google Map" widget but also in "WordPress" section there's another "GoogleMap" widget that actually comes from the Google Maps Pro plugin. If that widget is used the Elementor editor doesn't load and the error is returned. I was able to replicate that on my own setup, getting the same error (though a bit different behavior of site which, I assume, depends on the theme).

    As I mentioned before, in Elementor the map should only be added using shortcode but in case of this template it's not, it's a widget. I think that after removing the GoogleMap widget and placing "shortcode" widget with Google Map shortcode instead - it should start working fine.

    One thing that bothers me a bit with this all is why this also randomly affects other templates and/or page(s) - that I couldn't replicate on my own setup - but my setup is much simpler than yours and I tested with different theme and on a different server. I'm wondering whether either internal Elementor's caching or some cache on the server (if any) might interfere here. Anyway - I think you should review your pages and templates and make sure that none of them is using GoogleMap widget but instead they use plain shortcode and then, after that, clear all caches and see if that error occurs ever again.

    Keep me updated, please.

    Kind regards,

  • Kenn

    I may have a problem with that: The templates don't know exactly which map to show. They are using the map associated with the post. Can the straight shortcode do that?

    I tried "query=current" but that shows all maps. I need just the one for the post currently being displayed.

    I thought about giving each post an individual tag, but it hits the same problem: How to tell the shortcode which tag to display?

    Is there an option "query=associated"? I don't see that in the documentation.

  • Kenn

    Also, I just double-checked the Neighborhood template. It *is* using the Google Maps widget, not the shortcode. See the third column over in the top section.

    It's misleading because you can see [map id="1"] when editing the template. But that is coming from the Post Content widget in the next section. Elementor seems to show almost random data in the template when there is no real post available. I think it must be leftover from whatever content it saw last.

  • Adam Czajczyk

    Hi Kenn

    The widget and the shortcode - they are using the same "attributes". If there's a widget, what options are set for it? Is it set to use "current posts"?

    The idea with the tag might actually be quite good. The shortcode that you could use would be like that:

    [map query=”tag=my_tag” ]

    But I do see the issue with templates then. Using it like that in template wouldn't let you use "dynamic" tag - whatever tag you'd put in a shortocode, that tag would be used. I'm not that familiar with Elementor's templates but what about actually building a "real template? I mean - a custom template file that could then be "re-used" in your Elementor templates? That could do the trick because in a template file you could actually use php to dynamically retrieve tags for the current post.

    For example: you could assume that it's always the first or the last tag or you could use specific tag structure like "post-map-1", "post-map-2" etc and detect this. Then this could be called with WP core "do_shortcode()" function.

    As for your second post. I would like to take yet another look at this but it seems that the support access to the site has expired. Could you enable it again for me and let me know once it's done?

    Best regards,

  • Adam Czajczyk

    Hi Kenn

    Thanks for re-enabling access. You're right, I missed that widget there.

    And I must admit I feel quite "stumped" now. I just realized that this sort of took as back to the beginning where you state that the issues is intermittent - it sometimes happens, sometimes not, sometimes on a template and sometimes on a page.

    I did more tests on my own setup and, surprisingly for me, I was now able to edit both pages and templates each time, regardless whether I used the widget or shortocode - unlike with previous tests where it was always like "shortcode = working" and "widget = not working". That's strange because I used the same setup with the same configuration, I don't have any cache on site and server so basically it was the very same environment as previously.

    I'm utterly confused, I must say :slight_frown:

    It seems to be working on your site now for me too, each time. I just tried all the templates, some multiple times and the About Us page and didn't encounter the issue again a single time. I'm wondering what might have changed since my last post - something that could affect both our setups. Or did I just got lucky? I apologize that it's taking that long and I we didn't get anywhere yet. I think I need some more testing on my end and with a little help of my colleagues (sometimes it takes a fresh pair of eyes to spot something quite obvious that's just "hidden in a plain sight" ).

    If you got any reflections or remarks (or maybe you have noticed something new meanwhile) I'd also appreciate every, even remotely related, ideas :wink:

    Best regards,

  • Kenn

    I'm afraid you saw it working on my site because I had removed the map widget from the House for Sale template. It was showing no map at all. When I added the widget back just now, the problem came back. :slight_frown:

    The Neighborhood template is still working, with the widget. About Us is working but with the shortcode. It's easier to use the shortcode on that page, since it doesn't need to variable in the same way the templates do.

    I even completely deleted and re-built the House template last night, in case the template itself was corrupt in some way I couldn't see. It didn't help, the problem came right back.

    Now I'm wondering if something could be different between the underlying House posts vs the Neighborhood posts. But they are both defined in pretty much the same way, using Custompress and a few custom fields.

    My next thought to try this weekend is some custom coding. I might be able to write my own shortcode (in Code Snippets to start with, a full custom plugin maybe in the future). It would retrieve the associated map ID from the post, the feed into a do_shortcode of the map: [map id=myvariableID]. For that, how would I retrieve the ID? Is it in a custom meta that I could get with wp_query?

  • Kenn

    A couple more thoughts...

    Other widgets in the Elementor editor have a pencil/edit icon in the upper right corner. This widget does not. That is true even for the Neighborhood template that is working. Maybe there's something that makes a widget acceptable to Elementor that is just slightly off?

    The error is "Class 'AgmDependencies' not found" by "class-agm-maps-widget.php:166". I can see that class clearly defined in file "class-agm-dependencies.php" BUT it is in a conditional statement "if ( ! is_admin() )". I can understand the Elementor editor being considered an Admin back-end page. But in that case, why would it EVER work? (I have done very little to trace thru the programs, so I'm probably overlooking something obvious.)

    Thanks for your work on this!

  • Adam Czajczyk

    Hi Kenn

    I actually was checking all your templates and the about us page so they all worked for me this time regardless whether there was a widget or a shortocde. I was also testing that on my end. It's inconsistent and I think you're most likely on a right path with the

    if ( ! is_admin() )

    check finding. But I'm not sure how the Elementor works codewise. It "looks like" fired up on front-end but might not necessarily be. That would explain that as the "is_admin()" function checks exactly this: if it's back-end or not.

    However, I was thinking about that entire issue a bit more today and and I spent great deal of time doing various tests and I just noticed something more. You mentioned fetching associated maps with your own shortcode - but I'm not quite sure how you are actually making such association on your site. I mean, I didn't find any custom fields related or any Google Maps plugin add-ons related to this to be enabled on your site. The only thing that seems to be there are just maps that must have been created manually.

    Therefore, I assume you're just creating a map (e.g. drop a marker on a map) and check the "Associate map with this post" check box there, is this correct?

    If so, it would actually be possible to do the "custom shortcode way". In a shortcode you do know the current post ID as it's used in a loop. Knowing that post ID you can find associated maps. It's not that straight forward but doable.

    What you'd need would be to do a search on a "wp_agm_maps" table in the database (note please: the prefix might be different on your setup). That would basically be a SELECT query on the "post_ids" column with a WHERE conditions set to

    LIKE '%"123";%'

    where 123 is your post ID. Still, that would return all the maps associated with the post, just like existing shortcode with "current" query attribute does. So you'd need to add LIMIT and ORDER BY to your db query to fetch just one, most recent map.

    I'm thinking something like this should do the trick:

    SELECT id FROM wp_agm_maps WHERE post_ids LIKE LIKE '%"123";%' ORDER BY id DESC LIMIT 1

    I haven't tested it and since it's a "pure" query you'd need to actually adjust it to follow WP db query convention (prefix, sanitization) but I think you got the idea.

    Having that "id" fetched that way you could then easily put it as a map id parameter in a shortcode for "do_shortcode()".

    Best regards,

  • Kenn

    I only have one map associated with each specific post (the location of the house that is for sale). I put shortcode [map query="current"] into the template, hoping that would translate to "current post being displayed". Instead, it apparently thinks "all posts of this type", since the template isn't on a specific post at the time it is being edited. Oh, well...

    I'll try the custom approach and see what I can come up with. Thanks for telling me about the custom table. I'll start there. Wish me luck! :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.