/
live-admin-warning.php
175 lines (141 loc) · 4.1 KB
/
live-admin-warning.php
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/*
Plugin Name: Live admin warning
Plugin URI: http://github.com/rhlee/live-admin-warning
Description: A plugin to warn you that you are on a live Wordpress admin
Version: 0.1
Author: Richard H Lee
Author URI: http://github.com/rhlee
License: GPL
*/
//error_reporting(E_ALL);
//ini_set('display_errors', '1');
require_once(ABSPATH . WPINC . '/pluggable.php');
$current_user = wp_get_current_user();
if(function_exists('get_usermeta'))
$show = get_usermeta($current_user->ID, 'live-admin-warning-show');
else
$show = get_user_meta($current_user->ID, 'live-admin-warning-show', true);
if($show == '1')
add_action('admin_notices', "live_admin_warning");
if(!class_exists('live_admin_warning_class'))
{
class live_admin_warning_class
{
private $uid, $options;
function live_admin_warning_class()
{
$current_user = wp_get_current_user();
$this->uid = $current_user->ID;
$this->get_options();
}
function get_options()
{
$default_options = array(
'live_admin_warning_show' => '0',
'live_admin_warning_message' => 'Warning! This is a live site!'
);
$options = array();
foreach($default_options as $key => $value)
{
$option = $this->get_user_meta($this->uid, $key);
if($option)
$options[$key] = $option;
else
$test = $this->update_user_meta($this->uid, $key, $value);
}
$this->options = empty($options)? $default_options : $options;
return (empty($options)? $default_options : $options);
}
function get_option($key)
{
return $this->options[$key];
}
function get_user_meta($uid, $key)
{
if(function_exists('get_usermeta'))
return get_usermeta($uid, $key);
else
return get_user_meta($uid, $key, true);
}
function update_user_meta($uid, $key, $val)
{
if(function_exists('update_usermeta'))
return update_usermeta($uid, $key, $val);
else
return update_user_meta($uid, $key, $val);
}
function printSettingsPage()
{
if( $_POST['update_live_admin_warning_settings'] &&
$_POST['live_admin_warning_message'] )
{
$this->update_user_meta(
$this->uid,
'live_admin_warning_show',
(isset($_POST['live_admin_warning_show'])? '1' : '0')
);
$this->update_user_meta(
$this->uid,
'live_admin_warning_message',
$_POST['live_admin_warning_message']
);
}
$this->get_options();
?>
<div class=wrap>
<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
<h2>Live Admin Warning</h2>
<table class="form-table">
<tbody>
<tr>
<th>Show warning</th>
<td><input type="checkbox" value="<?php echo $this->get_option('live_admin_warning_show'); ?>" id="live_admin_warning_show" name="live_admin_warning_show" <?php if($this->get_option('live_admin_warning_show') == '1')echo 'checked="checked" '; ?>/></td>
<tr>
</tr>
<th>Warning message</th>
<td><input type="text" class="regular-text" value="<?php echo $this->get_option('live_admin_warning_message'); ?>" id="live_admin_warning_message" name="live_admin_warning_message" /></td>
</tr>
</tbody>
</table>
<div class="submit">
<input type="submit" name="update_live_admin_warning_settings" value="Update Settings" />
</div>
</form>
</div>
<?php
}
function display()
{ ?>
<link type="text/css" href="<?php echo plugins_url('live-admin-warning/css/live-admin-warning.css'); ?>" rel="stylesheet" />
<div id="live-admin-warning">
<?php echo $this->get_option('live_admin_warning_message'); ?>
</div><?php
}
}
}
if(class_exists('live_admin_warning_class'))
$live_admin_warning = new live_admin_warning_class();
if(isset($live_admin_warning))
{
}
if(!function_exists('LiveAdminWarning_ap'))
{
function LiveAdminWarning_ap()
{
global $live_admin_warning;
if(!isset($live_admin_warning))
return;
if (function_exists('add_submenu_page'))
add_submenu_page(
'options-general.php', "Live Admin Warning",
"Live Admin Warning", 0, basename(__FILE__),
array(&$live_admin_warning, 'printSettingsPage'
));
if($live_admin_warning->get_option('live_admin_warning_show') == '1')
add_action('admin_notices',
array(&$live_admin_warning, 'display'));
}
}
add_action('admin_menu', 'LiveAdminWarning_ap');
?>