-
Notifications
You must be signed in to change notification settings - Fork 0
/
innerteapot-log.php
128 lines (110 loc) · 2.8 KB
/
innerteapot-log.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
<?php
/*
Plugin Name: Inner Tea Pot Log
Plugin URI: https://github.com/innerteapot/innerteapot-log
Description: Keep a manual log of activities in a database table
Version: 0.1
Author: Joel Sutton
Author URI: http://innerteapot.com/
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
GitHub Plugin URI: https://github.com/innerteapot/innerteapot-log
GitHub Branch: master
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
function il_install() {
global $wpdb;
$table_name = $wpdb->prefix . 'innerteapot_log';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
time timestamp,
note text NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;";
$wpdb->query($sql);
}
register_activation_hook(__FILE__, 'il_install');
function il_install_data() {
global $wpdb;
$welcome_note = 'Congratulations, you just completed the installation!';
$table_name = $wpdb->prefix . 'innerteapot_log';
$wpdb->insert(
$table_name,
array(
'note' => $welcome_note,
)
);
}
register_activation_hook(__FILE__, 'il_install_data');
function il_menu()
{
global $wpdb;
$table_name = $wpdb->prefix . 'innerteapot_log';
if (!empty($_POST) &&
isset($_POST['Submit']) &&
check_admin_referer('name_of_my_action', 'wpnf_ft'))
{
if (!empty($_POST['note']))
{
$wpdb->insert(
$table_name,
array(
'note' => $_POST['note']
),
array(
'%s'
)
);
}
}
echo "<h1>Inner Tea Pot Log</h1>";
$admin_log = $wpdb->get_results(
"
SELECT *
FROM $table_name
ORDER BY time DESC
"
);
// input form
//
?>
<form name="il_form" method="post" action="">
<?php wp_nonce_field('name_of_my_action', 'wpnf_ft'); ?>
<textarea name="note" rows="4" cols="50"></textarea>
<br />
<input type="submit" class="button-primary" name="Submit" value="Add" />
</form>
<hr>
<?php
if ($admin_log)
{
foreach ($admin_log as $entry)
{
?>
<h2><?php echo $entry->time; ?></h2>
<p><?php echo $entry->note; ?></p>
<hr>
<?php
}
}
else
{
echo "No entries found";
}
}
function il_admin_actions()
{
add_menu_page(
"Inner Tea Pot Log",
"Inner Tea Pot Log",
1,
"innerteapot-log",
"il_menu"
);
}
add_action('admin_menu', 'il_admin_actions');
?>