Fatal Error Due to Array Length Mismatch in menu-list-item.php

This topic has 4 replies, 2 voices, and was last updated 3 months, 3 weeks ago ago by Luca Rossi

  • Avatar: delovionline
    delovionline
    Participant
    July 26, 2024 at 16:06

    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.

    3 Answers
    Avatar: Justin
    Luca Rossi
    Support staff
    July 28, 2024 at 04:09

    Dear @delovionline,

    We hope this message finds you well. We kindly request that you refrain from incorporating special characters (such as “| ,”) into the links. These characters may cause technical issues.

    We have forwarded this matter to our development team for further review. It is anticipated that a resolution will be included in forthcoming updates.

    Thank you for your attention to this matter.

    Best Regards,
    The 8Theme Team

    Avatar: delovionline
    delovionline
    Participant
    July 28, 2024 at 21:58

    We get that error on the front page of the site after every update, so there are no characters in our URLs 🙂

    Avatar: Justin
    Luca Rossi
    Support staff
    July 29, 2024 at 05:54

    Hi @delovionline,

    We would need access to your WP Admin and FTP accounts to further investigate and address the problem.

    To grant WP-Admin access, kindly create a new user account with an administrator role via your WordPress Dashboard. Once the account is set up, please securely share the login credentials with us through the Private Content section designated for this purpose.

    For FTP access, please provide us with the following details: FTP host, FTP username, FTP password, FTP port, and FTP encryption type. If you require assistance in setting up these credentials, your hosting provider should be able to assist you.

    Thank you for your cooperation and assistance. We look forward to your prompt response.

    Best Regards,
    8Theme’s Team

  • Viewing 4 results - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.Log in/Sign up

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.