Permalink
Browse files

Basic staging domain rewriting. More to come.

  • Loading branch information...
1 parent 6c49d1d commit 1f64f490d02f59a54f3342ccef72e90c0b8bc3f9 @markjaquith committed Jun 6, 2012
Showing with 34 additions and 0 deletions.
  1. +34 −0 WordPress-Dropins/wp-stack-staging.php
@@ -0,0 +1,34 @@
+<?php
+/*
+Plugin Name: WP Stack Staging
+Version: 0.1
+Author: Mark Jaquith
+Author URI: http://coveredwebservices.com/
+*/
+
+// Convenience methods
+if(!class_exists('WP_Stack_Plugin')){class WP_Stack_Plugin{function hook($h){$p=10;$m=$this->sanitize_method($h);$b=func_get_args();unset($b[0]);foreach((array)$b ass
+ $a){if(is_int($a))$p=$a;else $m=$a;}return add_action($h,array($this,$m),$p,999);}private function sanitize_method($m){return str_replace(array('.','-'),array('_DOTT
+_','_DASH_'),$m);}}}
+
+// The plugin
+class WP_Stack_Staging_Plugin extends WP_Stack_Plugin {
+ public static $instance;
+
+ public function __construct() {
+ self::$instance = $this;
+ if ( !defined( 'WP_STAGE' ) || WP_STAGE !== 'staging' || !defined( 'STAGING_DOMAIN' ) )
+ return;
+ $this->hook( 'option_home', 'replace_domain' );
+ $this->hook( 'option_siteurl', 'replace_domain' );
+ }
+
+ public function replace_domain ( $url ) {
+ $current_domain = parse_url( $url, PHP_URL_HOST );
+ $url = str_replace( '//' . $current_domain, '//' . STAGING_DOMAIN, $url );
+ return $url;
+ }
+}
+
+new WP_Stack_Staging_Plugin;
+

0 comments on commit 1f64f49

Please sign in to comment.