@@ -29,28 +29,28 @@ 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 occurences in content |
| 41 | - add_filter( 'the_content', array( $this, 'setup_content' ) ); |
|
| 41 | + add_filter('the_content', array($this, 'setup_content')); |
|
| 42 | 42 | |
| 43 | 43 | // replace occurences in widget text |
| 44 | - add_filter( 'widget_text', array( $this, 'setup_content' ) ); |
|
| 44 | + add_filter('widget_text', array($this, 'setup_content')); |
|
| 45 | 45 | |
| 46 | 46 | // replace occurences in wp_upload_dir(); |
| 47 | - add_filter( 'upload_dir', array( $this, 'setup_upload_dir' ) ); |
|
| 47 | + add_filter('upload_dir', array($this, 'setup_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,33 +61,33 @@ 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'] ) ) { |
|
| 69 | + if (empty($original_domain_parts['host'])) { |
|
| 70 | 70 | return $url; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // get original and current domain |
| 74 | 74 | $original_domain = $original_domain_parts['host']; |
| 75 | - $current_domain = sanitize_text_field( $_SERVER['HTTP_HOST'] ); // input var ok. |
|
| 75 | + $current_domain = sanitize_text_field($_SERVER['HTTP_HOST']); // input var ok. |
|
| 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 | 82 | // prepare original domain and current domain with the current protocol |
| 83 | - $protocols = array( 'http://', 'https://' ); |
|
| 84 | - $current_protocol = ( is_ssl() ? 'https' : 'http' ) . '://'; |
|
| 85 | - foreach ( $protocols as $protocol ) { |
|
| 83 | + $protocols = array('http://', 'https://'); |
|
| 84 | + $current_protocol = (is_ssl() ? 'https' : 'http') . '://'; |
|
| 85 | + foreach ($protocols as $protocol) { |
|
| 86 | 86 | $original_base = $protocol . $original_domain; |
| 87 | 87 | $new_base = $current_protocol . $current_domain; |
| 88 | 88 | |
| 89 | 89 | // replace original domain with current domain |
| 90 | - $url = str_replace( $original_base, $new_base, $url ); |
|
| 90 | + $url = str_replace($original_base, $new_base, $url); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | return $url; |
@@ -101,17 +101,17 @@ discard block |
||
| 101 | 101 | * @param string $content The current content with the original domain. |
| 102 | 102 | * @return string $content The content with the new domain. |
| 103 | 103 | */ |
| 104 | - public function setup_content( $content ) { |
|
| 104 | + public function setup_content($content) { |
|
| 105 | 105 | // get original home URL |
| 106 | - remove_filter( 'option_home', array( $this, 'setup_domain' ), 1 ); |
|
| 107 | - $original_home = home_url( '/' ); |
|
| 108 | - add_filter( 'option_home', array( $this, 'setup_domain' ), 1 ); |
|
| 106 | + remove_filter('option_home', array($this, 'setup_domain'), 1); |
|
| 107 | + $original_home = home_url('/'); |
|
| 108 | + add_filter('option_home', array($this, 'setup_domain'), 1); |
|
| 109 | 109 | |
| 110 | 110 | // get current home URL |
| 111 | - $current_home = home_url( '/' ); |
|
| 111 | + $current_home = home_url('/'); |
|
| 112 | 112 | |
| 113 | 113 | // replace occurences of original URL with current home URL |
| 114 | - $content = str_replace( $original_home, $current_home, $content ); |
|
| 114 | + $content = str_replace($original_home, $current_home, $content); |
|
| 115 | 115 | |
| 116 | 116 | return $content; |
| 117 | 117 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * @param array $upload_dir The current upload dir settings with the original domain. |
| 125 | 125 | * @return array $upload_dir The upload dir settings with the new domain. |
| 126 | 126 | */ |
| 127 | - public function setup_upload_dir( $upload_dir ) { |
|
| 127 | + public function setup_upload_dir($upload_dir) { |
|
| 128 | 128 | // keys of array element that we'll be updating |
| 129 | 129 | $keys_to_update = array( |
| 130 | 130 | 'url', |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | ); |
| 133 | 133 | |
| 134 | 134 | // fix all targeted array elements |
| 135 | - foreach ( $keys_to_update as $key ) { |
|
| 136 | - $upload_dir[ $key ] = apply_filters( 'wp_hydra_domain', $upload_dir[ $key ] ); |
|
| 135 | + foreach ($keys_to_update as $key) { |
|
| 136 | + $upload_dir[$key] = apply_filters('wp_hydra_domain', $upload_dir[$key]); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | return $upload_dir; |