@@ -14,12 +14,12 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | 16 | // Exit if accessed directly. |
| 17 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 17 | +if (!defined('ABSPATH')) { |
|
| 18 | 18 | exit; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | // Load main class. |
| 22 | -include_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class-wp-hydra.php' ); |
|
| 22 | +include_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'class-wp-hydra.php'); |
|
| 23 | 23 | |
| 24 | 24 | // initialize WP Hydra - Polycephaly FTW! |
| 25 | 25 | global $wp_hydra; |
@@ -18,24 +18,24 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | public function __construct() { |
| 20 | 20 | // Modify domain where necessary. |
| 21 | - add_filter( 'option_blogname', array( $this, 'setup_domain' ), 1 ); |
|
| 22 | - add_filter( 'option_siteurl', array( $this, 'setup_domain' ), 1 ); |
|
| 23 | - add_filter( 'option_home', array( $this, 'setup_domain' ), 1 ); |
|
| 24 | - add_filter( 'stylesheet_uri', array( $this, 'setup_domain' ), 1 ); |
|
| 25 | - add_filter( 'stylesheet_directory_uri', array( $this, 'setup_domain' ), 1 ); |
|
| 26 | - add_filter( 'template_directory_uri', array( $this, 'setup_domain' ), 1 ); |
|
| 27 | - add_filter( 'plugins_url', array( $this, 'setup_domain' ), 1 ); |
|
| 21 | + add_filter('option_blogname', array($this, 'setup_domain'), 1); |
|
| 22 | + add_filter('option_siteurl', array($this, 'setup_domain'), 1); |
|
| 23 | + add_filter('option_home', array($this, 'setup_domain'), 1); |
|
| 24 | + add_filter('stylesheet_uri', array($this, 'setup_domain'), 1); |
|
| 25 | + add_filter('stylesheet_directory_uri', array($this, 'setup_domain'), 1); |
|
| 26 | + add_filter('template_directory_uri', array($this, 'setup_domain'), 1); |
|
| 27 | + add_filter('plugins_url', array($this, 'setup_domain'), 1); |
|
| 28 | 28 | |
| 29 | 29 | // Replace various occurences. |
| 30 | - add_filter( 'the_content', array( $this, 'setup_content' ) ); // In oost content. |
|
| 31 | - add_filter( 'widget_text', array( $this, 'setup_content' ) ); // In Widget text. |
|
| 32 | - add_filter( 'upload_dir', array( $this, 'setup_upload_dir' ) ); // In wp_upload_dir(). |
|
| 30 | + add_filter('the_content', array($this, 'setup_content')); // In oost content. |
|
| 31 | + add_filter('widget_text', array($this, 'setup_content')); // In Widget text. |
|
| 32 | + add_filter('upload_dir', array($this, 'setup_upload_dir')); // In wp_upload_dir(). |
|
| 33 | 33 | |
| 34 | 34 | // Allow developers to support multiple domains in fields that contain only a site URL. |
| 35 | - add_filter( 'wp_hydra_domain', array( $this, 'setup_domain' ) ); |
|
| 35 | + add_filter('wp_hydra_domain', array($this, 'setup_domain')); |
|
| 36 | 36 | |
| 37 | 37 | // Allow developers to support URLs with multiple domains in their content. |
| 38 | - add_filter( 'wp_hydra_content', array( $this, 'setup_content' ) ); |
|
| 38 | + add_filter('wp_hydra_content', array($this, 'setup_content')); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -46,12 +46,12 @@ discard block |
||
| 46 | 46 | * @param string $url The current URL. |
| 47 | 47 | * @return string $url The URL with the (maybe) replaced domain. |
| 48 | 48 | */ |
| 49 | - public function setup_domain( $url ) { |
|
| 49 | + public function setup_domain($url) { |
|
| 50 | 50 | // Parse current URL. |
| 51 | - $original_domain_parts = parse_url( $url ); |
|
| 51 | + $original_domain_parts = parse_url($url); |
|
| 52 | 52 | |
| 53 | 53 | // If unable to retrieve the host, skip. |
| 54 | - if ( empty( $original_domain_parts['host'] ) || ! isset( $_SERVER['HTTP_HOST'] ) ) { |
|
| 54 | + if (empty($original_domain_parts['host']) || !isset($_SERVER['HTTP_HOST'])) { |
|
| 55 | 55 | return $url; |
| 56 | 56 | } |
| 57 | 57 | |
@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | $current_domain = $_SERVER['HTTP_HOST']; |
| 61 | 61 | |
| 62 | 62 | // If original and current domain match, skip. |
| 63 | - if ( $original_domain == $current_domain ) { |
|
| 63 | + if ($original_domain == $current_domain) { |
|
| 64 | 64 | return $url; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - return $this->replace_domain( $url, $original_domain, $current_domain ); |
|
| 67 | + return $this->replace_domain($url, $original_domain, $current_domain); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -77,17 +77,17 @@ discard block |
||
| 77 | 77 | * @param string $new_domain The new domain. |
| 78 | 78 | * @return string $url The new URL. |
| 79 | 79 | */ |
| 80 | - protected function replace_domain( $url, $old_domain, $new_domain ) { |
|
| 80 | + protected function replace_domain($url, $old_domain, $new_domain) { |
|
| 81 | 81 | // Prepare original domain and current domain with the current protocol. |
| 82 | - $protocols = array( 'http://', 'https://' ); |
|
| 83 | - $current_protocol = ( $this->is_ssl() ? 'https' : 'http' ) . '://'; |
|
| 82 | + $protocols = array('http://', 'https://'); |
|
| 83 | + $current_protocol = ($this->is_ssl() ? 'https' : 'http').'://'; |
|
| 84 | 84 | |
| 85 | - foreach ( $protocols as $protocol ) { |
|
| 86 | - $original_base = $protocol . $old_domain; |
|
| 87 | - $new_base = $current_protocol . $new_domain; |
|
| 85 | + foreach ($protocols as $protocol) { |
|
| 86 | + $original_base = $protocol.$old_domain; |
|
| 87 | + $new_base = $current_protocol.$new_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; |