Home Forums Plugin Support WP User Frontend Pro Pronamic Google Maps action hook

This topic is: resolved

This topic contains 6 replies, has 3 voices, and was last updated by  onafets 5 years, 8 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #2517

    Post count: 17

    Dear Tarek,

    Thank you for this pro version. I used the free one since a year and it was very useful. Currently I'm working on a migration between WP User Frontend free version to the pro version since yesterday.

    I discovered that your Google Maps field in the form generator does not saves the address field, it only saves the lat/long data. Which is a problem since I used both.

    I tried to add an action hook in the form (name: ‘wpuf_pronamic_location'). The functions below worked well with the free version. With the pro version the additional fields are displayed in the form, but the custom fields are not saved. Could you please have a look and help me?

    Thanks a lot!
    //////// PRONAMIC GOOGLE MAPS IN FRONT END //////////

    add_action(‘wpuf_pronamic_location', ‘wpuf_pronamic_location', 10, 3 );

    function wpuf_pronamic_location( $post_id ) {

    print_r(pronamic_get_google_maps_meta()); // delete to hide data checking

    $pgm_map_type = ( $post != null ) ? get_post_meta( $post_id, ‘_pronamic_google_maps_map_type', true ) : ”;
    $pgm_zoom = ( $post != null ) ? get_post_meta( $post_id, ‘_pronamic_google_maps_zoom', true ) : ”;
    $pgm_address = ( $post != null ) ? get_post_meta( $post_id, ‘_pronamic_google_maps_address', true ) : ”;
    $pgm_latitude = ( $post != null ) ? get_post_meta( $post_id, ‘_pronamic_google_maps_latitude', true ) : ”;
    $pgm_longitude = ( $post != null ) ? get_post_meta( $post_id, ‘_pronamic_google_maps_longitude', true ) : ”;

    wp_nonce_field(‘save-post', Pronamic_Google_Maps_Maps::NONCE_NAME);

    <div id=”pronamic-google-maps-meta-box”>
    <li><input id=”pgm-map-type-field” type=”hidden” name=”<?php echo Pronamic_Google_Maps_Post::META_KEY_MAP_TYPE; ?>” value=”<?php echo esc_attr( $pgm_map_type ); ?>” />
    <input id=”pgm-zoom-field” type=”hidden” name=”<?php echo Pronamic_Google_Maps_Post::META_KEY_ZOOM; ?>” value=”<?php echo esc_attr( $pgm_zoom ); ?>” />
    <input id=”pgm-active-field” type=”hidden” name=”<?php echo Pronamic_Google_Maps_Post::META_KEY_ACTIVE; ?>” value=”true” /><label for=”pgm-address-field”>Address <span class=”required”>*</span></label>
    <textarea class=”requiredField” id=”pgm-address-field” cols=”40″ name=”<?php echo Pronamic_Google_Maps_Post::META_KEY_ADDRESS; ?>” rows=”2″><?php echo esc_attr( $pgm_address ); ?></textarea>
    <p class=”description”>Please type the address then click on “Geocode ↓” to show the location on the map.</p>
    <p class=”description”>Or you can drag the marker on the map then click on “Reverse Geocode ↑” to update the address.</p>
    <li><input class=”button” id=”pgm-geocode-button” type=”button” name=”pgm_geocode” value=”<?php _e(‘Geocode ↓', ‘pronamic_google_maps'); ?>” /><input class=”button” id=”pgm-reverse-geocode-button” type=”button” name=”pgm_reverse_geocode” value=”<?php echo _e(‘Reverse Geocode ↑', ‘pronamic_google_maps'); ?>” /></li>
    <li><label for=”pgm-lat-field”>Latitude</label>
    <input id=”pgm-lat-field” style=”width: 200px;” type=”text” name=”<?php echo Pronamic_Google_Maps_Post::META_KEY_LATITUDE; ?>” value=”<?php echo esc_attr($pgm_latitude); ?>” />
    <li><label for=”pgm-lng-field”>Longitude</label>
    <input id=”pgm-lng-field” style=”width: 200px;” type=”text” name=”<?php echo Pronamic_Google_Maps_Post::META_KEY_LONGITUDE; ?>” value=”<?php echo esc_attr($pgm_longitude); ?>” />
    <li><label for=”pgm-canvas”>Location result</label>
    <div id=”pgm-canvas” style=”width: 600px; height: 350px; margin-left: 140px; border: 1px solid white;”></div>
    <p class=”description”>Tip: Change the zoom level and map type to your own wishes.</p>
    <!–?php </p–>


    * Add the gg maps data after creation/edition
    * *
    * @param int $post_id the post id
    function wpufe_add_anecdote_gmaps( $post_id ) {

    update_post_meta( $post_id, ‘_pronamic_google_maps_map_type', $_POST[‘_pronamic_google_maps_map_type'] );
    update_post_meta( $post_id, ‘_pronamic_google_maps_zoom', $_POST[‘_pronamic_google_maps_zoom'] );
    update_post_meta( $post_id, ‘_pronamic_google_maps_active', $_POST[‘_pronamic_google_maps_active'] );
    update_post_meta( $post_id, ‘_pronamic_google_maps_address', $_POST[‘_pronamic_google_maps_address'] );
    update_post_meta( $post_id, ‘_pronamic_google_maps_latitude', $_POST[‘_pronamic_google_maps_latitude'] );
    update_post_meta( $post_id, ‘_pronamic_google_maps_longitude', $_POST[‘_pronamic_google_maps_longitude'] );

    add_action( ‘wpuf_add_post_after_insert', ‘wpufe_add_anecdote_gmaps' );
    add_action( ‘wpuf_edit_post_after_update', ‘wpufe_add_anecdote_gmaps' );


    Tareq Hasan
    Post count: 2831

    Hello Jeremy, take a look at the plugin integration I did for pronamic. The name of that address finder field is “address”, so adding this `update_post_meta( $post_id, ‘address', $_POST[‘address'] );` to that code (mine) should save the address. So the map custom field meta key should be not “address”, otherwise it won't work.


    Post count: 17

    But this code is for saving the data on the new posts.

    My other concern is that your Google Maps box will not display the pronamic data input in the previously created posts and I can't get that through your address finder. Also I need to use some advanced functions of Pronamic GG Maps like the geocode/reverse geocode buttons.The data is saved (I can see it in the back end form) but it is not displayed on the front end form when you reload it. Is there a problem with the get_post_meta() functions here?Thanks a lot for your help, I'm really stuck with this.


    Tareq Hasan
    Post count: 2831

    I think you can use the code from your first post. You've a small problem in the function argument. Change the function parameter: `function wpuf_pronamic_location( $form_id, $post_id ) {`. The `$post_id` will be the second parameter.


    Post count: 17

    It's working like a charm. Thank you so much for your time Tareq. Apparently I was not careful enough when I read your developer documentation.


    Tareq Hasan
    Post count: 2831

    Cool 😀


    Post count: 30


    can you please share the whole snippet?
    thank you in advance

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Pronamic Google Maps action hook’ is closed to new replies.