[wp-trac] [WordPress Trac] #45227: Using "__" in a plugin's main file, outside of an action callback prevents post saving in the editor.

WordPress Trac noreply at wordpress.org
Tue Oct 30 13:18:41 UTC 2018


#45227: Using "__" in a plugin's main file, outside of an action callback prevents
post saving in the editor.
--------------------------+-----------------------------
 Reporter:  kmgalanakis   |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Editor        |    Version:  5.0
 Severity:  critical      |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45227>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list