[wp-trac] [WordPress Trac] #41498: Why are global functions not wrapped in function_exists?

WordPress Trac noreply at wordpress.org
Mon Mar 11 11:40:38 UTC 2019


#41498: Why are global functions not wrapped in function_exists?
-----------------------------+------------------------------
 Reporter:  doecode          |       Owner:  (none)
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  I18N             |     Version:
 Severity:  normal           |  Resolution:
 Keywords:                   |     Focuses:
-----------------------------+------------------------------

Comment (by jonasemde):

 This thread is about wrapping the {{{ __(...) }}} function to be more
 flexible as a developer.

 Out of the box, this will not cause any issues because if no {{{ __(...)
 }}} function is declared earlier the WordPress default is loaded.

 But development wise we gain some flexibility.

 This allows initializing a {{{ __(...) }}} adapter function before the
 WordPress PHP-files are loaded. In case of a Laravel/WordPress it could be
 something like that:

 {{{#!php
 <?php
 function __(...$args) {
     // Check if laravel translation exists:
     if(Lang::has(...$args)) {
         return app('translator')->getFromJson(...$args);
     }

     // WordPress as fallback
     return translate(...$args);
 }
 }}}

 So this did not cause any sites to lose translations.

 Replying to [comment:7 swissspidy]:
 > > Wouldn't this cause any sites to loose translations if other-project
 didn't support the WordPress translations?
 >
 > @jonasemde Can you address this question as well?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/41498#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list