@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // Exit if accessed directly |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if (!defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -33,24 +33,24 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public function __construct() { |
35 | 35 | // modify domain where necessary |
36 | - add_filter( 'option_blogname', array( $this, 'setup_domain' ), 1 ); |
|
37 | - add_filter( 'option_siteurl', array( $this, 'setup_domain' ), 1 ); |
|
38 | - add_filter( 'option_home', array( $this, 'setup_domain' ), 1 ); |
|
39 | - add_filter( 'stylesheet_uri', array( $this, 'setup_domain' ), 1 ); |
|
40 | - add_filter( 'stylesheet_directory_uri', array( $this, 'setup_domain' ), 1 ); |
|
41 | - add_filter( 'template_directory_uri', array( $this, 'setup_domain' ), 1 ); |
|
42 | - add_filter( 'plugins_url', array( $this, 'setup_domain' ), 1 ); |
|
36 | + add_filter('option_blogname', array($this, 'setup_domain'), 1); |
|
37 | + add_filter('option_siteurl', array($this, 'setup_domain'), 1); |
|
38 | + add_filter('option_home', array($this, 'setup_domain'), 1); |
|
39 | + add_filter('stylesheet_uri', array($this, 'setup_domain'), 1); |
|
40 | + add_filter('stylesheet_directory_uri', array($this, 'setup_domain'), 1); |
|
41 | + add_filter('template_directory_uri', array($this, 'setup_domain'), 1); |
|
42 | + add_filter('plugins_url', array($this, 'setup_domain'), 1); |
|
43 | 43 | |
44 | 44 | // replace various occurences |
45 | - add_filter( 'the_content', array( $this, 'setup_content' ) ); // content |
|
46 | - add_filter( 'widget_text', array( $this, 'setup_content' ) ); // widget text |
|
47 | - add_filter( 'upload_dir', array( $this, 'setup_upload_dir' ) ); // wp_upload_dir(); |
|
45 | + add_filter('the_content', array($this, 'setup_content')); // content |
|
46 | + add_filter('widget_text', array($this, 'setup_content')); // widget text |
|
47 | + add_filter('upload_dir', array($this, 'setup_upload_dir')); // wp_upload_dir(); |
|
48 | 48 | |
49 | 49 | // allow developers to support multiple domains in fields that contain only a site URL |
50 | - add_filter( 'wp_hydra_domain', array( $this, 'setup_domain' ) ); |
|
50 | + add_filter('wp_hydra_domain', array($this, 'setup_domain')); |
|
51 | 51 | |
52 | 52 | // allow developers to support URLs with multiple domains in their content |
53 | - add_filter( 'wp_hydra_content', array( $this, 'setup_content' ) ); |
|
53 | + add_filter('wp_hydra_content', array($this, 'setup_content')); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -61,12 +61,12 @@ discard block |
||
61 | 61 | * @param string $url The current URL. |
62 | 62 | * @return string $url The URL with the (maybe) replaced domain. |
63 | 63 | */ |
64 | - public function setup_domain( $url ) { |
|
64 | + public function setup_domain($url) { |
|
65 | 65 | // parse current URL |
66 | - $original_domain_parts = parse_url( $url ); |
|
66 | + $original_domain_parts = parse_url($url); |
|
67 | 67 | |
68 | 68 | // if unable to retrieve the host, skip |
69 | - if ( empty( $original_domain_parts['host'] ) || ! isset( $_SERVER['HTTP_HOST'] ) ) { |
|
69 | + if (empty($original_domain_parts['host']) || !isset($_SERVER['HTTP_HOST'])) { |
|
70 | 70 | return $url; |
71 | 71 | } |
72 | 72 | |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | $current_domain = $_SERVER['HTTP_HOST']; |
76 | 76 | |
77 | 77 | // if original and current domain match, skip |
78 | - if ( $original_domain == $current_domain ) { |
|
78 | + if ($original_domain == $current_domain) { |
|
79 | 79 | return $url; |
80 | 80 | } |
81 | 81 | |
82 | - return $this->replace_domain( $url, $original_domain, $current_domain ); |
|
82 | + return $this->replace_domain($url, $original_domain, $current_domain); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -92,17 +92,17 @@ discard block |
||
92 | 92 | * @param string $new_domain The new domain. |
93 | 93 | * @return string $url The new URL. |
94 | 94 | */ |
95 | - protected function replace_domain( $url, $old_domain, $new_domain ) { |
|
95 | + protected function replace_domain($url, $old_domain, $new_domain) { |
|
96 | 96 | // prepare original domain and current domain with the current protocol |
97 | - $protocols = array( 'http://', 'https://' ); |
|
98 | - $current_protocol = ( $this->is_ssl() ? 'https' : 'http' ) . '://'; |
|
97 | + $protocols = array('http://', 'https://'); |
|
98 | + $current_protocol = ($this->is_ssl() ? 'https' : 'http').'://'; |
|
99 | 99 | |
100 | - foreach ( $protocols as $protocol ) { |
|
101 | - $original_base = $protocol . $old_domain; |
|
102 | - $new_base = $current_protocol . $new_domain; |
|
100 | + foreach ($protocols as $protocol) { |
|
101 | + $original_base = $protocol.$old_domain; |
|
102 | + $new_base = $current_protocol.$new_domain; |
|
103 | 103 | |
104 | 104 | // replace original domain with current domain |
105 | - $url = str_replace( $original_base, $new_base, $url ); |
|
105 | + $url = str_replace($original_base, $new_base, $url); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | return $url; |
@@ -116,17 +116,17 @@ discard block |
||
116 | 116 | * @param string $content The current content with the original domain. |
117 | 117 | * @return string $content The content with the new domain. |
118 | 118 | */ |
119 | - public function setup_content( $content ) { |
|
119 | + public function setup_content($content) { |
|
120 | 120 | // get original home URL |
121 | - remove_filter( 'option_home', array( $this, 'setup_domain' ), 1 ); |
|
122 | - $original_home = home_url( '/' ); |
|
123 | - add_filter( 'option_home', array( $this, 'setup_domain' ), 1 ); |
|
121 | + remove_filter('option_home', array($this, 'setup_domain'), 1); |
|
122 | + $original_home = home_url('/'); |
|
123 | + add_filter('option_home', array($this, 'setup_domain'), 1); |
|
124 | 124 | |
125 | 125 | // get current home URL |
126 | - $current_home = home_url( '/' ); |
|
126 | + $current_home = home_url('/'); |
|
127 | 127 | |
128 | 128 | // replace occurences of original URL with current home URL |
129 | - $content = str_replace( $original_home, $current_home, $content ); |
|
129 | + $content = str_replace($original_home, $current_home, $content); |
|
130 | 130 | |
131 | 131 | return $content; |
132 | 132 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * @param array $upload_dir The current upload dir settings with the original domain. |
140 | 140 | * @return array $upload_dir The upload dir settings with the new domain. |
141 | 141 | */ |
142 | - public function setup_upload_dir( $upload_dir ) { |
|
142 | + public function setup_upload_dir($upload_dir) { |
|
143 | 143 | // keys of array element that we'll be updating |
144 | 144 | $keys_to_update = array( |
145 | 145 | 'url', |
@@ -147,8 +147,8 @@ discard block |
||
147 | 147 | ); |
148 | 148 | |
149 | 149 | // fix all targeted array elements |
150 | - foreach ( $keys_to_update as $key ) { |
|
151 | - $upload_dir[ $key ] = apply_filters( 'wp_hydra_domain', $upload_dir[ $key ] ); |
|
150 | + foreach ($keys_to_update as $key) { |
|
151 | + $upload_dir[$key] = apply_filters('wp_hydra_domain', $upload_dir[$key]); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | return $upload_dir; |