switch_to_user_locale example


function switch_to_user_locale( $user_id ) {
    /* @var WP_Locale_Switcher $wp_locale_switcher */
    global $wp_locale_switcher;

    if ( ! $wp_locale_switcher ) {
        return false;
    }

    return $wp_locale_switcher->switch_to_user_locale( $user_id );
}

/** * Restores the translations according to the previous locale. * * @since 4.7.0 * * @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object. * * @return string|false Locale on success, false on error. */
// `$deprecated` was pre-4.3 `$plaintext_pass`. An empty `$plaintext_pass` didn't sent a user notification.         if ( 'admin' === $notify || true !== $send_notification_to_user || ( empty( $deprecated ) && empty( $notify ) ) ) {
            return;
        }

        $key = get_password_reset_key( $user );
        if ( is_wp_error( $key ) ) {
            return;
        }

        $switched_locale = switch_to_user_locale( $user_id );

        /* translators: %s: User login. */
        $message  = sprintf( __( 'Username: %s' )$user->user_login ) . "\r\n\r\n";
        $message .= __( 'To set your password, visit the following address:' ) . "\r\n\r\n";
        $message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user->user_login ), 'login' ) . "\r\n\r\n";

        $message .= wp_login_url() . "\r\n";

        $wp_new_user_notification_email = array(
            'to'      => $user->user_email,
            /* translators: Login details notification email subject. %s: Site title. */
            

    public function export_preview_data() {
        $partials = array();

        foreach ( $this->partials() as $partial ) {
            if ( $partial->check_capabilities() ) {
                $partials[ $partial->id ] = $partial->json();
            }
        }

        $switched_locale = switch_to_user_locale( get_current_user_id() );
        $l10n            = array(
            'shiftClickToEdit' => __( 'Shift-click to edit this element.' ),
            'clickEditMenu'    => __( 'Click to edit this menu.' ),
            'clickEditWidget'  => __( 'Click to edit this widget.' ),
            'clickEditTitle'   => __( 'Click to edit the site title.' ),
            'clickEditMisc'    => __( 'Click to edit this element.' ),
            /* translators: %s: document.write() */
            'badDocumentWrite' => sprintf( __( '%s is forbidden' ), 'document.write()' ),
        );
        if ( $switched_locale ) {
            restore_previous_locale();
        }
$admin_email = get_site_option( 'admin_email' );

    if ( '' === $admin_email ) {
        $admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST );
    }

    $from_name       = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress';
    $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n";

    $user            = get_user_by( 'login', $user_login );
    $switched_locale = $user && switch_to_user_locale( $user->ID );

    $message = sprintf(
        /** * Filters the message content of the new blog notification email. * * Content should be formatted for transmission via wp_mail(). * * @since MU (3.0.0) * * @param string $content Content of the notification email. * @param string $domain Site domain. * @param string $path Site path. * @param string $title Site title. * @param string $user_login User login name. * @param string $user_email User email address. * @param string $key Activation key created in wpmu_signup_blog(). * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. */
/** * Fires immediately after an existing user is invited to join the site, but before the notification is sent. * * @since 4.4.0 * * @param int $user_id The invited user's ID. * @param array $role Array containing role information for the invited user. * @param string $newuser_key The key of the invitation. */
            do_action( 'invite_user', $user_id$role$newuser_key );

            $switched_locale = switch_to_user_locale( $user_id );

            if ( '' !== get_option( 'blogname' ) ) {
                $site_title = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
            } else {
                $site_title = parse_url( home_url(), PHP_URL_HOST );
            }

            /* translators: 1: Site title, 2: Site URL, 3: User role, 4: Activation URL. */
            $message = __(
                'Hi, You\'ve been invited to join \'%1$s\' at %2$s with the role of %3$s. Please click the following link to confirm the invite: %4$s'

    public function export_preview_data() {
        global $wp_registered_sidebars$wp_registered_widgets;

        $switched_locale = switch_to_user_locale( get_current_user_id() );

        $l10n = array(
            'widgetTooltip' => __( 'Shift-click to edit this widget.' ),
        );

        if ( $switched_locale ) {
            restore_previous_locale();
        }

        $rendered_sidebars = array_filter( $this->rendered_sidebars );
        $rendered_widgets  = array_filter( $this->rendered_widgets );

        
$parsed = wp_parse_url( $allowed_url );
            if ( empty( $parsed['host'] ) ) {
                continue;
            }
            $host = $parsed['host'];
            if ( ! empty( $parsed['port'] ) ) {
                $host .= ':' . $parsed['port'];
            }
            $allowed_hosts[] = $host;
        }

        $switched_locale = switch_to_user_locale( get_current_user_id() );
        $l10n            = array(
            'shiftClickToEdit'  => __( 'Shift-click to edit this element.' ),
            'linkUnpreviewable' => __( 'This link is not live-previewable.' ),
            'formUnpreviewable' => __( 'This form is not live-previewable.' ),
        );
        if ( $switched_locale ) {
            restore_previous_locale();
        }

        $settings = array(
            'changeset'         => array(
                
    $userdata = array_merge( $user$userdata );
    $user_id  = wp_insert_user( $userdata );

    if ( is_wp_error( $user_id ) ) {
        return $user_id;
    }

    $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );

    $switched_locale = false;
    if ( ! empty( $send_password_change_email ) || ! empty( $send_email_change_email ) ) {
        $switched_locale = switch_to_user_locale( $user_id );
    }

    if ( ! empty( $send_password_change_email ) ) {
        /* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */
        $pass_change_text = __(
            'Hi ###USERNAME###, This notice confirms that your password was changed on ###SITENAME###. If you did not change your password, please contact the Site Administrator at ###ADMIN_EMAIL### This email has been sent to ###EMAIL### Regards, All at ###SITENAME### ###SITEURL###'
if ( get_option( 'admin_email' ) === $value || ! is_email( $value ) ) {
        return;
    }

    $hash            = md5( $value . time() . wp_rand() );
    $new_admin_email = array(
        'hash'     => $hash,
        'newemail' => $value,
    );
    update_option( 'adminhash', $new_admin_email );

    $switched_locale = switch_to_user_locale( get_current_user_id() );

    /* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */
    $email_text = __(
        'Howdy ###USERNAME###, Someone with administrator capabilities recently requested to have the administration email address changed on this site: ###SITEURL### To confirm this change, please click on the following link: ###ADMIN_URL### You can safely ignore and delete this email if you do not want to take this action. This email has been sent to ###EMAIL### Regards, All at ###SITENAME### ###SITEURL###'

function wp_privacy_send_personal_data_export_email( $request_id ) {
    // Get the request.     $request = wp_get_user_request( $request_id );

    if ( ! $request || 'export_personal_data' !== $request->action_name ) {
        return new WP_Error( 'invalid_request', __( 'Invalid request ID when sending personal data export email.' ) );
    }

    // Localize message content for user; fallback to site default for visitors.     if ( ! empty( $request->user_id ) ) {
        $switched_locale = switch_to_user_locale( $request->user_id );
    } else {
        $switched_locale = switch_to_locale( get_locale() );
    }

    /** This filter is documented in wp-includes/functions.php */
    $expiration      = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS );
    $expiration_date = date_i18n( get_option( 'date_format' )time() + $expiration );

    $exports_url      = wp_privacy_exports_url();
    $export_file_name = get_post_meta( $request_id, '_export_file_name', true );
    $export_file_url  = $exports_url . $export_file_name;

    
Home | Imprint | This part of the site doesn't use cookies.