Title: Retrieving an incorrect constants value
Last modified: February 10, 2026

---

# Retrieving an incorrect constants value

 *  Resolved [hjfkr](https://wordpress.org/support/users/hjfkr/)
 * (@hjfkr)
 * [5 months, 1 week ago](https://wordpress.org/support/topic/retrieving-an-incorrect-constants-value/)
 * 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:
 *     ```wp-block-code
       $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](https://wordpress.org/support/users/danieldandu/)
 * (@danieldandu)
 * [5 months, 1 week ago](https://wordpress.org/support/topic/retrieving-an-incorrect-constants-value/#post-18816592)
 * Hello [@hjfkr](https://wordpress.org/support/users/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](https://wordpress.org/support/users/hjfkr/)
 * (@hjfkr)
 * [5 months, 1 week ago](https://wordpress.org/support/topic/retrieving-an-incorrect-constants-value/#post-18820420)
 * [@danieldandu](https://wordpress.org/support/users/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](https://wordpress.org/support/users/danieldandu/)
 * (@danieldandu)
 * [5 months, 1 week ago](https://wordpress.org/support/topic/retrieving-an-incorrect-constants-value/#post-18823304)
 * Hello [@hjfkr](https://wordpress.org/support/users/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](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fretrieving-an-incorrect-constants-value%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/translatepress-multilingual/assets/icon.svg?rev=3166541)
 * [TranslatePress - Translate Multilingual sites with AI Translation](https://wordpress.org/plugins/translatepress-multilingual/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/translatepress-multilingual/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/translatepress-multilingual/)
 * [Active Topics](https://wordpress.org/support/plugin/translatepress-multilingual/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/translatepress-multilingual/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/translatepress-multilingual/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Daniel](https://wordpress.org/support/users/danieldandu/)
 * Last activity: [5 months, 1 week ago](https://wordpress.org/support/topic/retrieving-an-incorrect-constants-value/#post-18823304)
 * Status: resolved