class ZT_Usermeta
{
	
	function __construct()
	{
		$this->zt_users_hooks();
	}

	/*
	 * This fucntion is used for displaying custom usermeta into users.php in 
	 * backend. 
	 */
	function zt_usermeta_display($user){
		$userData = get_user_meta($user->ID , 'referat', true); //get usermeta named referat

		//HTML for displying meta fields
		echo "<h3>Custom Users Fields</h3>";
		echo '<table class="form-table"><tbody><tr class="user-referat-wrap"><th><label for="description">Referat</label></th><td><input name="referat" type="text" id="referat" class="regular-text code" value="' . $userData . '" ></td></tr></tbody></table>';
	}

	/*
	 * This fucntion is used for saving/updating custom usermeta of users.php in 
	 * backend. 
	 */
	function zt_usermeta_save($user_id) {
		update_user_meta( $user_id, 'referat', $_POST['referat'] ); 
	}

	/*
	 * This function collects all hooks that uses into functions 
	 */
	function zt_users_hooks(){
		add_action('show_user_profile', array($this, 'zt_usermeta_display'));
		add_action('edit_user_profile', array($this, 'zt_usermeta_display'));
		add_action('personal_options_update', array($this, 'zt_usermeta_save'));
		add_action('edit_user_profile_update', array($this, 'zt_usermeta_save'));

	}
}
new ZT_Usermeta;