Support » Plugin: Theme My Login » Get custom TML fields to show up on front end Buddypress profile

  • Naomi

    (@livingcminca)


    I followed instructions here: https://www.jfarthing.com/development/theme-my-login/adding-extra-registration-fields/

    and copied register-form.php to my current theme’s directory and added this code:

    <p>
    	<label for="first_name<?php $template->the_instance(); ?>"><?php _e( 'First name', 'theme-my-login' ) ?></label>
    	<input type="text" name="first_name" id="first_name<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'first_name' ); ?>" size="20" tabindex="20" />
    </p>
    <p>
    	<label for="last_name<?php $template->the_instance(); ?>"><?php _e( 'Last name', 'theme-my-login' ) ?></label>
    	<input type="text" name="last_name" id="last_name<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'last_name' ); ?>" size="20" tabindex="20" />
    </p>
    <p>
    	<label for="city<?php $template->the_instance(); ?>"><?php _e( 'City', 'theme-my-login' ) ?></label>
    	<input type="text" name="city" id="first_name<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'city' ); ?>" size="20" tabindex="20" />
    </p>
    <p>
    	<label for="state<?php $template->the_instance(); ?>"><?php _e( 'State', 'theme-my-login' ) ?></label>
    	<input type="text" name="state" id="state<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'state' ); ?>" size="20" tabindex="20" />
    </p>
    <p>
    	<label for="reason_for_join<?php $template->the_instance(); ?>"><?php _e( 'Reason for joining CME', 'theme-my-login' ) ?></label>
    	<input type="text" name="reason_for_join" id="first_name<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'reason_for_join' ); ?>" size="20" tabindex="20" />
    </p>

    Then I added the following code to theme-my-login-custom.php in my plugins folder

    <?php
    function tml_registration_errors( $errors ) {
    	if ( empty( $_POST['first_name'] ) )
    		$errors->add( 'empty_first_name', '<strong>ERROR</strong>: Please enter your first name.' );
    	if ( empty( $_POST['last_name'] ) )
    		$errors->add( 'empty_last_name', '<strong>ERROR</strong>: Please enter your last name.' );
    
    if ( empty( $_POST['city'] ) )
    		$errors->add( 'empty_city', '<strong>ERROR</strong>: Please enter your city.' );
    if ( empty( $_POST['state'] ) )
    		$errors->add( 'empty_state', '<strong>ERROR</strong>: Please enter your state.' );
    if ( empty( $_POST['reason_for_join'] ) )
    		$errors->add( 'empty_reason_for_join', '<strong>ERROR</strong>: Please enter your reason for joining CME.' );
    return $errors;
    }
    add_filter( 'registration_errors', 'tml_registration_errors' );
    
    function tml_user_register( $user_id ) {
    	if ( !empty( $_POST['first_name'] ) )
    		update_user_meta( $user_id, 'first_name', $_POST['first_name'] );
    	if ( !empty( $_POST['last_name'] ) )
    		update_user_meta( $user_id, 'last_name', $_POST['last_name'] );
    
    if ( !empty( $_POST['city'] ) )
    		update_user_meta( $user_id, 'city', $_POST['city'] );
    
    if ( !empty( $_POST['state'] ) )
    		update_user_meta( $user_id, 'state', $_POST['state'] );
    
    if ( !empty( $_POST['reason_for_join'] ) )
    		update_user_meta( $user_id, 'reason_for_join', $_POST['reason_for_join'] );
    }
    add_action( 'user_register', 'tml_user_register' );
    
    function tml_edit_user_profile( $profileuser ) {
    	?>
    	<p>
    		<label for="first_name">First Name</label>
    		<input id="first_name" type="text" name="first_name" value="<?php echo $profileuser->first_name; ?>" />
    	</p>
    
    <p>
    		<label for="last_name">Last Name</label>
    		<input id="last_name" type="text" name="last_name" value="<?php echo $profileuser->last_name; ?>" />
    	</p>
    
    <p>
    		<label for="city">City</label>
    		<input id="city" type="text" name="city" value="<?php echo $profileuser->city; ?>" />
    	</p>
    
    <p>
    		<label for="state">State</label>
    		<input id="state" type="text" name="state" value="<?php echo $profileuser->state; ?>" />
    	</p>
    
    <p>
    		<label for="reason_for_join">Reason for joining CME</label>
    		<input id="reason_for_join" type="text" name="reason_for_join" value="<?php echo $profileuser->reason_for_join; ?>" />
    	</p>
    
    	<?php
    }
    add_action( 'edit_user_profile', 'tml_edit_user_profile' );
    ?>

    It is working to the point where I can see the added fields from the backend dashboard, but I’d like to add them to the front-end Buddypress profile so all registered members can see the info there. Is that possible?

    https://wordpress.org/plugins/theme-my-login/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Get custom TML fields to show up on front end Buddypress profile’ is closed to new replies.