This repository was archived by the owner on Sep 28, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ public function __construct( $args ) {
111111 return ;
112112 }
113113
114- $ this ->locale = get_locale ();
114+ $ this ->locale = $ this -> get_admin_locale ();
115115 if ( 'en_US ' === $ this ->locale ) {
116116 return ;
117117 }
@@ -123,6 +123,25 @@ public function __construct( $args ) {
123123 }
124124 }
125125
126+ /**
127+ * Returns the locale used in the admin.
128+ *
129+ * WordPress 4.7 introduced the ability for users to specify an Admin language
130+ * different from the language used on the front end. This checks if the feature
131+ * is available and returns the user's language, with a fallback to the site's language.
132+ * Can be removed when support for WordPress 4.6 will be dropped, in favor
133+ * of WordPress get_user_locale() that already fallbacks to the site’s locale.
134+ *
135+ * @returns string The locale.
136+ */
137+ private function get_admin_locale () {
138+ if ( function_exists ( 'get_user_locale ' ) ) {
139+ return get_user_locale ();
140+ }
141+
142+ return get_locale ();
143+ }
144+
126145 /**
127146 * This is where you decide where to display the messages and where you set the plugin specific variables.
128147 *
You can’t perform that action at this time.
0 commit comments