dimanche 7 mai 2017

hyperDB - show main DB to logged in user

I want to show the main Wordpress database to a logged in user instead of just exclude for /wp-admin/ sites:

$url = $_SERVER["REQUEST_URI"];
$isItAdmin = strpos($url, '/wp-admin/');
if($isItAdmin!==false) {
$wpdb->add_database( array(
        'host'     => DB_HOST,
        'user'     => DB_USER,
        'password' => DB_PASSWORD,
        'name'     => DB_NAME,
        'write'    => 1,
        'read'     => 1,
) );
} else {
$wpdb->add_database( array(
        'host'     => DB_HOST,
        'user'     => DB_USER,
        'password' => DB_PASSWORD,
        'name'     => DB_NAME,
        'write'    => 1,
        'read'     => 0,
) );    

$wpdb->add_database(array(
    'host'     => DB_HOST,     // If port is other than 3306, use host:port.
    'user'     => 'readonly_user',
    'password' => 'pw_readonly',
    'name'     => 'db_readonly',
    'write'    => 0,
    'read'     => 1,
    'dataset'  => 'global',
    'timeout'  => 0.2,
)); 
    }

I´ve tried to add this, but it breaks hyperDB:

    global $current_user; get_currentuserinfo();
    if ($current_user->ID !== '') { 
} else { }

Aucun commentaire:

Enregistrer un commentaire