current->prefix_in_url(); if ( ! $lang ) { return $parse; } $slug = (string) $this->settings->get()->language( $lang )?->slug; $original = isset( $_SERVER['REQUEST_URI'] ) ? (string) $_SERVER['REQUEST_URI'] : '/'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- kept byte for byte and put back in restore_uri(), so other plugins see the request unchanged; never output or queried. $this->current->mark_prefix_cut( $original ); $_SERVER['REQUEST_URI'] = $this->urls->strip_prefix( wp_unslash( $original ), $slug ); $this->raw->enter(); // WordPress reads home_url() while parsing: give it the real one. return $parse; } /** Parse_request: put the original URL back for canonical checks and links. */ public function restore_uri(): void { $original = $this->current->take_original_uri(); if ( null !== $original ) { $_SERVER['REQUEST_URI'] = $original; $this->raw->leave(); } } /** * Home_url( '/' ) on a UK page -> /uk/ (logo, search form, "home" links). * Other paths (wp-json, assets, sitemaps) are left alone. */ public function home_url( mixed $url, mixed $path = '' ): mixed { if ( ! is_string( $url ) || $this->raw->active() || ! $this->urls->pretty() || ! in_array( (string) $path, array( '', '/' ), true ) ) { return $url; } return $this->current->is_other_than_default() ? $this->urls->lang_home( $this->current->get() ) : $url; } /** Page_on_front / page_for_posts: the published version in the current language. */ public function special_page( mixed $value ): mixed { if ( $this->raw->active() || ! $value ) { return $value; } $lang = $this->current->get(); if ( '' === $lang ) { return $value; } $id = $this->posts->published_in( (int) $value, $lang ); if ( ! $id ) { $id = $this->previewed_in( (int) $value, $lang ); } return $id ? $id : $value; } /** * Preview of the unpublished translation of the home (or posts page): * use it as the special page, so the preview gets the front-page template * and looks like the page will look once published. */ private function previewed_in( int $post_id, string $lang ): int { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- read-only, WordPress shows draft previews the same way. if ( empty( $_GET['preview'] ) || ! did_action( 'init' ) ) { return 0; } $asked = isset( $_GET['page_id'] ) ? absint( $_GET['page_id'] ) : ( isset( $_GET['p'] ) ? absint( $_GET['p'] ) : 0 ); // phpcs:enable WordPress.Security.NonceVerification.Recommended $id = $this->posts->in_language( $post_id, $lang ); return $id && $id === $asked && current_user_can( 'edit_post', $id ) ? $id : 0; } }