MainWP Child - Version 3.5.5

Version Description

  • 3-6-19 =
  • Fixed: an issue with hook for controlling branding options for specific roles
  • Fixed: branding issues
  • Fixed: multiple PHP Warnings
  • Fixed: multiple typos
  • Fixed: MainWP UpdraftPlus Extension performance issues
  • Fixed: an issue with creating double media files when editing posts and pages from MainWP Dashboard
  • Fixed: an issue with creating duplicate Boilerplate posts and pages
  • Updated: added improvements for detecting premium plugin updates on specific setups
Download this release

Release Info

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

Code changes from version 3.5.4.1 to 3.5.5

class/class-mainwp-child-branding.php CHANGED
@@ -795,6 +795,7 @@ class MainWP_Child_Branding {
795
  $sub = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_subject'] ) ) );
796
  $subject = !empty( $sub ) ? $sub : "MainWP - Support Contact";
797
  $content = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_content'] ) ) );
 
798
  if ( ! empty( $_POST['mainwp_branding_contact_message_content'] ) && ! empty( $email ) ) {
799
  global $current_user;
800
  $headers .= "Content-Type: text/html;charset=utf-8\r\n";
@@ -842,7 +843,7 @@ class MainWP_Child_Branding {
842
  $back_link = ! empty( $from_page ) ? '<a href="' . esc_url( $from_page ) . '" title="' . esc_attr( $back_link ) . '">' . esc_html( $back_link ) . '</a>' : '';
843
 
844
  if ( $this->send_support_mail() ) {
845
- $send_email_message = $opts['send_email_message'];
846
  if ( ! empty( $send_email_message ) ) {
847
  $send_email_message = stripslashes( $send_email_message );
848
  } else {
@@ -910,7 +911,10 @@ class MainWP_Child_Branding {
910
  * @param WP_Admin_Bar $wp_admin_bar
911
  */
912
  public function add_support_button_in_top_admin_bar( $wp_admin_bar ) {
913
- if ( !current_user_can( 'administrator' ) ) {
 
 
 
914
  return false;
915
  }
916
 
@@ -1129,7 +1133,7 @@ class MainWP_Child_Branding {
1129
  if ( $is_hide === 'T' ) {
1130
  foreach ( $plugins as $key => $value ) {
1131
  $plugin_slug = basename( $key, '.php' );
1132
- if ( 'mainwp-child-reports' === $plugin_slug ) {
1133
  unset( $plugins[ $key ] );
1134
  }
1135
  }
795
  $sub = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_subject'] ) ) );
796
  $subject = !empty( $sub ) ? $sub : "MainWP - Support Contact";
797
  $content = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_content'] ) ) );
798
+ $mail = $headers = '';
799
  if ( ! empty( $_POST['mainwp_branding_contact_message_content'] ) && ! empty( $email ) ) {
800
  global $current_user;
801
  $headers .= "Content-Type: text/html;charset=utf-8\r\n";
843
  $back_link = ! empty( $from_page ) ? '<a href="' . esc_url( $from_page ) . '" title="' . esc_attr( $back_link ) . '">' . esc_html( $back_link ) . '</a>' : '';
844
 
845
  if ( $this->send_support_mail() ) {
846
+ $send_email_message = isset( $opts['send_email_message'] ) ? $opts['send_email_message'] : '';
847
  if ( ! empty( $send_email_message ) ) {
848
  $send_email_message = stripslashes( $send_email_message );
849
  } else {
911
  * @param WP_Admin_Bar $wp_admin_bar
912
  */
913
  public function add_support_button_in_top_admin_bar( $wp_admin_bar ) {
914
+ $allow_contact = apply_filters('mainwp_branding_role_cap_enable_contact_form', false);
915
+ if ( $allow_contact ) {
916
+ ; // ok
917
+ } else if ( !current_user_can( 'administrator' ) ) {
918
  return false;
919
  }
920
 
1133
  if ( $is_hide === 'T' ) {
1134
  foreach ( $plugins as $key => $value ) {
1135
  $plugin_slug = basename( $key, '.php' );
1136
+ if ( 'mainwp-child' === $plugin_slug ) {
1137
  unset( $plugins[ $key ] );
1138
  }
1139
  }
class/class-mainwp-child-updraft-plus-backups.php CHANGED
@@ -54,10 +54,14 @@ class MainWP_Child_Updraft_Plus_Backups {
54
  // ok
55
  function syncOthersData( $information, $data = array() ) {
56
  try{
57
- if ( isset( $data['syncUpdraftData'] ) && $data['syncUpdraftData'] ) {
58
  if ( $this->is_plugin_installed ) {
59
- $information['syncUpdraftData'] = $this->get_sync_data();
 
 
60
  }
 
 
61
  }
62
  if ( isset( $data['sync_Updraftvault_quota_text'] ) && $data['sync_Updraftvault_quota_text'] ) {
63
  if ( $this->is_plugin_installed ) {
@@ -1057,7 +1061,7 @@ class MainWP_Child_Updraft_Plus_Backups {
1057
 
1058
  }
1059
 
1060
- private function get_updraft_data() {
1061
  global $updraftplus;
1062
 
1063
  if ( empty( $updraftplus ) && class_exists( 'UpdraftPlus' ) ) {
@@ -1123,7 +1127,12 @@ class MainWP_Child_Updraft_Plus_Backups {
1123
  }
1124
 
1125
  $bh = $this->build_historystatus();
 
 
 
1126
  $out['updraft_historystatus'] = $bh['h'];
 
 
1127
  $out['updraft_count_backups'] = $bh['c'];
1128
 
1129
  $last_backup = $this->last_backup_html();
@@ -3305,6 +3314,9 @@ ENDHERE;
3305
  $wpcore_restore_descrip = $sdescrip;
3306
  }
3307
  }
 
 
 
3308
  if ( isset( $backup[ $type ] ) ) {
3309
  if ( ! is_array( $backup[ $type ] ) ) {
3310
  $backup[ $type ] = array( $backup[ $type ] );
@@ -3352,6 +3364,10 @@ ENDHERE;
3352
  } else {
3353
  $first_printed = false;
3354
  }
 
 
 
 
3355
  }
3356
  }
3357
  }
@@ -4020,9 +4036,9 @@ ENDHERE;
4020
  return $value;
4021
  }
4022
 
4023
- public function get_sync_data() {
4024
  $this->required_files();
4025
- return $this->get_updraft_data();
4026
  }
4027
 
4028
  public function all_plugins( $plugins ) {
54
  // ok
55
  function syncOthersData( $information, $data = array() ) {
56
  try{
57
+ if ( isset( $data['syncUpdraftData'] ) && $info = $data['syncUpdraftData'] ) {
58
  if ( $this->is_plugin_installed ) {
59
+ $with_hist = true;
60
+ if ( version_compare( $info, '1.7', '>=' ) ) {
61
+ $with_hist = false;
62
  }
63
+ $information['syncUpdraftData'] = $this->get_sync_data( $with_hist );
64
+ }
65
  }
66
  if ( isset( $data['sync_Updraftvault_quota_text'] ) && $data['sync_Updraftvault_quota_text'] ) {
67
  if ( $this->is_plugin_installed ) {
1061
 
1062
  }
1063
 
1064
+ private function get_updraft_data( $with_hist = true ) {
1065
  global $updraftplus;
1066
 
1067
  if ( empty( $updraftplus ) && class_exists( 'UpdraftPlus' ) ) {
1127
  }
1128
 
1129
  $bh = $this->build_historystatus();
1130
+
1131
+ // to fix performance issue
1132
+ if ( $with_hist ) {
1133
  $out['updraft_historystatus'] = $bh['h'];
1134
+ }
1135
+
1136
  $out['updraft_count_backups'] = $bh['c'];
1137
 
1138
  $last_backup = $this->last_backup_html();
3314
  $wpcore_restore_descrip = $sdescrip;
3315
  }
3316
  }
3317
+
3318
+ $fix_perfomance = 0;
3319
+
3320
  if ( isset( $backup[ $type ] ) ) {
3321
  if ( ! is_array( $backup[ $type ] ) ) {
3322
  $backup[ $type ] = array( $backup[ $type ] );
3364
  } else {
3365
  $first_printed = false;
3366
  }
3367
+
3368
+ $fix_perfomance++;
3369
+ if ($fix_perfomance > 50) // // to fix perfomance issue of response when too much backup files
3370
+ break;
3371
  }
3372
  }
3373
  }
4036
  return $value;
4037
  }
4038
 
4039
+ public function get_sync_data( $with_hist = false) {
4040
  $this->required_files();
4041
+ return $this->get_updraft_data( $with_hist );
4042
  }
4043
 
4044
  public function all_plugins( $plugins ) {
class/class-mainwp-child.php CHANGED
@@ -115,7 +115,7 @@ if ( isset( $_GET['skeleton_keyuse_nonce_key'] ) && isset( $_GET['skeleton_keyus
115
  }
116
 
117
  class MainWP_Child {
118
- public static $version = '3.5.4.1';
119
  private $update_version = '1.5';
120
 
121
  private $callableFunctions = array(
@@ -230,8 +230,8 @@ class MainWP_Child {
230
  add_action( 'admin_init', array( &$this, 'admin_init' ) );
231
  add_action( 'admin_head', array( &$this, 'admin_head' ) );
232
  add_action( 'init', array( &$this, 'localization' ), 33 );
233
- add_action( 'pre_current_active_plugins', array( &$this, 'detect_premium_themesplugins_updates' ) ); // to support detect premium themes/plugins update
234
- add_action( 'core_upgrade_preamble', array( &$this, 'detect_premium_themesplugins_updates' ) );
235
 
236
 
237
  if ( is_admin() ) {
@@ -569,6 +569,7 @@ class MainWP_Child {
569
  }
570
 
571
  public function detect_premium_themesplugins_updates() {
 
572
  if (isset($_GET['_detect_plugins_updates']) && $_GET['_detect_plugins_updates'] == 'yes') {
573
  // to fix some premium plugins update notification
574
  $current = get_site_transient( 'update_plugins' );
@@ -591,6 +592,25 @@ class MainWP_Child {
591
  set_site_transient( 'mainwp_update_themes_cached', $themes, DAY_IN_SECONDS);
592
  wp_destroy_current_session(); // to fix issue multi user session
593
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
594
  }
595
 
596
  function checkOtherAuth() {
@@ -761,10 +781,10 @@ class MainWP_Child {
761
  }
762
  $branding_opts = MainWP_Child_Branding::Instance()->get_branding_options();
763
 
764
- $hide_settings = $branding_opts['remove_setting'] ? true : false;
765
- $hide_restore = $branding_opts['remove_restore'] ? true : false;
766
- $hide_server_info = $branding_opts['remove_server_info'] ? true : false;
767
- $hide_connection_detail = $branding_opts['remove_connection_detail'] ? true : false;
768
 
769
  $hide_style = 'style="display:none"';
770
 
@@ -837,10 +857,10 @@ class MainWP_Child {
837
 
838
  $branding_opts = MainWP_Child_Branding::Instance()->get_branding_options();
839
 
840
- $hide_settings = $branding_opts['remove_setting'] ? true : false;
841
- $hide_restore = $branding_opts['remove_restore'] ? true : false;
842
- $hide_server_info = $branding_opts['remove_server_info'] ? true : false;
843
- $hide_connection_detail = $branding_opts['remove_connection_detail'] ? true : false;
844
 
845
  $sitesToClone = get_option( 'mainwp_child_clone_sites' );
846
 
@@ -3883,7 +3903,7 @@ class MainWP_Child {
3883
  $theme = wp_get_theme($translation_update->slug);
3884
  $new_translation_update['name'] = $theme->name;
3885
  } else if ( ( 'core' === $translation_update->type ) && ( 'default' === $translation_update->slug ) ) {
3886
- $new_translation_update['name'] = 'Wordpress core';
3887
  }
3888
  $information['translation_updates'][] = $new_translation_update;
3889
  }
115
  }
116
 
117
  class MainWP_Child {
118
+ public static $version = '3.5.5';
119
  private $update_version = '1.5';
120
 
121
  private $callableFunctions = array(
230
  add_action( 'admin_init', array( &$this, 'admin_init' ) );
231
  add_action( 'admin_head', array( &$this, 'admin_head' ) );
232
  add_action( 'init', array( &$this, 'localization' ), 33 );
233
+ add_action( 'pre_current_active_plugins', array( &$this, 'detect_premium_themesplugins_updates' ) ); // to support detect premium plugins update
234
+ add_action( 'core_upgrade_preamble', array( &$this, 'detect_premium_themesplugins_updates' ) ); // to support detect premium themes
235
 
236
 
237
  if ( is_admin() ) {
569
  }
570
 
571
  public function detect_premium_themesplugins_updates() {
572
+
573
  if (isset($_GET['_detect_plugins_updates']) && $_GET['_detect_plugins_updates'] == 'yes') {
574
  // to fix some premium plugins update notification
575
  $current = get_site_transient( 'update_plugins' );
592
  set_site_transient( 'mainwp_update_themes_cached', $themes, DAY_IN_SECONDS);
593
  wp_destroy_current_session(); // to fix issue multi user session
594
  }
595
+
596
+
597
+ $type = isset($_GET['_request_update_premiums_type']) ? $_GET['_request_update_premiums_type'] : '';
598
+ if ( $type == 'plugin' || $type == 'theme' ) {
599
+ $list = isset( $_GET['list'] ) ? $_GET['list'] : '';
600
+ if ( !empty($list) ) {
601
+ // to call function upgradePluginTheme(),
602
+ // will not get the response result
603
+ $_POST['type'] = $type;
604
+ $_POST['list'] = $list;
605
+
606
+ $function = 'upgradeplugintheme';
607
+ if (isset($this->callableFunctions[ $function ])) {
608
+ call_user_func( array( $this, $this->callableFunctions[ $function ] ) );
609
+ }
610
+ wp_destroy_current_session(); // to fix issue multi user session
611
+ }
612
+ }
613
+
614
  }
615
 
616
  function checkOtherAuth() {
781
  }
782
  $branding_opts = MainWP_Child_Branding::Instance()->get_branding_options();
783
 
784
+ $hide_settings = isset( $branding_opts['remove_setting'] ) && $branding_opts['remove_setting'] ? true : false;
785
+ $hide_restore = isset( $branding_opts['remove_restore'] ) && $branding_opts['remove_restore'] ? true : false;
786
+ $hide_server_info = isset( $branding_opts['remove_server_info'] ) && $branding_opts['remove_server_info'] ? true : false;
787
+ $hide_connection_detail = isset( $branding_opts['remove_connection_detail'] ) && $branding_opts['remove_connection_detail'] ? true : false;
788
 
789
  $hide_style = 'style="display:none"';
790
 
857
 
858
  $branding_opts = MainWP_Child_Branding::Instance()->get_branding_options();
859
 
860
+ $hide_settings = isset( $branding_opts['remove_setting'] ) && $branding_opts['remove_setting'] ? true : false;
861
+ $hide_restore = isset( $branding_opts['remove_restore'] ) && $branding_opts['remove_restore'] ? true : false;
862
+ $hide_server_info = isset( $branding_opts['remove_server_info'] ) && $branding_opts['remove_server_info'] ? true : false;
863
+ $hide_connection_detail = isset( $branding_opts['remove_connection_detail'] ) && $branding_opts['remove_connection_detail'] ? true : false;
864
 
865
  $sitesToClone = get_option( 'mainwp_child_clone_sites' );
866
 
3903
  $theme = wp_get_theme($translation_update->slug);
3904
  $new_translation_update['name'] = $theme->name;
3905
  } else if ( ( 'core' === $translation_update->type ) && ( 'default' === $translation_update->slug ) ) {
3906
+ $new_translation_update['name'] = 'WordPress core';
3907
  }
3908
  $information['translation_updates'][] = $new_translation_update;
3909
  }
class/class-mainwp-custom-post-type.php CHANGED
@@ -74,7 +74,7 @@ class MainWP_Custom_Post_Type {
74
  /**
75
  * Search image inside post content and upload it to child
76
  **/
77
- private function _search_images( $post_content, $upload_dir ) {
78
  $foundMatches = preg_match_all( '/(<a[^>]+href=\"(.*?)\"[^>]*>)?(<img[^>\/]*src=\"((.*?)(png|gif|jpg|jpeg))\")/ix', $post_content, $matches, PREG_SET_ORDER );
79
  if ( $foundMatches > 0 ) {
80
  foreach ( $matches as $match ) {
@@ -94,7 +94,7 @@ class MainWP_Custom_Post_Type {
94
  }
95
 
96
  try {
97
- $downloadfile = MainWP_Helper::uploadImage( $originalImgUrl );
98
  $localUrl = $downloadfile['url'];
99
  $linkToReplaceWith = dirname( $localUrl );
100
  if ( '' !== $hrefLink ) {
@@ -125,7 +125,7 @@ class MainWP_Custom_Post_Type {
125
  return $post_content;
126
  }
127
 
128
- private function _insert_post( $data, $edit_id, $parent_id = 0 ) {
129
 
130
  // Insert post
131
  $data_insert = array();
@@ -164,13 +164,15 @@ class MainWP_Custom_Post_Type {
164
  return array( 'error' => __( 'Please install', $this->plugin_translate ) . ' ' . $data_insert['post_type'] . ' ' . __( 'on child and try again', $this->plugin_translate ) );
165
  }
166
 
167
- $data_insert['post_content'] = $this->_search_images( $data_insert['post_content'], $data['extras']['upload_dir'] );
168
 
169
  $is_woocomerce = false;
170
  if ( ($data_insert['post_type'] == 'product' || $data_insert['post_type'] == 'product_variation' )&& function_exists( 'wc_product_has_unique_sku' ) ) {
171
  $is_woocomerce = true;
172
  }
173
 
 
 
174
  // Support post_edit
175
  if ( !empty( $edit_id ) ) {
176
  $old_post_id = (int) $edit_id;
@@ -185,7 +187,7 @@ class MainWP_Custom_Post_Type {
185
  if ( get_post_status( $old_post_id ) == 'trash' ) {
186
  return array( 'error' => __( 'This post is inside trash on child website. Please try publish it manually and try again.', $this->plugin_translate ) );
187
  }
188
-
189
  // Set id
190
  $data_insert['ID'] = $old_post_id;
191
 
@@ -200,6 +202,9 @@ class MainWP_Custom_Post_Type {
200
  // Remove all previous taxonomy
201
  wp_delete_object_term_relationships( $old_post_id, get_object_taxonomies( $data_insert['post_type'] ) );
202
  }
 
 
 
203
  if (!empty($parent_id)) {
204
  $data_insert['post_parent'] = $parent_id; // for product variation
205
  }
@@ -224,7 +229,7 @@ class MainWP_Custom_Post_Type {
224
  if ( isset($data['extras']['woocommerce']['product_images']) ) {
225
  foreach ( $data['extras']['woocommerce']['product_images'] as $product_image ) {
226
  try {
227
- $upload_featured_image = MainWP_Helper::uploadImage( $product_image );
228
 
229
  if ( null !== $upload_featured_image ) {
230
  $product_image_gallery[] = $upload_featured_image['id'];
@@ -245,7 +250,7 @@ class MainWP_Custom_Post_Type {
245
  if ( $key['meta_key'] == '_thumbnail_id' ) {
246
  if ( isset( $data['extras']['featured_image']) ) {
247
  try {
248
- $upload_featured_image = MainWP_Helper::uploadImage( $data['extras']['featured_image'] );
249
 
250
  if ( null !== $upload_featured_image ) {
251
  $key['meta_value'] = $upload_featured_image['id'];
74
  /**
75
  * Search image inside post content and upload it to child
76
  **/
77
+ private function _search_images( $post_content, $upload_dir, $check_image = false ) {
78
  $foundMatches = preg_match_all( '/(<a[^>]+href=\"(.*?)\"[^>]*>)?(<img[^>\/]*src=\"((.*?)(png|gif|jpg|jpeg))\")/ix', $post_content, $matches, PREG_SET_ORDER );
79
  if ( $foundMatches > 0 ) {
80
  foreach ( $matches as $match ) {
94
  }
95
 
96
  try {
97
+ $downloadfile = MainWP_Helper::uploadImage( $originalImgUrl , array(), $check_image );
98
  $localUrl = $downloadfile['url'];
99
  $linkToReplaceWith = dirname( $localUrl );
100
  if ( '' !== $hrefLink ) {
125
  return $post_content;
126
  }
127
 
128
+ private function _insert_post( $data, $edit_id, $parent_id = 0 ) {
129
 
130
  // Insert post
131
  $data_insert = array();
164
  return array( 'error' => __( 'Please install', $this->plugin_translate ) . ' ' . $data_insert['post_type'] . ' ' . __( 'on child and try again', $this->plugin_translate ) );
165
  }
166
 
167
+ //$data_insert['post_content'] = $this->_search_images( $data_insert['post_content'], $data['extras']['upload_dir'] );
168
 
169
  $is_woocomerce = false;
170
  if ( ($data_insert['post_type'] == 'product' || $data_insert['post_type'] == 'product_variation' )&& function_exists( 'wc_product_has_unique_sku' ) ) {
171
  $is_woocomerce = true;
172
  }
173
 
174
+ $check_image_existed = false;
175
+
176
  // Support post_edit
177
  if ( !empty( $edit_id ) ) {
178
  $old_post_id = (int) $edit_id;
187
  if ( get_post_status( $old_post_id ) == 'trash' ) {
188
  return array( 'error' => __( 'This post is inside trash on child website. Please try publish it manually and try again.', $this->plugin_translate ) );
189
  }
190
+ $check_image_existed = true;
191
  // Set id
192
  $data_insert['ID'] = $old_post_id;
193
 
202
  // Remove all previous taxonomy
203
  wp_delete_object_term_relationships( $old_post_id, get_object_taxonomies( $data_insert['post_type'] ) );
204
  }
205
+
206
+ $data_insert['post_content'] = $this->_search_images( $data_insert['post_content'], $data['extras']['upload_dir'], $check_image_existed );
207
+
208
  if (!empty($parent_id)) {
209
  $data_insert['post_parent'] = $parent_id; // for product variation
210
  }
229
  if ( isset($data['extras']['woocommerce']['product_images']) ) {
230
  foreach ( $data['extras']['woocommerce']['product_images'] as $product_image ) {
231
  try {
232
+ $upload_featured_image = MainWP_Helper::uploadImage( $product_image, array(), $check_image_existed );
233
 
234
  if ( null !== $upload_featured_image ) {
235
  $product_image_gallery[] = $upload_featured_image['id'];
250
  if ( $key['meta_key'] == '_thumbnail_id' ) {
251
  if ( isset( $data['extras']['featured_image']) ) {
252
  try {
253
+ $upload_featured_image = MainWP_Helper::uploadImage( $data['extras']['featured_image'], array(), $check_image_existed );
254
 
255
  if ( null !== $upload_featured_image ) {
256
  $key['meta_value'] = $upload_featured_image['id'];
class/class-mainwp-helper.php CHANGED
@@ -121,20 +121,13 @@ class MainWP_Helper {
121
 
122
  }
123
 
124
- static function uploadImage( $img_url, $img_data = array() , $check_file_existed = false ) {
125
- if (!is_array($img_data))
 
 
126
  $img_data = array();
127
  include_once( ABSPATH . 'wp-admin/includes/file.php' ); //Contains download_url
128
  $upload_dir = wp_upload_dir();
129
-
130
- if ($check_file_existed) {
131
- $local_img_url = $upload_dir['url'] . '/' . basename( $img_url );
132
- $attach_id = MainWP_Helper::get_image_id($local_img_url);
133
- if ($attach_id) {
134
- return array( 'id' => $attach_id, 'url' => $local_img_url );
135
- }
136
- }
137
-
138
  //Download $img_url
139
  $temporary_file = download_url( $img_url );
140
 
@@ -142,8 +135,28 @@ class MainWP_Helper {
142
  throw new Exception( 'Error: ' . $temporary_file->get_error_message() );
143
  } else {
144
  $local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url ); //Local name
145
- $local_img_url = $upload_dir['url'] . '/' . basename( $img_url );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  $moved = @rename( $temporary_file, $local_img_path );
 
147
  if ( $moved ) {
148
  $wp_filetype = wp_check_filetype( basename( $img_url ), null ); //Get the filetype to set the mimetype
149
  $attachment = array(
@@ -152,7 +165,14 @@ class MainWP_Helper {
152
  'post_content' => isset( $img_data['description'] ) && !empty( $img_data['description'] ) ? $img_data['description'] : '',
153
  'post_excerpt' => isset( $img_data['caption'] ) && !empty( $img_data['caption'] ) ? $img_data['caption'] : '',
154
  'post_status' => 'inherit',
 
155
  );
 
 
 
 
 
 
156
  $attach_id = wp_insert_attachment( $attachment, $local_img_path ); //Insert the image in the database
157
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
158
  $attach_data = wp_generate_attachment_metadata( $attach_id, $local_img_path );
@@ -321,9 +341,16 @@ class MainWP_Helper {
321
  $wpr_options = isset( $_POST['wpr_options'] ) ? $_POST['wpr_options'] : array();
322
 
323
  $edit_post_id = 0;
 
324
  if ( isset( $post_custom['_mainwp_edit_post_id'] ) && $post_custom['_mainwp_edit_post_id'] ) {
325
  $edit_post_id = current($post_custom['_mainwp_edit_post_id']);
326
- require_once ABSPATH . 'wp-admin/includes/post.php';
 
 
 
 
 
 
327
  if ( $user_id = wp_check_post_lock( $edit_post_id ) ) {
328
  $user = get_userdata( $user_id );
329
  $error = sprintf( __( 'This content is currently locked. %s is currently editing.' ), $user->display_name );
@@ -331,6 +358,10 @@ class MainWP_Helper {
331
  }
332
  }
333
 
 
 
 
 
334
  //Search for all the images added to the new post
335
  //some images have a href tag to click to navigate to the image.. we need to replace this too
336
  $foundMatches = preg_match_all( '/(<a[^>]+href=\"(.*?)\"[^>]*>)?(<img[^>\/]*src=\"((.*?)(png|gif|jpg|jpeg))\")/ix', $new_post['post_content'], $matches, PREG_SET_ORDER );
@@ -353,13 +384,7 @@ class MainWP_Helper {
353
  }
354
 
355
  try {
356
- // in the case edit post will check if file existed
357
- if ( $edit_post_id ) {
358
- $downloadfile = MainWP_Helper::uploadImage( $originalImgUrl , array(), true );
359
- } else {
360
- $downloadfile = MainWP_Helper::uploadImage( $originalImgUrl );
361
- }
362
-
363
  $localUrl = $downloadfile['url'];
364
  $linkToReplaceWith = dirname( $localUrl );
365
  if ( '' !== $hrefLink ) {
@@ -621,8 +646,7 @@ class MainWP_Helper {
621
  //If featured image exists - set it
622
  if ( null !== $post_featured_image ) {
623
  try {
624
- $upload = MainWP_Helper::uploadImage( $post_featured_image ); //Upload image to WP
625
-
626
  if ( null !== $upload ) {
627
  update_post_meta( $new_post_id, '_thumbnail_id', $upload['id'] ); //Add the thumbnail to the post!
628
  $featured_image_exist = true;
121
 
122
  }
123
 
124
+ // $check_file_existed: to support checking if file existed
125
+ // $parent_id: optional
126
+ static function uploadImage( $img_url, $img_data = array() , $check_file_existed = false, $parent_id = 0 ) {
127
+ if ( !is_array($img_data) )
128
  $img_data = array();
129
  include_once( ABSPATH . 'wp-admin/includes/file.php' ); //Contains download_url
130
  $upload_dir = wp_upload_dir();
 
 
 
 
 
 
 
 
 
131
  //Download $img_url
132
  $temporary_file = download_url( $img_url );
133
 
135
  throw new Exception( 'Error: ' . $temporary_file->get_error_message() );
136
  } else {
137
  $local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url ); //Local name
138
+ $local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path );
139
+
140
+ $gen_unique_fn = true;
141
+
142
+ if ( $check_file_existed ) {
143
+ if ( file_exists( $local_img_path ) ) {
144
+ if ( filesize( $local_img_path ) == filesize( $temporary_file ) ) { // file exited
145
+ $attach_id = attachment_url_to_postid( $local_img_url );
146
+ if ( $attach_id ) { // found attachment
147
+ return array( 'id' => $attach_id, 'url' => $local_img_url );
148
+ }
149
+ }
150
+ }
151
+ }
152
+
153
+ if ( $gen_unique_fn ) {
154
+ $local_img_path = dirname( $local_img_path ) . '/' . wp_unique_filename( dirname( $local_img_path ), basename( $local_img_path ) );
155
+ $local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path );
156
+ }
157
+
158
  $moved = @rename( $temporary_file, $local_img_path );
159
+
160
  if ( $moved ) {
161
  $wp_filetype = wp_check_filetype( basename( $img_url ), null ); //Get the filetype to set the mimetype
162
  $attachment = array(
165
  'post_content' => isset( $img_data['description'] ) && !empty( $img_data['description'] ) ? $img_data['description'] : '',
166
  'post_excerpt' => isset( $img_data['caption'] ) && !empty( $img_data['caption'] ) ? $img_data['caption'] : '',
167
  'post_status' => 'inherit',
168
+ 'guid' => $local_img_url // to fix
169
  );
170
+
171
+ // for post attachments, thumbnail
172
+ if ( $parent_id ) {
173
+ $attachment['post_parent'] = $parent_id;
174
+ }
175
+
176
  $attach_id = wp_insert_attachment( $attachment, $local_img_path ); //Insert the image in the database
177
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
178
  $attach_data = wp_generate_attachment_metadata( $attach_id, $local_img_path );
341
  $wpr_options = isset( $_POST['wpr_options'] ) ? $_POST['wpr_options'] : array();
342
 
343
  $edit_post_id = 0;
344
+
345
  if ( isset( $post_custom['_mainwp_edit_post_id'] ) && $post_custom['_mainwp_edit_post_id'] ) {
346
  $edit_post_id = current($post_custom['_mainwp_edit_post_id']);
347
+ } else if (isset( $new_post['ID'] ) && $new_post['ID']) {
348
+ $edit_post_id = $new_post['ID'];
349
+ }
350
+
351
+
352
+ require_once ABSPATH . 'wp-admin/includes/post.php';
353
+ if ($edit_post_id) {
354
  if ( $user_id = wp_check_post_lock( $edit_post_id ) ) {
355
  $user = get_userdata( $user_id );
356
  $error = sprintf( __( 'This content is currently locked. %s is currently editing.' ), $user->display_name );
358
  }
359
  }
360
 
361
+ $check_image_existed = false;
362
+ if ( $edit_post_id )
363
+ $check_image_existed = true; // if editing post then will check if image existed
364
+
365
  //Search for all the images added to the new post
366
  //some images have a href tag to click to navigate to the image.. we need to replace this too
367
  $foundMatches = preg_match_all( '/(<a[^>]+href=\"(.*?)\"[^>]*>)?(<img[^>\/]*src=\"((.*?)(png|gif|jpg|jpeg))\")/ix', $new_post['post_content'], $matches, PREG_SET_ORDER );
384
  }
385
 
386
  try {
387
+ $downloadfile = MainWP_Helper::uploadImage( $originalImgUrl, array(), $check_image_existed );
 
 
 
 
 
 
388
  $localUrl = $downloadfile['url'];
389
  $linkToReplaceWith = dirname( $localUrl );
390
  if ( '' !== $hrefLink ) {
646
  //If featured image exists - set it
647
  if ( null !== $post_featured_image ) {
648
  try {
649
+ $upload = MainWP_Helper::uploadImage( $post_featured_image, array(), $check_image_existed, $new_post_id); //Upload image to WP
 
650
  if ( null !== $upload ) {
651
  update_post_meta( $new_post_id, '_thumbnail_id', $upload['id'] ); //Add the thumbnail to the post!
652
  $featured_image_exist = true;
mainwp-child.php CHANGED
@@ -6,7 +6,7 @@
6
  Author: MainWP
7
  Author URI: https://mainwp.com
8
  Text Domain: mainwp-child
9
- Version: 3.5.4.1
10
  */
11
  //if ( ( isset( $_REQUEST['heatmap'] ) && '1' === $_REQUEST['heatmap'] ) || ( isset( $_REQUEST['mainwpsignature'] ) && ( ! empty( $_REQUEST['mainwpsignature'] ) ) ) ) {
12
  // header( 'X-Frame-Options: ALLOWALL' );
6
  Author: MainWP
7
  Author URI: https://mainwp.com
8
  Text Domain: mainwp-child
9
+ Version: 3.5.5
10
  */
11
  //if ( ( isset( $_REQUEST['heatmap'] ) && '1' === $_REQUEST['heatmap'] ) || ( isset( $_REQUEST['mainwpsignature'] ) && ( ! empty( $_REQUEST['mainwpsignature'] ) ) ) ) {
12
  // header( 'X-Frame-Options: ALLOWALL' );
readme.txt CHANGED
@@ -6,8 +6,8 @@ Author: mainwp
6
  Author URI: https://mainwp.com
7
  Plugin URI: https://mainwp.com
8
  Requires at least: 3.6
9
- Tested up to: 5.0.3
10
- Stable tag: 3.5.4.1
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
 
@@ -71,6 +71,16 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
71
 
72
  == Changelog ==
73
 
 
 
 
 
 
 
 
 
 
 
74
  = 3.5.4.1 - 2-19-19 =
75
  * Added: proper attribution to plugin code used for Extensions
76
  * Removed: unused code
@@ -81,9 +91,9 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
81
  * Fixed: an issue with publishing "future" posts
82
  * Fixed: an issue with sending email alerts in specific setups
83
  * Fixed: an issue with saving code snippets in wp-config.php when the file is in a custom location
84
- * Fixed: an issue with clearing unused scheduled cron jobs
85
  * Added: support for the new PageSpeed Insights plugin options
86
- * Updated: disabled the "Remove readme.html" security check feature for WPEngine hosted child sites
87
  * Updated: support for detecting premium themes updates
88
 
89
  = 3.5.3 - 12-19-18 =
@@ -314,7 +324,7 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
314
  * Added: Support for the new WP Rocket features
315
  * Added: "Currently connected to" check in the Server Information
316
  * Fixed: PHP Notice
317
- * Removed: Unnecesary checks in the Server Information page
318
 
319
  = 3.1.4 - 5-9-16 =
320
  * Updated: function execute_snippet() extracted to a separate file
@@ -348,7 +358,7 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
348
  * Added: Server Information items
349
  * Added: New Subject text box to support email in Branding Extension
350
  * Added: Support themes using invalid screen functions
351
- * Tweaked: Support new version of BackupWordpress plugin version
352
  * Updated: Added support in Client Reports Extension for BackWPup backups
353
 
354
  = 3.1 - 2-17-16 =
@@ -358,14 +368,14 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
358
  * Fixed: Update issue for the iThemes Security Pro and the Monarch plugin
359
  * Fixed: Compatibility issue with the BackUpWordPress plugin
360
  * Added: Auto detect manually removed script/style versions feature
361
- * Added: Wordpress translation updates
362
  * Added: New Branding option to disable theme switching
363
  * Enhancement: Removed ctype_digit requirement
364
  * Enhancement: Install plugin error message
365
 
366
  = 3.0.2 - 1-22-16 =
367
- * Fixed: Issue with scheduled BackupWordpress when run from dashboard
368
- * Fixed: Issue with Heatmap tracker javascript
369
  * Added: Support for hosts with PHP with disabled mb_regex
370
  * Tweaked: Code snippet result message
371
 
@@ -394,7 +404,7 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
394
  * Added: Support new Wordfence settings options for the Wordfence Extension
395
  * Added: Force Check Pages function for the MainWP PageSpeed Extensions
396
  * Added: Allow to see MainWP child plugin in MainWP Dashboard plugins search
397
- * Updated: MainWP URL Extractor Extension logic to extract urls by Post published date instead of last change date
398
 
399
  = 2.0.29 - 9-22-15 =
400
  * Fixed: 404 error that occurs in case Links Manger extension is in use when child plugin is hidden
@@ -436,12 +446,12 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
436
 
437
  = 2.0.22 - 7-22-15 =
438
  * Fixed: Bug where the OptmizePress theme has not been updated properly
439
- * Fixed: Bug where the Client Report extenison recored incorrect time
440
- * Added: Support for the upcomming extension
441
 
442
  = 2.0.21 - 7-9-15 =
443
  * Fixed: Bug with time schedule for the UpdraftPlus extension
444
- * Added: Support for the upcomming extension
445
 
446
  = 2.0.20 - 7-6-15 =
447
  * Fixed: Bug with time schedule for the UpdraftPlus extension
@@ -474,7 +484,7 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
474
  * Fixed: Issue with sites running PHP 5.2 and lower
475
  * Fixed: Sync error on some sites with UpdraftPlus installed
476
  * Fixed: PHP Warning
477
- * Changed: Server page to reflect requested mininum of PHP 5.3
478
 
479
  = 2.0.15 - 5-14-15 =
480
  * Added: Support for the upcoming extension
@@ -495,7 +505,7 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
495
  = 2.0.12 - 4-16-15 =
496
  * Fixed: Bug for the MainWP iThemes Security Extension
497
  * Fixed: Bug for the MainWP WordFence Extension
498
- * Fixed: Bug where the MainWP Child plugin was breaking cron jobs on child sites
499
 
500
  = 2.0.11 - 4-12-15 =
501
  * Fixed: Upcoming extension bug
@@ -503,7 +513,7 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
503
  = 2.0.10 - 4-06-15 =
504
  * Added: Support for the display Favicon for child sites feature
505
  * Added: Support for upcoming extension
506
- * Fixed: Plugin conflicts with Wordpress SEO by Yoast and Backupbuddy
507
 
508
  = 2.0.9.2 - 3-06-15 =
509
  * Fixed: Bug where SEO values are not being set for Boilerplate Pages and Posts
@@ -541,7 +551,7 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
541
  * Added: A new Branding extension option - hiding the child plugin server information page
542
 
543
  = 2.0.5 - 1-07-15 =
544
- * Fixed: Links Manager Extension: Now using the wordpress home option instead of siteurl for the links
545
 
546
  = 2.0.4 - 12-26-14 =
547
  * Fixed: Backups for hosts having issues with "compress.zlib://" stream wrappers from PHP causing corrupt backup archives
@@ -552,7 +562,7 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
552
 
553
  = 2.0.2 - 12-11-14 =
554
  * Added: Support hosts with PHP Heap classes
555
- * Fixed: Javascript issue disabling the popup menu on the admin menu
556
 
557
  = 2.0.1 - 12-10-14 =
558
  * Fixed: Restore/Clone from Tar via server upload
@@ -670,7 +680,7 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
670
 
671
  = 0.29 =
672
  * Added ability to view Child site error logs on MainWP Dashboard
673
- * Added ability to view Child site Wp-Config on MainWP Dashboard
674
  * Added new Hooks for Branding Extension
675
  * Added tweak for Code Snippet Extension
676
 
@@ -757,7 +767,7 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
757
  * Fixed conflict with main dashboard on same site
758
 
759
  = 0.11 =
760
- * Plugin localisation
761
  * Extra check for readme.html file
762
  * Added child server information
763
  * Fixed restore issue: not all previous plugins/themes were removed
@@ -787,7 +797,7 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
787
 
788
  = 0.5 =
789
  * Fixed issue with importing database with custom foreign key references
790
- * Fixed issue with disabled functions from te "suhosin" extension
791
  * Fixed issue with click-heatmap
792
 
793
  = 0.4 =
6
  Author URI: https://mainwp.com
7
  Plugin URI: https://mainwp.com
8
  Requires at least: 3.6
9
+ Tested up to: 5.1
10
+ Stable tag: 3.5.5
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
 
71
 
72
  == Changelog ==
73
 
74
+ = 3.5.5 - 3-6-19 =
75
+ * Fixed: an issue with hook for controlling branding options for specific roles
76
+ * Fixed: branding issues
77
+ * Fixed: multiple PHP Warnings
78
+ * Fixed: multiple typos
79
+ * Fixed: MainWP UpdraftPlus Extension performance issues
80
+ * Fixed: an issue with creating double media files when editing posts and pages from MainWP Dashboard
81
+ * Fixed: an issue with creating duplicate Boilerplate posts and pages
82
+ * Updated: added improvements for detecting premium plugin updates on specific setups
83
+
84
  = 3.5.4.1 - 2-19-19 =
85
  * Added: proper attribution to plugin code used for Extensions
86
  * Removed: unused code
91
  * Fixed: an issue with publishing "future" posts
92
  * Fixed: an issue with sending email alerts in specific setups
93
  * Fixed: an issue with saving code snippets in wp-config.php when the file is in a custom location
94
+ * Fixed: an issue with clearing unused scheduled Cron jobs
95
  * Added: support for the new PageSpeed Insights plugin options
96
+ * Updated: disabled the "Remove readme.html" security check feature for WPEngine hosted child sites
97
  * Updated: support for detecting premium themes updates
98
 
99
  = 3.5.3 - 12-19-18 =
324
  * Added: Support for the new WP Rocket features
325
  * Added: "Currently connected to" check in the Server Information
326
  * Fixed: PHP Notice
327
+ * Removed: Unnecessary checks in the Server Information page
328
 
329
  = 3.1.4 - 5-9-16 =
330
  * Updated: function execute_snippet() extracted to a separate file
358
  * Added: Server Information items
359
  * Added: New Subject text box to support email in Branding Extension
360
  * Added: Support themes using invalid screen functions
361
+ * Tweaked: Support new version of BackupWordPress plugin version
362
  * Updated: Added support in Client Reports Extension for BackWPup backups
363
 
364
  = 3.1 - 2-17-16 =
368
  * Fixed: Update issue for the iThemes Security Pro and the Monarch plugin
369
  * Fixed: Compatibility issue with the BackUpWordPress plugin
370
  * Added: Auto detect manually removed script/style versions feature
371
+ * Added: WordPress translation updates
372
  * Added: New Branding option to disable theme switching
373
  * Enhancement: Removed ctype_digit requirement
374
  * Enhancement: Install plugin error message
375
 
376
  = 3.0.2 - 1-22-16 =
377
+ * Fixed: Issue with scheduled BackupWordPress when run from dashboard
378
+ * Fixed: Issue with Heatmap tracker JavaScript
379
  * Added: Support for hosts with PHP with disabled mb_regex
380
  * Tweaked: Code snippet result message
381
 
404
  * Added: Support new Wordfence settings options for the Wordfence Extension
405
  * Added: Force Check Pages function for the MainWP PageSpeed Extensions
406
  * Added: Allow to see MainWP child plugin in MainWP Dashboard plugins search
407
+ * Updated: MainWP URL Extractor Extension logic to extract URLs by Post published date instead of last change date
408
 
409
  = 2.0.29 - 9-22-15 =
410
  * Fixed: 404 error that occurs in case Links Manger extension is in use when child plugin is hidden
446
 
447
  = 2.0.22 - 7-22-15 =
448
  * Fixed: Bug where the OptmizePress theme has not been updated properly
449
+ * Fixed: Bug where the Client Report extension recorded incorrect time
450
+ * Added: Support for the upcoming extension
451
 
452
  = 2.0.21 - 7-9-15 =
453
  * Fixed: Bug with time schedule for the UpdraftPlus extension
454
+ * Added: Support for the upcoming extension
455
 
456
  = 2.0.20 - 7-6-15 =
457
  * Fixed: Bug with time schedule for the UpdraftPlus extension
484
  * Fixed: Issue with sites running PHP 5.2 and lower
485
  * Fixed: Sync error on some sites with UpdraftPlus installed
486
  * Fixed: PHP Warning
487
+ * Changed: Server page to reflect requested minimum of PHP 5.3
488
 
489
  = 2.0.15 - 5-14-15 =
490
  * Added: Support for the upcoming extension
505
  = 2.0.12 - 4-16-15 =
506
  * Fixed: Bug for the MainWP iThemes Security Extension
507
  * Fixed: Bug for the MainWP WordFence Extension
508
+ * Fixed: Bug where the MainWP Child plugin was breaking Cron jobs on child sites
509
 
510
  = 2.0.11 - 4-12-15 =
511
  * Fixed: Upcoming extension bug
513
  = 2.0.10 - 4-06-15 =
514
  * Added: Support for the display Favicon for child sites feature
515
  * Added: Support for upcoming extension
516
+ * Fixed: Plugin conflicts with WordPress SEO by Yoast and Backupbuddy
517
 
518
  = 2.0.9.2 - 3-06-15 =
519
  * Fixed: Bug where SEO values are not being set for Boilerplate Pages and Posts
551
  * Added: A new Branding extension option - hiding the child plugin server information page
552
 
553
  = 2.0.5 - 1-07-15 =
554
+ * Fixed: Links Manager Extension: Now using the WordPress home option instead of site URL for the links
555
 
556
  = 2.0.4 - 12-26-14 =
557
  * Fixed: Backups for hosts having issues with "compress.zlib://" stream wrappers from PHP causing corrupt backup archives
562
 
563
  = 2.0.2 - 12-11-14 =
564
  * Added: Support hosts with PHP Heap classes
565
+ * Fixed: JavaScript issue disabling the popup menu on the admin menu
566
 
567
  = 2.0.1 - 12-10-14 =
568
  * Fixed: Restore/Clone from Tar via server upload
680
 
681
  = 0.29 =
682
  * Added ability to view Child site error logs on MainWP Dashboard
683
+ * Added ability to view Child site wp-config.php on MainWP Dashboard
684
  * Added new Hooks for Branding Extension
685
  * Added tweak for Code Snippet Extension
686
 
767
  * Fixed conflict with main dashboard on same site
768
 
769
  = 0.11 =
770
+ * Plugin localization
771
  * Extra check for readme.html file
772
  * Added child server information
773
  * Fixed restore issue: not all previous plugins/themes were removed
797
 
798
  = 0.5 =
799
  * Fixed issue with importing database with custom foreign key references
800
+ * Fixed issue with disabled functions from the "suhosin" extension
801
  * Fixed issue with click-heatmap
802
 
803
  = 0.4 =