Как перенаправить на главную страницу после регистрации?
Сделал плагин, который добавляет шорткод, который выводит форму регистрации пользователей. Однако, появилась проблемка. Необходимо, чтобы после регистрации пользователя отправляло на главную страницу, и всплывало уведомление о том, что регистрация прошла успешно. Подскажите, как это сделать? Вот код плагина:
class RegisterFormByKazzi
{
function __construct(){
add_shortcode('kazzis-regform', [$this, 'custom_registration_shortcode']);
add_action( 'wp_enqueue_scripts', [$this, 'regform_enqueue_styles'] );
}
function regform_enqueue_styles () {
wp_enqueue_style('RegisterFormByKazziStyle', plugins_url('/assets/styles/main.css', __FILE__));
}
// The callback function that will replace [book]
function custom_registration_shortcode() {
//ob_start();
$this->custom_registration_function();
//return ob_get_clean();
}
function registration_form( $username, $password, $email ) {
echo '
<form action="' . $_SERVER['REQUEST_URI'] . '" method="post" class="regform">
<p><img loading="lazy" class="size-full wp-image-1604 aligncenter" src="https://test-dev.wolfberrycrafts.com/wp-content/uploads/2021/10/white-logo.png" alt="" width="224" height="104" srcset="https://test-dev.wolfberrycrafts.com/wp-content/uploads/2021/10/white-logo.png 224w, https://test-dev.wolfberrycrafts.com/wp-content/uploads/2021/10/white-logo-64x30.png 64w" sizes="(max-width: 224px) 100vw, 224px"></p>
<div class="regform-field">
<input type="text" name="username" value="' . ( isset( $_POST['username'] ) ? $username : null ) . '" placeholder="Name">
</div>
<div class="regform-field">
<input type="password" name="password" value="' . ( isset( $_POST['password'] ) ? $password : null ) . '" placeholder="Password">
</div>
<div class="regform-field">
<input type="text" name="email" value="' . ( isset( $_POST['email']) ? $email : null ) . '" placeholder="Email">
</div>
<input type="submit" name="submit" value="Register"/>
</form>
';
}
function registration_validation( $username, $password, $email ) {
global $reg_errors;
$reg_errors = new WP_Error;
if ( empty( $username ) || empty( $password ) || empty( $email ) ) {
$reg_errors->add('field', 'Required form field is missing');
}
if ( 4 > strlen( $username ) ) {
$reg_errors->add( 'username_length', 'Username too short. At least 4 characters is required' );
}
if ( username_exists( $username ) )
$reg_errors->add('user_name', 'Sorry, that username already exists!');
if ( ! validate_username( $username ) ) {
$reg_errors->add( 'username_invalid', 'Sorry, the username you entered is not valid' );
}
if ( 5 > strlen( $password ) ) {
$reg_errors->add( 'password', 'Password length must be greater than 5' );
}
if ( !is_email( $email ) ) {
$reg_errors->add( 'email_invalid', 'Email is not valid' );
}
if ( email_exists( $email ) ) {
$reg_errors->add( 'email', 'Email Already in use' );
}
if ( is_wp_error( $reg_errors ) ) {
foreach ( $reg_errors->get_error_messages() as $error ) {
echo '<div>';
echo '<strong>ERROR</strong>:';
echo $error . '<br/>';
echo '</div>';
}
}
}
function complete_registration() {
global $reg_errors, $username, $password, $email;
if ( 1 > count( $reg_errors->get_error_messages() ) ) {
$userdata = array(
'user_login' => $username,
'user_email' => $email,
'user_pass' => $password,
);
$user = wp_insert_user( $userdata );
}
}
function custom_registration_function() {
if ( isset($_POST['submit'] ) ) {
$this->registration_validation(
$_POST['username'],
$_POST['password'],
$_POST['email'],
);
// sanitize user form input
global $username, $password, $email;
$username = sanitize_user( $_POST['username'] );
$password = esc_attr( $_POST['password'] );
$email = sanitize_email( $_POST['email'] );
// call @function complete_registration to create the user
// only when no WP_error is found
$this->complete_registration(
$username,
$password,
$email,
);
}
$this->registration_form(
$username,
$password,
$email,
);
}
}