Wordpress - Отправить сообщение после отправки завершено - PullRequest
0 голосов
/ 26 ноября 2018

До сих пор я нашел этот фрагмент для изменения роли пользователя, используя небольшую форму, как показано ниже, и мне нужна эта простая форма для отправки электронной почты администратору, когда отправка завершена,

И после отправки мне нужноперезагрузить ту же страницу или перенаправить на тот же URL.

Я новичок в Wordpress, заранее спасибо.

Извините за мой плохой английский.

add_shortcode( 'upgrade_to_trusted_zone', 'upgrade_to_trusted_zone' );
function upgrade_to_trusted_zone() {

    // Stop if user is not logged in.
    if ( ! is_user_logged_in() )
        return;

    ob_start();

    ?>

    <form method="post" action="">
        Please select a role:<br/>
        <select name="role">
            <option value="contributor" selected="selected">Member</option>
            <option value="author">Trusted Zoner</option>
        </select>
        <input name="terms" type="checkbox" required value="Yes" /> 
            <label>I have read and agree of the <a href="">terms and conditions</a>.</label>
        <input type="hidden" name="submitted" id="submitted" value="true" /><button type="submit">Upgrade</button>
    </form>

    <?php

    // Do not process anything if it's not $_POST
    if ( ! isset( $_POST['role'] ) )
        return;

    // Never trust user input.
    $role = sanitize_key( $_POST['role'] );
    if ( ! in_array( $role, array( 'contributor', 'author' ) ) )
        return;

    // Get the user object
    $user = new WP_User( get_current_user_id() );
    $index = key( $user->roles );
    $user_role = $user->roles[ $index ];

    // User already got that user
    if ( $user_role == $role ) {

        echo sprintf( __( 'You already have %s role.' ), $role );

    } else {

        // update user role
        $user->set_role( $role );
        echo sprintf( __( 'Your role was changed to %s.' ), $role );

    }

    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...