Version Description
(September 2015) =
Added: Basic support for plugin https://wordpress.org/plugins/ultimate-member/, so users logging in using the plugin will now be logged in Simple History. Fixes https://wordpress.org/support/topic/compatibility-with-ultimate-member.
Added: Filter
simple_history/logger/interpolate/context
that can be used to modify the variables sent to the message template.Changed: Remove "type" key from context detail table, because it's an old an unused column.
Changed: During a first install the plugin now creates a few less columns than before (some columns where left from version 1 of the plugin).
Changed: Don't show the "translate this plugin" metabox for any english talking locale.
Changed: Don't show the GitHub metabox.
Fixed: If the plugin is deleted (but why?!) then the context table is also removed now.
Behind the scenes: More unit tests! Hopefully more nasty things will get caught before releasing new versions of the plugin.
Release Info
Developer | eskapism |
Plugin | Simple History |
Version | 2.2.4 |
Comparing to | |
See all releases |
Code changes from version 2.2.3 to 2.2.4
- dropins/SimpleHistorySidebarDropin.php +4 -2
- inc/SimpleHistory.php +53 -55
- inc/SimpleHistoryLogQuery.php +0 -1
- index.php +2 -2
- loggers/Plugin_UltimateMembers_Logger.php +56 -0
- loggers/SimpleCommentsLogger.php +1 -1
- loggers/SimpleLogger.php +17 -6
- loggers/SimpleMediaLogger.php +2 -2
- loggers/SimplePostLogger.php +1 -1
- loggers/SimpleThemeLogger.php +1 -1
- loggers/SimpleUserLogger.php +2 -2
- readme.txt +21 -1
- tests/test-sample.php +0 -115
- tests/test-simplehistory.php +226 -0
- uninstall.php +5 -1
@@ -110,7 +110,7 @@ class SimpleHistorySidebarDropin {
|
|
110 |
$arrBoxes = array(
|
111 |
"boxReview" => $boxReview,
|
112 |
"boxDonate" => $boxDonate,
|
113 |
-
"boxGithub" => $boxGithub,
|
114 |
);
|
115 |
|
116 |
/**
|
@@ -131,7 +131,9 @@ class SimpleHistorySidebarDropin {
|
|
131 |
/** WordPress Translation Install API. This file exists only since 4.0. */
|
132 |
$translation_install_file = ABSPATH . 'wp-admin/includes/translation-install.php';
|
133 |
|
134 |
-
|
|
|
|
|
135 |
|
136 |
require_once $translation_install_file;
|
137 |
|
110 |
$arrBoxes = array(
|
111 |
"boxReview" => $boxReview,
|
112 |
"boxDonate" => $boxDonate,
|
113 |
+
// "boxGithub" => $boxGithub,
|
114 |
);
|
115 |
|
116 |
/**
|
131 |
/** WordPress Translation Install API. This file exists only since 4.0. */
|
132 |
$translation_install_file = ABSPATH . 'wp-admin/includes/translation-install.php';
|
133 |
|
134 |
+
// Show only the translation box if current language is not an english language
|
135 |
+
|
136 |
+
if ( in_array( $current_locale, array("en_US", "en_GB", "en_CA", "en_NZ", "en_AU") ) != $current_locale && file_exists( $translation_install_file ) ) {
|
137 |
|
138 |
require_once $translation_install_file;
|
139 |
|
@@ -645,7 +645,8 @@ class SimpleHistory {
|
|
645 |
|
646 |
// Loggers for third party plugins
|
647 |
$loggersDir . "PluginUserSwitchingLogger.php",
|
648 |
-
$loggersDir . "PluginEnableMediaReplaceLogger.php"
|
|
|
649 |
);
|
650 |
|
651 |
// SimpleLogger.php must be loaded first and always since the other loggers extend it
|
@@ -1093,43 +1094,20 @@ class SimpleHistory {
|
|
1093 |
$table_name = $wpdb->prefix . SimpleHistory::DBTABLE;
|
1094 |
$table_name_contexts = $wpdb->prefix . SimpleHistory::DBTABLE_CONTEXTS;
|
1095 |
$first_install = false;
|
1096 |
-
|
1097 |
// If no db_version is set then this
|
1098 |
// is a version of Simple History < 0.4
|
1099 |
// or it's a first install
|
1100 |
// Fix database not using UTF-8
|
1101 |
-
if ( false === $db_version ) {
|
1102 |
|
1103 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
1104 |
|
1105 |
// Table creation, used to be in register_activation_hook
|
1106 |
-
/*
|
1107 |
-
$sql = "CREATE TABLE " . $table_name . " (
|
1108 |
-
id int(10) NOT NULL AUTO_INCREMENT,
|
1109 |
-
date datetime NOT NULL,
|
1110 |
-
action varchar(255) NOT NULL COLLATE utf8_general_ci,
|
1111 |
-
object_type varchar(255) NOT NULL COLLATE utf8_general_ci,
|
1112 |
-
object_subtype VARCHAR(255) NOT NULL COLLATE utf8_general_ci,
|
1113 |
-
user_id int(10) NOT NULL,
|
1114 |
-
object_id int(10) NOT NULL,
|
1115 |
-
object_name varchar(255) NOT NULL COLLATE utf8_general_ci,
|
1116 |
-
action_description longtext,
|
1117 |
-
PRIMARY KEY (id)
|
1118 |
-
) CHARACTER SET=utf8;";
|
1119 |
-
dbDelta($sql);
|
1120 |
-
*/
|
1121 |
-
|
1122 |
// We change the varchar size to add one num just to force update of encoding. dbdelta didn't see it otherwise.
|
1123 |
-
// This table is missing action_description, but we add that later on
|
1124 |
$sql = "CREATE TABLE " . $table_name . " (
|
1125 |
id bigint(20) NOT NULL AUTO_INCREMENT,
|
1126 |
date datetime NOT NULL,
|
1127 |
-
action VARCHAR(256) NOT NULL COLLATE utf8_general_ci,
|
1128 |
-
object_type VARCHAR(256) NOT NULL COLLATE utf8_general_ci,
|
1129 |
-
object_subtype VARCHAR(256) NOT NULL COLLATE utf8_general_ci,
|
1130 |
-
user_id int(10) NOT NULL,
|
1131 |
-
object_id int(10) NOT NULL,
|
1132 |
-
object_name VARCHAR(256) NOT NULL COLLATE utf8_general_ci,
|
1133 |
PRIMARY KEY (id)
|
1134 |
) CHARACTER SET=utf8;";
|
1135 |
|
@@ -1149,15 +1127,14 @@ class SimpleHistory {
|
|
1149 |
// but it is at least a very old version that is being updated
|
1150 |
$first_install = true;
|
1151 |
|
1152 |
-
}// done pre db ver 1 things
|
1153 |
|
1154 |
// If db version is 1 then upgrade to 2
|
1155 |
// Version 2 added the action_description column
|
1156 |
if ( 1 == intval( $db_version ) ) {
|
1157 |
|
1158 |
-
//
|
1159 |
-
|
1160 |
-
$wpdb->query( $sql );
|
1161 |
|
1162 |
$db_version_prev = $db_version;
|
1163 |
$db_version = 2;
|
@@ -1209,25 +1186,17 @@ class SimpleHistory {
|
|
1209 |
level varchar(20) DEFAULT NULL,
|
1210 |
message varchar(255) DEFAULT NULL,
|
1211 |
occasionsID varchar(32) DEFAULT NULL,
|
1212 |
-
type varchar(16) DEFAULT NULL,
|
1213 |
initiator varchar(16) DEFAULT NULL,
|
1214 |
-
action varchar(255) NOT NULL,
|
1215 |
-
object_type varchar(255) NOT NULL,
|
1216 |
-
object_subtype varchar(255) NOT NULL,
|
1217 |
-
user_id int(10) NOT NULL,
|
1218 |
-
object_id int(10) NOT NULL,
|
1219 |
-
object_name varchar(255) NOT NULL,
|
1220 |
-
action_description longtext,
|
1221 |
PRIMARY KEY (id),
|
1222 |
KEY date (date),
|
1223 |
-
KEY loggerdate (logger,
|
1224 |
) CHARSET=utf8;";
|
1225 |
|
1226 |
dbDelta( $sql );
|
1227 |
|
1228 |
// Add context table
|
1229 |
$sql = "
|
1230 |
-
CREATE TABLE {$table_name_contexts} (
|
1231 |
context_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
1232 |
history_id bigint(20) unsigned NOT NULL,
|
1233 |
`key` varchar(255) DEFAULT NULL,
|
@@ -1244,7 +1213,7 @@ class SimpleHistory {
|
|
1244 |
$db_version = 3;
|
1245 |
update_option( "simple_history_db_version", $db_version );
|
1246 |
|
1247 |
-
// Update old items to use SimpleLegacyLogger
|
1248 |
$sql = sprintf( '
|
1249 |
UPDATE %1$s
|
1250 |
SET
|
@@ -1261,7 +1230,7 @@ class SimpleHistory {
|
|
1261 |
// use a filter to load it later
|
1262 |
add_action( "simple_history/loggers_loaded", array( $this, "addWelcomeLogMessage" ) );
|
1263 |
|
1264 |
-
}// db version 2 » 3
|
1265 |
|
1266 |
/**
|
1267 |
* If db version = 3
|
@@ -1275,18 +1244,27 @@ class SimpleHistory {
|
|
1275 |
|
1276 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
1277 |
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1290 |
|
1291 |
$db_version_prev = $db_version;
|
1292 |
$db_version = 4;
|
@@ -1295,6 +1273,25 @@ class SimpleHistory {
|
|
1295 |
|
1296 |
} // end db version 3 » 4
|
1297 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1298 |
} // end check_for_upgrade
|
1299 |
|
1300 |
/**
|
@@ -2171,7 +2168,8 @@ Because Simple History was just recently installed, this feed does not contain m
|
|
2171 |
$logRowKeysToShow["rep"],
|
2172 |
$logRowKeysToShow["repeated"],
|
2173 |
$logRowKeysToShow["occasionsIDType"],
|
2174 |
-
$logRowKeysToShow["context"]
|
|
|
2175 |
);
|
2176 |
|
2177 |
|
645 |
|
646 |
// Loggers for third party plugins
|
647 |
$loggersDir . "PluginUserSwitchingLogger.php",
|
648 |
+
$loggersDir . "PluginEnableMediaReplaceLogger.php",
|
649 |
+
$loggersDir . "Plugin_UltimateMembers_Logger.php"
|
650 |
);
|
651 |
|
652 |
// SimpleLogger.php must be loaded first and always since the other loggers extend it
|
1094 |
$table_name = $wpdb->prefix . SimpleHistory::DBTABLE;
|
1095 |
$table_name_contexts = $wpdb->prefix . SimpleHistory::DBTABLE_CONTEXTS;
|
1096 |
$first_install = false;
|
1097 |
+
|
1098 |
// If no db_version is set then this
|
1099 |
// is a version of Simple History < 0.4
|
1100 |
// or it's a first install
|
1101 |
// Fix database not using UTF-8
|
1102 |
+
if ( false === $db_version || intval( $db_version ) == 0 ) {
|
1103 |
|
1104 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
1105 |
|
1106 |
// Table creation, used to be in register_activation_hook
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1107 |
// We change the varchar size to add one num just to force update of encoding. dbdelta didn't see it otherwise.
|
|
|
1108 |
$sql = "CREATE TABLE " . $table_name . " (
|
1109 |
id bigint(20) NOT NULL AUTO_INCREMENT,
|
1110 |
date datetime NOT NULL,
|
|
|
|
|
|
|
|
|
|
|
|
|
1111 |
PRIMARY KEY (id)
|
1112 |
) CHARACTER SET=utf8;";
|
1113 |
|
1127 |
// but it is at least a very old version that is being updated
|
1128 |
$first_install = true;
|
1129 |
|
1130 |
+
} // done pre db ver 1 things
|
1131 |
|
1132 |
// If db version is 1 then upgrade to 2
|
1133 |
// Version 2 added the action_description column
|
1134 |
if ( 1 == intval( $db_version ) ) {
|
1135 |
|
1136 |
+
// V2 used to add column "action_description"
|
1137 |
+
// but it's not used any more so don't do i
|
|
|
1138 |
|
1139 |
$db_version_prev = $db_version;
|
1140 |
$db_version = 2;
|
1186 |
level varchar(20) DEFAULT NULL,
|
1187 |
message varchar(255) DEFAULT NULL,
|
1188 |
occasionsID varchar(32) DEFAULT NULL,
|
|
|
1189 |
initiator varchar(16) DEFAULT NULL,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1190 |
PRIMARY KEY (id),
|
1191 |
KEY date (date),
|
1192 |
+
KEY loggerdate (logger,date)
|
1193 |
) CHARSET=utf8;";
|
1194 |
|
1195 |
dbDelta( $sql );
|
1196 |
|
1197 |
// Add context table
|
1198 |
$sql = "
|
1199 |
+
CREATE TABLE IF NOT EXISTS {$table_name_contexts} (
|
1200 |
context_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
1201 |
history_id bigint(20) unsigned NOT NULL,
|
1202 |
`key` varchar(255) DEFAULT NULL,
|
1213 |
$db_version = 3;
|
1214 |
update_option( "simple_history_db_version", $db_version );
|
1215 |
|
1216 |
+
// Update possible old items to use SimpleLegacyLogger
|
1217 |
$sql = sprintf( '
|
1218 |
UPDATE %1$s
|
1219 |
SET
|
1230 |
// use a filter to load it later
|
1231 |
add_action( "simple_history/loggers_loaded", array( $this, "addWelcomeLogMessage" ) );
|
1232 |
|
1233 |
+
} // db version 2 » 3
|
1234 |
|
1235 |
/**
|
1236 |
* If db version = 3
|
1244 |
|
1245 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
1246 |
|
1247 |
+
// If old columns exist = this is an old install, then modify the columns so we still can keep them
|
1248 |
+
// we want to keep them because user may have logged items that they want to keep
|
1249 |
+
|
1250 |
+
$db_cools = $wpdb->get_col( "DESCRIBE $table_name" );
|
1251 |
+
|
1252 |
+
if ( in_array("action", $db_cools) ) {
|
1253 |
+
|
1254 |
+
$sql = sprintf( '
|
1255 |
+
ALTER TABLE %1$s
|
1256 |
+
MODIFY `action` varchar(255) NULL,
|
1257 |
+
MODIFY `object_type` varchar(255) NULL,
|
1258 |
+
MODIFY `object_subtype` varchar(255) NULL,
|
1259 |
+
MODIFY `user_id` int(10) NULL,
|
1260 |
+
MODIFY `object_id` int(10) NULL,
|
1261 |
+
MODIFY `object_name` varchar(255) NULL
|
1262 |
+
',
|
1263 |
+
$table_name
|
1264 |
+
);
|
1265 |
+
$wpdb->query( $sql );
|
1266 |
+
|
1267 |
+
}
|
1268 |
|
1269 |
$db_version_prev = $db_version;
|
1270 |
$db_version = 4;
|
1273 |
|
1274 |
} // end db version 3 » 4
|
1275 |
|
1276 |
+
// Some installs on 2.2.2 got failed installs
|
1277 |
+
// We detect these by checking for db_version and then running the install stuff again
|
1278 |
+
if ( 4 == intval( $db_version ) ) {
|
1279 |
+
|
1280 |
+
if ( ! $this->does_database_have_data() ) {
|
1281 |
+
|
1282 |
+
// not ok, decrease db number so installs will run again and hopefully fix things
|
1283 |
+
$db_version = 0;
|
1284 |
+
|
1285 |
+
} else {
|
1286 |
+
// all looks ok, upgrade to db version 5, so this part is not done again
|
1287 |
+
$db_version = 5;
|
1288 |
+
|
1289 |
+
}
|
1290 |
+
|
1291 |
+
update_option( "simple_history_db_version", $db_version );
|
1292 |
+
|
1293 |
+
}
|
1294 |
+
|
1295 |
} // end check_for_upgrade
|
1296 |
|
1297 |
/**
|
2168 |
$logRowKeysToShow["rep"],
|
2169 |
$logRowKeysToShow["repeated"],
|
2170 |
$logRowKeysToShow["occasionsIDType"],
|
2171 |
+
$logRowKeysToShow["context"],
|
2172 |
+
$logRowKeysToShow["type"]
|
2173 |
);
|
2174 |
|
2175 |
|
@@ -139,7 +139,6 @@ class SimpleHistoryLogQuery {
|
|
139 |
h.level,
|
140 |
h.date,
|
141 |
h.message,
|
142 |
-
h.type,
|
143 |
h.initiator,
|
144 |
h.occasionsID,
|
145 |
count(t.repeated) AS subsequentOccasions,
|
139 |
h.level,
|
140 |
h.date,
|
141 |
h.message,
|
|
|
142 |
h.initiator,
|
143 |
h.occasionsID,
|
144 |
count(t.repeated) AS subsequentOccasions,
|
@@ -5,7 +5,7 @@ Plugin URI: http://simple-history.com
|
|
5 |
Text Domain: simple-history
|
6 |
Domain Path: /languages
|
7 |
Description: Plugin that logs various things that occur in WordPress and then presents those events in a very nice GUI.
|
8 |
-
Version: 2.2.
|
9 |
Author: Pär Thernström
|
10 |
Author URI: http://simple-history.com/
|
11 |
License: GPL2
|
@@ -46,7 +46,7 @@ if ( version_compare( phpversion(), "5.3", ">=") ) {
|
|
46 |
// register_activation_hook( trailingslashit(WP_PLUGIN_DIR) . trailingslashit( plugin_basename(__DIR__) ) . "index.php" , array("SimpleHistory", "on_plugin_activate" ) );
|
47 |
|
48 |
if ( ! defined( 'SIMPLE_HISTORY_VERSION' ) ) {
|
49 |
-
define( 'SIMPLE_HISTORY_VERSION', '2.2.
|
50 |
}
|
51 |
|
52 |
if ( ! defined( 'SIMPLE_HISTORY_PATH' ) ) {
|
5 |
Text Domain: simple-history
|
6 |
Domain Path: /languages
|
7 |
Description: Plugin that logs various things that occur in WordPress and then presents those events in a very nice GUI.
|
8 |
+
Version: 2.2.4
|
9 |
Author: Pär Thernström
|
10 |
Author URI: http://simple-history.com/
|
11 |
License: GPL2
|
46 |
// register_activation_hook( trailingslashit(WP_PLUGIN_DIR) . trailingslashit( plugin_basename(__DIR__) ) . "index.php" , array("SimpleHistory", "on_plugin_activate" ) );
|
47 |
|
48 |
if ( ! defined( 'SIMPLE_HISTORY_VERSION' ) ) {
|
49 |
+
define( 'SIMPLE_HISTORY_VERSION', '2.2.4' );
|
50 |
}
|
51 |
|
52 |
if ( ! defined( 'SIMPLE_HISTORY_PATH' ) ) {
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
defined( 'ABSPATH' ) or die();
|
4 |
+
|
5 |
+
/**
|
6 |
+
*
|
7 |
+
* Plugin URL: https://sv.wordpress.org/plugins/ultimate-member/
|
8 |
+
*
|
9 |
+
* @since 2.2
|
10 |
+
*/
|
11 |
+
class Plugin_UltimateMembers_Logger extends SimpleLogger {
|
12 |
+
|
13 |
+
public $slug = __CLASS__;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Get array with information about this logger
|
17 |
+
*
|
18 |
+
* @return array
|
19 |
+
*/
|
20 |
+
function getInfo() {
|
21 |
+
|
22 |
+
$arr_info = array(
|
23 |
+
"name" => _x("Ultimate Members Logger", "PluginUltimateMembersLogger", "simple-history"),
|
24 |
+
"description" => _x("Logs actions from the Ultimate Members plugin", "PluginUltimateMembersLogger", "simple-history"),
|
25 |
+
"capability" => "edit_users",
|
26 |
+
"messages" => array(
|
27 |
+
'logged_in' => _x('Logged in', "PluginUltimateMembersLogger", "simple-history"),
|
28 |
+
),
|
29 |
+
);
|
30 |
+
|
31 |
+
return $arr_info;
|
32 |
+
|
33 |
+
}
|
34 |
+
|
35 |
+
function loaded() {
|
36 |
+
|
37 |
+
// Action that is called when Enable Media Replace loads it's admin options page (both when viewing and when posting new file to it)
|
38 |
+
add_action( 'um_on_login_before_redirect', array( $this, "on_um_on_login_before_redirect" ), 10, 1 );
|
39 |
+
}
|
40 |
+
|
41 |
+
function on_um_on_login_before_redirect( $user_id ) {
|
42 |
+
|
43 |
+
$this->infoMessage("logged_in", array(
|
44 |
+
//"user_id" => $user_id,
|
45 |
+
/*
|
46 |
+
"get" => $_GET,
|
47 |
+
"post" => $_POST,
|
48 |
+
"files" => $_FILES,
|
49 |
+
"old_attachment_post" => $prev_attachment_post,
|
50 |
+
"old_attachment_meta" => $prev_attachment_meta
|
51 |
+
*/
|
52 |
+
));
|
53 |
+
|
54 |
+
}
|
55 |
+
|
56 |
+
}
|
@@ -560,7 +560,7 @@ class SimpleCommentsLogger extends SimpleLogger
|
|
560 |
}
|
561 |
|
562 |
|
563 |
-
return $this->interpolate($message, $context);
|
564 |
|
565 |
}
|
566 |
|
560 |
}
|
561 |
|
562 |
|
563 |
+
return $this->interpolate($message, $context, $row);
|
564 |
|
565 |
}
|
566 |
|
@@ -114,20 +114,31 @@ class SimpleLogger {
|
|
114 |
|
115 |
/**
|
116 |
* Interpolates context values into the message placeholders.
|
|
|
|
|
|
|
|
|
117 |
*/
|
118 |
-
function interpolate($message, $context = array()) {
|
119 |
|
120 |
-
if (!is_array($context)) {
|
121 |
return $message;
|
122 |
}
|
123 |
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
$replace = array();
|
126 |
-
foreach ($context as $key => $val) {
|
127 |
$replace['{' . $key . '}'] = $val;
|
128 |
}
|
129 |
|
130 |
-
//
|
131 |
return strtr($message, $replace);
|
132 |
|
133 |
}
|
@@ -472,7 +483,7 @@ class SimpleLogger {
|
|
472 |
|
473 |
}
|
474 |
|
475 |
-
$html = $this->interpolate($message, $row->context);
|
476 |
|
477 |
// All messages are escaped by default.
|
478 |
// If you need unescaped output override this method
|
114 |
|
115 |
/**
|
116 |
* Interpolates context values into the message placeholders.
|
117 |
+
*
|
118 |
+
* @param string $message
|
119 |
+
* @param array $context
|
120 |
+
* @param array $row Currently not always passed, because loggers need to be updated to support this...
|
121 |
*/
|
122 |
+
function interpolate($message, $context = array(), $row = null) {
|
123 |
|
124 |
+
if ( ! is_array( $context ) ) {
|
125 |
return $message;
|
126 |
}
|
127 |
|
128 |
+
/**
|
129 |
+
* Filter the context used to create the message from the message template
|
130 |
+
*
|
131 |
+
* @since 2.2.4
|
132 |
+
*/
|
133 |
+
$context = apply_filters( "simple_history/logger/interpolate/context", $context, $message, $row );
|
134 |
+
|
135 |
+
// Build a replacement array with braces around the context keys
|
136 |
$replace = array();
|
137 |
+
foreach ( $context as $key => $val ) {
|
138 |
$replace['{' . $key . '}'] = $val;
|
139 |
}
|
140 |
|
141 |
+
// Interpolate replacement values into the message and return
|
142 |
return strtr($message, $replace);
|
143 |
|
144 |
}
|
483 |
|
484 |
}
|
485 |
|
486 |
+
$html = $this->interpolate($message, $row->context, $row);
|
487 |
|
488 |
// All messages are escaped by default.
|
489 |
// If you need unescaped output override this method
|
@@ -131,7 +131,7 @@ class SimpleMediaLogger extends SimpleLogger
|
|
131 |
$context["attachment_filename"] = esc_html( $context["attachment_filename"] );
|
132 |
$context["edit_link"] = get_edit_post_link( $attachment_id );
|
133 |
|
134 |
-
$message = $this->interpolate($message, $context);
|
135 |
|
136 |
} else {
|
137 |
|
@@ -256,7 +256,7 @@ class SimpleMediaLogger extends SimpleLogger
|
|
256 |
//$message .= " <span class='SimpleHistoryLogitem__inlineDivided'>" . sprintf( __('<a href="%1$s">Edit attachment</a>'), $edit_link ) . "</span>";
|
257 |
$message .= "</p>";
|
258 |
|
259 |
-
$output .= $this->interpolate($message, $context);
|
260 |
|
261 |
}
|
262 |
|
131 |
$context["attachment_filename"] = esc_html( $context["attachment_filename"] );
|
132 |
$context["edit_link"] = get_edit_post_link( $attachment_id );
|
133 |
|
134 |
+
$message = $this->interpolate($message, $context, $row);
|
135 |
|
136 |
} else {
|
137 |
|
256 |
//$message .= " <span class='SimpleHistoryLogitem__inlineDivided'>" . sprintf( __('<a href="%1$s">Edit attachment</a>'), $edit_link ) . "</span>";
|
257 |
$message .= "</p>";
|
258 |
|
259 |
+
$output .= $this->interpolate($message, $context, $row);
|
260 |
|
261 |
}
|
262 |
|
@@ -703,7 +703,7 @@ class SimplePostLogger extends SimpleLogger
|
|
703 |
$context["post_title"] = isset( $context["post_title"] ) ? esc_html( $context["post_title"] ) : "";
|
704 |
$context["edit_link"] = get_edit_post_link( $post_id );
|
705 |
|
706 |
-
return $this->interpolate($message, $context);
|
707 |
|
708 |
}
|
709 |
|
703 |
$context["post_title"] = isset( $context["post_title"] ) ? esc_html( $context["post_title"] ) : "";
|
704 |
$context["edit_link"] = get_edit_post_link( $post_id );
|
705 |
|
706 |
+
return $this->interpolate($message, $context, $row);
|
707 |
|
708 |
}
|
709 |
|
@@ -625,7 +625,7 @@ return;
|
|
625 |
$message = $this->interpolate( $message, array(
|
626 |
"widget_id_base" => $widget->name,
|
627 |
"sidebar_id" => $sidebar["name"],
|
628 |
-
) );
|
629 |
|
630 |
$output .= $message;
|
631 |
|
625 |
$message = $this->interpolate( $message, array(
|
626 |
"widget_id_base" => $widget->name,
|
627 |
"sidebar_id" => $sidebar["name"],
|
628 |
+
), $row );
|
629 |
|
630 |
$output .= $message;
|
631 |
|
@@ -234,7 +234,7 @@ class SimpleUserLogger extends SimpleLogger {
|
|
234 |
|
235 |
}
|
236 |
|
237 |
-
$output = $this->interpolate($msg, $context);
|
238 |
|
239 |
} else {
|
240 |
|
@@ -251,7 +251,7 @@ class SimpleUserLogger extends SimpleLogger {
|
|
251 |
// Edited user still exist, so link to their profile
|
252 |
$context["edit_profile_link"] = get_edit_user_link($wp_user->ID);
|
253 |
$msg = __('Edited the profile for user <a href="{edit_profile_link}">{edited_user_login} ({edited_user_email})</a>', "simple-history");
|
254 |
-
$output = $this->interpolate($msg, $context);
|
255 |
|
256 |
} else {
|
257 |
|
234 |
|
235 |
}
|
236 |
|
237 |
+
$output = $this->interpolate($msg, $context, $row);
|
238 |
|
239 |
} else {
|
240 |
|
251 |
// Edited user still exist, so link to their profile
|
252 |
$context["edit_profile_link"] = get_edit_user_link($wp_user->ID);
|
253 |
$msg = __('Edited the profile for user <a href="{edit_profile_link}">{edited_user_login} ({edited_user_email})</a>', "simple-history");
|
254 |
+
$output = $this->interpolate($msg, $context, $row);
|
255 |
|
256 |
} else {
|
257 |
|
@@ -4,7 +4,7 @@ Donate link: http://eskapism.se/sida/donate/
|
|
4 |
Tags: history, log, changes, changelog, audit, trail, pages, attachments, users, cms, dashboard, admin, syslog, feed, activity, stream, audit trail, brute-force
|
5 |
Requires at least: 3.6.0
|
6 |
Tested up to: 4.3
|
7 |
-
Stable tag: 2.2.
|
8 |
|
9 |
View changes made by users within WordPress. See who created a page, uploaded an attachment or approved an comment, and more.
|
10 |
|
@@ -119,10 +119,30 @@ initiated by a specific user.
|
|
119 |
|
120 |
## Changelog
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
= 2.2.3 (September 2015) =
|
123 |
|
124 |
- Fixed: On new installs the database tables was not created correctly and new events could not be logged.
|
125 |
|
|
|
126 |
= 2.2.2 (September 2015) =
|
127 |
|
128 |
- Fixed: Logging stopped working for languages other then English. Sorry about that!
|
4 |
Tags: history, log, changes, changelog, audit, trail, pages, attachments, users, cms, dashboard, admin, syslog, feed, activity, stream, audit trail, brute-force
|
5 |
Requires at least: 3.6.0
|
6 |
Tested up to: 4.3
|
7 |
+
Stable tag: 2.2.4
|
8 |
|
9 |
View changes made by users within WordPress. See who created a page, uploaded an attachment or approved an comment, and more.
|
10 |
|
119 |
|
120 |
## Changelog
|
121 |
|
122 |
+
= 2.2.4 (September 2015) =
|
123 |
+
|
124 |
+
- Added: Basic support for plugin [https://wordpress.org/plugins/ultimate-member/](Ultimate Member), so users logging in using the plugin will now be logged in Simple History. Fixes https://wordpress.org/support/topic/compatibility-with-ultimate-member.
|
125 |
+
|
126 |
+
- Added: Filter `simple_history/logger/interpolate/context` that can be used to modify the variables sent to the message template.
|
127 |
+
|
128 |
+
- Changed: Remove "type" key from context detail table, because it's an old an unused column.
|
129 |
+
|
130 |
+
- Changed: During a first install the plugin now creates a few less columns than before (some columns where left from version 1 of the plugin).
|
131 |
+
|
132 |
+
- Changed: Don't show the "translate this plugin" metabox for any english talking locale.
|
133 |
+
|
134 |
+
- Changed: Don't show the GitHub metabox.
|
135 |
+
|
136 |
+
- Fixed: If the plugin is deleted (but why?!) then the context table is also removed now.
|
137 |
+
|
138 |
+
- Behind the scenes: More unit tests! Hopefully more nasty things will get caught before releasing new versions of the plugin.
|
139 |
+
|
140 |
+
|
141 |
= 2.2.3 (September 2015) =
|
142 |
|
143 |
- Fixed: On new installs the database tables was not created correctly and new events could not be logged.
|
144 |
|
145 |
+
|
146 |
= 2.2.2 (September 2015) =
|
147 |
|
148 |
- Fixed: Logging stopped working for languages other then English. Sorry about that!
|
@@ -1,115 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class SampleTest extends WP_UnitTestCase {
|
4 |
-
|
5 |
-
function test_sample() {
|
6 |
-
|
7 |
-
// replace this with some actual testing code
|
8 |
-
$this->assertTrue( true );
|
9 |
-
}
|
10 |
-
|
11 |
-
function test_history_setup() {
|
12 |
-
|
13 |
-
$this->assertTrue( defined("SIMPLE_HISTORY_VERSION") );
|
14 |
-
$this->assertTrue( defined("SIMPLE_HISTORY_PATH") );
|
15 |
-
$this->assertTrue( defined("SIMPLE_HISTORY_BASENAME") );
|
16 |
-
$this->assertTrue( defined("SIMPLE_HISTORY_DIR_URL") );
|
17 |
-
$this->assertTrue( defined("SIMPLE_HISTORY_FILE") );
|
18 |
-
|
19 |
-
$this->assertFalse( defined("SIMPLE_HISTORY_DEV") );
|
20 |
-
$this->assertFalse( defined("SIMPLE_HISTORY_LOG_DEBUG") );
|
21 |
-
|
22 |
-
}
|
23 |
-
|
24 |
-
function test_history_classes() {
|
25 |
-
|
26 |
-
$this->assertTrue( class_exists("SimpleHistory") );
|
27 |
-
$this->assertTrue( class_exists("SimpleHistoryLogQuery") );
|
28 |
-
|
29 |
-
$sh = SimpleHistory::get_instance();
|
30 |
-
$this->assertTrue( is_object($sh) );
|
31 |
-
$this->assertTrue( is_a($sh, "SimpleHistory") );
|
32 |
-
|
33 |
-
}
|
34 |
-
|
35 |
-
function test_default_loggers() {
|
36 |
-
|
37 |
-
$sh = SimpleHistory::get_instance();
|
38 |
-
$loggers = $sh->getInstantiatedLoggers();
|
39 |
-
|
40 |
-
$arr_default_loggers = array(
|
41 |
-
"SimpleCommentsLogger",
|
42 |
-
"SimpleCoreUpdatesLogger",
|
43 |
-
"SimpleExportLogger",
|
44 |
-
"SimpleLegacyLogger",
|
45 |
-
"SimpleLogger",
|
46 |
-
"SimpleMediaLogger",
|
47 |
-
"SimpleMenuLogger",
|
48 |
-
"SimpleOptionsLogger",
|
49 |
-
"SimplePluginLogger",
|
50 |
-
"SimplePostLogger",
|
51 |
-
"SimpleThemeLogger",
|
52 |
-
"SimpleUserLogger",
|
53 |
-
);
|
54 |
-
|
55 |
-
foreach ($arr_default_loggers as $slug) {
|
56 |
-
|
57 |
-
$this->assertArrayHasKey( $slug, $loggers );
|
58 |
-
|
59 |
-
}
|
60 |
-
|
61 |
-
}
|
62 |
-
|
63 |
-
function test_default_dropins() {
|
64 |
-
|
65 |
-
$sh = SimpleHistory::get_instance();
|
66 |
-
$dropins = $sh->getInstantiatedDropins();
|
67 |
-
|
68 |
-
$arr_default_dropins = array(
|
69 |
-
"SimpleHistoryDonateDropin",
|
70 |
-
"SimpleHistoryExportDropin",
|
71 |
-
"SimpleHistoryFilterDropin",
|
72 |
-
"SimpleHistoryIpInfoDropin",
|
73 |
-
"SimpleHistoryNewRowsNotifier",
|
74 |
-
"SimpleHistoryRSSDropin",
|
75 |
-
"SimpleHistorySettingsLogtestDropin",
|
76 |
-
"SimpleHistorySettingsStatsDropin",
|
77 |
-
"SimpleHistorySidebarDropin",
|
78 |
-
);
|
79 |
-
|
80 |
-
foreach ($arr_default_dropins as $slug) {
|
81 |
-
|
82 |
-
$this->assertArrayHasKey( $slug, $dropins );
|
83 |
-
|
84 |
-
}
|
85 |
-
|
86 |
-
}
|
87 |
-
|
88 |
-
function test_default_settings_tabs() {
|
89 |
-
|
90 |
-
$sh = SimpleHistory::get_instance();
|
91 |
-
$settings_tabs = $sh->getSettingsTabs();
|
92 |
-
$arr_default_settings = array(
|
93 |
-
"settings",
|
94 |
-
"export"
|
95 |
-
);
|
96 |
-
|
97 |
-
$loaded_settings_slugs = wp_list_pluck( $settings_tabs, "slug" );
|
98 |
-
$this->assertEquals($arr_default_settings, $loaded_settings_slugs);
|
99 |
-
|
100 |
-
}
|
101 |
-
|
102 |
-
/*
|
103 |
-
|
104 |
-
# Todo
|
105 |
-
|
106 |
-
- test loggers and dropins loaded
|
107 |
-
- test logging a thing
|
108 |
-
- test logging of different log levels
|
109 |
-
- test context
|
110 |
-
- test api query
|
111 |
-
|
112 |
-
*/
|
113 |
-
|
114 |
-
}
|
115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class SimpleHistoryTest extends WP_UnitTestCase {
|
4 |
+
|
5 |
+
function test_sample() {
|
6 |
+
|
7 |
+
// replace this with some actual testing code
|
8 |
+
$this->assertTrue( true );
|
9 |
+
}
|
10 |
+
|
11 |
+
function test_history_setup() {
|
12 |
+
|
13 |
+
$this->assertTrue( defined("SIMPLE_HISTORY_VERSION") );
|
14 |
+
$this->assertTrue( defined("SIMPLE_HISTORY_PATH") );
|
15 |
+
$this->assertTrue( defined("SIMPLE_HISTORY_BASENAME") );
|
16 |
+
$this->assertTrue( defined("SIMPLE_HISTORY_DIR_URL") );
|
17 |
+
$this->assertTrue( defined("SIMPLE_HISTORY_FILE") );
|
18 |
+
|
19 |
+
$this->assertFalse( defined("SIMPLE_HISTORY_DEV") );
|
20 |
+
$this->assertFalse( defined("SIMPLE_HISTORY_LOG_DEBUG") );
|
21 |
+
|
22 |
+
}
|
23 |
+
|
24 |
+
function test_history_classes() {
|
25 |
+
|
26 |
+
$this->assertTrue( class_exists("SimpleHistory") );
|
27 |
+
$this->assertTrue( class_exists("SimpleHistoryLogQuery") );
|
28 |
+
|
29 |
+
$sh = SimpleHistory::get_instance();
|
30 |
+
$this->assertTrue( is_object($sh) );
|
31 |
+
$this->assertTrue( is_a($sh, "SimpleHistory") );
|
32 |
+
|
33 |
+
}
|
34 |
+
|
35 |
+
function test_default_loggers() {
|
36 |
+
|
37 |
+
$sh = SimpleHistory::get_instance();
|
38 |
+
$loggers = $sh->getInstantiatedLoggers();
|
39 |
+
|
40 |
+
$arr_default_loggers = array(
|
41 |
+
"SimpleCommentsLogger",
|
42 |
+
"SimpleCoreUpdatesLogger",
|
43 |
+
"SimpleExportLogger",
|
44 |
+
"SimpleLegacyLogger",
|
45 |
+
"SimpleLogger",
|
46 |
+
"SimpleMediaLogger",
|
47 |
+
"SimpleMenuLogger",
|
48 |
+
"SimpleOptionsLogger",
|
49 |
+
"SimplePluginLogger",
|
50 |
+
"SimplePostLogger",
|
51 |
+
"SimpleThemeLogger",
|
52 |
+
"SimpleUserLogger",
|
53 |
+
);
|
54 |
+
|
55 |
+
foreach ($arr_default_loggers as $slug) {
|
56 |
+
|
57 |
+
$this->assertArrayHasKey( $slug, $loggers );
|
58 |
+
|
59 |
+
}
|
60 |
+
|
61 |
+
}
|
62 |
+
|
63 |
+
function test_default_dropins() {
|
64 |
+
|
65 |
+
$sh = SimpleHistory::get_instance();
|
66 |
+
$dropins = $sh->getInstantiatedDropins();
|
67 |
+
|
68 |
+
$arr_default_dropins = array(
|
69 |
+
"SimpleHistoryDonateDropin",
|
70 |
+
"SimpleHistoryExportDropin",
|
71 |
+
"SimpleHistoryFilterDropin",
|
72 |
+
"SimpleHistoryIpInfoDropin",
|
73 |
+
"SimpleHistoryNewRowsNotifier",
|
74 |
+
"SimpleHistoryRSSDropin",
|
75 |
+
"SimpleHistorySettingsLogtestDropin",
|
76 |
+
"SimpleHistorySettingsStatsDropin",
|
77 |
+
"SimpleHistorySidebarDropin",
|
78 |
+
);
|
79 |
+
|
80 |
+
foreach ($arr_default_dropins as $slug) {
|
81 |
+
|
82 |
+
$this->assertArrayHasKey( $slug, $dropins );
|
83 |
+
|
84 |
+
}
|
85 |
+
|
86 |
+
}
|
87 |
+
|
88 |
+
function test_default_settings_tabs() {
|
89 |
+
|
90 |
+
$sh = SimpleHistory::get_instance();
|
91 |
+
$settings_tabs = $sh->getSettingsTabs();
|
92 |
+
$arr_default_settings = array(
|
93 |
+
"settings",
|
94 |
+
"export"
|
95 |
+
);
|
96 |
+
|
97 |
+
$loaded_settings_slugs = wp_list_pluck( $settings_tabs, "slug" );
|
98 |
+
$this->assertEquals($arr_default_settings, $loaded_settings_slugs);
|
99 |
+
|
100 |
+
}
|
101 |
+
|
102 |
+
function test_install() {
|
103 |
+
|
104 |
+
global $wpdb;
|
105 |
+
|
106 |
+
// Test table simple history
|
107 |
+
$table_name_simple_history = $wpdb->prefix . SimpleHistory::DBTABLE;
|
108 |
+
$table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name_simple_history ) );
|
109 |
+
$this->assertEquals( $table_name_simple_history, $table_exists );
|
110 |
+
|
111 |
+
$table_cols = $wpdb->get_col("DESCRIBE $table_name_simple_history");
|
112 |
+
$expected_table_cols = array(
|
113 |
+
"id",
|
114 |
+
"date",
|
115 |
+
"logger",
|
116 |
+
"level",
|
117 |
+
"message",
|
118 |
+
"occasionsID",
|
119 |
+
"initiator"
|
120 |
+
);
|
121 |
+
|
122 |
+
$this->assertEquals($expected_table_cols, $table_cols, "cols in history table should be the same");
|
123 |
+
|
124 |
+
|
125 |
+
// Test table simple history contexts
|
126 |
+
$table_name_contexts = $wpdb->prefix . SimpleHistory::DBTABLE_CONTEXTS;
|
127 |
+
$table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name_contexts ) );
|
128 |
+
$this->assertEquals( $table_name_contexts, $table_exists );
|
129 |
+
|
130 |
+
$table_cols_context = $wpdb->get_col("DESCRIBE $table_name_contexts");
|
131 |
+
$expected_table_cols_context = array(
|
132 |
+
"context_id",
|
133 |
+
"history_id",
|
134 |
+
"key",
|
135 |
+
"value"
|
136 |
+
);
|
137 |
+
|
138 |
+
$this->assertEquals($expected_table_cols_context, $table_cols_context, "cols in context table should be the same");
|
139 |
+
|
140 |
+
|
141 |
+
}
|
142 |
+
|
143 |
+
function test_loglevels_and_initiators() {
|
144 |
+
|
145 |
+
$refl = new ReflectionClass('SimpleLoggerLogLevels');
|
146 |
+
$log_levels = (array) $refl->getConstants();
|
147 |
+
|
148 |
+
$expected_log_levels = array(
|
149 |
+
'EMERGENCY' => "emergency",
|
150 |
+
'ALERT' => "alert",
|
151 |
+
'CRITICAL' => "critical",
|
152 |
+
'ERROR' => "error",
|
153 |
+
'WARNING' => "warning",
|
154 |
+
'NOTICE' => "notice",
|
155 |
+
'INFO' => "info",
|
156 |
+
'DEBUG' => "debug"
|
157 |
+
);
|
158 |
+
|
159 |
+
$this->assertEquals( $expected_log_levels, $log_levels, "log levels" );
|
160 |
+
|
161 |
+
$refl = new ReflectionClass('SimpleLoggerLogInitiators');
|
162 |
+
$log_initiators = (array) $refl->getConstants();
|
163 |
+
|
164 |
+
$expected_log_initiators = array(
|
165 |
+
"WP_USER" => 'wp_user',
|
166 |
+
"WEB_USER" => 'web_user',
|
167 |
+
"WORDPRESS" => "wp",
|
168 |
+
"WP_CLI" => "wp_cli",
|
169 |
+
"OTHER" => 'other'
|
170 |
+
);
|
171 |
+
|
172 |
+
$this->assertEquals( $expected_log_initiators, $log_initiators, "log initiators" );
|
173 |
+
|
174 |
+
|
175 |
+
}
|
176 |
+
|
177 |
+
// test logging and retrieving logs
|
178 |
+
function test_logging() {
|
179 |
+
|
180 |
+
global $wpdb;
|
181 |
+
|
182 |
+
$table_name_simple_history = $wpdb->prefix . SimpleHistory::DBTABLE;
|
183 |
+
|
184 |
+
$refl_log_levels = new ReflectionClass('SimpleLoggerLogLevels');
|
185 |
+
$log_levels = (array) $refl_log_levels->getConstants();
|
186 |
+
|
187 |
+
$refl_log_initiators = new ReflectionClass('SimpleLoggerLogInitiators');
|
188 |
+
$log_initiators = (array) $refl_log_initiators->getConstants();
|
189 |
+
|
190 |
+
foreach ( $log_levels as $level_const => $level_str ) {
|
191 |
+
|
192 |
+
foreach ( $log_initiators as $initiator_const => $initiator_str ) {
|
193 |
+
|
194 |
+
$message = "This is a message with log level $level_str";
|
195 |
+
|
196 |
+
SimpleLogger()->log( $level_str, $message, array(
|
197 |
+
"_initiator" => $initiator_str
|
198 |
+
) );
|
199 |
+
|
200 |
+
// Last logged message in db should be the above
|
201 |
+
$db_row = $wpdb->get_row( "SELECT logger, level, message, initiator FROM $table_name_simple_history ORDER BY id DESC LIMIT 1", ARRAY_A );
|
202 |
+
|
203 |
+
$expected_row = array(
|
204 |
+
'logger' => "SimpleLogger",
|
205 |
+
'level' => $level_str,
|
206 |
+
'message' => $message,
|
207 |
+
'initiator' => $initiator_str
|
208 |
+
);
|
209 |
+
|
210 |
+
$this->assertEquals( $expected_row, $db_row, "logged event in db" );
|
211 |
+
|
212 |
+
}
|
213 |
+
|
214 |
+
}
|
215 |
+
|
216 |
+
// TODO: test logging with context
|
217 |
+
|
218 |
+
}
|
219 |
+
|
220 |
+
function test_api() {
|
221 |
+
|
222 |
+
}
|
223 |
+
|
224 |
+
|
225 |
+
}
|
226 |
+
|
@@ -27,9 +27,13 @@ foreach ($arr_options as $one_option) {
|
|
27 |
delete_option( $one_option );
|
28 |
}
|
29 |
|
30 |
-
// Remove database table
|
31 |
global $wpdb;
|
|
|
|
|
32 |
$table_name = $wpdb->prefix . "simple_history";
|
33 |
$wpdb->query("DROP TABLE IF EXISTS $table_name");
|
34 |
|
|
|
|
|
|
|
35 |
// And we are done. Simple History is ... history.
|
27 |
delete_option( $one_option );
|
28 |
}
|
29 |
|
|
|
30 |
global $wpdb;
|
31 |
+
|
32 |
+
// Remove database tables
|
33 |
$table_name = $wpdb->prefix . "simple_history";
|
34 |
$wpdb->query("DROP TABLE IF EXISTS $table_name");
|
35 |
|
36 |
+
$table_name = $wpdb->prefix . "simple_history_contexts";
|
37 |
+
$wpdb->query("DROP TABLE IF EXISTS $table_name");
|
38 |
+
|
39 |
// And we are done. Simple History is ... history.
|