Plugin option and read data in wp-config.php

Hi,

Is it possible to create a plugin option and then read that data and assigned it a defined variable in wp-config.php.

Eg. i want to be able to login to my dashboard and enter an item in a text field, that item is saved and then i want to retrieve and assigned that item to defined variable.

define('DB_NAME2', 'variableName');

so far in the plugin im able to add value to the text and saved it and retrieve that value. however i want to be able to retrieve it in the wp-config.php file. i don’t know if that make since. here’s how i read the saved data and this working fine but except in the wp-config.php

global $wpdb;
/* @var wpdb $wpdb */
$bawebsdbname = esc_attr( plug912_Option::get( $jid, 'variableName' ) ) ;
echo $variableName'

  • Sajid
    • DEV MAN’s Sidekick

    Hi Tom,

    Hope you are doing good today :slight_smile:

    If I understand correctly you want to update an constant in wp-config.php. If yes then that’s a bad idea. These are unchangeable/unupdatable thats why they are constants and not variables.

    Please see this discussion on stackoverflow for changing the values of a constant.

    http://stackoverflow.com/questions/6455877/can-you-undefine-or-change-a-constant-in-php

    Hope that helps! Feel free to post a reply if you need further assistance :slight_smile:

    Cheers, Sajid

  • Tom
    • Design Lord, Child of Thor

    HI @ Sajid,

    here’s what im trying to do. i have this code snippet its not in the WP-CONFIG.PHP file, its in a plugin file, i want to retrieve a db_name dynamically. eg. i have text field where i enter a database name for instance “testdbname” and then i have a variable call “$bawebsdbname” that i used to retrieved the name of the database i need to connect to and assigned that name to the variable “$bawebsdbname” . so what i want do now is use the same variable $bawebsdbname assign it to tthe example below where i have ‘dbname’ => DB_NAME.

    i want it to be ‘dbname’ => $bawebsdbname,

    $default_args = array(
    'dbhost' => DB_HOST,
    'dbname' => DB_NAME,
    'dbuser' => DB_USER,
    'dbpassword' => DB_PASSWORD,
    'dbcharset' => defined( 'DB_CHARSET' ) ? DB_CHARSET : '',
    'dumpfilehandle' => fopen( 'php://output', 'wb' ),
    'dumpfile' => NULL,
    'dbclientflags' => defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0,
    'compression' => ''
    );

    i don’t know if that make sense.

    thanks in advanced

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.