class-wpml-url-converter-url-helper.php
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
class WPML_URL_Converter_Url_Helper {
/**
* @var wpdb
*/
private $wpdb;
/**
* @var WPML_Include_Url
*/
private $wpml_include_url_filter;
/**
* @var string
*/
private $absolute_home;
/**
*
* @param wpdb $wpdb
* @param WPML_Include_Url $wpml_include_url_filter
*/
public function __construct( wpdb $wpdb = null, WPML_Include_Url $wpml_include_url_filter = null ) {
if ( ! $wpdb ) {
global $wpdb;
}
if ( ! $wpml_include_url_filter ) {
global $wpml_include_url_filter;
}
$this->wpdb = $wpdb;
$this->wpml_include_url_filter = $wpml_include_url_filter;
}
/**
* Returns the unfiltered home_url by directly retrieving it from wp_options.
*
* @return string
*/
public function get_abs_home() {
if ( ! $this->absolute_home ) {
$is_multisite = is_multisite();
if ( ! $is_multisite && defined( 'WP_HOME' ) ) {
$this->absolute_home = WP_HOME;
} elseif ( $is_multisite && ! is_main_site() ) {
$protocol = preg_match( '/^(https)/', get_option( 'home' ) ) === 1 ? 'https://' : 'http://';
$sql = "
SELECT CONCAT(b.domain, b.path)
FROM {$this->wpdb->blogs} b
WHERE blog_id = {$this->wpdb->blogid}
LIMIT 1
";
$this->absolute_home = $protocol . $this->wpdb->get_var( $sql );
} else {
$this->absolute_home = $this->get_unfiltered_home_option();
}
}
return apply_filters( 'wpml_url_converter_get_abs_home', $this->absolute_home );
}
/**
* Checks if a $url points to a WP Admin screen.
*
* @param string $url
* @return bool True if the input $url points to an admin screen.
*/
public function is_url_admin( $url ) {
$url_query_parts = wpml_parse_url( strpos( $url, 'http' ) === false ? 'http://' . $url : $url );
return isset( $url_query_parts['path'] )
&& strpos( wpml_strip_subdir_from_url( $url_query_parts['path'] ), '/wp-admin' ) === 0;
}
/**
* Returns the unfiltered home option from the database.
*
* @uses \WPML_Include_Url::get_unfiltered_home in case the $wpml_include_url_filter global is loaded
*
* @return string
*/
public function get_unfiltered_home_option() {
if ( $this->wpml_include_url_filter ) {
return $this->wpml_include_url_filter->get_unfiltered_home();
} else {
$sql = "
SELECT option_value
FROM {$this->wpdb->options}
WHERE option_name = 'home'
LIMIT 1
";
return $this->wpdb->get_var( $sql );
}
}
}