你好吗?我写信给他们咨询,我在function.php中有一个shotcode,我做的是在点击按钮时更新手机的值,但问题是它并没有将我更改为更新后的值,我有更新页面以显示新值。
add_shortcode('editar-celular', 'get_current_user_prof');
function get_current_user_prof() {
global $current_user;
get_currentuserinfo();
if(is_user_logged_in()) {
$tableuserinf = "<form method='post' action='#'><table><tbody>";
$tableuserinf .= "<tr><td>Celular:</td><td><input type='text' name='phone' value='". $current_user->billing_phone ."'/></td></tr>";
$tableuserinf .= "</tbody></table><button>Submit</button></form>";
$user_id = $current_user->ID;
// Not sure if sanitize_user() is needed or is executed by wp_update_user(). Anyway, it doesn't hurt
$phone = isset($_POST['phone']) ? sanitize_user($_POST['phone']) : '';
//check if new nickname is different before performing the update operation
if($phone != $current_user->billing_phone){
update_user_meta($user_id, 'billing_phone', $phone ) ;
}
return $tableuserinf;
}
}
EDIT VERSION 2:
add_shortcode('editar-celular', 'get_current_user_prof');
function get_current_user_prof() {
global $current_user;
get_currentuserinfo();
if(is_user_logged_in()) {
$user_id = $current_user->ID;
$phone = isset($_POST['phone']) ? sanitize_user($_POST['phone']) : '';
if($phone != $current_user->billing_phone){
update_user_meta($user_id, 'billing_phone', $phone ) ;
}
return "<form method='post'>
<input type='text' name='phone' value='". $current_user->billing_phone ."' />
<input type='submit' value='Validate' />
</form>";
}
}