Completed
Pull Request — master (#14)
by Marin
01:42
created
wp-hydra.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,12 +14,12 @@
 block discarded – undo
14 14
  */
15 15
 
16 16
 // Exit if accessed directly.
17
-if ( ! defined( 'ABSPATH' ) ) {
17
+if (!defined('ABSPATH')) {
18 18
 	exit;
19 19
 }
20 20
 
21 21
 // Load main class.
22
-include_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class-wp-hydra.php' );
22
+include_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'class-wp-hydra.php');
23 23
 
24 24
 // initialize WP Hydra - Polycephaly FTW!
25 25
 global $wp_hydra;
Please login to merge, or discard this patch.
class-wp-hydra.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -17,24 +17,24 @@  discard block
 block discarded – undo
17 17
 	 */
18 18
 	public function __construct() {
19 19
 		// Modify domain where necessary.
20
-		add_filter( 'option_blogname', array( $this, 'setup_domain' ), 1 );
21
-		add_filter( 'option_siteurl', array( $this, 'setup_domain' ), 1 );
22
-		add_filter( 'option_home', array( $this, 'setup_domain' ), 1 );
23
-		add_filter( 'stylesheet_uri', array( $this, 'setup_domain' ), 1 );
24
-		add_filter( 'stylesheet_directory_uri', array( $this, 'setup_domain' ), 1 );
25
-		add_filter( 'template_directory_uri', array( $this, 'setup_domain' ), 1 );
26
-		add_filter( 'plugins_url', array( $this, 'setup_domain' ), 1 );
20
+		add_filter('option_blogname', array($this, 'setup_domain'), 1);
21
+		add_filter('option_siteurl', array($this, 'setup_domain'), 1);
22
+		add_filter('option_home', array($this, 'setup_domain'), 1);
23
+		add_filter('stylesheet_uri', array($this, 'setup_domain'), 1);
24
+		add_filter('stylesheet_directory_uri', array($this, 'setup_domain'), 1);
25
+		add_filter('template_directory_uri', array($this, 'setup_domain'), 1);
26
+		add_filter('plugins_url', array($this, 'setup_domain'), 1);
27 27
 
28 28
 		// Replace various occurences.
29
-		add_filter( 'the_content', array( $this, 'setup_content' ) ); // In oost content.
30
-		add_filter( 'widget_text', array( $this, 'setup_content' ) ); // In Widget text.
31
-		add_filter( 'upload_dir', array( $this, 'setup_upload_dir' ) ); // In wp_upload_dir().
29
+		add_filter('the_content', array($this, 'setup_content')); // In oost content.
30
+		add_filter('widget_text', array($this, 'setup_content')); // In Widget text.
31
+		add_filter('upload_dir', array($this, 'setup_upload_dir')); // In wp_upload_dir().
32 32
 
33 33
 		// Allow developers to support multiple domains in fields that contain only a site URL.
34
-		add_filter( 'wp_hydra_domain', array( $this, 'setup_domain' ) );
34
+		add_filter('wp_hydra_domain', array($this, 'setup_domain'));
35 35
 
36 36
 		// Allow developers to support URLs with multiple domains in their content.
37
-		add_filter( 'wp_hydra_content', array( $this, 'setup_content' ) );
37
+		add_filter('wp_hydra_content', array($this, 'setup_content'));
38 38
 	}
39 39
 
40 40
 	/**
@@ -45,12 +45,12 @@  discard block
 block discarded – undo
45 45
 	 * @param string $url The current URL.
46 46
 	 * @return string $url The URL with the (maybe) replaced domain.
47 47
 	 */
48
-	public function setup_domain( $url ) {
48
+	public function setup_domain($url) {
49 49
 		// Parse current URL.
50
-		$original_domain_parts = parse_url( $url );
50
+		$original_domain_parts = parse_url($url);
51 51
 
52 52
 		// If unable to retrieve the host, skip.
53
-		if ( empty( $original_domain_parts['host'] ) || ! isset( $_SERVER['HTTP_HOST'] ) ) {
53
+		if (empty($original_domain_parts['host']) || !isset($_SERVER['HTTP_HOST'])) {
54 54
 			return $url;
55 55
 		}
56 56
 
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
 		$current_domain  = $_SERVER['HTTP_HOST'];
60 60
 
61 61
 		// If original and current domain match, skip.
62
-		if ( $original_domain == $current_domain ) {
62
+		if ($original_domain == $current_domain) {
63 63
 			return $url;
64 64
 		}
65 65
 
66
-		return $this->replace_domain( $url, $original_domain, $current_domain );
66
+		return $this->replace_domain($url, $original_domain, $current_domain);
67 67
 	}
68 68
 
69 69
 	/**
@@ -76,17 +76,17 @@  discard block
 block discarded – undo
76 76
 	 * @param string $new_domain The new domain.
77 77
 	 * @return string $url The new URL.
78 78
 	 */
79
-	protected function replace_domain( $url, $old_domain, $new_domain ) {
79
+	protected function replace_domain($url, $old_domain, $new_domain) {
80 80
 		// Prepare original domain and current domain with the current protocol.
81
-		$protocols        = array( 'http://', 'https://' );
82
-		$current_protocol = ( $this->is_ssl() ? 'https' : 'http' ) . '://';
81
+		$protocols        = array('http://', 'https://');
82
+		$current_protocol = ($this->is_ssl() ? 'https' : 'http').'://';
83 83
 
84
-		foreach ( $protocols as $protocol ) {
85
-			$original_base = $protocol . $old_domain;
86
-			$new_base      = $current_protocol . $new_domain;
84
+		foreach ($protocols as $protocol) {
85
+			$original_base = $protocol.$old_domain;
86
+			$new_base      = $current_protocol.$new_domain;
87 87
 
88 88
 			// Replace original domain with current domain.
89
-			$url = str_replace( $original_base, $new_base, $url );
89
+			$url = str_replace($original_base, $new_base, $url);
90 90
 		}
91 91
 
92 92
 		return $url;
@@ -100,17 +100,17 @@  discard block
 block discarded – undo
100 100
 	 * @param string $content The current content with the original domain.
101 101
 	 * @return string $content The content with the new domain.
102 102
 	 */
103
-	public function setup_content( $content ) {
103
+	public function setup_content($content) {
104 104
 		// Get original home URL.
105
-		remove_filter( 'option_home', array( $this, 'setup_domain' ), 1 );
106
-		$original_home = home_url( '/' );
107
-		add_filter( 'option_home', array( $this, 'setup_domain' ), 1 );
105
+		remove_filter('option_home', array($this, 'setup_domain'), 1);
106
+		$original_home = home_url('/');
107
+		add_filter('option_home', array($this, 'setup_domain'), 1);
108 108
 
109 109
 		// Get current home URL.
110
-		$current_home = home_url( '/' );
110
+		$current_home = home_url('/');
111 111
 
112 112
 		// Replace occurences of original URL with current home URL.
113
-		$content = str_replace( $original_home, $current_home, $content );
113
+		$content = str_replace($original_home, $current_home, $content);
114 114
 
115 115
 		return $content;	
116 116
 	}
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	 * @param array $upload_dir The current upload dir settings with the original domain.
124 124
 	 * @return array $upload_dir The upload dir settings with the new domain.
125 125
 	 */
126
-	public function setup_upload_dir( $upload_dir ) {
126
+	public function setup_upload_dir($upload_dir) {
127 127
 		// Keys of array element that we'll be updating.
128 128
 		$keys_to_update = array(
129 129
 			'url',
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 		);
132 132
 
133 133
 		// Fix all targeted array elements.
134
-		foreach ( $keys_to_update as $key ) {
135
-			$upload_dir[ $key ] = apply_filters( 'wp_hydra_domain', $upload_dir[ $key ] );
134
+		foreach ($keys_to_update as $key) {
135
+			$upload_dir[$key] = apply_filters('wp_hydra_domain', $upload_dir[$key]);
136 136
 		}
137 137
 
138 138
 		return $upload_dir;
Please login to merge, or discard this patch.