I mentioned a little bit ago about looking at map plugins for WordPress, as a significant element in a website I’ve been doing some groundwork for, and want to launch several months ago. Realistically, that last part is getting less likely every day, but you never know. If you happen to develop time travel, get in touch.
Anyway, I was trying out the plugin Geo Mashup. I think that actually trying something out (on a local machine) has given me a better sense of what features I actually want, and more of a sense where plugins fall short. Fortunately, Geo Mashup has some flexibilities, in the documentation it gives you sample code to put in your theme to add a feature that has some similarity to a feature that I want to add.
The features I’m very much liking at the moment, are that you can put a map on a post, and limit the number of items that appear there. Then you can have a page with a map that includes the map markers from all the posts you’ve ever done.
What would be a big step forward, would be the ability to assign particular markers to particular places. The documentation mentions the possibility of doing that based on the Category of the location, but what I’m doing, occasionally thing would fit into multiple categories, which suggests things getting messy. The code the documentation points you to, can change the marker based on the date you set for the location, and can be adapted to work with the categories.
So naturally, I want to do better, and I think it ought to be relatively straightforward to create a plugin that lets you assign a map marker to a particular location.
I say “relatively”, compared to making a full plugin that does everything from scratch. It would involve creating two database tables, a page in the admin end to set what you want the marker options to be, and to assign one of those chosen markers to the places you’ve put into the database, and finally to force the chosen markers to be displayed.
I say “ought”, because I haven’t actually made a plugin before. So I’ve been poking around in the Geo Mashup code, to see how it does things.
The most helpful file I found initially, was the “uninstall” file. I’d poked around in the database, and seen the tables that Geo Mashup had already created. In uninstall, I saw how it removed them. More of a challenge was finding where it had added them in the first place. This involved figuring out how to convince Windows to search for file contents, a feature I was happily using in XP, but from Vista on has been very helpfully hidden. Not removed, just made hard to find.
With the help of a brief web search, I found out how to search for file contents, and how to include .php files in that sort of search, and then I believe I found where the tables were created.
Now it gets more complicated, because while there’s an obvious “uninstall”, there’s not an obvious “install”: got quite a bit of figuring out where things are called and how, to follow that procedure to get my own plugin to set itself up.
Then the next challenge is to follow how plugins create their own options pages in the admin area of WordPress, and get that page set up. The contents should be uncomplicated, because I have a concept of what I want displayed and how, but I haven’t even looked at how plugins make their own pages yet.
The last thing will be to force the right markers to display on the map. So if I want red pins for some things, green pins for other things, and purple pins for still other things, and I’ve set them to do that in my plugin, how to stop the default Geo Mashup marker from displaying, and putting these up instead. I’ve a notion of how this works, but it’s a ways off. And at least there’s the sample code, that should give some hints, right?
Code is kind of like a big Cat’s Cradle. One big tangle of string. For it to work, it needs to remain a big tangle of string, but for you to do anything with it, you need to be able to follow it. Not necessarily from beginning to end as such, but what bit’s going where and why, and follow the string through a knot where lots of sections have been tied up together. It’s not always easy to just set down and pick up again.
To switch analogies, have you ever fiddled with the cords in the back of your computer? You need to plug something into the power strip, but all the slots are full, You know you’re not using the printer, so can unplug that for the time being. You follow the cord from the printer to the power strip, and unplug it, only to find you’ve unplugged the monitor or the router instead. Code’s like that, only much more so. One missed comma or semicolon, and things just don’t work right.
I think it’s doable, lots of people have made plugins, much more complicated than I hope to. Just a big string to untangle. Though in the last few years I’ve been learning weaving, there’s quite a few threads I’ve had to untangle, so I’ve had some practice.