• Resolved vespino

    (@vespino)


    With the latest version of the plugin I’m getting these warnings:

    [24-Apr-2025 05:01:21 UTC] PHP Warning:  Undefined array key "scheme" in /***/public_html/wp-content/plugins/wpcf7-redirect/vendor/codeinwp/themeisle-sdk/load.php on line 238
    [24-Apr-2025 05:01:21 UTC] PHP Warning:  Undefined array key "host" in /***/public_html/wp-content/plugins/wpcf7-redirect/vendor/codeinwp/themeisle-sdk/load.php on line 238
    [24-Apr-2025 05:01:23 UTC] PHP Warning:  Undefined array key "scheme" in /***/public_html/wp-content/plugins/wpcf7-redirect/vendor/codeinwp/themeisle-sdk/load.php on line 238
    • This topic was modified 1 year, 1 month ago by vespino.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support rodicaelena

    (@rodicaelena)

    Hi @vespino,

    Thank you very much for sharing this. We’ll fix it in the next release.

    Kind regards,

    Rodica

    Fix for PHP Warnings in ThemeIsle SDK (load.php)

    Hi there,

    I also noticed these PHP warnings in the debug log related to the ThemeIsle SDK used by the wpcf7-redirect plugin. The warnings occur in the tsdk_translate_link() function when trying to access undefined array keys ‘scheme’ and ‘host’.

    Warnings:

    PHP Warning: Undefined array key "scheme" in [...]/themeisle-sdk/load.php on line 238
    PHP Warning: Undefined array key "host" in [...]/themeisle-sdk/load.php on line 238

    I’ve created a fix that adds proper validation checks before accessing the URL components. Here’s the modified version of the function, which can be found in the file /wp-content/plugins/wpcf7-redirect/vendor/codeinwp/themeisle-sdk/load.php at line 205ff:

    	/**
    * Function to translate a link based on the current language.
    *
    * @param string $url URL to translate.
    * @param string{'path'|'query'|'domain'} $type Type of localization. Supports path, query and domain.
    * @param array $available_languages Available language to choose from.
    *
    * @return string
    */
    function tsdk_translate_link(
    $url, $type = 'path', $available_languages = [
    'de_DE' => 'de',
    'de_DE_formal' => 'de',
    ]
    ) {
    $language = get_user_locale();
    if ( ! isset( $available_languages[ $language ] ) ) {
    return $url;
    }
    $code = $available_languages[ $language ];
    // We asume that false is based on query and add the code via query arg.
    if ( $type === 'query' ) {
    return add_query_arg( 'lang', $code, $url );
    }

    $parsed_url = wp_parse_url($url);

    // Sicherheitsprüfung für ungültige URLs
    if (!is_array($parsed_url) || empty($parsed_url)) {
    return $url;
    }

    // we replace the domain here based on the localized one.
    if ( $type === 'domain' ) {
    if (!isset($parsed_url['scheme']) || !isset($parsed_url['path'])) {
    return $url;
    }
    return $parsed_url['scheme'] . '://' . $code .
    ( isset( $parsed_url['path'] ) ? $parsed_url['path'] : '' ) .
    ( isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '' ) .
    ( isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '' );
    }

    // default is the path based approach.
    $new_path = isset( $parsed_url['path'] ) ? "/$code" . $parsed_url['path'] : "/$code";

    // Stelle sicher, dass alle notwendigen URL-Komponenten vorhanden sind
    if (!isset($parsed_url['scheme']) || !isset($parsed_url['host'])) {
    return $url;
    }

    return $parsed_url['scheme'] . '://' . $parsed_url['host'] . $new_path .
    ( isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '' ) .
    ( isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '' );
    }

    The changes include:

    1. Validation of the parsed URL array
    2. Specific checks for the ‘domain’ type approach
    3. Validation of required URL components (scheme and host)
    4. Fallback to original URL if required components are missing

    This fix maintains all functionality while eliminating the PHP warnings. Feel free to incorporate these changes in a future update.

    Best regards

    Plugin Support Kush

    (@kushnamdev)

    Thank you for sharing this with us. Our team will take a look at this. Have a great day!

    Plugin Support rodicaelena

    (@rodicaelena)

    Hi there,

    The latest update should fix this. Can you please let us know if you are still experiencing issues or everything is ok?

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Undefined array key’ is closed to new replies.