Simple History - Version 2.7

Version Description

(May 2016) =

  • Added: When a user is created or edited the log now shows what fields have changed and from what old value to what new value. A much requested feature!
  • Fixed: If you edited your own profile the log would say that you edited "their profile". Now it says that you edited "your profile" instead.
  • Changed: Post diffs could get very tall. Now they are max approx 8 rows by default, but if you hover the diff (or give it focus with your keyboard) you get a scrollbar and can scroll the contents. Fixes https://wordpress.org/support/topic/dashboard-max-length-of-content and https://wordpress.org/support/topic/feature-request-make-content-diff-report-expandable-and-closed-by-default.
  • Fixed: Maybe fix a notice varning if a transient was missing a name or value.
Download this release

Release Info

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

Code changes from version 2.6 to 2.7

css/styles.css CHANGED
@@ -330,6 +330,15 @@ Style different log levels.
330
  }
331
 
332
 
 
 
 
 
 
 
 
 
 
333
 
334
  /* wrap span.SimpleHistoryLogitem__inlineDivided around things that should have a bullet between them */
335
  .SimpleHistoryLogitem__inlineDivided {
@@ -928,3 +937,35 @@ Modal window with detailss
928
  padding: 10px;
929
  font-weight: bold;
930
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330
  }
331
 
332
 
333
+ .SimpleHistoryLogitem__keyValueTable__addedThing {
334
+ text-decoration: none;
335
+ }
336
+
337
+ .SimpleHistoryLogitem__keyValueTable__removedThing {
338
+ text-decoration: line-through;
339
+ color: #999;
340
+ }
341
+
342
 
343
  /* wrap span.SimpleHistoryLogitem__inlineDivided around things that should have a bullet between them */
344
  .SimpleHistoryLogitem__inlineDivided {
937
  padding: 10px;
938
  font-weight: bold;
939
  }
940
+
941
+
942
+ /* diff contents can be very high sometimes, so we limit the height and add scrollbars in those cases */
943
+ .SimpleHistory__diff__contents {
944
+ max-height: 11em;
945
+ overflow: hidden;
946
+ position: relative;
947
+ }
948
+
949
+ /* fade out that indicate more content */
950
+ /*.SimpleHistory__diff__contents:after {
951
+ content: "";
952
+ position: absolute;
953
+ bottom: 0;
954
+ left: 0;
955
+ width: 100%;
956
+ height: 30px;
957
+ background: linear-gradient(transparent, white);
958
+ }*/
959
+
960
+ .SimpleHistory__diff__contents:hover,
961
+ .SimpleHistory__diff__contents:focus {
962
+ overflow-y: auto;
963
+ }
964
+
965
+ .SimpleHistory__diff__contents:focus {
966
+ outline: 1px solid rgb(0, 115, 170);
967
+ box-shadow: 0 0 0 1px #5b9dd9,0 0 2px 1px rgba(30,140,190,.8);
968
+ }
969
+
970
+ .SimpleHistory__diff__contentsInner {
971
+ }
inc/SimpleHistory.php CHANGED
@@ -3189,8 +3189,13 @@ function simple_history_text_diff( $left_string, $right_string, $args = null ) {
3189
 
3190
  if ( ! $diff )
3191
  return '';
 
 
 
 
 
3192
 
3193
- $r = "<table class='diff SimpleHistory__diff'>\n";
3194
 
3195
  if ( ! empty( $args[ 'show_split_view' ] ) ) {
3196
  $r .= "<col class='content diffsplit left' /><col class='content diffsplit middle' /><col class='content diffsplit right' />";
@@ -3211,8 +3216,11 @@ function simple_history_text_diff( $left_string, $right_string, $args = null ) {
3211
  if ( $args['title'] || $args['title_left'] || $args['title_right'] )
3212
  $r .= "</thead>\n";
3213
 
3214
- $r .= "<tbody>\n$diff\n</tbody>\n";
3215
  $r .= "</table>";
3216
 
 
 
 
3217
  return $r;
3218
  }
3189
 
3190
  if ( ! $diff )
3191
  return '';
3192
+
3193
+ $r = "";
3194
+
3195
+ $r .= "<div class='SimpleHistory__diff__contents' tabindex='0'>";
3196
+ $r .= "<div class='SimpleHistory__diff__contentsInner'>";
3197
 
3198
+ $r .= "<table class='diff SimpleHistory__diff'>\n";
3199
 
3200
  if ( ! empty( $args[ 'show_split_view' ] ) ) {
3201
  $r .= "<col class='content diffsplit left' /><col class='content diffsplit middle' /><col class='content diffsplit right' />";
3216
  if ( $args['title'] || $args['title_left'] || $args['title_right'] )
3217
  $r .= "</thead>\n";
3218
 
3219
+ $r .= "<tbody>\n$diff</div>\n</tbody>\n";
3220
  $r .= "</table>";
3221
 
3222
+ $r .= "</div>";
3223
+ $r .= "</div>";
3224
+
3225
  return $r;
3226
  }
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.6
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.6' );
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.7
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.7' );
46
  }
47
 
48
  if ( ! defined( 'SIMPLE_HISTORY_PATH' ) ) {
loggers/SimplePluginLogger.php CHANGED
@@ -314,7 +314,7 @@ class SimplePluginLogger extends SimpleLogger
314
  * We detect when that transient is set and then we have all info needed to log the plugin delete
315
  *
316
  */
317
- public function on_setted_transient_for_remove_files($transient, $value) {
318
 
319
  if ( ! $user_id = get_current_user_id() ) {
320
  return;
314
  * We detect when that transient is set and then we have all info needed to log the plugin delete
315
  *
316
  */
317
+ public function on_setted_transient_for_remove_files( $transient = "", $value = "" ) {
318
 
319
  if ( ! $user_id = get_current_user_id() ) {
320
  return;
loggers/SimplePostLogger.php CHANGED
@@ -399,13 +399,13 @@ class SimplePostLogger extends SimpleLogger
399
  * Adds diff data to the context array. Is called just before the event is logged.
400
  *
401
  * Since 2.0.29
402
-
403
- To detect
404
- - post thumb (part of custom fields)
405
- - categories
406
- - tags
407
- * @return array $context with diff data added
408
- */
409
  function add_post_data_diff_to_context($context, $old_post_data, $new_post_data) {
410
 
411
  $old_data = $old_post_data["post_data"];
@@ -625,6 +625,8 @@ class SimplePostLogger extends SimpleLogger
625
  }
626
 
627
  /**
 
 
628
  * Since 2.0.29
629
  */
630
  function add_diff($post_data_diff, $key, $old_value, $new_value) {
@@ -778,7 +780,6 @@ class SimplePostLogger extends SimpleLogger
778
  __("Status", "simple-history"),
779
  esc_html($post_old_value),
780
  esc_html($post_new_value)
781
-
782
  );
783
 
784
  } else if ( "post_date" == $key_to_diff ) {
399
  * Adds diff data to the context array. Is called just before the event is logged.
400
  *
401
  * Since 2.0.29
402
+ *
403
+ * To detect
404
+ * - post thumb (part of custom fields)
405
+ * - categories
406
+ * - tags
407
+ * @return array $context with diff data added
408
+ */
409
  function add_post_data_diff_to_context($context, $old_post_data, $new_post_data) {
410
 
411
  $old_data = $old_post_data["post_data"];
625
  }
626
 
627
  /**
628
+ * Add diff to array if old and new values are different
629
+ *
630
  * Since 2.0.29
631
  */
632
  function add_diff($post_data_diff, $key, $old_value, $new_value) {
780
  __("Status", "simple-history"),
781
  esc_html($post_old_value),
782
  esc_html($post_new_value)
 
783
  );
784
 
785
  } else if ( "post_date" == $key_to_diff ) {
loggers/SimpleUserLogger.php CHANGED
@@ -106,7 +106,7 @@ class SimpleUserLogger extends SimpleLogger {
106
  add_filter('authenticate', array($this, "on_authenticate"), 10, 3);
107
 
108
  // User is changed
109
- add_action("profile_update", array($this, "on_profile_update"), 10, 2);
110
 
111
  // User is created
112
  add_action("user_register", array($this, "on_user_register"), 10, 2);
@@ -122,18 +122,178 @@ class SimpleUserLogger extends SimpleLogger {
122
 
123
  add_action( 'retrieve_password_message', array( $this, "on_retrieve_password_message" ), 10, 4 );
124
 
 
 
 
125
  }
126
 
127
- /*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
- user requests a reset password link
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
- $errors = apply_filters( 'wp_login_errors', $errors, $redirect_to );
 
132
 
133
- elseif ( isset($_GET['checkemail']) && 'confirm' == $_GET['checkemail'] )
134
- $errors->add('confirm', __('Check your e-mail for the confirmation link.'), 'message');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
136
- */
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  function on_retrieve_password_message( $message, $key, $user_login, $user_data ) {
138
 
139
  if ( isset( $_GET["action"] ) && ( "lostpassword" == $_GET["action"] ) ) {
@@ -143,9 +303,6 @@ class SimpleUserLogger extends SimpleLogger {
143
  "message" => $message,
144
  "key" => $key,
145
  "user_login" => $user_login,
146
- // "user_data" => $user_data,
147
- "GET" => $_GET,
148
- "POST" => $_POST
149
  );
150
 
151
  if ( is_a( $user_data, "WP_User" ) ) {
@@ -297,7 +454,9 @@ class SimpleUserLogger extends SimpleLogger {
297
  }
298
 
299
  /**
300
- * Modify row output
 
 
301
  */
302
  public function getLogRowPlainTextOutput($row) {
303
 
@@ -316,12 +475,15 @@ class SimpleUserLogger extends SimpleLogger {
316
 
317
  if ( $wp_user ) {
318
 
319
- $context["edit_profile_link"] = get_edit_user_link($wp_user->ID);
320
 
321
  $use_you = apply_filters("simple_history/user_logger/plain_text_output_use_you", true);
 
 
 
322
 
323
  // User still exist, so link to their profile
324
- if ( $current_user_id === $context["_user_id"] && $use_you ) {
325
 
326
  // User that is viewing the log is the same as the edited user
327
  $msg = __('Edited <a href="{edit_profile_link}">your profile</a>', "simple-history");
@@ -344,7 +506,7 @@ class SimpleUserLogger extends SimpleLogger {
344
  } else {
345
 
346
  // User edited another users profile
347
- if ($wp_user) {
348
 
349
  // Edited user still exist, so link to their profile
350
  $context["edit_profile_link"] = get_edit_user_link($wp_user->ID);
@@ -359,7 +521,38 @@ class SimpleUserLogger extends SimpleLogger {
359
 
360
  }
361
 
362
- }// if user_updated_profile
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
 
364
  return $output;
365
  }
@@ -424,9 +617,14 @@ class SimpleUserLogger extends SimpleLogger {
424
 
425
  /**
426
  * User is edited
 
 
 
 
427
  */
428
- function on_profile_update($user_id) {
429
 
 
430
  if (!$user_id || !is_numeric($user_id)) {
431
  return;
432
  }
@@ -437,19 +635,26 @@ class SimpleUserLogger extends SimpleLogger {
437
  "edited_user_id" => $wp_user_edited->ID,
438
  "edited_user_email" => $wp_user_edited->user_email,
439
  "edited_user_login" => $wp_user_edited->user_login,
440
- "server_http_user_agent" => isset( $_SERVER["HTTP_USER_AGENT"] ) ? $_SERVER["HTTP_USER_AGENT"] : null
 
441
  );
442
 
 
443
  $this->infoMessage("user_updated_profile", $context);
 
444
 
445
  }
446
 
447
  /**
448
  * User is created
 
 
 
 
449
  */
450
- function on_user_register($user_id) {
451
 
452
- if (!$user_id || !is_numeric($user_id)) {
453
  return;
454
  }
455
 
@@ -457,15 +662,21 @@ class SimpleUserLogger extends SimpleLogger {
457
 
458
  // wp_user->roles (array) - the roles the user is part of.
459
  $role = null;
460
- if (is_array($wp_user_added->roles) && !empty($wp_user_added->roles[0])) {
461
  $role = $wp_user_added->roles[0];
462
  }
463
 
 
 
464
  $context = array(
465
  "created_user_id" => $wp_user_added->ID,
466
  "created_user_email" => $wp_user_added->user_email,
467
- "created_user_login" => $wp_user_added->user_login,
468
  "created_user_role" => $role,
 
 
 
 
469
  "server_http_user_agent" => isset( $_SERVER["HTTP_USER_AGENT"] ) ? $_SERVER["HTTP_USER_AGENT"] : null
470
  );
471
 
@@ -580,5 +791,218 @@ class SimpleUserLogger extends SimpleLogger {
580
  return $user;
581
 
582
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
583
 
584
  }
106
  add_filter('authenticate', array($this, "on_authenticate"), 10, 3);
107
 
108
  // User is changed
109
+ #add_action("profile_update", array($this, "on_profile_update"), 10, 2);
110
 
111
  // User is created
112
  add_action("user_register", array($this, "on_user_register"), 10, 2);
122
 
123
  add_action( 'retrieve_password_message', array( $this, "on_retrieve_password_message" ), 10, 4 );
124
 
125
+ add_filter( 'insert_user_meta', array( $this, "on_insert_user_meta" ), 10, 3 );
126
+
127
+
128
  }
129
 
130
+ /*
131
+ * Called before the user is updated
132
+ *
133
+ * Filter a user's meta values and keys before the user is created or updated.
134
+ *
135
+ * Does not include contact methods. These are added using `wp_get_user_contact_methods( $user )`.
136
+ *
137
+ * @param array $meta {
138
+ * Default meta values and keys for the user.
139
+ *
140
+ * @type string $nickname The user's nickname. Default is the user's username.
141
+ * @type string $first_name The user's first name.
142
+ * @type string $last_name The user's last name.
143
+ * @type string $description The user's description.
144
+ * @type bool $rich_editing Whether to enable the rich-editor for the user. False if not empty.
145
+ * @type bool $comment_shortcuts Whether to enable keyboard shortcuts for the user. Default false.
146
+ * @type string $admin_color The color scheme for a user's admin screen. Default 'fresh'.
147
+ * @type int|bool $use_ssl Whether to force SSL on the user's admin area. 0|false if SSL is
148
+ * not forced.
149
+ * @type bool $show_admin_bar_front Whether to show the admin bar on the front end for the user.
150
+ * Default true.
151
+ * }
152
+ * @param WP_User $user User object.
153
+ * @param bool $update Whether the user is being updated rather than created.
154
+ */
155
+ function on_insert_user_meta( $meta, $user, $update ) {
156
+
157
+ // We only log updates here
158
+ if ( ! $update ) {
159
+ return $meta;
160
+ }
161
+
162
+ // $user should be set, but check just in case
163
+ if ( empty( $user ) || ! is_object( $user ) ) {
164
+ return $meta;
165
+ }
166
 
167
+ // Make of copy of the posted data, because we change the keys
168
+ $posted_data = $_POST;
169
+ $posted_data = stripslashes_deep( $posted_data );
170
+
171
+ // Paranoid mode, just in case some other plugin fires the "insert_user_meta" filter and the user.php file is not loaded for some super wierd reason
172
+ if ( ! function_exists( "_get_additional_user_keys" ) ) {
173
+ return $meta;
174
+ }
175
+
176
+ // Get the default fields to include. This includes contact methods (including filter, so more could have been added)
177
+ $arr_keys_to_check = _get_additional_user_keys( $user );
178
+
179
+ // Somehow some fields are not include above, so add them manually
180
+ $arr_keys_to_check = array_merge( $arr_keys_to_check, array("user_email", "user_url", "display_name") );
181
 
182
+ // Skip some keys, because to much info or I don't know what they are
183
+ $arr_keys_to_check = array_diff( $arr_keys_to_check, array("use_ssl") );
184
 
185
+ // Some keys have different ways of getting data from user
186
+ // so change posted object to match those
187
+ $posted_data["user_url"] = isset( $posted_data["url"] ) ? $posted_data["url"] : null;
188
+ $posted_data["show_admin_bar_front"] = isset( $posted_data["admin_bar_front"] ) ? true : null;
189
+ $posted_data["user_email"] = isset( $posted_data["email"] ) ? $posted_data["email"] : null;
190
+
191
+ // Display name publicly as = POST "display_name"
192
+ #var_dump($user->display_name);
193
+
194
+ // Set vals for Enable keyboard shortcuts for comment moderation
195
+ $posted_data['comment_shortcuts'] = isset( $posted_data['comment_shortcuts'] ) ? "true" : "false";
196
+
197
+ // Set vals for Disable the visual editor when writing
198
+ // posted val = string "false" = yes, disable
199
+ $posted_data['rich_editing'] = isset( $posted_data['rich_editing'] ) ? "false" : "true";
200
+
201
+ // Set vals for Show Toolbar when viewing site
202
+ $posted_data['show_admin_bar_front'] = isset( $posted_data['admin_bar_front'] ) ? "true" : "false";
203
+
204
+ // if checkbox is checked in admin then this is the saved value on the user object
205
+ // @todo:
206
+
207
+ // Check if password was updated
208
+ $password_changed = false;
209
+ if ( ! empty( $posted_data['pass1'] ) && ! empty( $posted_data['pass2'] ) && $posted_data['pass1'] == $posted_data['pass2'] ) {
210
+ $password_changed = 1;
211
+ }
212
+
213
+ // Check if role was changed
214
+ //[role] => bbp_moderator
215
+ $role_changed = false;
216
+
217
+ // if user is network admin then role dropdown does not exist and role is not posted here
218
+ $new_role = isset( $posted_data["role"] ) ? $posted_data["role"] : null;
219
+
220
+ if ( $new_role ) {
221
+ // as done in user-edit.php
222
+ // Compare user role against currently editable roles
223
+ $user_roles = array_intersect( array_values( $user->roles ), array_keys( get_editable_roles() ) );
224
+ $old_role = reset( $user_roles );
225
+
226
+ $role_changed = $new_role != $old_role;
227
+ }
228
+
229
+ // Will contain the differences
230
+ $user_data_diff = array();
231
+
232
+ // Check all keys for diff values
233
+ foreach ( $arr_keys_to_check as $one_key_to_check ) {
234
+
235
+ $old_val = $user->$one_key_to_check;
236
+ $new_val = isset( $posted_data[ $one_key_to_check ] ) ? $posted_data[ $one_key_to_check ] : null;
237
+
238
+ #echo "<hr>key: $one_key_to_check";
239
+ #echo "<br>old val: $old_val";
240
+ #echo "<br>new val: $new_val";
241
+
242
+ // new val must be set, because otherwise we are not setting anything
243
+ if ( ! isset( $new_val ) ) {
244
+ continue;
245
+ }
246
+
247
+ $user_data_diff = $this->add_diff($user_data_diff, $one_key_to_check, $old_val, $new_val);
248
+
249
+ }
250
+
251
+ // Setup basic context
252
+ $context = array(
253
+ "edited_user_id" => $user->ID,
254
+ "edited_user_email" => $user->user_email,
255
+ "edited_user_login" => $user->user_login,
256
+ "server_http_user_agent" => isset( $_SERVER["HTTP_USER_AGENT"] ) ? $_SERVER["HTTP_USER_AGENT"] : null,
257
+ );
258
+
259
+ if ( $password_changed ) {
260
+ $context["edited_user_password_changed"] = "1";
261
+ }
262
+
263
+ if ( $role_changed ) {
264
+ $context["user_prev_role"] = $old_role;
265
+ $context["user_new_role"] = $new_role;
266
+ }
267
+
268
+ // Add diff to context
269
+ if ( $user_data_diff ) {
270
+
271
+ foreach ( $user_data_diff as $one_diff_key => $one_diff_vals ) {
272
+ /*
273
+ One diff looks like:
274
+ "nickname": {
275
+ "old": "MyOldNick",
276
+ "new": "MyNewNick"
277
+ }
278
+ */
279
+ $context["user_prev_{$one_diff_key}"] = $one_diff_vals["old"];
280
+ $context["user_new_{$one_diff_key}"] = $one_diff_vals["new"];
281
+ }
282
 
283
+ }
284
+
285
+
286
+ $this->infoMessage("user_updated_profile", $context);
287
+
288
+ return $meta;
289
+
290
+ }
291
+
292
+ /**
293
+ *
294
+ * user requests a reset password link
295
+ *
296
+ */
297
  function on_retrieve_password_message( $message, $key, $user_login, $user_data ) {
298
 
299
  if ( isset( $_GET["action"] ) && ( "lostpassword" == $_GET["action"] ) ) {
303
  "message" => $message,
304
  "key" => $key,
305
  "user_login" => $user_login,
 
 
 
306
  );
307
 
308
  if ( is_a( $user_data, "WP_User" ) ) {
454
  }
455
 
456
  /**
457
+ * Modify plain text row output
458
+ * - adds link to user profil
459
+ * - change to "your profile" if you're looking at your own edit
460
  */
461
  public function getLogRowPlainTextOutput($row) {
462
 
475
 
476
  if ( $wp_user ) {
477
 
478
+ $context["edit_profile_link"] = get_edit_user_link( $wp_user->ID );
479
 
480
  $use_you = apply_filters("simple_history/user_logger/plain_text_output_use_you", true);
481
+
482
+ //error_log( serialize( $current_user_id) ); // int 1
483
+ //error_log( serialize( $context["_user_id"]) ); // string 1
484
 
485
  // User still exist, so link to their profile
486
+ if ( (int) $current_user_id === (int) $context["_user_id"] && $use_you ) {
487
 
488
  // User that is viewing the log is the same as the edited user
489
  $msg = __('Edited <a href="{edit_profile_link}">your profile</a>', "simple-history");
506
  } else {
507
 
508
  // User edited another users profile
509
+ if ( $wp_user ) {
510
 
511
  // Edited user still exist, so link to their profile
512
  $context["edit_profile_link"] = get_edit_user_link($wp_user->ID);
521
 
522
  }
523
 
524
+ // if user_updated_profile
525
+
526
+ } else if ( "user_created" == $context["_message_key"] ) {
527
+
528
+ // A user was created. Create link of username that goes to user profile.
529
+ $wp_user = get_user_by( "id", $context["created_user_id"] );
530
+
531
+ // If edited_user_id and _user_id is the same then a user edited their own profile
532
+ // Note: it's not the same thing as the currently logged in user (but.. it can be!)
533
+
534
+ if ( $wp_user ) {
535
+
536
+ $context["edit_profile_link"] = get_edit_user_link( $wp_user->ID );
537
+
538
+ // User that is viewing the log is the same as the edited user
539
+ $msg = __('Created user <a href="{edit_profile_link}">{created_user_login} ({created_user_email})</a> with role {created_user_role}', "simple-history");
540
+
541
+ $output = $this->interpolate(
542
+ $msg,
543
+ $context,
544
+ $row
545
+ );
546
+
547
+ } else {
548
+
549
+ // User does not exist any longer, keep original message
550
+
551
+
552
+ }
553
+
554
+ }
555
+
556
 
557
  return $output;
558
  }
617
 
618
  /**
619
  * User is edited
620
+ *
621
+ * Called immediately after an existing user is updated.
622
+ * @param int $user_id User ID.
623
+ * @param object $old_user_data Object containing user's data prior to update.
624
  */
625
+ function on_profile_update( $user_id, $old_user_data ) {
626
 
627
+ /*
628
  if (!$user_id || !is_numeric($user_id)) {
629
  return;
630
  }
635
  "edited_user_id" => $wp_user_edited->ID,
636
  "edited_user_email" => $wp_user_edited->user_email,
637
  "edited_user_login" => $wp_user_edited->user_login,
638
+ "server_http_user_agent" => isset( $_SERVER["HTTP_USER_AGENT"] ) ? $_SERVER["HTTP_USER_AGENT"] : null,
639
+ "old_user_data" => $old_user_data
640
  );
641
 
642
+
643
  $this->infoMessage("user_updated_profile", $context);
644
+ */
645
 
646
  }
647
 
648
  /**
649
  * User is created
650
+ *
651
+ * "This action hook allows you to access data for a new user immediately after they are added to the database.
652
+ * The user id is passed to hook as an argument."
653
+ *
654
  */
655
+ function on_user_register( $user_id ) {
656
 
657
+ if ( ! $user_id || ! is_numeric( $user_id )) {
658
  return;
659
  }
660
 
662
 
663
  // wp_user->roles (array) - the roles the user is part of.
664
  $role = null;
665
+ if ( is_array( $wp_user_added->roles ) && ! empty( $wp_user_added->roles[0]) ) {
666
  $role = $wp_user_added->roles[0];
667
  }
668
 
669
+ $send_user_notification = (int) ( isset( $_POST["send_user_notification"] ) && $_POST["send_user_notification"] );
670
+
671
  $context = array(
672
  "created_user_id" => $wp_user_added->ID,
673
  "created_user_email" => $wp_user_added->user_email,
674
+ "created_user_login" => $wp_user_added->user_login, // username
675
  "created_user_role" => $role,
676
+ "created_user_first_name" => $wp_user_added->first_name,
677
+ "created_user_last_name" => $wp_user_added->last_name,
678
+ "created_user_url" => $wp_user_added->user_url,
679
+ "send_user_notification" => $send_user_notification,
680
  "server_http_user_agent" => isset( $_SERVER["HTTP_USER_AGENT"] ) ? $_SERVER["HTTP_USER_AGENT"] : null
681
  );
682
 
791
  return $user;
792
 
793
  }
794
+
795
+ /**
796
+ * Add diff to array if old and new values are different
797
+ *
798
+ * Since 2.0.29
799
+ */
800
+ function add_diff($post_data_diff, $key, $old_value, $new_value) {
801
+
802
+ if ( $old_value != $new_value ) {
803
+
804
+ $post_data_diff[$key] = array(
805
+ "old" => $old_value,
806
+ "new" => $new_value
807
+ );
808
+
809
+ }
810
+
811
+ return $post_data_diff;
812
+
813
+ }
814
+
815
+ /**
816
+ * Return more info about an logged event
817
+ * Supports so far:
818
+ */
819
+ function getLogRowDetailsOutput( $row ) {
820
+
821
+ $context = $row->context;
822
+ $message_key = $context["_message_key"];
823
+
824
+ $out = "";
825
+
826
+ if ( "user_updated_profile" == $message_key ) {
827
+
828
+ // Find all user_prev_ and user_new_ values and show them
829
+ $arr_user_keys_to_show_diff_for = array(
830
+ "first_name" => array(
831
+ "title" => _x("First name", "User logger", "simple-history")
832
+ ),
833
+ "last_name" => array(
834
+ "title" => _x("Last name", "User logger", "simple-history")
835
+ ),
836
+ "nickname" => array(
837
+ "title" => _x("Nickname", "User logger", "simple-history")
838
+ ),
839
+ "description" => array(
840
+ "title" => _x("Description", "User logger", "simple-history"),
841
+ ),
842
+ "rich_editing" => array(
843
+ "title" => _x("Visual editor", "User logger", "simple-history") // Disable visual editor
844
+ ),
845
+ "comment_shortcuts" => array(
846
+ "title" => _x("Keyboard shortcuts", "User logger", "simple-history") // Enable keyboard shortcuts for comment moderation
847
+ ),
848
+ "show_admin_bar_front" => array(
849
+ "title" => _x("Show Toolbar", "User logger", "simple-history") // Show Toolbar when viewing site
850
+ ),
851
+ "admin_color" => array(
852
+ "title" => _x("Colour Scheme", "User logger", "simple-history") // Admin Colour Scheme
853
+ ),
854
+ "aim" => array(
855
+ "title" => _x("AIM", "User logger", "simple-history")
856
+ ),
857
+ "yim" => array(
858
+ "title" => _x("Yahoo IM", "User logger", "simple-history")
859
+ ),
860
+ "jabber" => array(
861
+ "title" => _x("Jabber / Google Talk ", "User logger", "simple-history")
862
+ ),
863
+ /*"user_nicename" => array(
864
+ "title" => _x("Nicename", "User logger", "simple-history")
865
+ ),*/
866
+ "user_email" => array(
867
+ "title" => _x("Email", "User logger", "simple-history")
868
+ ),
869
+ "display_name" => array(
870
+ //"title" => _x("Display name publicly as", "User logger", "simple-history")
871
+ "title" => _x("Display name", "User logger", "simple-history")
872
+ ),
873
+ "user_url" => array(
874
+ "title" => _x("Website", "User logger", "simple-history")
875
+ ),
876
+ "role" => array(
877
+ //"title" => _x("Display name publicly as", "User logger", "simple-history")
878
+ "title" => _x("Role", "User logger", "simple-history")
879
+ )
880
+ );
881
+
882
+ $diff_table_output = "";
883
+
884
+ foreach ( $arr_user_keys_to_show_diff_for as $key => $val ) {
885
+
886
+ if ( isset( $context["user_prev_{$key}"] ) && isset( $context["user_new_{$key}"] ) ) {
887
+
888
+ $user_old_value = $context["user_prev_{$key}"];
889
+ $user_new_value = $context["user_new_{$key}"];
890
+
891
+ $diff_table_output .= sprintf(
892
+ '<tr>
893
+ <td>%1$s</td>
894
+ <td>%2$s</td>
895
+ </tr>',
896
+ $val["title"],
897
+ sprintf(
898
+ '<ins class="SimpleHistoryLogitem__keyValueTable__addedThing">%1$s</ins> <del class="SimpleHistoryLogitem__keyValueTable__removedThing">%2$s</del>',
899
+ esc_html( $user_new_value ), // 1
900
+ esc_html( $user_old_value ) // 2
901
+ )
902
+ );
903
+
904
+ }
905
+
906
+ }
907
+
908
+ // check if password was changed
909
+ if ( isset( $context["edited_user_password_changed"] ) ) {
910
+
911
+ $diff_table_output .= sprintf(
912
+ '<tr>
913
+ <td>%1$s</td>
914
+ <td>%2$s</td>
915
+ </tr>',
916
+ _x("Password", "User logger", "simple-history"),
917
+ _x("Changed", "User logger", "simple-history")
918
+ );
919
+
920
+ }
921
+
922
+ if ( $diff_table_output ) {
923
+ $diff_table_output = '<table class="SimpleHistoryLogitem__keyValueTable">' . $diff_table_output . '</table>';
924
+ }
925
+
926
+ $out .= $diff_table_output;
927
+
928
+ } else if ( "user_created" == $message_key ) {
929
+
930
+ // Show fields for created users
931
+ $arr_user_keys_to_show_diff_for = array(
932
+ "created_user_first_name" => array(
933
+ "title" => _x("First name", "User logger", "simple-history")
934
+ ),
935
+ "created_user_last_name" => array(
936
+ "title" => _x("Last name", "User logger", "simple-history")
937
+ ),
938
+ "created_user_url" => array(
939
+ "title" => _x("Website", "User logger", "simple-history")
940
+ ),
941
+ "send_user_notification" => array(
942
+ "title" => _x("User notification email sent", "User logger", "simple-history")
943
+ )
944
+ );
945
+
946
+ foreach ( $arr_user_keys_to_show_diff_for as $key => $val ) {
947
+
948
+ if ( isset( $context[ $key ] ) && trim( $context[ $key ] ) ) {
949
+
950
+ if ( "send_user_notification" == $key ) {
951
+
952
+ if ( intval( $context[ $key ] ) == 1 ) {
953
+ $sent_status = _x("Yes, email with account details was sent", "User logger", "simple-history");
954
+ } else {
955
+ // $sent_status = _x("No, no email with account details was sent", "User logger", "simple-history");
956
+ $sent_status = "";
957
+ }
958
+
959
+ if ( $sent_status ) {
960
+
961
+ $diff_table_output .= sprintf(
962
+ '<tr>
963
+ <td>%1$s</td>
964
+ <td>%2$s</td>
965
+ </tr>',
966
+ _x("Notification", "User logger", "simple-history"),
967
+ sprintf(
968
+ '<ins class="SimpleHistoryLogitem__keyValueTable__addedThing">%1$s</ins>',
969
+ esc_html( $sent_status ) // 1
970
+ )
971
+ );
972
+
973
+ }
974
+
975
+ } else {
976
+
977
+ $diff_table_output .= sprintf(
978
+ '<tr>
979
+ <td>%1$s</td>
980
+ <td>%2$s</td>
981
+ </tr>',
982
+ $val["title"],
983
+ sprintf(
984
+ '<ins class="SimpleHistoryLogitem__keyValueTable__addedThing">%1$s</ins>',
985
+ esc_html( $context[ $key ] ) // 1
986
+ )
987
+ );
988
+
989
+ }
990
+
991
+ }
992
+
993
+ }
994
+
995
+ if ( $diff_table_output ) {
996
+ $diff_table_output = '<table class="SimpleHistoryLogitem__keyValueTable">' . $diff_table_output . '</table>';
997
+ }
998
+
999
+ $out .= $diff_table_output;
1000
+
1001
+ } // message key
1002
+
1003
+ return $out;
1004
+
1005
+
1006
+ }
1007
 
1008
  }
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
- === Simple History ===
2
  Contributors: eskapism
3
  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: 4.5.1
6
  Tested up to: 4.5.2
7
- Stable tag: 2.6
8
 
9
  View changes made by users within WordPress. See who created a page, uploaded an attachment or approved an comment, and more.
10
 
@@ -140,14 +140,25 @@ initiated by a specific user.
140
 
141
  6. See even more details about a logged event (by clicking on the date and time of the event).
142
 
 
 
 
 
143
 
144
  == Changelog ==
145
 
146
  ## Changelog
147
 
 
 
 
 
 
 
 
148
  = 2.6 (May 2016) =
149
 
150
- - Added: A nice little graph in the sidebar that displays the number of logged events per day the last 28 days. Graph is powered by [Graph.js](http://www.chartjs.org/).
151
  - Added: Function `get_num_events_last_n_days()`
152
  - Added: Function `get_num_events_per_day_last_n_days()`
153
  - Changed: Switched to transients from cache at some places, because more people will benefit from transients instead of cache (that requires object cache to be installed).
1
+ === Simple History ===
2
  Contributors: eskapism
3
  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: 4.5.1
6
  Tested up to: 4.5.2
7
+ Stable tag: 2.7
8
 
9
  View changes made by users within WordPress. See who created a page, uploaded an attachment or approved an comment, and more.
10
 
140
 
141
  6. See even more details about a logged event (by clicking on the date and time of the event).
142
 
143
+ 7. A chart with some quick statistics is available, so you can see the number of events that has been logged each day.
144
+ A simple way to see any uncommon activity, for example an increased number of logins or similar.
145
+
146
+ 8. When users are created or changed you can see details on what have changed.
147
 
148
  == Changelog ==
149
 
150
  ## Changelog
151
 
152
+ = 2.7 (May 2016) =
153
+
154
+ - Added: When a user is created or edited the log now shows what fields have changed and from what old value to what new value. A much requested feature!
155
+ - Fixed: If you edited your own profile the log would say that you edited "their profile". Now it says that you edited "your profile" instead.
156
+ - Changed: Post diffs could get very tall. Now they are max approx 8 rows by default, but if you hover the diff (or give it focus with your keyboard) you get a scrollbar and can scroll the contents. Fixes https://wordpress.org/support/topic/dashboard-max-length-of-content and https://wordpress.org/support/topic/feature-request-make-content-diff-report-expandable-and-closed-by-default.
157
+ - Fixed: Maybe fix a notice varning if a transient was missing a name or value.
158
+
159
  = 2.6 (May 2016) =
160
 
161
+ - Added: A nice little graph in the sidebar that displays the number of logged events per day the last 28 days. Graph is powered by [Chart.js](http://www.chartjs.org/).
162
  - Added: Function `get_num_events_last_n_days()`
163
  - Added: Function `get_num_events_per_day_last_n_days()`
164
  - Changed: Switched to transients from cache at some places, because more people will benefit from transients instead of cache (that requires object cache to be installed).