Настроить сообщение об активации учетной записи пользователя


В процессе создания пользователем новой учетной записи, как только он нажимает на ссылку в электронном письме для активации, он получает сообщение на странице входа в систему:

Ваша учетная запись теперь активна!

Имя пользователя: **

Пароль: **

Теперь ваша учетная запись активирована. Просмотрите свой сайт или войдите в систему

Мне нужно настроить это сообщение. Этот контент, похоже, создается wp-activate.php, но я не вижу никаких крючки, такие как wpmu_signup_user_notification, найденные в ms-functions.php.

Я использую WordPress 3.8 мультисайт (поддомен).

Author: Chris, 2013-12-18

1 answers

Я нашел ответ здесь: Настройка wp-activate.php

На самом деле это своего рода обходной путь, но он работает довольно хорошо.

Шаг 1 Создайте новую страницу под названием "активировать"

Шаг 2 Создайте новый шаблон под названием'template-activate.php 'и добавьте следующий код:

**Template (template-activate.php)**
<?php
/**
 * Template Name: Activation
 *
 */

/**
 * Confirms that the activation key that is sent in an email after a user signs
 * up for a new blog matches the key for that user and then displays confirmation.
 *
 * @package WordPress
 */

if ( !is_multisite() OR (empty($_GET['key']) && empty($_POST['key'])) ) {
    wp_redirect( site_url( '/wp-login.php?action=register' ) );
    die();
}

if ( is_object( $wp_object_cache ) )
    $wp_object_cache->cache_enabled = false;

// Fix for page title
$wp_query->is_404 = false;

/**
 * Fires before the Site Activation page is loaded.
 *
 * @since 3.0
 */
do_action( 'activate_header' );

/**
 * Adds an action hook specific to this page that fires on wp_head
 *
 * @since MU
 */
function do_activate_header() {
    /**
     * Fires before the Site Activation page is loaded, but on the wp_head action.
     *
     * @since 3.0
     */
    do_action( 'activate_wp_head' );
}
add_action( 'wp_head', 'do_activate_header' );

get_header();

//theme specific (CoWorker)
get_template_part( 'include/content', 'head' );
?>

<?php
        $key = !empty($_GET['key']) ? $_GET['key'] : $_POST['key'];
        $result = wpmu_activate_signup($key);
      $siteurl = site_url();
      $lostpassword = $siteurl.'/lostpassword';
        if ( is_wp_error($result) ) {
            if ( 'already_active' == $result->get_error_code() || 'blog_taken' == $result->get_error_code() ) {
                $signup = $result->get_error_data();
                ?>
                <h2><?php _e('Your account is now active!'); ?></h2>
                <?php
                echo '<p class="lead-in">';
                if ( $signup->domain . $signup->path == '' ) {
                    printf( __('You may now <a href="%1$s">log in</a> to the site using your chosen username of <strong>&#8220;%2$s&#8221;</strong>.</p><p>Please check your email inbox at <strong>%3$s</strong> for your password and login instructions.</p></p>If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.</p>'), $siteurl.'/login', $signup->user_login, $signup->user_email, $lostpassword );
                } else {
                    printf( __('Your site at <a href="%1$s">%2$s</a> is active. You may now log in to your site using your chosen username of <strong>&#8220;%3$s&#8221;</strong>.</p><p>Please check your email inbox at %4$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%5$s">reset your password</a>.'), 'http://' . $signup->domain, $signup->domain, $signup->user_login, $signup->user_email, $lostpassword );
                }
                echo '</p>';
            } else {
                ?>
                <h2><?php _e('An error occurred during the activation'); ?></h2>
                <?php
                echo '<p>'.$result->get_error_message().'</p>';
            }
        } else {
            extract($result);
            $url = get_blogaddress_by_id( (int) $blog_id);
            $user = get_userdata( (int) $user_id);
         $username = $user->user_login;
         $useremail = $user->user_email;
            ?>
            <h2><?php _e('Your account is now active!'); ?></h2>

            <div id="signup-welcome">
              <p class="view"><?php printf( __('You may now <a href="%1$s">log in</a> to the site using your chosen username of <strong>&#8220;%2$s&#8221;</strong>.</p><p>Please check your email inbox at <strong>%3$s</strong> for your password and login instructions.</p></p>If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.</p>'), $siteurl.'/login', $username, $useremail, $lostpassword ); ?></p>
         </div>
            <?php
        }
    ?>

<script type="text/javascript">
    var key_input = document.getElementById('key');
    key_input && key_input.focus();
</script>

<?php
//theme specific (CoWorker)
get_template_part( 'include/content', 'foot' ); 

get_footer();
?>  

Шаг 3 Создайте новый файл плагина под названием'custom-activation-email.php '

<?php 
/*
Plugin Name: Custom Activation Email
Plugin URI: YOUR URL
Description: Plugin to customize the automated user account activation email
Author: ME
Version: 1.0
Author URI: YOUR URL
*/
    add_filter( 'wpmu_signup_user_notification', 'kc_wpmu_signup_user_notification', 10, 4 );
    function kc_wpmu_signup_user_notification($user, $user_email, $key, $meta = '') {
        $sitename = get_bloginfo( 'name' );
        $blog_id = get_current_blog_id();
        // Send email with activation link.
        $admin_email = get_option( 'admin_email' );
        if ( $admin_email == '' )
            $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
        $from_name = get_option( 'blogname' ) == '' ? $sitename : esc_html( get_option( 'blogname' ) );
        $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
        $message = sprintf(
            apply_filters( 'wpmu_signup_user_notification_email',
                __( "Hi %s,\n\nThank you for registering with %s.\n\nTo activate your account, please click the following link:\n\n%s\n\nYou will then receive an email with your login details." ),
                $user, $user_email, $key, $meta
            ),
            $user,
            $sitename,
            site_url( "activate/?key=$key" )


        );
        // TODO: Don't hard code activation link.
        $subject = sprintf(
            apply_filters( 'wpmu_signup_user_notification_subject',
                __( '%3$s - Activate your account' ),
                $user, $user_email, $key, $meta
            ),
            $from_name,
            $user,
            $sitename
        );
        wp_mail($user_email, $subject, $message, $message_headers);

        return false;
    }
?>

Примечания Я использую "Тему моего входа" плагин, следовательно, изменены ссылки на /login и /lostpassword. Я решил сделать шаг 3 в качестве плагина вместо добавления в мою тему functions.php потому что я, похоже, так не работал.

 3
Author: Chris, 2017-04-13 12:37:38