Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ipokkel/134276d1fd5ddf3aa08ee21899352a85 to your computer and use it in GitHub Desktop.
Save ipokkel/134276d1fd5ddf3aa08ee21899352a85 to your computer and use it in GitHub Desktop.
PMPro Register Helper Example to Embed MyGeoPosition.com GeoPicker
function my_pmprorh_init()
{
//don't break if Register Helper is not loaded
if(!function_exists("pmprorh_add_registration_field"))
{
return false;
}
//define the fields
$fields = array();
//save address info to some hidden fields
$fields[] = new PMProRH_Field(
"geo_lat",
"hidden",
array(
'label'=>false,
'divclass'=>'pmpro_hidden',
'memberslistcsv'=>true,
)
);
$fields[] = new PMProRH_Field(
"geo_long",
"hidden",
array(
'label'=>false,
'divclass'=>'pmpro_hidden',
'memberslistcsv'=>true,
)
);
$fields[] = new PMProRH_Field(
"geo_city",
"hidden",
array(
'label'=>false,
'divclass'=>'pmpro_hidden',
'memberslistcsv'=>true,
)
);
$fields[] = new PMProRH_Field(
"geo_address",
"hidden",
array(
'label'=>false,
'divclass'=>'pmpro_hidden',
'memberslistcsv'=>true,
)
);
//the geo picker, not working over https right now
$fields[] = new PMProRH_Field(
"geo", // input name, will also be used as meta key
"html", // type of field
array(
"html" => '
<script src="http://api.mygeoposition.com/api/geopicker/api.js" type="text/javascript"></script>
<script type="text/javascript">
function lookupGeoData() {
myGeoPositionGeoPicker({
startAddress : \'White House, Washington\',
returnFieldMap : {
\'geo_lat\' : \'<LAT>\',
\'geo_long\' : \'<LNG>\',
\'geo_city\' : \'<CITY>\', /* ...or <COUNTRY>, <STATE>, <DISTRICT>,
<CITY>, <SUBURB>, <ZIP>, <STREET>, <STREETNUMBER> */
\'geo_address\' : \'<ADDRESS>\'
}
});
}
</script>
<button type="button" onclick="lookupGeoData();">GeoPicker</button>
',
"profile"=>true,
"required"=>false,
));
//add the fields into a new checkout_boxes are of the checkout page
foreach($fields as $field)
pmprorh_add_registration_field(
"checkout_boxes", // location on checkout page
$field // PMProRH_Field object
);
//that's it. see the PMPro Register Helper readme for more information and examples.
}
add_action("init", "my_pmprorh_init");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment