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