WordPress 更新用户元前端配置文件
WordPress Update User Meta Front End Profiles
我创建了一个插件来创建用户个人资料页面。在此用户能够通过表单更新自定义元信息。这是我的功能:
// Function to edit User Meta
function personalfragebogen_konto_bearbeiten() {
global $current_user;
// Get User Meta
$strasse = get_user_meta( $current_user->ID, '_strasse', true);
// Create Form
<form name="personalfragebogen" action="" method="POST">
<span class="full" >
<span class="two_fifth first">
<h3><?php _e( 'Straße:', 'themesdojo' ); ?></h3>
</span>
<span class="three_fifth">
<input type="text" name="strasse" id="strasse" value="<?php echo $strasse; ?>" class="input-textarea"/>
</span>
</span>
<button type="submit">Speichern</button>
</form>
// Get New User Meta
$strasse = $_POST['strasse'];
// Update/Create User Meta
update_user_meta( $current_user->ID, '_strasse', $strasse);
// Add Hook
add_action( 'personalfragebogen_init', 'personalfragebogen_konto_bearbeiten');
function personalfragebogen_init() {
do_action('personalfragebogen_init');
}
一切正常,除了一件事。当我提交表单时,数据将保存到数据库并且页面会刷新。但是现在在我刷新的页面上,表单是空的。再次刷新页面时会显示数据。这有什么问题吗?
提前致谢!
像这样的东西可以工作...
<?php
// Function to edit User Meta
function personalfragebogen_konto_bearbeiten() {
global $current_user;
// Get New User Meta
if(isset($_POST['strasse'])) {
$strasse = $_POST['strasse'];
// Update/Create User Meta
update_user_meta( $current_user->ID, '_strasse', $strasse);
else {
// Get User Meta
$strasse = get_user_meta( $current_user->ID, '_strasse', true);
}
?>
<form name="personalfragebogen" action="" method="POST">
<span class="full" >
<span class="two_fifth first">
<h3><?php _e( 'Straße:', 'themesdojo' ); ?></h3>
</span>
<span class="three_fifth">
<input type="text" name="strasse" id="strasse" value="<?php echo $strasse; ?>" class="input-textarea"/>
</span>
</span>
<button type="submit">Speichern</button>
</form>
<?php
}
// Add Hook
add_action( 'personalfragebogen_init', 'personalfragebogen_konto_bearbeiten');
function personalfragebogen_init() {
do_action('personalfragebogen_init');
}
我创建了一个插件来创建用户个人资料页面。在此用户能够通过表单更新自定义元信息。这是我的功能:
// Function to edit User Meta
function personalfragebogen_konto_bearbeiten() {
global $current_user;
// Get User Meta
$strasse = get_user_meta( $current_user->ID, '_strasse', true);
// Create Form
<form name="personalfragebogen" action="" method="POST">
<span class="full" >
<span class="two_fifth first">
<h3><?php _e( 'Straße:', 'themesdojo' ); ?></h3>
</span>
<span class="three_fifth">
<input type="text" name="strasse" id="strasse" value="<?php echo $strasse; ?>" class="input-textarea"/>
</span>
</span>
<button type="submit">Speichern</button>
</form>
// Get New User Meta
$strasse = $_POST['strasse'];
// Update/Create User Meta
update_user_meta( $current_user->ID, '_strasse', $strasse);
// Add Hook
add_action( 'personalfragebogen_init', 'personalfragebogen_konto_bearbeiten');
function personalfragebogen_init() {
do_action('personalfragebogen_init');
}
一切正常,除了一件事。当我提交表单时,数据将保存到数据库并且页面会刷新。但是现在在我刷新的页面上,表单是空的。再次刷新页面时会显示数据。这有什么问题吗?
提前致谢!
像这样的东西可以工作...
<?php
// Function to edit User Meta
function personalfragebogen_konto_bearbeiten() {
global $current_user;
// Get New User Meta
if(isset($_POST['strasse'])) {
$strasse = $_POST['strasse'];
// Update/Create User Meta
update_user_meta( $current_user->ID, '_strasse', $strasse);
else {
// Get User Meta
$strasse = get_user_meta( $current_user->ID, '_strasse', true);
}
?>
<form name="personalfragebogen" action="" method="POST">
<span class="full" >
<span class="two_fifth first">
<h3><?php _e( 'Straße:', 'themesdojo' ); ?></h3>
</span>
<span class="three_fifth">
<input type="text" name="strasse" id="strasse" value="<?php echo $strasse; ?>" class="input-textarea"/>
</span>
</span>
<button type="submit">Speichern</button>
</form>
<?php
}
// Add Hook
add_action( 'personalfragebogen_init', 'personalfragebogen_konto_bearbeiten');
function personalfragebogen_init() {
do_action('personalfragebogen_init');
}