@@ -29,24 +29,24 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public function __construct() { |
| 31 | 31 | // modify domain where necessary |
| 32 | - add_filter( 'option_blogname', array( $this, 'setup_domain' ), 1 ); |
|
| 33 | - add_filter( 'option_siteurl', array( $this, 'setup_domain' ), 1 ); |
|
| 34 | - add_filter( 'option_home', array( $this, 'setup_domain' ), 1 ); |
|
| 35 | - add_filter( 'stylesheet_uri', array( $this, 'setup_domain' ), 1 ); |
|
| 36 | - add_filter( 'stylesheet_directory_uri', array( $this, 'setup_domain' ), 1 ); |
|
| 37 | - add_filter( 'template_directory_uri', array( $this, 'setup_domain' ), 1 ); |
|
| 38 | - add_filter( 'plugins_url', array( $this, 'setup_domain' ), 1 ); |
|
| 32 | + add_filter('option_blogname', array($this, 'setup_domain'), 1); |
|
| 33 | + add_filter('option_siteurl', array($this, 'setup_domain'), 1); |
|
| 34 | + add_filter('option_home', array($this, 'setup_domain'), 1); |
|
| 35 | + add_filter('stylesheet_uri', array($this, 'setup_domain'), 1); |
|
| 36 | + add_filter('stylesheet_directory_uri', array($this, 'setup_domain'), 1); |
|
| 37 | + add_filter('template_directory_uri', array($this, 'setup_domain'), 1); |
|
| 38 | + add_filter('plugins_url', array($this, 'setup_domain'), 1); |
|
| 39 | 39 | |
| 40 | 40 | // replace various occurences |
| 41 | - add_filter( 'the_content', array( $this, 'setup_content' ) ); // content |
|
| 42 | - add_filter( 'widget_text', array( $this, 'setup_content' ) ); // widget text |
|
| 43 | - add_filter( 'upload_dir', array( $this, 'setup_upload_dir' ) ); // wp_upload_dir(); |
|
| 41 | + add_filter('the_content', array($this, 'setup_content')); // content |
|
| 42 | + add_filter('widget_text', array($this, 'setup_content')); // widget text |
|
| 43 | + add_filter('upload_dir', array($this, 'setup_upload_dir')); // wp_upload_dir(); |
|
| 44 | 44 | |
| 45 | 45 | // allow developers to support multiple domains in fields that contain only a site URL |
| 46 | - add_filter( 'wp_hydra_domain', array( $this, 'setup_domain' ) ); |
|
| 46 | + add_filter('wp_hydra_domain', array($this, 'setup_domain')); |
|
| 47 | 47 | |
| 48 | 48 | // allow developers to support URLs with multiple domains in their content |
| 49 | - add_filter( 'wp_hydra_content', array( $this, 'setup_content' ) ); |
|
| 49 | + add_filter('wp_hydra_content', array($this, 'setup_content')); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | * @param string $url The current URL. |
| 58 | 58 | * @return string $url The URL with the (maybe) replaced domain. |
| 59 | 59 | */ |
| 60 | - public function setup_domain( $url ) { |
|
| 60 | + public function setup_domain($url) { |
|
| 61 | 61 | // parse current URL |
| 62 | - $original_domain_parts = parse_url( $url ); |
|
| 62 | + $original_domain_parts = parse_url($url); |
|
| 63 | 63 | |
| 64 | 64 | // if unable to retrieve the host, skip |
| 65 | - if ( empty( $original_domain_parts['host'] ) ) { |
|
| 65 | + if (empty($original_domain_parts['host'])) { |
|
| 66 | 66 | return $url; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -71,11 +71,11 @@ discard block |
||
| 71 | 71 | $current_domain = $_SERVER['HTTP_HOST']; |
| 72 | 72 | |
| 73 | 73 | // if original and current domain match, skip |
| 74 | - if ( $original_domain == $current_domain ) { |
|
| 74 | + if ($original_domain == $current_domain) { |
|
| 75 | 75 | return $url; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - return $this->replace_domain( $url, $original_domain, $current_domain ); |
|
| 78 | + return $this->replace_domain($url, $original_domain, $current_domain); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -88,17 +88,17 @@ discard block |
||
| 88 | 88 | * @param string $new_domain The new domain. |
| 89 | 89 | * @return string $url The new URL. |
| 90 | 90 | */ |
| 91 | - protected function replace_domain( $url, $old_domain, $new_domain ) { |
|
| 91 | + protected function replace_domain($url, $old_domain, $new_domain) { |
|
| 92 | 92 | // prepare original domain and current domain with the current protocol |
| 93 | - $protocols = array( 'http://', 'https://' ); |
|
| 94 | - $current_protocol = ( is_ssl() ? 'https' : 'http' ) . '://'; |
|
| 93 | + $protocols = array('http://', 'https://'); |
|
| 94 | + $current_protocol = (is_ssl() ? 'https' : 'http') . '://'; |
|
| 95 | 95 | |
| 96 | - foreach ( $protocols as $protocol ) { |
|
| 96 | + foreach ($protocols as $protocol) { |
|
| 97 | 97 | $original_base = $protocol . $old_domain; |
| 98 | 98 | $new_base = $current_protocol . $new_domain; |
| 99 | 99 | |
| 100 | 100 | // replace original domain with current domain |
| 101 | - $url = str_replace( $original_base, $new_base, $url ); |
|
| 101 | + $url = str_replace($original_base, $new_base, $url); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | return $url; |
@@ -112,17 +112,17 @@ discard block |
||
| 112 | 112 | * @param string $content The current content with the original domain. |
| 113 | 113 | * @return string $content The content with the new domain. |
| 114 | 114 | */ |
| 115 | - public function setup_content( $content ) { |
|
| 115 | + public function setup_content($content) { |
|
| 116 | 116 | // get original home URL |
| 117 | - remove_filter( 'option_home', array( $this, 'setup_domain' ), 1 ); |
|
| 118 | - $original_home = home_url( '/' ); |
|
| 119 | - add_filter( 'option_home', array( $this, 'setup_domain' ), 1 ); |
|
| 117 | + remove_filter('option_home', array($this, 'setup_domain'), 1); |
|
| 118 | + $original_home = home_url('/'); |
|
| 119 | + add_filter('option_home', array($this, 'setup_domain'), 1); |
|
| 120 | 120 | |
| 121 | 121 | // get current home URL |
| 122 | - $current_home = home_url( '/' ); |
|
| 122 | + $current_home = home_url('/'); |
|
| 123 | 123 | |
| 124 | 124 | // replace occurences of original URL with current home URL |
| 125 | - $content = str_replace( $original_home, $current_home, $content ); |
|
| 125 | + $content = str_replace($original_home, $current_home, $content); |
|
| 126 | 126 | |
| 127 | 127 | return $content; |
| 128 | 128 | } |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * @param array $upload_dir The current upload dir settings with the original domain. |
| 136 | 136 | * @return array $upload_dir The upload dir settings with the new domain. |
| 137 | 137 | */ |
| 138 | - public function setup_upload_dir( $upload_dir ) { |
|
| 138 | + public function setup_upload_dir($upload_dir) { |
|
| 139 | 139 | // keys of array element that we'll be updating |
| 140 | 140 | $keys_to_update = array( |
| 141 | 141 | 'url', |
@@ -143,8 +143,8 @@ discard block |
||
| 143 | 143 | ); |
| 144 | 144 | |
| 145 | 145 | // fix all targeted array elements |
| 146 | - foreach ( $keys_to_update as $key ) { |
|
| 147 | - $upload_dir[ $key ] = apply_filters( 'wp_hydra_domain', $upload_dir[ $key ] ); |
|
| 146 | + foreach ($keys_to_update as $key) { |
|
| 147 | + $upload_dir[$key] = apply_filters('wp_hydra_domain', $upload_dir[$key]); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | return $upload_dir; |