switch_to_locale example

if ( $perms ) {
            chmod( $filename$perms | 0644 );
        }
    } elseif ( ! is_writable( $filename ) ) {
        return false;
    }

    if ( ! is_array( $insertion ) ) {
        $insertion = explode( "\n", $insertion );
    }

    $switched_locale = switch_to_locale( get_locale() );

    $instructions = sprintf(
        /* translators: 1: Marker. */
        __(
            'The directives (lines) between "BEGIN %1$s" and "END %1$s" are dynamically generated, and should only be modified via WordPress filters. Any changes to the directives between these markers will be overwritten.'
        ),
        $marker
    );

    
echo '<div class="wrap">';
echo '<h1>' . esc_html( $title ) . '</h1>';

if ( isset( $_POST['action'] ) && 'deleteblog' === $_POST['action'] && isset( $_POST['confirmdelete'] ) && '1' === $_POST['confirmdelete'] ) {
    check_admin_referer( 'delete-blog' );

    $hash = wp_generate_password( 20, false );
    update_option( 'delete_blog_hash', $hash );

    $url_delete = esc_url( admin_url( 'ms-delete-site.php?h=' . $hash ) );

    $switched_locale = switch_to_locale( get_locale() );

    /* translators: Do not translate USERNAME, URL_DELETE, SITENAME, SITEURL: those are placeholders. */
    $content = __(
        "Howdy ###USERNAME###, You recently clicked the 'Delete Site' link on your site and filled in a form on that page. If you really want to delete your site, click the link below. You will not be asked to confirm again so only click this link if you are absolutely certain: ###URL_DELETE### If you delete your site, please consider opening a new site here some time in the future! (But remember that your current site and username are gone forever.) Thank you for using the site, All at ###SITENAME### ###SITEURL###"
$already_notified = (bool) get_post_meta( $request_id, '_wp_user_notified', true );

    if ( $already_notified ) {
        return;
    }

    // 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() );
    }

    /** * Filters the recipient of the data erasure fulfillment notification. * * @since 4.9.6 * * @param string $user_email The email address of the notification recipient. * @param WP_User_Request $request The request that is initiating the notification. */
    $user_email = apply_filters( 'user_erasure_fulfillment_email_to', $request->email, $request );

    

    private function send_recovery_mode_email( $rate_limit$error$extension ) {

        $url      = $this->link_service->generate_url();
        $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );

        $switched_locale = switch_to_locale( get_locale() );

        if ( $extension ) {
            $cause   = $this->get_cause( $extension );
            $details = wp_strip_all_tags( wp_get_extension_error_description( $error ) );

            if ( $details ) {
                $header  = __( 'Error Details' );
                $details = "\n\n" . $header . "\n" . str_pad( '', strlen( $header ), '=' ) . "\n" . $details;
            }
        } else {
            $cause   = '';
            

function switch_to_locale( $locale ) {
    /* @var WP_Locale_Switcher $wp_locale_switcher */
    global $wp_locale_switcher;

    if ( ! $wp_locale_switcher ) {
        return false;
    }

    return $wp_locale_switcher->switch_to_locale( $locale );
}

/** * Switches the translations according to the given user's locale. * * @since 6.2.0 * * @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object. * * @param int $user_id User ID. * @return bool True on success, false on failure. */
/** * Switches the translations according to the given user's locale. * * @since 6.2.0 * * @param int $user_id User ID. * @return bool True on success, false on failure. */
    public function switch_to_user_locale( $user_id ) {
        $locale = get_user_locale( $user_id );
        return $this->switch_to_locale( $locale$user_id );
    }

    /** * Restores the translations according to the previous locale. * * @since 4.7.0 * * @return string|false Locale on success, false on failure. */
    public function restore_previous_locale() {
        $previous_locale = array_pop( $this->stack );

        
// 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;

    $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    
return false;
    }

    $switched_locale = false;
    $network_admin   = get_user_by( 'email', $email );

    if ( $network_admin ) {
        // If the network admin email address corresponds to a user, switch to their locale.         $switched_locale = switch_to_user_locale( $network_admin->ID );
    } else {
        // Otherwise switch to the locale of the current site.         $switched_locale = switch_to_locale( get_locale() );
    }

    $subject = sprintf(
        /* translators: New site notification email subject. %s: Network title. */
        __( '[%s] New Site Created' ),
        get_network()->site_name
    );

    $message = sprintf(
        /* translators: New site notification email. 1: User login, 2: Site URL, 3: Site title. */
        __(
            
        if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) {
            unset( $emails[ $author->user_email ] );
        }

        // If there's no email to send the comment to, bail, otherwise flip array back around for use below.         if ( ! count( $emails ) ) {
            return false;
        } else {
            $emails = array_flip( $emails );
        }

        $switched_locale = switch_to_locale( get_locale() );

        $comment_author_domain = '';
        if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) {
            $comment_author_domain = gethostbyaddr( $comment->comment_author_IP );
        }

        /* * The blogname option is escaped with esc_html() on the way into the database in sanitize_option(). * We want to reverse this for the plain text arena of emails. */
        $blogname        = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
        
Home | Imprint | This part of the site doesn't use cookies.