• Rhand

    (@rhand)


    I got some code created by a third party developer to grab author_meta from the database and display it on a page when a certain code was entered. What was not done, was the adding of the same custom fields to all user profiles so these details can be adjusted from the backend in user profiles.
    @ https://wpengineer.com/2173/custom-fields-wordpress-user-profile/ I found a relatively easy way to add a custom field and store it. Now I need to add the author meta added in the profile view page to all pages. Here is the profile view viewprofile.php file as created by dev:

    <?php
    		if(empty($_REQUEST['enterCodeId'])){
    
    				echo "<script>
    					location.replace('".$_SERVER['HTTP_REFERER']."');
    					</script>";
    		}else{
    				$getId=substr($_REQUEST['enterCodeId'], 4, 10);
    				$querystr ="SELECT ID FROM wp_7d8ftw_users WHERE ID='".$getId."'";
    				$querystrChecking = mysql_query($querystr);
    				if(mysql_num_rows($querystrChecking)<=0){
    					echo "<script>
    					location.replace('".$_SERVER['HTTP_REFERER']."');
    					</script>";
    				}
    				$uploads = wp_upload_dir();
    			//
    		}
    		?>
    	<?php get_header(); ?>
       	<div id="wrapper2nd" class="inner">
    		<div class="content" id="inner">
    
    		<h1>PROFILE</h1>
    		<div id="profileView">
    			<div class="alignLeft">
    			 <strong> Name:</strong> <?php the_author_meta( 'first_name', $getId ); ?>   <?php the_author_meta( 'last_name', $getId); ?><br />
    			  <strong> Nick Name:</strong> <?php the_author_meta( 'nickname', $getId ); ?><br />
    			  <strong>Age:</strong><?php echo date("Y")-date("Y",get_the_author_meta( 'dateofbirth', $getId ));?><br />
    			  <strong>Birthday: </strong>
    			  <?=date("D M Y",get_the_author_meta( 'dateofbirth', $getId ));?><br />
    			  <strong>Birthplace:</strong>
    			  <?=get_the_author_meta( 'birthplace', $getId );?><br />
    			  <strong>Current City:</strong>
    			  <?=get_the_author_meta( 'currentcity', $getId );?> <br />
    			  <strong>Favourite Colour:</strong>
    			  <?=get_the_author_meta( 'favouritecolour', $getId );?> <br />
    			  <strong>Favourite Book:</strong>
    			  <?=get_the_author_meta( 'favouritebook', $getId );?><br />
    			  <strong>Favourite Film:</strong>
    			  <?=get_the_author_meta( 'favouritefilm', $getId );?><br />
    			  <strong>Favourite Restaurant: </strong>
    			  <?=get_the_author_meta( 'favouriterestaurant', $getId );?><br />
    			  <strong>Favourite Quote:</strong>
    			  <?=get_the_author_meta( 'favouritequote', $getId );?><br />
    			  <strong>Favourite Quality in Women: </strong>
    			  <?=get_the_author_meta( 'favouritequalityinwomen', $getId );?> <br />
    			  <strong>My Favourite TV programs: </strong><br />
    			<?=get_the_author_meta( 'myfavouritetvprograms', $getId );?><br />
    			<strong>My Favourite Groups:</strong><br />
    			<?=get_the_author_meta( 'myfavouritegroups', $getId );?><br />
    			<strong>My Favourite Links:</strong><br />
    			<?=get_the_author_meta( 'myfavouritelinks', $getId );?>
    
    		  </div>
    		  	 <div class="alignRight">
    			 	<div class="left"><i>About Me:</i>
    					<p>	<?=the_author_meta( 'description', $getId); ?></p>
    				</div>
    				<div class="right">
    					<?php if(get_the_author_meta( 'userphoto_thumb_file', $getId )!=""){?>
    						<img src="<?=$uploads['baseurl'];?>/thumbs/<?=get_the_author_meta( 'userphoto_thumb_file', $getId );?>" />
    					<?php }?>
    				<a href="#" class="allpic">see all pictures</a>
    				</div>
    				<div class="clr"></div>
    				<div class="contact"><strong>Contact information:</strong> [email protected]</div>
    			 </div>
    			 <div class="clr"></div>
    		</div>
    		</div>
    	</div>
    
    	 <?php if ( is_active_sidebar('inner')): ?>
    	<div id="wrapper3rd">
          <div id="innerSidebarContent">
    	 <?php dynamic_sidebar( 'inner' ); ?>
    
    	  </div>
        </div>
    	<?php endif; // end sidebar widget area ?>
     <?php get_footer(); ?>

    A visitor that enters the correct code will see this profile

    Can anyone tell me how I can add the same author_meta in profile_view as custom fields to all profile pages so they can be adjusted from the Dashboard under user profiles?

Viewing 1 replies (of 1 total)
  • Thread Starter Rhand

    (@rhand)

    I found some other code at Bavotasan.com that I am working on adjusting:

    // Add Extr profile fields https://bavotasan.com/2009/adding-extra-fields-to-the-wordpress-user-profile/
    
    function extra_user_profile_fields( $user ) { ?>
    <h3><?php _e("Extra profile information", "blank"); ?></h3>
    
    <table class="form-table">
    <tr>
    <th><label for="address"><?php _e("Address"); ?></label></th>
    <td>
    <input type="text" name="address" id="address" value="<?php echo esc_attr( get_the_author_meta( 'address', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter your address."); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="city"><?php _e("Birth Place"); ?></label></th>
    <td>
    <input type="text" name="city" id="city" value="<?php echo esc_attr( get_the_author_meta( 'birthplace', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter your birth place."); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="province"><?php _e("Province"); ?></label></th>
    <td>
    <input type="text" name="province" id="province" value="<?php echo esc_attr( get_the_author_meta( 'province', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter your province."); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="postalcode"><?php _e("Postal Code"); ?></label></th>
    <td>
    <input type="text" name="postalcode" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'postalcode', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter your postal code."); ?></span>
    </td>
    </tr>
    </table>
    <?php }
    
    add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
    add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
    
    function save_extra_user_profile_fields( $user_id ) {
    
    if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
    
    update_user_meta( $user_id, 'address', $_POST['address'] );
    update_user_meta( $user_id, 'city', $_POST['birthplace'] );
    update_user_meta( $user_id, 'province', $_POST['province'] );
    update_user_meta( $user_id, 'postalcode', $_POST['postalcode'] );

    I have been able to retrieve stored data already. I will adjust some more fields and update data in a bit.

Viewing 1 replies (of 1 total)
  • The topic ‘Add extra custom fields to user profiles based on user view’ is closed to new replies.