Hello,
Every time I update my et core plugin, I encounter a Fatal Error. The issue is caused by a mismatch in the lengths of the arrays passed to the array_combine function in the menu-list-item.php file of the et-core-plugin. The array_combine function requires two arrays of equal length to create a new array where one array is used as keys and the other as values.
The specific problem occurs when the title_link attribute is exploded into two parts (keys and values), but these parts do not always have the same number of elements. This mismatch causes a ValueError and results in a fatal error.
To resolve the issue, I modified the code to include a check ensuring that the two arrays (keys and values) are of equal length before calling array_combine. If the lengths do not match, an appropriate error message is logged, and an empty array is assigned to $atts[‘link’] to avoid further issues.
Here is a summary of the changes made:
1. Validation of title_link Format: Ensure the title_link is in the expected format and contains two parts after being exploded by the delimiter |.
2. Length Check: Added a check to compare the lengths of the keys and values arrays before combining them.
3. Error Handling: If the lengths do not match, log an error message and assign an empty array to $atts[‘link’].
Original Code
if (!$atts[‘is_elementor’]) {
$atts[‘link’] = (‘||’ === $atts[‘title_link’]) ? ” : $atts[‘title_link’];
unset($atts[‘title_link’]);
$atts[‘link’] = parent::build_link($atts[‘link’]);
} else {
$atts[‘link’] = array_combine(
explode(‘,’, $atts[‘title_link’][0]),
explode(‘,’, $atts[‘title_link’][1])
);
}
Modified Code
if (!$atts[‘is_elementor’]) {
$atts[‘link’] = (‘||’ === $atts[‘title_link’]) ? ” : $atts[‘title_link’];
unset($atts[‘title_link’]);
$atts[‘link’] = parent::build_link($atts[‘link’]);
} else {
$atts[‘link’] = explode(‘|’, $atts[‘title_link’]);
if (count($atts[‘link’]) >= 2) {
$keys = explode(‘,’, $atts[‘link’][0]);
$values = explode(‘,’, $atts[‘link’][1]);
// Log the lengths of keys and values
error_log(‘Keys count: ‘ . count($keys));
error_log(‘Values count: ‘ . count($values));
// Ensure both keys and values are arrays and have equal length before calling array_combine
if (is_array($keys) && is_array($values) && count($keys) == count($values)) {
error_log(‘Keys and values are valid and of equal length, combining arrays.’);
$atts[‘link’] = array_combine($keys, $values);
} else {
error_log(‘Cannot combine keys and values: Invalid or mismatched arrays.’);
$atts[‘link’] = array();
}
} else {
error_log(‘Invalid title_link format: ‘ . $atts[‘title_link’]);
$atts[‘link’] = array();
}
}
Suggested Permanent Fix
Incorporate the above validation and error-handling logic into the plugin’s codebase to ensure that array_combine only gets called with valid, equal-length arrays. This will prevent the fatal error from occurring and ensure compatibility with future updates.
Thank you.