code && ( null !== $this->original_uri || $uri_now === $this->detected_uri ) ) { return $this->code; } $this->detected_uri = $uri_now; $this->prefix_lang = ''; if ( is_admin() || wp_doing_cron() || ( defined( 'WP_CLI' ) && WP_CLI ) || isset( $_GET['rest_route'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification -- presence check only. $this->code = ''; return $this->code; } $uri = '' !== $uri_now ? $uri_now : '/'; $parts = explode( '/', $this->urls->request_path( $uri ) ); $lang = $this->urls->lang_by_slug( $parts[0] ); $rest = $lang ? ( $parts[1] ?? '' ) : $parts[0]; if ( function_exists( 'rest_get_url_prefix' ) && rest_get_url_prefix() === $rest ) { $this->code = ''; return $this->code; } $this->prefix_lang = $lang; $this->code = $lang ? $lang : $this->settings->get()->default_code(); return $this->code; } /** Is this a front-end request in a language other than the default one? */ public function is_other_than_default(): bool { $code = $this->get(); return '' !== $code && $this->settings->get()->default_code() !== $code; } /** Language whose prefix was in the URL ('' if none). */ public function prefix_in_url(): string { $this->get(); return $this->prefix_lang; } /** Router cut the prefix from REQUEST_URI; remember the original. */ public function mark_prefix_cut( string $original_uri ): void { $this->original_uri = $original_uri; } /** The original REQUEST_URI if the prefix is cut right now, and forget it. */ public function take_original_uri(): ?string { $uri = $this->original_uri; $this->original_uri = null; return $uri; } /** Tests: forget everything detected for the current request. */ public function reset(): void { $this->code = null; $this->prefix_lang = ''; $this->detected_uri = null; $this->original_uri = null; } }