Skip to content

Instantly share code, notes, and snippets.

@pyrmont
Last active December 17, 2015 04:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pyrmont/5553858 to your computer and use it in GitHub Desktop.
Save pyrmont/5553858 to your computer and use it in GitHub Desktop.
Initial version of a plugin to ease local development of WordPress websites.
<?php
/*
Plugin Name: Localist
Plugin URI:
Description: Localist allows you to reach an installation of WordPress regardless of the WordPress address defined in the database.
Version: 1.0
Author: Michael Camilleri
Author URI: http://inqk.net/
License: Public Domain
*/
$localist = array();
$localist['protocol'] = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$localist['req_server'] = $localist['protocol'] . $_SERVER['HTTP_HOST'];
$localist['sav_server'] = get_bloginfo('siteurl');
add_filter('template_directory_uri', 'localist_requested_host');
add_filter('stylesheet_directory_uri', 'localist_requested_host');
add_filter('plugins_url', 'localist_requested_host');
add_filter('wp_get_attachment_url', 'localist_requested_host');
// WARNING: Used in the admin section. Enabling these will inject the req_server into the database.
// add_filter('option_siteurl', 'localist_requested_host', 1); //
// add_filter('option_home', 'localist_requested_host', 1); //
// NOTICE: These appear not do anything.
// add_filter('bloginfo', 'localist_bloginfo', 10, 2);
// add_filter('bloginfo_url', 'localist_siteurl');
// add_filter('pre_option_siteurl', 'localist_siteurl');
function localist_requested_host($content) {
global $localist;
$pos = strpos($content, $localist['sav_server']);
return ($pos !== false) ? $content = substr_replace($content, $localist['req_server'], $pos, strlen($localist['sav_server'])) : $content;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment