Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#45973 closed enhancement (duplicate)

Wrap global functions like __() in 'function_exists' condition

Reported by: jonasemde's profile jonasemde Owned by:
Milestone: Priority: normal
Severity: trivial Version:
Component: I18N Keywords:
Focuses: Cc:

Description

The () function is used in multiple frameworks and other open source libraries.

When both systems (e.g. WordPress and Laravel or WordPress and Magento) are required in one composer project the 'function already exists' Exception got thrown.

To override the function behaviour and/or be compatible with other frameworks like Laravel the functions should be wrapped within a 'function_exists' condition like so:

<?php
if (! function_exists('__')) {
    function __( $text, $domain = 'default' ) {
        return translate( $text, $domain );
    }
}

Especially the Laravel core does the same: https://github.com/laravel/framework/blob/5.7/src/Illuminate/Foundation/helpers.php

Attachments (2)

l10n.php (46.9 KB) - added by jonasemde 5 years ago.
patch.diff (9.4 KB) - added by jonasemde 5 years ago.
Patch

Download all attachments as: .zip

Change History (3)

@jonasemde
5 years ago

@jonasemde
5 years ago

Patch

#1 @swissspidy
5 years ago

  • Component changed from General to I18N
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there and welcome to WordPress Trac!

We've already gotten the same request in #41498, thus I am going to close this one as a duplicate.

Note: See TracTickets for help on using tickets.