I have setup WP instance with 2 different database, one for read only and other for admin purpose.
But once the admin make the changes, then the ADMIN-DB should be copied and added to SLAVE-DB server.
// check if url contains wp-login or wp-admin and then create DB configuration for Master DB else Slave DB.
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if ( false !== strpos( $url, 'wp-admin' ) || false !== strpos( $url, 'wp-login' ) ) {
define( 'DB_NAME', 'SLAVE_DB_NAME' );
define( 'DB_USER', 'SLAVE_DB_USER' );
define( 'DB_PASSWORD', 'SLAVE_DB_PASSWORD' );
define( 'DB_HOST', 'SLAVE_DB_HOST' );
} else {
define( 'DB_NAME', 'MASTER_DB_NAME' );
define( 'DB_USER', 'MASTER_DB_USER' );
define( 'DB_PASSWORD', 'MASTER_DB_PASSWORD' );
define( 'DB_HOST', 'MASTER_DB_HOST' );
}
Related Posts:
- Is sanitize_text_field() is enough to save to DB?
- What is the most secure way to store post meta data in WP?
- Is $wpdb->prepare escaping to much? How to use it properly?
- Who is responsible for data sanitization in WordPress development?
- How do I properly update the WordPress database password?
- WordPress and user security
- What’s the proper way to sanitize checkbox value sent to the database
- What can I do when an outside party hacks into my weblog and changes my display name?
- WordPress security [closed]
- Secure way to use name_save_pre?
- WordPress Database – wp_usermeta and the correct number of session_tokens rows
- Insert NULL value using prepare()
- spambot registering without providing email or password, bypassing registration process
- Hash user emails in database?
- What is this JavaScript “require”?
- Using wpdb to connect to a separate database
- How can I make updates to a site, on a development copy, but then move updates back without overriding live site’s evolving database?
- get_results using wpdb
- How can I make a WordPress database portable and url independent?
- wpdb->insert multiple record at once
- How to migrate a HTTPS WordPress installation to localhost?
- How to stop WordPress using utf8mb4_unicode_520_ci collation?
- How to monitor server for error establishing a database connection
- Exporting revisions
- WP_Options ID high
- Default WordPress settings API data sanitization
- Fatal error: Call to undefined function dbDelta()
- Connect to remote database using Localhost install
- remove missing image attachments
- How to use multiple database in wordpress?
- How to ensure data consistency in WordPress
- Is removing orphaned wp_postmeta records safe?
- How to intercept update_option() before it saves data?
- Finding the login page from database?
- Does thumbnail regeneration edit the database?
- When and why should I use $wpdb different return types?
- Database with mixed collation (utf8mb4 & utf8_general_ci)
- Delete all post meta except featured image Using SQL
- WordPress doesn’t show all posts in database
- Adding new row to wp_post table
- Extracting the post_id via the wp_insert_post action (external db query)
- How to interact with another wordpress install on same database?
- Are custom tables in the database overwritten when WordPress is updated to new versions?
- What is the proper way to validate and sanitize JSON response from REST API?
- How do I get the posts within a certain year/date(with sql query)?
- batch UPDATE autoload value in wp_options table
- Displaying BLOB PDF File
- Saving into post_excerpt or post_content
- Maintain user profile data in a non-WordPress database
- How to fix the disappearance of the “\” character when updating a post in the database
- Data storage for JS app using WP REST API
- Update from 4.5 to 4.6 failing
- Setup 3 Sites To Connect To 1 Database and Share Data
- How can I push local database changes to production, without impacting recent posts/pages that were published on production server?
- Setup private content for specific users with daily updates [closed]
- Does auto_load to ‘no’ in wp_options improve performance
- Connection refused on locahost after importing database?
- Is it possible to rebuild the website while not accesseing the original database?
- Error message on blog posts only on my local environment [closed]
- how to read database fields
- $wpdb->query can’t insert data
- WSOD 3.9.1 – Tried Everything so far
- Can you refresh ONLY the wordpress adminbar and not the whole page?
- Sending posts from Python to WordPress
- Problem migrating to localhost
- SQL query to set posts in bulk based on the post content
- Automate WordPress website setup with prefilled data
- How can I detect right db type?
- Add search bar to Custom Database Table in WordPress Dashboard
- Design problems when exporting remote database for local development
- How do you render posts from outside wordpress?
- A change in URL slug in database returns 404, how can I do auto-redirect?
- Second ezSQL initialization for MSSQL
- Fetch a single row from a custom table for to a given ID
- Database create or redirect
- Database structure cheatsheet
- White Screen in Home Page
- Continuous SQL query errors from outside source
- How to escape percentage sign(%) in sql query with $wpdb->prepare?
- Recovery – Restore Database after moving folder location locally
- Migrate Users From laravel to wordpress
- WordPress has been updated! Before we send you on your way, we have to update your database to the newest version
- how add more field to wp user and save it to database
- How do I cleanup my database with data that is no longer being used?
- Malware in old website – how to migrate?
- error establishing database connection (WAMP + filezilla)
- Is there a way for two deferent themes to consume two different DB on a same WP instance?
- How to display $wpdb->insert_id; value on redirected page
- Should I Use only wpdb Class to Write Custom Queries?
- Auto populate form fields based on serial input or pull listings from other websites?
- How to extract some part of WordPress full source code
- Wrong url for the images while using same database for two WordPress installations
- Error establishing a database connection for some files
- Sending WordPress database information to cross domain the safe way?
- Database Name Change
- Weird characters in title if it contain “ ”
- Where To Find bb_profile_data(); In bbPress?
- Saving data to database and exporting to excel
- One information repeated on multiple locations on one site [closed]
- Showing Error(TAble already exist)