fix: admin cannot add new posts
error handling in report #166 By excluding the admin from using the features in the administration, ensuring data is always accurate and timely, users will still be able to navigate as usual.
Quality Gate passed
Issues
1 New issue
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
I'm not sure everyone is going to want to bypass replicas in the admin. In some setups, replicas could accept reads or could contain specific parts of the database. We've solved this in our db-config.php with this (probably still not fully optimized) setup:
if (defined( 'WP_CLI' ) && WP_CLI || defined( 'WP_ADMIN' ) && WP_ADMIN) {
/**
* If we're in the WP CLI, we want to prevent cache/replica sync race conditions,
* so we will only use the master db here
*/
$wpdb->add_database( array(
'host' => DB_HOST,
'user' => DB_USER,
'password' => DB_PASSWORD,
'name' => DB_NAME,
'write' => 1,
'read' => 1,
) );
} else {
/**
* Front end reads all come from the replica. All writes go to the master.
*/
$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' => REPLICA_DB_HOST,
'user' => REPLICA_DB_USER,
'password' => REPLICA_DB_PASSWORD,
'name' => REPLICA_DB_NAME,
'write' => 0, // replica doesn't take write queries
'read' => 1, // ... but it does take read queries
));
}
@justinmaurerdotdev i know it's extreme to ignore it but really the new post feature can't work so just leave this part alone, this merger may not be accepted but it's a good solution to the problem of not being able to access the new post creation page