-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform_field.php
More file actions
104 lines (85 loc) · 3.9 KB
/
form_field.php
File metadata and controls
104 lines (85 loc) · 3.9 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
100
101
102
103
104
<form action="<?php plugin_dir_path(__FILE__) . "/form_field.php"; ?>" method="post">
<?php
$current_url = get_home_url();
$exec = exec("hostname"); //the "hostname" is a valid command in both windows and linux
$hostname = trim($exec); //remove any spaces before and after
$ip = gethostbyname($hostname); //resolves the hostname using local hosts resolver or DNS
//check string
$check_localhost = true;
if (strpos($current_url, 'localhost') !== false) {
$check_localhost = false;
}
else{
$check_localhost = true;
}
wp_nonce_field('ltp');
?>
<div class="Form_wrapper">
<?php
echo "<h2 class='Title'>Localhost to IP</h2>";
if($check_localhost == true){
echo '<h3 class="short_description">If your site url is <span class="text-underline">' . get_home_url() . '</span> then it will be change to <span class="text-underline">' . str_replace($ip, "localhost", get_home_url()) . '</span></h3>';
echo "Please make sure your site url is ". get_home_url();
}
else{
echo '<h3 class="short_description">If your site url is <span class="text-underline">' . get_home_url() . '</span> then it will be change to <span class="text-underline">' . str_replace("localhost", $ip, get_home_url()) . '</span></h3>';
}
?>
<div class="form-group">
<?php
if($check_localhost == false){
submit_button('Click to Update IP');
$check_localhost = false;
}
else{
submit_button('Back To localhost');
$check_localhost = true;
}
?>
</div>
</div>
</form>
<?php
global $wpdb;
$table_name = $wpdb->prefix . "options";
if (isset($_POST['submit'])) {
global $wpdb;
if($check_localhost == false){
$exec = exec("hostname"); //the "hostname" is a valid command in both windows and linux
$hostname = trim($exec); //remove any spaces before and after
$ip = gethostbyname($hostname); //resolves the hostname using local hosts resolver or DNS
$ip = $ip;
$ip = sanitize_text_field($ip);
$url = str_replace("localhost", $ip, get_home_url());
$execut = $wpdb->query($wpdb->prepare("UPDATE $table_name SET option_value = %s WHERE option_id = %s ", $url, 1));
$execut2 = $wpdb->query($wpdb->prepare("UPDATE $table_name SET option_value = %s WHERE option_id = %s ", $url, 2));
if (($execut > 0) && ($execut2)) {
printf(
esc_html__('Successfully Updated Your site url is now ' . $url ,'ltp'));
printf(
'<br><a href="%s/wp-admin">%s</a>',
esc_url( $url),
esc_html__( 'Click to Login', 'ltp' )
);
} else {
exit(var_dump($wpdb->last_query));
}
$wpdb->flush();
}
if($check_localhost == true){
$exec = exec("hostname"); //the "hostname" is a valid command in both windows and linux
$hostname = trim($exec); //remove any spaces before and after
$ip = gethostbyname($hostname); //resolves the hostname using local hosts resolver or DNS
$ip = sanitize_text_field($ip);
$url = str_replace($ip, "localhost", get_home_url());
$execut = $wpdb->query($wpdb->prepare("UPDATE $table_name SET option_value = %s WHERE option_id = %s ", $url, 1));
$execut2 = $wpdb->query($wpdb->prepare("UPDATE $table_name SET option_value = %s WHERE option_id = %s ", $url, 2));
if (($execut > 0) && ($execut2)) {
printf(esc_html__('Successfully Updated Your site url is now' . $url ,'ltp'));
printf('<br><a href="%s/wp-admin">%s</a>', esc_url( $url), esc_html__( 'Click to Login', 'ltp' ) );
} else {
exit(var_dump($wpdb->last_query));
}
$wpdb->flush();
}
}