Wordpress Geocaching Plugin 3

code

codeHere's my latest report on progress.

I have discovered that it is relatively straightforward to get the plugin to register a new post type called creationcache (my version of a geocache). As shown in a previous article, I can get the page to read straight from a .gpx file. I am currently researching how to make the plugin create its own table in the database, on activation – though I need to work out how to make the plugin delete the table again on deactivation (this should not be too difficult).

It is also fairly straightforward to get information saved into this new table. It is simple to display the information, and I can also create a .gpx file on-the-fly from this information.

However, how does Wordpress manage to recognize this post type, so that saving a creationcache post saves the information into this new table? I know how to do this, if this was my own site from scratch. But what are the special Wordpress functions involved for this process?

Well, here are 2 pieces of my current code that you might find useful. Two functions.

ocws_randomstring creates a random string of any number of letters and numbers, to use as a catalog number. In my case, a fixed prefix is included.

function ocws_randomstring($ocwsl) {
$olength = $ocwsl;
$ostring = “”;
$ocharacters = “ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789”; // change to whatever characters you want
while ($olength > 0) {
$ostring .= $ocharacters[mt_rand(0,strlen($ocharacters)-1)];
$olength -= 1;
}
$ostring = “MHSCC_” . $ostring;

return $ostring;
}

ocws_googlemap displays a Google Map extract, from givebn longitude and latitude, as well as image dimensions.

function ocws_googlemap($olon,$olat,$ow,$oh) {
// this function creates a Google map from inputted longitude and latitude
$html=””;
$html .= “<iframe src=\”https://www.google.com/maps/embed?pb=!1m14!1m12!1m3!1d11020.919125834707!2d”.$olon.”!3d”.$olat.”!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sen!2sus!4v1439768024304\” width=\””.$ow.”\” height=\””.$oh.”\” frameborder=\”0\” style=\”border:0\” allowfullscreen></iframe>”;
return $html;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*