Php WordPress。用于选择显示名称的子服务器前端页面未在后端更新
在我的WordPress v5.5.1中,我有一个前端页面供订阅者仅更改其显示名称。 我使用了这个SE答案()中的代码 我能够获得所需的用户详细信息,但是显示名称字段没有得到更新。 下面是长时间修改的代码和pastebin()Php WordPress。用于选择显示名称的子服务器前端页面未在后端更新,php,wordpress,Php,Wordpress,在我的WordPress v5.5.1中,我有一个前端页面供订阅者仅更改其显示名称。 我使用了这个SE答案()中的代码 我能够获得所需的用户详细信息,但是显示名称字段没有得到更新。 下面是长时间修改的代码和pastebin() <?php /* Get user info. */ global $current_user, $wp_roles; $current_user = wp_get_current_user(); $wp_http_referer = remove_quer
<?php
/* Get user info. */
global $current_user, $wp_roles;
$current_user = wp_get_current_user();
$wp_http_referer = remove_query_arg(array('update', 'delete_count', 'user_id'), $wp_http_referer);
/* Load the registration file. */
$error = array();
/* If profile was saved, update profile. */
if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == 'update-user') {
/* Update user password. */
if (!empty($_POST['pass1']) && !empty($_POST['pass2'])) {
if ($_POST['pass1'] == $_POST['pass2']) {
wp_update_user(array('ID' => $current_user->ID, 'user_pass' => esc_attr($_POST['pass1'])));
} else {
$error[] = __('The passwords you entered do not match. Your password was not updated.', 'profile');
}
}
/* Update user information. */
if (!empty($_POST['url'])) {
wp_update_user(array('ID' => $current_user->ID, 'user_url' => esc_url($_POST['url'])));
}
if (!empty($_POST['email'])) {
if (!is_email(esc_attr($_POST['email']))) {
$error[] = __('The Email you entered is not valid. please try again.', 'profile');
} elseif (email_exists(esc_attr($_POST['email'])) != $current_user->id) {
$error[] = __('This email is already used by another user. try a different one.', 'profile');
} else {
wp_update_user(array('ID' => $current_user->ID, 'user_email' => esc_attr($_POST['email'])));
}
}
if (!empty($_POST['first-name'])) {
update_user_meta($current_user->ID, 'first_name', esc_attr($_POST['first-name']));
}
if (!empty($_POST['last-name'])) {
update_user_meta($current_user->ID, 'last_name', esc_attr($_POST['last-name']));
}
if (!empty($_POST['display_name'])) {
update_user_meta($current_user->ID, 'display_name', esc_attr($_POST['display_name']));
}
}
?>
<?php
if (!is_user_logged_in()) {
wp_redirect(get_bloginfo('url'));
exit;
}
?>
<form id="your-profile" action="<?php echo admin_url() . 'user-edit.php'; ?>" method="post" novalidate="novalidate"
<?php do_action('user_edit_form_tag'); ?>
>
<?php wp_nonce_field('update-user_' . $user_id); ?>
<?php if ($wp_http_referer) : ?>
<input type="hidden" name="wp_http_referer" value="<?php echo esc_url($wp_http_referer); ?>" />
<?php endif; ?>
<p>
<input type="hidden" name="from" value="profile" />
<input type="hidden" name="checkuser_id" value="<?php echo get_current_user_id(); ?>" />
</p>
<!-- FISRT NAME -->
<input id="first-name" name="first-name" type="text" value="<?php the_author_meta('first_name', $current_user->ID); ?>" disabled="disabled"/>
<!-- LAST NAME -->
<input id="last-name" name="first-name" type="text" value="<?php the_author_meta('last_name', $current_user->ID); ?>" disabled="disabled"/>
<!-- DISPLAY NAME -->
<select id="display_name" name="display_name">
<?php
$public_display = array();
$public_display['display_nickname'] = $current_user->nickname;
$public_display['display_username'] = $current_user->user_login;
if (!empty($current_user->first_name)) {
$public_display['display_firstname'] = $current_user->first_name;
}
if (!empty($current_user->last_name)) {
$public_display['display_lastname'] = $current_user->last_name;
}
if (!empty($current_user->first_name) && !empty($current_user->last_name)) {
$public_display['display_firstlast'] = $current_user->first_name . ' ' . $current_user->last_name;
$public_display['display_lastfirst'] = $current_user->last_name . ' ' . $current_user->first_name;
}
if (!in_array($current_user->display_name, $public_display, true)) { // Only add this if it isn't duplicated elsewhere.
$public_display = array('display_displayname' => $current_user->display_name) + $public_display;
}
$public_display = array_map('trim', $public_display);
$public_display = array_unique($public_display);
foreach ($public_display as $id => $item) {
?>
<option <?php selected($current_user->display_name, $item); ?>><?php echo $item; ?></option>
<?php
}
?>
</select>
<button id="updateuser" name="updateuser" type="submit" class="btn"><?php _e('Update Profile', 'text_domain'); ?></button>
<?php wp_nonce_field('update-user') ?>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr($current_user->ID); ?>" />
</form><!-- #adduser -->