PluginProbe
Metricool – Social media and site statistics / 2.0.2
Metricool – Social media and site statistics v2.0.2
2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / app / Http / Middleware / SetLocale.php

SetLocale.php in Metricool – Social media and site statistics 2.0.2, at app/Http/Middleware/SetLocale.php

25 lines 570 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Metricool\Http\Middleware;
6
7 use Carbon\Carbon;
8 use Metricool\Interfaces\MiddlewareInterface;
9
10 /**
11 * Set the locale for the current request. The locale is determined by the user's locale, or the site's locale if the user is not logged in.
12 */
13 class SetLocale implements MiddlewareInterface
14 {
15 public function handle(\WP_REST_Request $request): ?\WP_REST_Response
16 {
17 $locale = get_user_locale() ?: get_locale();
18 switch_to_locale($locale);
19
20 Carbon::setLocale($locale);
21
22 return null;
23 }
24 }
25