Opened 6 years ago
Closed 6 years ago
#45227 closed defect (bug) (duplicate)
Using "__" in a plugin's main file, outside of an action callback prevents post saving in the editor.
Reported by: | kmgalanakis | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.0 |
Component: | I18N | Keywords: | |
Focuses: | Cc: |
Description
When trying to save a post in the new editor (Gutenberg), the saving fails if there is an activated plugin that uses __
outside of a callback action.
I managed to reproduce the issue by creating a test-plugin using the wp scaffold plugin test-plugin
. Then, in the main file of the plugin, I added $test = __( 'test', 'my-plugin' )
.
After activating the plugin, the post saving stopped working. The saving is done through the REST API and the code from my plugin is loaded as well, but is_user_logged_in
is not registered at that point, which gives me the following fatal error.
[30-Oct-2018 13:17:04 UTC] PHP Fatal error: Uncaught Error: Call to undefined function is_user_logged_in() in /srv/www/xxxxxx/public_html/wp-includes/l10n.php:137 Stack trace: #0 /srv/www/xxxxxx/public_html/wp-includes/l10n.php(1051): determine_locale() #1 /srv/www/xxxxxx/public_html/wp-includes/l10n.php(1013): _get_path_to_translation_from_lang_dir('test-plugin') #2 /srv/www/xxxxxx/public_html/wp-includes/l10n.php(983): _get_path_to_translation('test-plugin') #3 /srv/www/xxxxxx/public_html/wp-includes/l10n.php(1081): _load_textdomain_just_in_time('test-plugin') #4 /srv/www/xxxxxx/public_html/wp-includes/l10n.php(170): get_translations_for_domain('test-plugin') #5 /srv/www/xxxxxx/public_html/wp-includes/l10n.php(250): translate('test', 'test-plugin') #6 /srv/www/xxxxxx/public_html/wp-content/plugins/test-plugin/test-plugin.php(27): __('test', 'test-plugin') #7 /srv/www/xxxxxx/public_html/wp-settings.php(322): include_once('/srv/www/xxxxxx/...') #8 /srv/www/xxxxxx/public_html/wp-config.php(81): require_once('/srv/www/xxxxxx/...') #9 /srv/www/xxxxxx/public_html/wp-lo in /srv/www/xxxxxx/public_html/wp-includes/l10n.php on line 137
Change History (5)
#2
@
6 years ago
Mine was I test plugin that I prepared for something else and I happened to see that issue. The strange thing is that this test plugin was working nicely in WP 5.0-beta1.
Whatever changed in WP 5.0-beta2 and broke my plugin will surely break other plugins as well.
#3
@
6 years ago
@swissspidy This issue is probably quite severe. WooCommerce or ACF prevent a post to be saved with this same error.
#4
@
6 years ago
@Chouby You're correct. ACF 5.7.7 on an otherwise vanilla 5.0-beta2 installation triggers a fatal error when attempting to save a post.
[30-Oct-2018 21:25:23 UTC] PHP Fatal error: Uncaught Error: Call to undefined function is_user_logged_in() in /Users/sb05/sites/wp-beta2/wp-includes/l10n.php:137 Stack trace: #0 /Users/sb05/sites/wp-beta2/wp-includes/l10n.php(1051): determine_locale() #1 /Users/sb05/sites/wp-beta2/wp-includes/l10n.php(1013): _get_path_to_translation_from_lang_dir('acf') #2 /Users/sb05/sites/wp-beta2/wp-includes/l10n.php(983): _get_path_to_translation('acf') #3 /Users/sb05/sites/wp-beta2/wp-includes/l10n.php(1081): _load_textdomain_just_in_time('acf') #4 /Users/sb05/sites/wp-beta2/wp-includes/l10n.php(170): get_translations_for_domain('acf') #5 /Users/sb05/sites/wp-beta2/wp-includes/l10n.php(250): translate('Advanced Custom...', 'acf') #6 /Users/sb05/sites/wp-beta2/wp-content/plugins/advanced-custom-fields-pro/acf.php(80): __('Advanced Custom...', 'acf') #7 /Users/sb05/sites/wp-beta2/wp-content/plugins/advanced-custom-fields-pro/acf.php(690): ACF->initial in /Users/sb05/sites/wp-beta2/wp-includes/l10n.php on line 137
Sounds like a duplicate of #43869 to me.
It's not editor related though. You just happen to use a function way too early because you execute something straight away before WordPress has fully loaded. What are you trying to achieve that can't be done by hooking into
init
or something?