php 添加了一个手机到AJAX登录和注册模式弹出PRO
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 添加了一个手机到AJAX登录和注册模式弹出PRO相关的知识,希望对你有一定的参考价值。
<?php
add_action( 'register_form', 'lrm_custom_registration_form' );
function lrm_custom_registration_form() {
$phone = ! empty( $_POST['phone'] ) ? sanitize_text_field( $_POST['phone'] ) : '';
?>
<p>
<label for="phone"><?php esc_html_e( 'Phone', 'cn' ) ?><br/>
<input type="text"
id="phone"
name="phone"
value="<?php echo esc_attr( $phone ); ?>"
class="input"
/>
</label>
</p>
<?php
}
add_filter( 'registration_errors', 'lrm_custom_registration_errors', 10, 3 );
function lrm_custom_registration_errors( $errors, $sanitized_user_login, $user_email ) {
if ( empty( $_POST['phone'] ) ) {
$errors->add( 'phone_error', __( '<strong>ERROR</strong>: Please enter your Phone.', 'cn' ) );
}
return $errors;
}
add_action( 'user_register', 'lrm_custom_user_register' );
function lrm_custom_user_register( $user_id ) {
if ( ! empty( $_POST['phone'] ) ) {
update_user_meta( $user_id, 'phone', sanitize_text_field($_POST['phone'] ) );
}
}
/**
* Back end registration
*/
add_action( 'user_new_form', 'lrm_custom_admin_registration_form' );
function lrm_custom_admin_registration_form( $operation ) {
if ( 'add-new-user' !== $operation ) {
// $operation may also be 'add-existing-user'
return;
}
$phone = ! empty( $_POST['phone'] ) ? sanitize_text_field( $_POST['phone'] ) : '';
?>
<h3><?php esc_html_e( 'Personal Information', 'cn' ); ?></h3>
<table class="form-table">
<tr>
<th><label for="phone"><?php esc_html_e( 'Phone', 'cn' ); ?></label> <span class="description"><?php esc_html_e( '(required)', 'cn' ); ?></span></th>
<td>
<input type="text"
id="phone"
name="phone"
value="<?php echo esc_attr( $phone ); ?>"
class="regular-text"
/>
</td>
</tr>
</table>
<?php
}
add_action( 'user_profile_update_errors', 'lrm_custom_user_profile_update_errors', 10, 3 );
function lrm_custom_user_profile_update_errors( $errors, $update, $user ) {
if ( $update ) {
return;
}
if ( empty( $_POST['phone'] ) ) {
$errors->add( 'phone_error', __( '<strong>ERROR</strong>: Please enter your Phone.', 'cn' ) );
}
}
add_action( 'edit_user_created_user', 'lrm_custom_user_register' );
/**
* Back end display
*/
add_action( 'show_user_profile', 'lrm_custom_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'lrm_custom_show_extra_profile_fields' );
function lrm_custom_show_extra_profile_fields( $user ) {
?>
<h3><?php esc_html_e( 'Personal Information', 'cn' ); ?></h3>
<table class="form-table">
<tr>
<th><label for="phone"><?php esc_html_e( 'Phone', 'cn' ); ?></label></th>
<td><?php echo esc_html( get_user_meta( $user->ID, 'phone', true ) ); ?></td>
</tr>
</table>
<?php
}
以上是关于php 添加了一个手机到AJAX登录和注册模式弹出PRO的主要内容,如果未能解决你的问题,请参考以下文章