This topic contains 2 reply and 1 voices, and was last updated by ced 5 years ago
Viewing 2 Posts - 1 through 2 (of 2 total)
Author Posts
October 2, 2014 at 2:28 pm 27895
ced Hi, It could be great to have an example for the action hook in register form. What are the datas diiferents from the post form hook ?
function render_my_awesome_hook( $form_id, $post_id, $form_settings ) {
    $value = '';
  
    if ( $post_id ) {
        $value = get_post_meta( $post_id, 'your_meta_key', true );
    }
    ?>
  
    <div class="wpuf-label">
        <label>A demo field</label>
    </div>
  
    <div class="wpuf-fields">
        <input type="text" name="my_custom_field" value="<?php echo esc_attr( $value ); ?>">
    </div>
    <?php
}
 
add_action( 'my_awesome_hook', 'render_my_awesome_hook', 10, 3 );
function update_my_brand_new_hook( $post_id ) {
    if ( isset( $_POST['my_custom_field'] ) ) {
        update_post_meta( $post_id, 'your_meta_key', $_POST['my_custom_field'] );
    }
}
  
add_action( 'wpuf_add_post_after_insert', 'update_my_brand_new_hook' );
add_action( 'wpuf_edit_post_after_update', 'update_my_brand_new_hook' );
October 3, 2014 at 10:33 am 27942
ced ced

May, we, have, please, a, working, example.
And an answer on this forum ?

October 3, 2014 at 1:10 pm 27945
ced ced

Never mind !

function render_your registrationfield( $user_id, $userdata, $form_id, $form_settings ) {
		$value = '';
		if ( $user_id ) {
			$value = get_user_meta( $user_id, 'YOURFIELD_META', true );
		}
		?>
			<div class="wpuf-label">
				<label>your label<span class="required">*</span></label>
			</div>
			<div class="wpuf-fields">
				your field
			</div>

		<?php
	}
	add_action( 'your registrationfield', 'render_your registrationfield', 10, 3 );
	
	/**
	 * Update the custom field when the form submits
	 *
	 * @param type $post_id
	 */
	function update_your registrationfield( $user_id ) {
		if ( isset( $_POST['YOURFIELD'] ) ) {
			update_user_meta( $user_id, 'YOURFIELD_META', $_POST['YOURFIELD'] );
		}
	}
	add_action( 'wpuf_after_register', 'update_your registrationfield' );
Viewing 2 Posts - 1 through 2 (of 2 total)