Closed brunodeangelis closed 2 years ago
Hi, I've investigated this issue, and I found out that the error was due to WPML using the same helper function that Laravel/Acorn blade component used behind the scene, specifically the value()
helper function. Since WPML first loaded before the theme, any helper function previously declared can't be redeclare, in this case redeclaring by theme functions.php.
WPML I think is using an older version of value()
helper function here, that only have single parameter. As you can see the code below:
<?php
if (!function_exists('value')) {
/**
* Return the default value of the given value.
*
* @param mixed $value
*
* @return mixed
*/
function value($value)
{
return $value instanceof Closure ? $value() : $value;
}
}
And as I checked the Laravel ManageComponents
trait that use to render a component, you can see that the value()
helper function has a second parameter. Which you can also see on Laravel/Acorn value()
helper function version, that indeed accepts multiple arguments.
<?php
public function renderComponent()
{
$view = array_pop($this->componentStack);
$this->currentComponentData = array_merge(
$previousComponentData = $this->currentComponentData,
$data = $this->componentData()
);
try {
$view = value($view, $data);
if ($view instanceof View) {
return $view->with($data)->render();
} elseif ($view instanceof Htmlable) {
return $view->toHtml();
} else {
return $this->make($view, $data)->render();
}
} finally {
$this->currentComponentData = $previousComponentData;
}
}
if (! function_exists('value')) {
/**
* Return the default value of the given value.
*
* @param mixed $value
* @return mixed
*/
function value($value, ...$args)
{
return $value instanceof Closure ? $value(...$args) : $value;
}
}
Right now, my solution for this is to create an MU-plugin and declare the value()
function same with Laravel/Acorn version. This is because MU-plugins will load first before any normal plugins, in this case WPML.
<?php
/**
* Plugin Name: Fix WPML Helper Functions Conflict
* Version: 1.0.0
* License: MIT License
*/
if (!function_exists('value')) {
/**
* Return the default value of the given value.
*
* @param mixed $value
* @return mixed
*/
function value($value, ...$args)
{
return $value instanceof Closure ? $value(...$args) : $value;
}
}
?>
@ckyoung my team has confirmed that this solution works. Thank you very much mate!
Terms
Description
Activating WPML or OTGS Installer crashes the frontend of the site. The exception is: "Undefined index: __laravel_slots". You can see more in this screenshot:
I have tried switching themes and it works fine. It's only when using Sage 10 that this happens. Hasn't happened with Sage 9. Also tried reinstalling composer packages, doesn't fix the issue.
I'm really not sure what can be causing this. Any insight is greatly appreciated!
Steps To Reproduce
Expected Behavior
Site frontend loading properly and WPML functioning as expected.
Actual Behavior
Site frontend crashes when WPML is active.
Relevant Log Output
Versions
Sage 10.1.4 - macOS Monterey 12.3.1 - PHP 7.4.21 - Apache 2.4.46