This is something that was bugging me for a while. How can multiple developers work on same wordpress without messing up the code ?
The answer came from two wordpress variables : WP_SITEURL and WP_HOME.
If the two variables are set , wordpress blog do not get them from the database.
Step 1.
Adding this code at top of wp-config.php
/**
* This code adds base url for wordpress site.
* This means that it will work no matter the directory ,
* if get_parmalink() is used.
* @author Ivan Gospodinow
* @site http://www.ivangospodinow.com
* @mail ivangospodinow@gmail.com
* @date 30.09.2012
*/
foreach(array('/wp-admin','/wp-content','/wp-includes') as $_folder){
if(strpos($_SERVER['PHP_SELF'],$_folder) !== false){
$_r = explode($_folder,$_SERVER['PHP_SELF']);
$_path = $_r[0];
break;
}
}
if(!isset($_path)){
$_r = strrpos($_SERVER['PHP_SELF'], '/');
$_path = substr($_SERVER['PHP_SELF'], 0,$_r);
}
$_http = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https':'http').'://';
/**
* WP variables
*/
define('WP_SITEURL',$_http.$_SERVER['HTTP_HOST'].$_path);
define('WP_HOME', WP_SITEURL);
unset($_path,$_r,$_http,$_folder);
This code will insure that WP_SITEURL and WP_HOME variables point to current wordpress directory.
Step 2.
Adding non directory .htaccess
# BEGIN WordPressRewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] # END WordPress
This code will insure that the .htaccess will work no matter the directory.
Step 3.
How to use this method ?
Install wordpress blog in folder ‘path_to_public_dir/dev/developer_1/project_name/’.
Do step 1 and step 2.
Copy project to folder ‘path_to_public_dir/dev/developer_2/project_name/’ or ‘path_to_public_dir/live/project_name/’.
Suggestions or problems ?
Write a comment.