Created
March 6, 2019 16:22
-
-
Save saltnpixels/a649e42aa2eedf9589a125fbcd3abf25 to your computer and use it in GitHub Desktop.
WordPress Workflow with remote DB on local
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Working on a WordPress theme with others can be difficult if you want to use the same database, but work locally and use git for the code. | |
//To do this we came up with a solution that allows working with a remote DB that everyone on the team can access, while still developing locally. | |
//First make sure that your wp-config file is set to use the remote db: | |
//set the credentials for the remote DB username and table | |
//change DB host to be the ip of the remote server | |
//Example: | |
define( 'DB_HOST', '123.45.678.195' ); | |
//Now make sure the home url is set to use the local version of your wordpress enviroment. We used local by flywheel. | |
//also make sure the admin end is using the remote site completely. | |
define('WP_HOME', 'http://yoursite.local'); //front end will use the local site | |
define('WP_SITEURL', 'http://staging.remote.com'); //the actual site where the database is | |
//lastly add this to your theme or a plugin so when viewing on local it will get your theme | |
//on local development load local theme instead. Everything else loads in as remote | |
if ( strpos($_SERVER['HTTP_HOST'], '.local' ) ) { | |
add_filter( 'theme_root_uri', 'ign_theme_root_uri', 10, 3 ); | |
} | |
function ign_theme_root_uri( $theme_root_uri, $siteurl, $stylesheet_or_template ) { | |
//replace thew siteurl with the local siteurl from the theme uri | |
return str_replace( $siteurl, 'http://yoursite.local', $theme_root_uri ); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment