Simple History - Version 2.13

Version Description

(November 2016) =

  • Added filter simple_history_log that is a simplified way to add message to the log, without the need to check for the existance of Simple History or its SimpleLogger function. Use it like this: apply_filters("simple_history_log", "This is a logged message"); See the examples file for more examples.
  • IP info now displays a popup with map + geolocation info for users using HTTPS again. Thanks to the great https://twitter.com/ipinfoio for letting all users use their service :)
  • Fix notice warning for missing $data_parent_row
Download this release

Release Info

Developer eskapism
Plugin Icon 128x128 Simple History
Version 2.13
Comparing to
See all releases

Code changes from version 2.12 to 2.13

dropins/SimpleHistoryIpInfoDropin.js CHANGED
@@ -18,6 +18,14 @@
18
  return;
19
  }
20
 
 
 
 
 
 
 
 
 
21
  // If we are on a HTTPS site we cant use ipinfo because lookups over https require pro account
22
  // Fallback to plain link
23
  var isHTTPS = document.location.protocol == "https:";
@@ -32,6 +40,7 @@
32
 
33
  return lookupIpAddress(ipAddress);
34
  }
 
35
 
36
  });
37
 
@@ -94,7 +103,7 @@
94
 
95
  //try {
96
 
97
- var ajax = $.get("http://ipinfo.io/" + ipAddress, onIpAddressLookupResponse, "jsonp");
98
 
99
  // If the ajax call fail, for example because of blocked connections using adblocker-similar software
100
  // err_blocked_by_client
18
  return;
19
  }
20
 
21
+ // since 24 sept 2016 ipinfo supports ssl/https for all users, so we can enable ipinfo for all
22
+ // https://twitter.com/ipinfoio/status/779374440417103872
23
+ showPopup($elm);
24
+
25
+ return lookupIpAddress(ipAddress);
26
+
27
+
28
+ /*
29
  // If we are on a HTTPS site we cant use ipinfo because lookups over https require pro account
30
  // Fallback to plain link
31
  var isHTTPS = document.location.protocol == "https:";
40
 
41
  return lookupIpAddress(ipAddress);
42
  }
43
+ */
44
 
45
  });
46
 
103
 
104
  //try {
105
 
106
+ var ajax = $.get("https://ipinfo.io/" + ipAddress, onIpAddressLookupResponse, "jsonp");
107
 
108
  // If the ajax call fail, for example because of blocked connections using adblocker-similar software
109
  // err_blocked_by_client
