• Resolved hjfkr

    (@hjfkr)


    There is an issue with the section in trp-ajax.php that retrieves database constants from wp-config.php, which may sometimes produce incorrect results.

    • define() statements commented out with # become active.
    • It does not handle definitions expecting variable expansion, such as define(“DB_HOST”, “db.{$_SERVER[‘ENV’]}.example.com”);

    This likely occurs because constant values cannot be defined twice. Please modify connect_to_db() as follows to ensure correct operation:

    $const = get_defined_constants(true)['user'] ?? [];

    $credentials = [
    'db_name' => 'DB_NAME',
    'db_user' => 'DB_USER',
    'db_password' => 'DB_PASSWORD',
    'db_host' => 'DB_HOST',
    'db_charset' => 'DB_CHARSET'
    ];

    foreach($credentials as $credential => $constant_name) {
    if (isset($const[$constant_name])) {
    $credentials[$credential] = $const[$constant_name];
    } else {
    return false;
    }
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Daniel

    (@danieldandu)

    Hello @hjfkr,

    Thank you for reporting this and for taking the time to investigate it.

    We’ve reviewed the issue internally. The behavior you’re seeing is related to how trp-ajax.php works: it does not execute wp-config.php, it only reads it as a file. Because of this, certain define() setups cannot be reliably interpreted in this context.

    For safety reasons, executing wp-config.php directly is not something we can do, as it may contain additional logic or includes that would make the endpoint unpredictable.

    That said, your findings did help us think of a possible workaround. One approach we’re considering is allowing users to provide a small, dedicated file (for example trp-wp-config.php) containing only the required database define() statements. TranslatePress could safely load this file if present, without touching the full wp-config.php.

    Would this approach work for your setup?

    Thread Starter hjfkr

    (@hjfkr)

    @danieldandu

    I see, I understand perfectly.

    It seems possible to extract only the database-related constants from the script that includes wp-config.php using a mechanism like the one I wrote, and output them to trp-wp-config.php.

    If trp-wp-config.php doesn’t exist, it would be great if it could be automatically generated by executing the above. However, if that’s difficult, I’d like to create it manually by running the script.

    Plugin Support Daniel

    (@danieldandu)

    Hello @hjfkr,

    I’ve discussed this further with our development team, and we will be adding official support for this scenario, so that the database constants can be handled properly without relying on parsing wp-config.php in a fragile way.

    We will notify you as soon as the update including this improvement is released.

    Thank you again for your valuable input.

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

You must be logged in to reply to this topic.