MainWP Child Reports - Version 2.0.4

Version Description

  • 4-30-2020 =
  • Fixed: an issue with logging themes updates
  • Fixed: an issue with logging created posts
  • Added: option to recreate the plugin database tables
  • Added: support for logging WPVivid backups
Download this release

Release Info

Developer mainwp
Plugin Icon 128x128 MainWP Child Reports
Version 2.0.4
Comparing to
See all releases

Code changes from version 2.0.3 to 2.0.4

classes/class-admin.php CHANGED
@@ -768,6 +768,8 @@ class Admin {
768
  }
769
 
770
  $this->erase_stream_records();
 
 
771
 
772
  if ( defined( 'WP_MAINWP_STREAM_TESTS' ) && WP_MAINWP_STREAM_TESTS ) {
773
  return true;
768
  }
769
 
770
  $this->erase_stream_records();
771
+
772
+ do_action( 'wp_mainwp_child_reposts_recreate_tables_if_not_exist' );
773
 
774
  if ( defined( 'WP_MAINWP_STREAM_TESTS' ) && WP_MAINWP_STREAM_TESTS ) {
775
  return true;
classes/class-install.php CHANGED
@@ -64,6 +64,7 @@ class Install {
64
 
65
  // Install the plugin
66
  add_action( 'wp_mainwp_stream_before_db_notices', array( $this, 'check' ) );
 
67
 
68
  register_activation_hook( $this->plugin->locations['plugin'], array( $this, 'check' ) );
69
  }
@@ -127,6 +128,35 @@ class Install {
127
  $this->update_db_option();
128
  }
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  /**
131
  * Verify that the required DB tables exists
132
  *
64
 
65
  // Install the plugin
66
  add_action( 'wp_mainwp_stream_before_db_notices', array( $this, 'check' ) );
67
+ add_action( 'wp_mainwp_child_reposts_recreate_tables_if_not_exist', array( $this, 'recreate_tables_if_not_exist' ) );
68
 
69
  register_activation_hook( $this->plugin->locations['plugin'], array( $this, 'check' ) );
70
  }
128
  $this->update_db_option();
129
  }
130
 
131
+ public function recreate_tables_if_not_exist() {
132
+ global $wpdb;
133
+
134
+ check_ajax_referer( 'stream_nonce_reset', 'wp_mainwp_stream_nonce_reset' );
135
+
136
+ $missing_tables = array();
137
+ foreach ( $this->plugin->db->get_table_names() as $table_name ) {
138
+ $table_search = $wpdb->get_var(
139
+ $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name )
140
+ );
141
+ if ( strcasecmp($table_search,$table_name ) != 0 ) {
142
+ $missing_tables[] = $table_name;
143
+ }
144
+ }
145
+
146
+ if ( $missing_tables ) {
147
+ $this->install( $this->plugin->get_version() );
148
+
149
+ // for debugging only
150
+ // if( $wpdb->last_error !== '') :
151
+ // $str = htmlspecialchars( $wpdb->last_result, ENT_QUOTES );
152
+ // $query = htmlspecialchars( $wpdb->last_query, ENT_QUOTES );
153
+ // error_log( $str );
154
+ // error_log( $query );
155
+ // endif;
156
+ }
157
+
158
+ }
159
+
160
  /**
161
  * Verify that the required DB tables exists
162
  *
classes/class-query.php CHANGED
@@ -107,10 +107,12 @@ class Query {
107
  // mainwp custom parameter
108
  if ( ! empty( $args['created'] ) ) {
109
  $created = strtotime( $args['created'] );
110
- $date = get_gmt_from_date( date( 'Y-m-d H:i:s', $created + 5 ) );
 
111
  //$where .= $wpdb->prepare( " AND DATE($wpdb->mainwp_stream.created) <= %s", $date );
112
  $where .= " AND ($wpdb->mainwp_stream.created <= STR_TO_DATE(" . $wpdb->prepare('%s', $date) . ", '%Y-%m-%d %H:%i:%s'))";
113
- $date = get_gmt_from_date( date( 'Y-m-d H:i:s', $created - 5 ) );
 
114
  //$where .= $wpdb->prepare( " AND DATE($wpdb->mainwp_stream.created) >= %s", $date );
115
  $where .= " AND ($wpdb->mainwp_stream.created >= STR_TO_DATE(" . $wpdb->prepare('%s', $date) . ", '%Y-%m-%d %H:%i:%s'))";
116
  }
107
  // mainwp custom parameter
108
  if ( ! empty( $args['created'] ) ) {
109
  $created = strtotime( $args['created'] );
110
+ //$date = get_gmt_from_date( date( 'Y-m-d H:i:s', $created + 5 ) );
111
+ $date = wp_mainwp_stream_get_iso_8601_extended_date( $created + 5, 0, true );
112
  //$where .= $wpdb->prepare( " AND DATE($wpdb->mainwp_stream.created) <= %s", $date );
113
  $where .= " AND ($wpdb->mainwp_stream.created <= STR_TO_DATE(" . $wpdb->prepare('%s', $date) . ", '%Y-%m-%d %H:%i:%s'))";
114
+ //$date = get_gmt_from_date( date( 'Y-m-d H:i:s', $created - 5 ) );
115
+ $date = wp_mainwp_stream_get_iso_8601_extended_date( $created - 5, 0, true );
116
  //$where .= $wpdb->prepare( " AND DATE($wpdb->mainwp_stream.created) >= %s", $date );
117
  $where .= " AND ($wpdb->mainwp_stream.created >= STR_TO_DATE(" . $wpdb->prepare('%s', $date) . ", '%Y-%m-%d %H:%i:%s'))";
118
  }
classes/class-settings.php CHANGED
@@ -377,7 +377,7 @@ class Settings {
377
  ),
378
  );
379
 
380
- //if ( isset( $_GET['try_repair'] ) && $_GET['try_repair'] == 'yes') {
381
  $repair_data = array(
382
  'name' => 'try_repair',
383
  'title' => esc_html__( 'Repair Data', 'mainwp-child-reports' ),
@@ -395,7 +395,7 @@ class Settings {
395
  'sticky' => 'bottom',
396
  );
397
  array_push( $fields['advanced']['fields'], $repair_data );
398
- //}
399
 
400
  // If Akismet is active, allow Admins to opt-in to Akismet tracking
401
  if ( class_exists( 'Akismet' ) ) {
377
  ),
378
  );
379
 
380
+ if ( isset( $_GET['try_repair'] ) && $_GET['try_repair'] == 'yes') {
381
  $repair_data = array(
382
  'name' => 'try_repair',
383
  'title' => esc_html__( 'Repair Data', 'mainwp-child-reports' ),
395
  'sticky' => 'bottom',
396
  );
397
  array_push( $fields['advanced']['fields'], $repair_data );
398
+ }
399
 
400
  // If Akismet is active, allow Admins to opt-in to Akismet tracking
401
  if ( class_exists( 'Akismet' ) ) {
connectors/class-connector-installer.php CHANGED
@@ -239,7 +239,8 @@ class Connector_Installer extends Connector {
239
  )
240
  );
241
  $name = $theme['Name'];
242
- $old_version = $theme['Version'];
 
243
  $version = $theme_data['Version'];
244
 
245
  $logs[] = compact( 'slug', 'name', 'old_version', 'version', 'message', 'action' );
239
  )
240
  );
241
  $name = $theme['Name'];
242
+ //$old_version = $theme['Version'];
243
+ $old_version = $upgrader->skin->theme_info->get('Version'); // to fix old version //$theme['Version'];
244
  $version = $theme_data['Version'];
245
 
246
  $logs[] = compact( 'slug', 'name', 'old_version', 'version', 'message', 'action' );
connectors/class-connector-mainwp-backups.php CHANGED
@@ -20,7 +20,8 @@ class Connector_MainWP_Backups extends Connector {
20
  'mainwp_reports_backupwordpress_backup',
21
  'mainwp_reports_backwpup_backup',
22
  'updraftplus_backup', // backup action from updraftplus
23
- 'mainwp_reports_wptimecapsule_backup'
 
24
  );
25
 
26
  /**
@@ -45,6 +46,7 @@ class Connector_MainWP_Backups extends Connector {
45
  'backwpup_backup' => __( 'BackWPup Backup', 'mainwp-child-reports' ),
46
  'updraftplus_backup' => __( 'Updraftplus Backup', 'mainwp-child-reports' ),
47
  'wptimecapsule_backup' => __( 'WP Time Capsule Backup', 'mainwp-child-reports' ),
 
48
  );
49
  }
50
 
@@ -138,6 +140,16 @@ class Connector_MainWP_Backups extends Connector {
138
  'wptimecapsule_backup'
139
  );
140
  }
 
 
 
 
 
 
 
 
 
 
141
  }
142
 
143
 
20
  'mainwp_reports_backupwordpress_backup',
21
  'mainwp_reports_backwpup_backup',
22
  'updraftplus_backup', // backup action from updraftplus
23
+ 'mainwp_reports_wptimecapsule_backup',
24
+ 'wpvivid_backup'
25
  );
26
 
27
  /**
46
  'backwpup_backup' => __( 'BackWPup Backup', 'mainwp-child-reports' ),
47
  'updraftplus_backup' => __( 'Updraftplus Backup', 'mainwp-child-reports' ),
48
  'wptimecapsule_backup' => __( 'WP Time Capsule Backup', 'mainwp-child-reports' ),
49
+ 'wpvivid_backup' => __( 'WPvivid Backup', 'mainwp-child-reports' )
50
  );
51
  }
52
 
140
  'wptimecapsule_backup'
141
  );
142
  }
143
+
144
+ public function callback_wpvivid_backup($destination, $message, $status, $type, $backup_time){
145
+ $this->log(
146
+ $message,
147
+ compact( 'destination', 'status', 'type', 'backup_time' ),
148
+ 0,
149
+ 'backups',
150
+ 'wpvivid_backup'
151
+ );
152
+ }
153
  }
154
 
155
 
connectors/class-connector-posts.php CHANGED
@@ -24,7 +24,7 @@ class Connector_Posts extends Connector {
24
  *
25
  * @var bool
26
  */
27
- public $register_frontend = false;
28
 
29
  /**
30
  * Return translated connector label
@@ -165,6 +165,14 @@ class Connector_Posts extends Connector {
165
  return;
166
  } elseif ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
167
  return;
 
 
 
 
 
 
 
 
168
  } elseif ( 'draft' === $new && 'publish' === $old ) {
169
  // translators: Placeholders refer to a post title, and a post type singular name (e.g. "Hello World", "Post")
170
  $summary = _x(
@@ -247,9 +255,25 @@ class Connector_Posts extends Connector {
247
  }
248
 
249
  if ( 'auto-draft' === $old && 'auto-draft' !== $new ) {
250
- $action = 'created';
251
- }
252
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  if ( empty( $action ) ) {
254
  $action = 'updated';
255
  }
24
  *
25
  * @var bool
26
  */
27
+ public $register_frontend = true; // to support rest api hooks
28
 
29
  /**
30
  * Return translated connector label
165
  return;
166
  } elseif ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
167
  return;
168
+ } elseif ( 'publish' === $new && 'draft' === $old ) {
169
+ // translators: Placeholders refer to a post title, and a post type singular name (e.g. "Hello World", "Post")
170
+ $summary = _x(
171
+ '"%1$s" %2$s created',
172
+ '1: Post title, 2: Post type singular name',
173
+ 'mainwp-child-reports'
174
+ );
175
+ $action = 'created';
176
  } elseif ( 'draft' === $new && 'publish' === $old ) {
177
  // translators: Placeholders refer to a post title, and a post type singular name (e.g. "Hello World", "Post")
178
  $summary = _x(
255
  }
256
 
257
  if ( 'auto-draft' === $old && 'auto-draft' !== $new ) {
258
+ $summary = _x(
259
+ '"%1$s" %2$s created',
260
+ '1: Post title, 2: Post type singular name',
261
+ 'mainwp-child-reports'
262
+ );
263
+ $action = 'created';
264
+ }
265
+
266
+ // if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
267
+ // if ( 'auto-draft' === $old && 'auto-draft' !== $new ) {
268
+ // $summary = _x(
269
+ // '"%1$s" %2$s created',
270
+ // '1: Post title, 2: Post type singular name',
271
+ // 'mainwp-child-reports'
272
+ // );
273
+ // $action = 'created';
274
+ // }
275
+ // }
276
+
277
  if ( empty( $action ) ) {
278
  $action = 'updated';
279
  }
includes/functions.php CHANGED
@@ -40,7 +40,7 @@ function wp_mainwp_stream_filter_var( $var, $filter = null, $options = array() )
40
  *
41
  * @return string an ISO 8601 extended formatted time
42
  */
43
- function wp_mainwp_stream_get_iso_8601_extended_date( $time = false, $offset = 0 ) {
44
  if ( $time ) {
45
  $microtime = (float) $time . '.0000';
46
  } else {
@@ -52,7 +52,11 @@ function wp_mainwp_stream_get_iso_8601_extended_date( $time = false, $offset = 0
52
 
53
  $timezone = new DateTimeZone( $offset_string );
54
  $date = new DateTime( date( 'Y-m-d H:i:s.' . $micro_seconds, $microtime ), $timezone );
55
-
 
 
 
 
56
  return sprintf(
57
  '%s%03d%s',
58
  $date->format( 'Y-m-d\TH:i:s.' ),
40
  *
41
  * @return string an ISO 8601 extended formatted time
42
  */
43
+ function wp_mainwp_stream_get_iso_8601_extended_date( $time = false, $offset = 0, $mysql_date_string = false ) {
44
  if ( $time ) {
45
  $microtime = (float) $time . '.0000';
46
  } else {
52
 
53
  $timezone = new DateTimeZone( $offset_string );
54
  $date = new DateTime( date( 'Y-m-d H:i:s.' . $micro_seconds, $microtime ), $timezone );
55
+
56
+ if ( $mysql_date_string ) {
57
+ return $date->format( 'Y-m-d H:i:s' );
58
+ }
59
+
60
  return sprintf(
61
  '%s%03d%s',
62
  $date->format( 'Y-m-d\TH:i:s.' ),
mainwp-child-reports.php CHANGED
@@ -5,13 +5,13 @@
5
  * Description: The MainWP Child Report plugin tracks Child sites for the MainWP Client Reports Extension. The plugin is only useful if you are using MainWP and the Client Reports Extension.
6
  * Author: MainWP
7
  * Author URI: https://mainwp.com
8
- * Version: 2.0.3
9
  */
10
 
11
  /*
12
- * Credit to the Stream Plugin which the MainWP Child Reports plugin is built on.
13
- *
14
- * Plugin-Name: Stream
15
  * Plugin-URI: https://wp-stream.com/
16
  * Description: Stream tracks logged-in user activity so you can monitor every change made on your WordPress site in beautifully organized detail. All activity is organized by context, action and IP address for easy filtering. Developers can extend Stream with custom connectors to log any kind of action.
17
  * Author: XWP
5
  * Description: The MainWP Child Report plugin tracks Child sites for the MainWP Client Reports Extension. The plugin is only useful if you are using MainWP and the Client Reports Extension.
6
  * Author: MainWP
7
  * Author URI: https://mainwp.com
8
+ * Version: 2.0.4
9
  */
10
 
11
  /*
12
+ * Credit to the Stream Plugin which the MainWP Child Reports plugin is built on.
13
+ *
14
+ * Plugin Name: Stream
15
  * Plugin-URI: https://wp-stream.com/
16
  * Description: Stream tracks logged-in user activity so you can monitor every change made on your WordPress site in beautifully organized detail. All activity is organized by context, action and IP address for easy filtering. Developers can extend Stream with custom connectors to log any kind of action.
17
  * Author: XWP
readme.txt CHANGED
@@ -5,9 +5,9 @@ Author: mainwp
5
  Author URI: https://mainwp.com
6
  Plugin URI: https://mainwp.com
7
  Requires at least: 3.6
8
- Tested up to: 5.4
9
  Requires PHP: 5.6
10
- Stable tag: 2.0.3
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
 
@@ -36,6 +36,12 @@ Credit to the [Stream Plugin](https://wordpress.org/plugins/stream/) which the M
36
 
37
  == Changelog ==
38
 
 
 
 
 
 
 
39
  = 2.0.3 - 2-7-2020 =
40
  * Fixed: an issue logging UpdraftPlus scheduled backups
41
  * Fixed: an issue with dismissing missing database tables warning
5
  Author URI: https://mainwp.com
6
  Plugin URI: https://mainwp.com
7
  Requires at least: 3.6
8
+ Tested up to: 5.4.1
9
  Requires PHP: 5.6
10
+ Stable tag: 2.0.4
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
 
36
 
37
  == Changelog ==
38
 
39
+ = 2.0.4 - 4-30-2020 =
40
+ * Fixed: an issue with logging themes updates
41
+ * Fixed: an issue with logging created posts
42
+ * Added: option to recreate the plugin database tables
43
+ * Added: support for logging WPVivid backups
44
+
45
  = 2.0.3 - 2-7-2020 =
46
  * Fixed: an issue logging UpdraftPlus scheduled backups
47
  * Fixed: an issue with dismissing missing database tables warning