1 | <?php |
||
26 | class WP_Hydra { |
||
27 | |||
28 | /** |
||
29 | * Constructor. |
||
30 | * |
||
31 | * Hooks all of the domain replacement functionality. |
||
32 | * |
||
33 | * @access public |
||
34 | */ |
||
35 | 1 | public function __construct() { |
|
56 | |||
57 | /** |
||
58 | * Replaces original domain with current domain in simple fields. |
||
59 | * |
||
60 | * @access public |
||
61 | * |
||
62 | * @param string $url The current URL. |
||
63 | * @return string $url The URL with the (maybe) replaced domain. |
||
64 | */ |
||
65 | 4 | public function setup_domain( $url ) { |
|
66 | // parse current URL |
||
67 | 4 | $original_domain_parts = parse_url( $url ); |
|
68 | |||
69 | // if unable to retrieve the host, skip |
||
70 | 4 | if ( empty( $original_domain_parts['host'] ) ) { |
|
71 | 1 | return $url; |
|
72 | } |
||
73 | |||
74 | // get original and current domain |
||
75 | 3 | $original_domain = $original_domain_parts['host']; |
|
76 | 3 | $current_domain = $_SERVER['HTTP_HOST']; |
|
|
|||
77 | |||
78 | // if original and current domain match, skip |
||
79 | 3 | if ( $original_domain == $current_domain ) { |
|
80 | 2 | return $url; |
|
81 | } |
||
82 | |||
83 | 1 | return $this->replace_domain( $url, $original_domain, $current_domain ); |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * Replace the old domain with a new domain in a specific URL. |
||
88 | * |
||
89 | * @access protected |
||
90 | * |
||
91 | * @param string $url The current URL. |
||
92 | * @param string $old_domain The old domain. |
||
93 | * @param string $new_domain The new domain. |
||
94 | * @return string $url The new URL. |
||
95 | */ |
||
96 | protected function replace_domain( $url, $old_domain, $new_domain ) { |
||
111 | |||
112 | /** |
||
113 | * Replaces original domain with current domain in content. |
||
114 | * |
||
115 | * @access public |
||
116 | * |
||
117 | * @param string $content The current content with the original domain. |
||
118 | * @return string $content The content with the new domain. |
||
119 | */ |
||
120 | public function setup_content( $content ) { |
||
134 | |||
135 | /** |
||
136 | * Replaces original domain with current domain in wp_upload_dir(). |
||
137 | * |
||
138 | * @access public |
||
139 | * |
||
140 | * @param array $upload_dir The current upload dir settings with the original domain. |
||
141 | * @return array $upload_dir The upload dir settings with the new domain. |
||
142 | */ |
||
143 | 1 | public function setup_upload_dir( $upload_dir ) { |
|
157 | |||
158 | } |
||
159 | |||
162 | $wp_hydra = new WP_Hydra(); |