dropins/SimpleHistoryIpInfoDropin.php CHANGED
@@ -161,7 +161,7 @@ class SimpleHistoryIpInfoDropin {
161
  </table>
162
 
163
  <p class="SimpleHistoryIpInfoDropin__provider">
164
- <?php printf( _x('IP info provided by %1$s ipinfo.io %2$s', "IP Info Dropin", "simple-history"), "<a href='http://ipinfo.io/{{ data.ip }}' target='_blank'>", "</a>" ); ?>
165
  </p>
166
 
167
  <# } #>
161
  </table>
162
 
163
  <p class="SimpleHistoryIpInfoDropin__provider">
164
+ <?php printf( _x('IP info provided by %1$s ipinfo.io %2$s', "IP Info Dropin", "simple-history"), "<a href='https://ipinfo.io/{{ data.ip }}' target='_blank'>", "</a>" ); ?>
165
  </p>
166
 
167
  <# } #>
examples/examples.php CHANGED
@@ -16,6 +16,24 @@ define("SIMPLE_HISTORY_LOG_DEBUG", true);
16
  * Some examples of filter usage and so on
17
  */
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  // Disable all logging
20
  add_filter( "simple_history/log/do_log", "__return_false" );
21
 
@@ -44,7 +62,7 @@ add_filter( "simple_history/logger/interpolate/context", function($context, $mes
44
  * Default capability is "manage_options"
45
  */
46
  add_filter("simple_history/view_settings_capability", function($capability) {
47
-
48
  $capability = "manage_options";
49
  return $capability;
50
 
@@ -53,18 +71,18 @@ add_filter("simple_history/view_settings_capability", function($capability) {
53
 
54
  /**
55
  * Change capability required to view main simple history page.
56
- * Default capability is "edit_pages". Change to for example "manage options"
57
  * to only allow admins to view the history log.
58
  */
59
  add_filter("simple_history/view_history_capability", function($capability) {
60
-
61
  $capability = "manage_options";
62
  return $capability;
63
 
64
  });
65
 
66
 
67
- // Skip adding things to the context table during logging.
68
  // Useful if you don't want to add cool and possible super useful info to your logged events.
69
  // Also nice to have if you want to make sure your database does not grow.
70
  add_filter("simple_history/log_insert_context", function($context, $data) {
@@ -80,7 +98,7 @@ add_filter("simple_history/log_insert_context", function($context, $data) {
80
 
81
  // Hide some columns from the detailed context view popup window
82
  add_filter("simple_history/log_html_output_details_table/row_keys_to_show", function($logRowKeysToShow, $oneLogRow) {
83
-
84
  $logRowKeysToShow["id"] = false;
85
  $logRowKeysToShow["logger"] = false;
86
  $logRowKeysToShow["level"] = false;
@@ -93,7 +111,7 @@ add_filter("simple_history/log_html_output_details_table/row_keys_to_show", func
93
 
94
  // Hide some more columns from the detailed context view popup window
95
  add_filter("simple_history/log_html_output_details_table/context_keys_to_show", function($logRowContextKeysToShow, $oneLogRow) {
96
-
97
  $logRowContextKeysToShow["plugin_slug"] = false;
98
  $logRowContextKeysToShow["plugin_name"] = false;
99
  $logRowContextKeysToShow["plugin_title"] = false;
@@ -117,7 +135,7 @@ function function_show_history_dashboard_or_page($show) {
117
  );
118
 
119
  $user = wp_get_current_user();
120
-
121
  if ( ! in_array( $user->user_email, $allowed_users ) ) {
122
  $show = false;
123
  }
@@ -158,7 +176,7 @@ add_filter("simple_history/logger/load_logger", function($load_logger, $logger_b
158
 
159
  // Skip the loading of dropins
160
  add_filter("simple_history/dropin/load_dropin", function($load_dropin, $dropinFileBasename) {
161
-
162
  // Don't load the RSS feed dropin
163
  if ( $dropinFileBasename == "SimpleHistoryRSSDropin" ) {
164
  $load_dropin = false;
@@ -196,9 +214,9 @@ add_filter("simple_history/db_purge_days_interval", "__return_zero");
196
 
197
  // Clear items that are older than a 7 days (i.e. keep only the most recent 7 days in the log)
198
  add_filter( "simple_history/db_purge_days_interval", function( $days ) {
199
-
200
  $days = 7;
201
-
202
  return $days;
203
 
204
  } );
@@ -213,6 +231,19 @@ add_filter("simple_history/dropin/load_dropin_SimpleHistoryRSSDropin", "__return
213
  * Example of logging
214
  */
215
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
  // Add a message to the history log
217
  SimpleLogger()->info("This is a message sent to the log");
218
 
16
  * Some examples of filter usage and so on
17
  */
18
 
19
+ // Do not log some post types, for example pages and attachments in this case
20
+ add_filter( "simple_history/log/do_log", function( $do_log = null, $level = null, $message = null, $context = null, $logger = null) {
21
+
22
+ $post_types_to_not_log = array(
23
+ "page",
24
+ "attachment"
25
+ );
26
+
27
+ if ( ( isset($logger->slug) && ($logger->slug === "SimplePostLogger" || $logger->slug === "SimpleMediaLogger") ) && ( isset($context["post_type"]) && in_array($context["post_type"], $post_types_to_not_log ) ) ) {
28
+
29
+ $do_log = false;
30
+
31
+ }
32
+
33
+ return $do_log;
34
+
35
+ }, 10, 5);
36
+
37
  // Disable all logging
38
  add_filter( "simple_history/log/do_log", "__return_false" );
39
 
62
  * Default capability is "manage_options"
63
  */
64
  add_filter("simple_history/view_settings_capability", function($capability) {
65
+
66
  $capability = "manage_options";
67
  return $capability;
68
 
71
 
72
  /**
73
  * Change capability required to view main simple history page.
74
+ * Default capability is "edit_pages". Change to for example "manage options"
75
  * to only allow admins to view the history log.
76
  */
77
  add_filter("simple_history/view_history_capability", function($capability) {
78
+
79
  $capability = "manage_options";
80
  return $capability;
81
 
82
  });
83
 
84
 
85
+ // Skip adding things to the context table during logging.
86
  // Useful if you don't want to add cool and possible super useful info to your logged events.
87
  // Also nice to have if you want to make sure your database does not grow.
88
  add_filter("simple_history/log_insert_context", function($context, $data) {
98
 
99
  // Hide some columns from the detailed context view popup window
100
  add_filter("simple_history/log_html_output_details_table/row_keys_to_show", function($logRowKeysToShow, $oneLogRow) {
101
+
102
  $logRowKeysToShow["id"] = false;
103
  $logRowKeysToShow["logger"] = false;
104
  $logRowKeysToShow["level"] = false;
111
 
112
  // Hide some more columns from the detailed context view popup window
113
  add_filter("simple_history/log_html_output_details_table/context_keys_to_show", function($logRowContextKeysToShow, $oneLogRow) {
114
+
115
  $logRowContextKeysToShow["plugin_slug"] = false;
116
  $logRowContextKeysToShow["plugin_name"] = false;
117
  $logRowContextKeysToShow["plugin_title"] = false;
135
  );
136
 
137
  $user = wp_get_current_user();
138
+
139
  if ( ! in_array( $user->user_email, $allowed_users ) ) {
140
  $show = false;
141
  }
176
 
177
  // Skip the loading of dropins
178
  add_filter("simple_history/dropin/load_dropin", function($load_dropin, $dropinFileBasename) {
179
+
180
  // Don't load the RSS feed dropin
181
  if ( $dropinFileBasename == "SimpleHistoryRSSDropin" ) {
182
  $load_dropin = false;
214
 
215
  // Clear items that are older than a 7 days (i.e. keep only the most recent 7 days in the log)
216
  add_filter( "simple_history/db_purge_days_interval", function( $days ) {
217
+
218
  $days = 7;
219
+
220
  return $days;
221
 
222
  } );
231
  * Example of logging
232
  */
233
 
234
+ // This is the easiest and safest way to add messages to the log:
235
+ apply_filters("simple_history_log", "This is a logged message");
236
+ apply_filters("simple_history_log", "This is a message with some context added", ["isATestMessage" => "yup", "debugRequestData" => $_REQUEST]);
237
+ apply_filters("simple_history_log", "This is another logged message, with another severity level", null, "debug");
238
+
239
+ // Below is the function way of adding things to the log
240
+ // Remember to check that the SimpleLogger function exists before trying to log anything,
241
+ // or else your site will break if you disable the Simple History plugin
242
+ // (Use the apply_filters method above if you want to stay safer!)
243
+ if (function_exists("SimpleLogger")) {
244
+ SimpleLogger()->info("This is a message added to the log");
245
+ }
246
+
247
  // Add a message to the history log
248
  SimpleLogger()->info("This is a message sent to the log");
249
 
inc/SimpleHistory.php CHANGED
@@ -117,6 +117,21 @@ class SimpleHistory {
117
  add_action( 'admin_bar_menu', array( $this, 'add_admin_bar_network_menu_item' ), 40 );
118
  add_action( 'admin_bar_menu', array( $this, 'add_admin_bar_menu_item' ), 40 );
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  if ( is_admin() ) {
121
 
122
  $this->add_admin_actions();
@@ -166,6 +181,30 @@ class SimpleHistory {
166
 
167
  }
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  /**
170
  * @since 2.5.2
171
  */
117
  add_action( 'admin_bar_menu', array( $this, 'add_admin_bar_network_menu_item' ), 40 );
118
  add_action( 'admin_bar_menu', array( $this, 'add_admin_bar_menu_item' ), 40 );
119
 
120
+ /**
121
+ * Filter that is used to log things, without the need to check that simple history is available
122
+ * i.e. you can have simple history acivated and log things and then you can disable the plugin
123
+ * and no errors will occur
124
+ *
125
+ * Usage:
126
+ * apply_filters("simple_history_log", "This is the log message");
127
+ * apply_filters("simple_history_log", "This is the log message with some extra data/info", ["extraThing1" => $variableWIihThing]);
128
+ * apply_filters("simple_history_log", "This is the log message with severity debug", null, "debug");
129
+ * apply_filters("simple_history_log", "This is the log message with severity debug and with some extra info/data logged", ["userData" => $userData, "shoppingCartDebugData" => $shopDebugData], "debug",);
130
+ *
131
+ * @since 2.13
132
+ */
133
+ add_filter( 'simple_history_log', array($this, "on_filter_simple_history_log"), 10, 3 );
134
+
135
  if ( is_admin() ) {
136
 
137
  $this->add_admin_actions();
181
 
182
  }
183
 
184
+ /**
185
+ * Log a message
186
+ *
187
+ * Function called when running filter "simple_history_log"
188
+ *
189
+ * @since 2.13
190
+ * @param mixed $logMessage
191
+ * @param array $context Optional context to add to the logged data
192
+ * @param string $level The loglevel. Must be one of the existing ones. Defaults to "info".
193
+ */
194
+ public function on_filter_simple_history_log( $message = null, $context = null, $level = "info" ) {
195
+
196
+ if (empty($message)) {
197
+ return;
198
+ }
199
+
200
+ if (!is_array($context)) {
201
+ $context = array();
202
+ }
203
+
204
+ SimpleLogger()->log($level, $message, $context);
205
+
206
+ }
207
+
208
  /**
209
  * @since 2.5.2
210
  */
index.php CHANGED
@@ -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.12
9
  Author: Pär Thernström
10
  Author URI: http://simple-history.com/
11
  License: GPL2
@@ -42,7 +42,7 @@ if ( version_compare( phpversion(), "5.3", ">=") ) {
42
  // register_activation_hook( trailingslashit(WP_PLUGIN_DIR) . trailingslashit( plugin_basename(__DIR__) ) . "index.php" , array("SimpleHistory", "on_plugin_activate" ) );
43
 
44
  if ( ! defined( 'SIMPLE_HISTORY_VERSION' ) ) {
45
- define( 'SIMPLE_HISTORY_VERSION', '2.12' );
46
  }
47
 
48
  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.13
9
  Author: Pär Thernström
10
  Author URI: http://simple-history.com/
11
  License: GPL2
42
  // register_activation_hook( trailingslashit(WP_PLUGIN_DIR) . trailingslashit( plugin_basename(__DIR__) ) . "index.php" , array("SimpleHistory", "on_plugin_activate" ) );
43
 
44
  if ( ! defined( 'SIMPLE_HISTORY_VERSION' ) ) {
45
+ define( 'SIMPLE_HISTORY_VERSION', '2.13' );
46
  }
47
 
48
  if ( ! defined( 'SIMPLE_HISTORY_PATH' ) ) {
loggers/SimpleLogger.php CHANGED
@@ -1143,6 +1143,8 @@ class SimpleLogger {
1143
 
1144
  $result = $wpdb->insert($db_table, $data);
1145
 
 
 
1146
  // Only save context if able to store row
1147
  if (false === $result) {
1148
 
1143
 
1144
  $result = $wpdb->insert($db_table, $data);
1145
 
1146
+ $data_parent_row = null;
1147
+
1148
  // Only save context if able to store row
1149
  if (false === $result) {
1150
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://eskapism.se/sida/donate/
4
  Tags: history, log, changes, changelog, audit, trail, pages, attachments, users, dashboard, admin, syslog, feed, activity, stream, audit trail, brute-force
5
  Requires at least: 4.5.1
6
  Tested up to: 4.6
7
- Stable tag: 2.12
8
 
9
  View changes made by users within WordPress. See who created a page, uploaded an attachment or approved an comment, and more.
10
 
@@ -43,19 +43,23 @@ view details about changes made in the differnt settings sections of WordPress.
43
 
44
  By default Simple History comes with built in support for the following plugins:
45
 
46
- **User Switching**
47
  The [User Switching plugin](https://wordpress.org/plugins/user-switching/) allows you to quickly swap between user accounts in WordPress at the click of a button.
48
  Simple History will log each user switch being made.
49
 
50
- **Enable Media Replace**
51
  The [Enable Media Replace plugin](https://wordpress.org/plugins/enable-media-replace/) allows you to replace a file in your media library by uploading a new file in its place.
52
  Simple history will log details about the file being replaced and details about the new file.
53
 
54
- **Limit Login Attempts**
55
  The plugin [Limit Login Attempts](https://sv.wordpress.org/plugins/limit-login-attempts/) is old
56
  and has not been updated for 4 years. However it still has +1 million installs, so many users will benefit from
57
  Simple History logging login attempts, lockouts, and configuration changes made in the plugin Limit Login Attempts.
58
 
 
 
 
 
59
  #### RSS feed available
60
 
61
  There is also a **RSS feed of changes** available, so you can keep track of the changes made via your favorite RSS reader on your phone, on your iPad, or on your computer.
@@ -153,6 +157,12 @@ A simple way to see any uncommon activity, for example an increased number of lo
153
 
154
  ## Changelog
155
 
 
 
 
 
 
 
156
  = 2.12 (September 2016) =
157
 
158
  - You can show a different number of log items in the log on the dashboard and on the dedicated history page. By default the dashboard will show 5 items and the page will show 30.
4
  Tags: history, log, changes, changelog, audit, trail, pages, attachments, users, dashboard, admin, syslog, feed, activity, stream, audit trail, brute-force
5
  Requires at least: 4.5.1
6
  Tested up to: 4.6
7
+ Stable tag: 2.13
8
 
9
  View changes made by users within WordPress. See who created a page, uploaded an attachment or approved an comment, and more.
10
 
43
 
44
  By default Simple History comes with built in support for the following plugins:
45
 
46
+ **User Switching**<br>
47
  The [User Switching plugin](https://wordpress.org/plugins/user-switching/) allows you to quickly swap between user accounts in WordPress at the click of a button.
48
  Simple History will log each user switch being made.
49
 
50
+ **Enable Media Replace**<br>
51
  The [Enable Media Replace plugin](https://wordpress.org/plugins/enable-media-replace/) allows you to replace a file in your media library by uploading a new file in its place.
52
  Simple history will log details about the file being replaced and details about the new file.
53
 
54
+ **Limit Login Attempts**<br>
55
  The plugin [Limit Login Attempts](https://sv.wordpress.org/plugins/limit-login-attempts/) is old
56
  and has not been updated for 4 years. However it still has +1 million installs, so many users will benefit from
57
  Simple History logging login attempts, lockouts, and configuration changes made in the plugin Limit Login Attempts.
58
 
59
+ **Redirection**
60
+ The [redirection plugin](https://sv.wordpress.org/plugins/redirection/) manages url redirections, using a nice GUI.
61
+ Simple History will log redirects and groups that are created, changed, enabled or disabled and also when the global plugin settings have been modified.
62
+
63
  #### RSS feed available
64
 
65
  There is also a **RSS feed of changes** available, so you can keep track of the changes made via your favorite RSS reader on your phone, on your iPad, or on your computer.
157
 
158
  ## Changelog
159
 
160
+ = 2.13 (November 2016) =
161
+
162
+ - Added filter `simple_history_log` that is a simplified way to add message to the log, without the need to check for the existance of Simple History or its SimpleLogger function. Use it like this: `apply_filters("simple_history_log", "This is a logged message");` See the [examples file](https://github.com/bonny/WordPress-Simple-History/blob/master/examples/examples.php) for more examples.
163
+ - IP info now displays a popup with map + geolocation info for users using HTTPS again. Thanks to the great https://twitter.com/ipinfoio for letting all users use their service :)
164
+ - Fix notice warning for missing `$data_parent_row`
165
+
166
  = 2.12 (September 2016) =
167
 
168
  - You can show a different number of log items in the log on the dashboard and on the dedicated history page. By default the dashboard will show 5 items and the page will show 30.