Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #57079


Ignore:
Timestamp:
11/11/2022 06:46:25 PM (13 months ago)
Author:
sabernhardt
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #57079

    • Property Focuses performance coding-standards removed
  • Ticket #57079 – Description

    initial v1  
    33**Part I**
    44
    5 I am a developer for W3TC and recently diagnosed an issue with our plugin under WP6.0.3/PHP8.1 regarding the use of an admin_print_scripts-{$hook_suffix} not applying under non-english translation due to our plugin's topmost menu page via add_menu_page containing a translated $menu_title parameter. This resulted in the hook's $page_type parameter under get_plugin_page_hookname being translated, thereby not allowing our JS/CSS to print as expected
     5I am a developer for W3TC and recently diagnosed an issue with our plugin under WP6.0.3/PHP8.1 regarding the use of an `admin_print_scripts-{$hook_suffix}` not applying under non-english translation due to our plugin's topmost menu page via `add_menu_page` containing a translated `$menu_title` parameter. This resulted in the hook's `$page_type` parameter under `get_plugin_page_hookname` being translated, thereby not allowing our JS/CSS to print as expected
    66
    7 Under es_ES translation:
    8 Expected: page hook = performance_page_w3tc_extensions
    9 Received: page hook = actuacion_page_w3tc_extensions
     7Under `es_ES` translation:
     8Expected: page hook = `performance_page_w3tc_extensions`
     9Received: page hook = `actuacion_page_w3tc_extensions`
    1010
    1111I determined 2 solutions
    12 1. Remove the translation from the add_menu_page resulting in the topmost menu item remaining in English which isn't preferred
     121. Remove the translation from the `add_menu_page` resulting in the topmost menu item remaining in English which isn't preferred
    1313{{{#!php
    1414<?php
     
    2626}}}
    2727
    28 2. Apply translations to our $hook_suffix in each use of admin_print_scripts-{$hook_suffix} which is preferred but seems "hackish"
     282. Apply translations to our `$hook_suffix` in each use of `admin_print_scripts-{$hook_suffix}` which is preferred but seems "hackish"
    2929{{{#!php
    3030<?php
     
    3737**Part II**
    3838
    39 Additionally with regard to applying translations I discovered that the user's locale/language setting (added in WP 4.7) wasn't applying for our plugin if the core language setting was set to non-english with our translation files automatically copied to wp-content/languages/plugins. My solution to this also felt "hackish" in that we reset the global $l10n and $l10n_unloaded variables before applying our load_plugin_textdomain. I attempted various other solutions I found during my research but non resolved the issue despite documentation seeming fairly straightforward and simple. My question here is whether the default behavior when applying translations to a plugin via load_plugin_textdomain takes the user's locale/language setting into account and/or if additional code is required for it to apply? Additionally the documentation for internationalizing themes/plugins doesn't appear to mention or reference the user locale/language setting so perhaps this needs to be updated?
     39Additionally with regard to applying translations I discovered that the user's locale/language setting (added in WP 4.7) wasn't applying for our plugin if the core language setting was set to non-english with our translation files automatically copied to `wp-content/languages/plugins`. My solution to this also felt "hackish" in that we reset the global `$l10n` and `$l10n_unloaded` variables before applying our `load_plugin_textdomain`. I attempted various other solutions I found during my research but non resolved the issue despite documentation seeming fairly straightforward and simple. My question here is whether the default behavior when applying translations to a plugin via `load_plugin_textdomain` takes the user's locale/language setting into account and/or if additional code is required for it to apply? Additionally the documentation for internationalizing themes/plugins doesn't appear to mention or reference the user locale/language setting so perhaps this needs to be updated?
    4040
    4141Via init hook: