@@ -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,19 +71,19 @@ 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 | 78 | // prepare original domain and current domain with the current protocol |
| 79 | - $protocols = array( 'http://', 'https://' ); |
|
| 80 | - $current_protocol = ( is_ssl() ? 'https' : 'http' ) . '://'; |
|
| 81 | - foreach ( $protocols as $protocol ) { |
|
| 79 | + $protocols = array('http://', 'https://'); |
|
| 80 | + $current_protocol = (is_ssl() ? 'https' : 'http') . '://'; |
|
| 81 | + foreach ($protocols as $protocol) { |
|
| 82 | 82 | $original_base = $protocol . $original_domain; |
| 83 | 83 | $new_base = $current_protocol . $current_domain; |
| 84 | 84 | |
| 85 | 85 | // replace original domain with current domain |
| 86 | - $url = str_replace( $original_base, $new_base, $url ); |
|
| 86 | + $url = str_replace($original_base, $new_base, $url); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | return $url; |
@@ -97,17 +97,17 @@ discard block |
||
| 97 | 97 | * @param string $content The current content with the original domain. |
| 98 | 98 | * @return string $content The content with the new domain. |
| 99 | 99 | */ |
| 100 | - public function setup_content( $content ) { |
|
| 100 | + public function setup_content($content) { |
|
| 101 | 101 | // get original home URL |
| 102 | - remove_filter( 'option_home', array( $this, 'setup_domain' ), 1 ); |
|
| 103 | - $original_home = home_url( '/' ); |
|
| 104 | - add_filter( 'option_home', array( $this, 'setup_domain' ), 1 ); |
|
| 102 | + remove_filter('option_home', array($this, 'setup_domain'), 1); |
|
| 103 | + $original_home = home_url('/'); |
|
| 104 | + add_filter('option_home', array($this, 'setup_domain'), 1); |
|
| 105 | 105 | |
| 106 | 106 | // get current home URL |
| 107 | - $current_home = home_url( '/' ); |
|
| 107 | + $current_home = home_url('/'); |
|
| 108 | 108 | |
| 109 | 109 | // replace occurences of original URL with current home URL |
| 110 | - $content = str_replace( $original_home, $current_home, $content ); |
|
| 110 | + $content = str_replace($original_home, $current_home, $content); |
|
| 111 | 111 | |
| 112 | 112 | return $content; |
| 113 | 113 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * @param array $upload_dir The current upload dir settings with the original domain. |
| 121 | 121 | * @return array $upload_dir The upload dir settings with the new domain. |
| 122 | 122 | */ |
| 123 | - public function setup_upload_dir( $upload_dir ) { |
|
| 123 | + public function setup_upload_dir($upload_dir) { |
|
| 124 | 124 | // keys of array element that we'll be updating |
| 125 | 125 | $keys_to_update = array( |
| 126 | 126 | 'url', |
@@ -128,8 +128,8 @@ discard block |
||
| 128 | 128 | ); |
| 129 | 129 | |
| 130 | 130 | // fix all targeted array elements |
| 131 | - foreach ( $keys_to_update as $key ) { |
|
| 132 | - $upload_dir[ $key ] = apply_filters( 'wp_hydra_domain', $upload_dir[ $key ] ); |
|
| 131 | + foreach ($keys_to_update as $key) { |
|
| 132 | + $upload_dir[$key] = apply_filters('wp_hydra_domain', $upload_dir[$key]); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | return $upload_dir; |