Skip to content

Instantly share code, notes, and snippets.

@talves
Last active September 7, 2016 15:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save talves/7346027 to your computer and use it in GitHub Desktop.
Save talves/7346027 to your computer and use it in GitHub Desktop.
A Wordpress mu-plugin for use with composer using [roots](https://github.com/roots/roots) to setup the correct paths for a custom path. Modified `upload_url_path` to work on a windows IIS Server. Change to `/media` when needed.
<?php
if (!is_blog_installed()) { return; }
$my_server_port = ((!empty ($_SERVER ['SERVER_PORT']) AND $_SERVER ['SERVER_PORT'] <> '80') ? (":" . $_SERVER ['SERVER_PORT']) : '');
$my_server_name = (!empty ($my_server_port) ?($_SERVER['SERVER_NAME'] . $my_server_port) : $_SERVER['SERVER_NAME'] );
if ('http://' . $my_server_name . '/wp' == get_option('home')) {
update_option('siteurl', 'http://' . $my_server_name . '/wp');
update_option('home', 'http://' . $my_server_name);
update_option('upload_path', $_SERVER['DOCUMENT_ROOT'] . '\media');
update_option('upload_url_path', 'http://' . $my_server_name . '/media');
update_option('permalink_structure', '/%postname%/');
}
if (get_option('upload_url_path') == ''){
update_option('upload_url_path', 'http://' . $my_server_name . '/media');
}
if (get_option('upload_path') == '' || get_option('upload_path') == 'media'){
update_option('upload_path', $_SERVER['DOCUMENT_ROOT'] . '\media');
}
if (defined('FRONT_PAGE') && defined('POSTS_PAGE') && !get_option('page_on_front')) {
$front = get_page_by_title(FRONT_PAGE);
$posts = get_page_by_title(POSTS_PAGE);
if ($front && $posts) {
update_option('show_on_front', 'page');
update_option('page_on_front', $front->ID);
update_option('page_for_posts', $posts->ID);
}
}
?>
@tjhole
Copy link

tjhole commented Sep 7, 2016

Minor issue - a few of the media paths are \media, they should be / otherwise it creates a "\media" directory instead of using "media"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment