Events Manager - Version 5.7.2

Version Description

  • fixed subsite events in MS Global mode not being able to save new events and resulting in orphaned entries in wp_em_events table
  • added admin tool to allow removal of orphaned events in wp_em_events database table
  • improved detection and handling of orphaned events when being displayed
Download this release

Release Info

Developer netweblogic
Plugin Icon 128x128 Events Manager
Version 5.7.2
Comparing to
See all releases

Code changes from version 5.7 to 5.7.2

admin/em-ms-options.php CHANGED
@@ -1,4 +1,4 @@
1
- <?php
2
  function em_ms_upgrade( $blog_id ){
3
  ?>
4
  <div class="wrap">
@@ -27,11 +27,11 @@ function em_ms_upgrade( $blog_id ){
27
  echo "<p>Done Upgrading</p>";
28
  }else{
29
  ?>
30
- <form action="" method="post">
31
- <p><?php esc_html_e('To update your network blogs with the latest Events Manager automatically, click the update button below.','events-manager'); ?></p>
32
- <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('em_ms_ugrade_'.get_current_user_id()); ?>" />
33
- <input type="hidden" name="action" value="upgrade" />
34
- <input type="submit" value="<?php esc_attr_e('Update','events-manager'); ?>" />
35
  </form>
36
  <?php
37
  }
1
+ <?php
2
  function em_ms_upgrade( $blog_id ){
3
  ?>
4
  <div class="wrap">
27
  echo "<p>Done Upgrading</p>";
28
  }else{
29
  ?>
30
+ <form action="" method="post">
31
+ <p><?php esc_html_e('To update your network blogs with the latest Events Manager automatically, click the update button below.','events-manager'); ?></p>
32
+ <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('em_ms_ugrade_'.get_current_user_id()); ?>" />
33
+ <input type="hidden" name="action" value="upgrade" />
34
+ <input type="submit" value="<?php esc_attr_e('Update','events-manager'); ?>" />
35
  </form>
36
  <?php
37
  }
admin/em-options.php CHANGED
@@ -139,10 +139,35 @@ function em_options_save(){
139
  }
140
  //go back to plugin options page
141
  $EM_Notices->add_confirm(__('Settings have been reset back to default. Your events, locations and categories have not been modified.','events-manager'), true);
142
- wp_redirect(EM_ADMIN_URL.'&page=events-manager-options');
143
  exit();
144
  }
145
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  //Force Update Recheck - Workaround for now
147
  if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'recheck_updates' && check_admin_referer('em_recheck_updates_'.get_current_user_id().'_wpnonce') && is_super_admin() ){
148
  //force recheck of plugin updates, to refresh dl links
@@ -163,7 +188,7 @@ function em_options_save(){
163
  exit();
164
  }
165
  //import EM settings
166
- if( !empty($_REQUEST['action']) && ($_REQUEST['action'] == 'import_em_settings' && check_admin_referer('import_em_settings')) || (is_multisite() && $_REQUEST['action'] == 'import_em_ms_settings' && check_admin_referer('import_em_ms_settings')) && is_super_admin() ){
167
  //upload uniquely named file to system for usage later
168
  if( !empty($_FILES['import_settings_file']['size']) && is_uploaded_file($_FILES['import_settings_file']['tmp_name']) ){
169
  $settings = file_get_contents($_FILES['import_settings_file']['tmp_name']);
@@ -617,6 +642,7 @@ function em_admin_option_box_uninstall(){
617
  $uninstall_url = admin_url().'network/admin.php?page=events-manager-options&amp;action=uninstall&amp;_wpnonce='.wp_create_nonce('em_uninstall_'.get_current_user_id().'_wpnonce');
618
  $reset_url = admin_url().'network/admin.php?page=events-manager-options&amp;action=reset&amp;_wpnonce='.wp_create_nonce('em_reset_'.get_current_user_id().'_wpnonce');
619
  $recheck_updates_url = admin_url().'network/admin.php?page=events-manager-options&amp;action=recheck_updates&amp;_wpnonce='.wp_create_nonce('em_recheck_updates_'.get_current_user_id().'_wpnonce');
 
620
  $check_devs = admin_url().'network/admin.php?page=events-manager-options&amp;action=check_devs&amp;_wpnonce='.wp_create_nonce('em_check_devs_wpnonce');
621
  $export_settings_url = admin_url().'network/admin.php?page=events-manager-options&amp;action=export_em_ms_settings&amp;_wpnonce='.wp_create_nonce('export_em_ms_settings');
622
  $import_nonce = wp_create_nonce('import_em_ms_settings');
@@ -624,6 +650,7 @@ function em_admin_option_box_uninstall(){
624
  $uninstall_url = EM_ADMIN_URL.'&amp;page=events-manager-options&amp;action=uninstall&amp;_wpnonce='.wp_create_nonce('em_uninstall_'.get_current_user_id().'_wpnonce');
625
  $reset_url = EM_ADMIN_URL.'&amp;page=events-manager-options&amp;action=reset&amp;_wpnonce='.wp_create_nonce('em_reset_'.get_current_user_id().'_wpnonce');
626
  $recheck_updates_url = EM_ADMIN_URL.'&amp;page=events-manager-options&amp;action=recheck_updates&amp;_wpnonce='.wp_create_nonce('em_recheck_updates_'.get_current_user_id().'_wpnonce');
 
627
  $check_devs = EM_ADMIN_URL.'&amp;page=events-manager-options&amp;action=check_devs&amp;_wpnonce='.wp_create_nonce('em_check_devs_wpnonce');
628
  $export_settings_url = EM_ADMIN_URL.'&amp;page=events-manager-options&amp;action=export_em_settings&amp;_wpnonce='.wp_create_nonce('export_em_settings');
629
  $import_nonce = wp_create_nonce('import_em_settings');
@@ -684,6 +711,34 @@ function em_admin_option_box_uninstall(){
684
  </tr>
685
  </table>
686
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
687
  <table class="form-table">
688
  <tr class="em-header"><td colspan="2">
689
  <h4><?php _e ( 'Uninstall/Reset', 'events-manager'); ?></h4>
139
  }
140
  //go back to plugin options page
141
  $EM_Notices->add_confirm(__('Settings have been reset back to default. Your events, locations and categories have not been modified.','events-manager'), true);
142
+ wp_redirect(em_wp_get_referer());
143
  exit();
144
  }
145
  }
146
+ //Cleanup Event Orphans
147
+ if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'cleanup_event_orphans' && check_admin_referer('em_cleanup_event_orphans_'.get_current_user_id().'_wpnonce') && is_super_admin() ){
148
+ //Firstly, get all orphans
149
+ global $wpdb;
150
+ $sql = 'SELECT event_id FROM '.EM_EVENTS_TABLE.' WHERE post_id NOT IN (SELECT ID FROM ' .$wpdb->posts. ' WHERE post_type="'. EM_POST_TYPE_EVENT .'" OR post_type="event-recurring")';
151
+ if( EM_MS_GLOBAL ){
152
+ if( is_main_site() ){
153
+ $sql .= $wpdb->prepare(' AND (blog_id=%d or blog_id IS NULL)', get_current_blog_id());
154
+ }else{
155
+ $sql .= $wpdb->prepare(' AND blog_id=%d', get_current_blog_id());
156
+ }
157
+ }
158
+ $results = $wpdb->get_col($sql);
159
+ $deleted_events = 0;
160
+ foreach( $results as $event_id ){
161
+ $EM_Event = new EM_Event($event_id);
162
+ if( !empty($EM_Event->orphaned_event) && $EM_Event->delete() ){
163
+ $deleted_events++;
164
+ }
165
+ }
166
+ //go back to plugin options page
167
+ $EM_Notices->add_confirm(sprintf(__('Found %d orphaned events, deleted %d successfully','events-manager'), count($results), $deleted_events), true);
168
+ wp_redirect(em_wp_get_referer());
169
+ exit();
170
+ }
171
  //Force Update Recheck - Workaround for now
172
  if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'recheck_updates' && check_admin_referer('em_recheck_updates_'.get_current_user_id().'_wpnonce') && is_super_admin() ){
173
  //force recheck of plugin updates, to refresh dl links
188
  exit();
189
  }
190
  //import EM settings
191
+ if( !empty($_REQUEST['action']) && ( ($_REQUEST['action'] == 'import_em_settings' && check_admin_referer('import_em_settings')) || (is_multisite() && $_REQUEST['action'] == 'import_em_ms_settings' && check_admin_referer('import_em_ms_settings')) ) && is_super_admin() ){
192
  //upload uniquely named file to system for usage later
193
  if( !empty($_FILES['import_settings_file']['size']) && is_uploaded_file($_FILES['import_settings_file']['tmp_name']) ){
194
  $settings = file_get_contents($_FILES['import_settings_file']['tmp_name']);
642
  $uninstall_url = admin_url().'network/admin.php?page=events-manager-options&amp;action=uninstall&amp;_wpnonce='.wp_create_nonce('em_uninstall_'.get_current_user_id().'_wpnonce');
643
  $reset_url = admin_url().'network/admin.php?page=events-manager-options&amp;action=reset&amp;_wpnonce='.wp_create_nonce('em_reset_'.get_current_user_id().'_wpnonce');
644
  $recheck_updates_url = admin_url().'network/admin.php?page=events-manager-options&amp;action=recheck_updates&amp;_wpnonce='.wp_create_nonce('em_recheck_updates_'.get_current_user_id().'_wpnonce');
645
+ $cleanup_event_orphans_url = admin_url().'network/admin.php?page=events-manager-options&amp;action=cleanup_event_orphans&amp;_wpnonce='.wp_create_nonce('em_cleanup_event_orphans_'.get_current_user_id().'_wpnonce');
646
  $check_devs = admin_url().'network/admin.php?page=events-manager-options&amp;action=check_devs&amp;_wpnonce='.wp_create_nonce('em_check_devs_wpnonce');
647
  $export_settings_url = admin_url().'network/admin.php?page=events-manager-options&amp;action=export_em_ms_settings&amp;_wpnonce='.wp_create_nonce('export_em_ms_settings');
648
  $import_nonce = wp_create_nonce('import_em_ms_settings');
650
  $uninstall_url = EM_ADMIN_URL.'&amp;page=events-manager-options&amp;action=uninstall&amp;_wpnonce='.wp_create_nonce('em_uninstall_'.get_current_user_id().'_wpnonce');
651
  $reset_url = EM_ADMIN_URL.'&amp;page=events-manager-options&amp;action=reset&amp;_wpnonce='.wp_create_nonce('em_reset_'.get_current_user_id().'_wpnonce');
652
  $recheck_updates_url = EM_ADMIN_URL.'&amp;page=events-manager-options&amp;action=recheck_updates&amp;_wpnonce='.wp_create_nonce('em_recheck_updates_'.get_current_user_id().'_wpnonce');
653
+ $cleanup_event_orphans_url= EM_ADMIN_URL.'&amp;page=events-manager-options&amp;action=cleanup_event_orphans&amp;_wpnonce='.wp_create_nonce('em_cleanup_event_orphans_'.get_current_user_id().'_wpnonce');
654
  $check_devs = EM_ADMIN_URL.'&amp;page=events-manager-options&amp;action=check_devs&amp;_wpnonce='.wp_create_nonce('em_check_devs_wpnonce');
655
  $export_settings_url = EM_ADMIN_URL.'&amp;page=events-manager-options&amp;action=export_em_settings&amp;_wpnonce='.wp_create_nonce('export_em_settings');
656
  $import_nonce = wp_create_nonce('import_em_settings');
711
  </tr>
712
  </table>
713
 
714
+
715
+ <table class="form-table">
716
+ <tr class="em-header"><td colspan="2">
717
+ <h4><?php esc_html_e( 'Database Cleanup', 'events-manager'); ?></h4>
718
+ </td></tr>
719
+ <tr>
720
+ <th style="text-align:right;"><a href="<?php echo $cleanup_event_orphans_url; ?>" class="button-secondary admin-tools-db-cleanup"><?php _e('Remove Orphaned Events','events-manager'); ?></a></th>
721
+ <td>
722
+ <?php
723
+ global $wpdb;
724
+ $sql = 'SELECT count(*) FROM '.EM_EVENTS_TABLE.' WHERE post_id NOT IN (SELECT ID FROM ' .$wpdb->posts. ' WHERE post_type="'. EM_POST_TYPE_EVENT .'" OR post_type="event-recurring")';
725
+ if( EM_MS_GLOBAL ){
726
+ if( is_main_site() ){
727
+ $sql .= $wpdb->prepare(' AND (blog_id=%d or blog_id IS NULL)', get_current_blog_id());
728
+ }else{
729
+ $sql .= $wpdb->prepare(' AND blog_id=%d', get_current_blog_id());
730
+ }
731
+ }
732
+ $results = $wpdb->get_var($sql);
733
+ echo sprintf(esc_html__('Orphaned events may show on your event lists but not point to real event pages, and can be deleted. %d potentially orphaned events have been found.', 'events-manager'), $results);
734
+ ?>
735
+ </td>
736
+ </tr>
737
+ </table>
738
+ <script type="text/javascript">
739
+ if( typeof EM == 'object' ){ EM.admin_db_cleanup_warning = '<?php echo esc_js(__('Are you sure you want to proceed? We recommend you back up your database first, just in case!', 'events-manager')); ?>'; }
740
+ </script>
741
+
742
  <table class="form-table">
743
  <tr class="em-header"><td colspan="2">
744
  <h4><?php _e ( 'Uninstall/Reset', 'events-manager'); ?></h4>
classes/em-event.php CHANGED
@@ -254,7 +254,7 @@ class EM_Event extends EM_Object{
254
  if($search_by == 'event_id' && !$is_post ){
255
  //search by event_id, get post_id and blog_id (if in ms mode) and load the post
256
  $results = $wpdb->get_row($wpdb->prepare("SELECT post_id, blog_id FROM ".EM_EVENTS_TABLE." WHERE event_id=%d",$id), ARRAY_A);
257
- if( !empty($results['post_id']) ){ $this->post_id = $results['post_id']; }
258
  if( is_multisite() && (is_numeric($results['blog_id']) || $results['blog_id']=='' ) ){
259
  if( $results['blog_id']=='' ) $results['blog_id'] = get_current_site()->blog_id;
260
  $event_post = get_blog_post($results['blog_id'], $results['post_id']);
@@ -290,7 +290,8 @@ class EM_Event extends EM_Object{
290
  }
291
 
292
  function load_postdata($event_post, $search_by = false){
293
- if( is_object($event_post) ){
 
294
  //load post data - regardless
295
  $this->post_id = $event_post->ID;
296
  $this->event_name = $event_post->post_title;
@@ -348,7 +349,15 @@ class EM_Event extends EM_Object{
348
  //we have an orphan... show it, so that we can at least remove it on the front-end
349
  global $wpdb;
350
  if( EM_MS_GLOBAL ){ //if MS Global mode enabled, make sure we search by blog too so there's no cross-post confusion
351
- $event_array = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".EM_EVENTS_TABLE." WHERE post_id=%d && blog_id=%d",$this->post_id, $this->blog_id), ARRAY_A);
 
 
 
 
 
 
 
 
352
  }else{
353
  $event_array = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".EM_EVENTS_TABLE." WHERE post_id=%d",$this->post_id), ARRAY_A);
354
  }
@@ -731,10 +740,6 @@ class EM_Event extends EM_Object{
731
  //unless events can be submitted by an anonymous user (and this is a new event), user must have permissions.
732
  return apply_filters('em_event_save', false, $this);
733
  }
734
- //sort out multisite blog id if appliable
735
- if( is_multisite() && empty($this->blog_id) ){
736
- $this->blog_id = get_current_blog_id();
737
- }
738
  //start saving process
739
  do_action('em_event_save_pre', $this);
740
  $post_array = array();
@@ -814,6 +819,11 @@ class EM_Event extends EM_Object{
814
 
815
  function save_meta(){
816
  global $wpdb;
 
 
 
 
 
817
  if( ( get_option('dbem_events_anonymous_submissions') && empty($this->event_id)) || $this->can_manage('edit_events', 'edit_others_events') ){
818
  do_action('em_event_save_meta_pre', $this);
819
  //first save location
@@ -1048,7 +1058,7 @@ class EM_Event extends EM_Object{
1048
  }
1049
  if( !$result && !empty($this->orphaned_event) ){
1050
  //this is an orphaned event, so the wp delete posts would have never worked, so we just delete the row in our events table
1051
- $this->delete_meta();
1052
  }
1053
  }else{
1054
  $result = false;
254
  if($search_by == 'event_id' && !$is_post ){
255
  //search by event_id, get post_id and blog_id (if in ms mode) and load the post
256
  $results = $wpdb->get_row($wpdb->prepare("SELECT post_id, blog_id FROM ".EM_EVENTS_TABLE." WHERE event_id=%d",$id), ARRAY_A);
257
+ if( !empty($results['post_id']) ){ $this->post_id = $results['post_id']; $this->event_id = $id; }
258
  if( is_multisite() && (is_numeric($results['blog_id']) || $results['blog_id']=='' ) ){
259
  if( $results['blog_id']=='' ) $results['blog_id'] = get_current_site()->blog_id;
260
  $event_post = get_blog_post($results['blog_id'], $results['post_id']);
290
  }
291
 
292
  function load_postdata($event_post, $search_by = false){
293
+ //load event post object if it's an actual object and also a post type of our event CPT names
294
+ if( is_object($event_post) && ($event_post->post_type == 'event-recurring' || $event_post->post_type == EM_POST_TYPE_EVENT) ){
295
  //load post data - regardless
296
  $this->post_id = $event_post->ID;
297
  $this->event_name = $event_post->post_title;
349
  //we have an orphan... show it, so that we can at least remove it on the front-end
350
  global $wpdb;
351
  if( EM_MS_GLOBAL ){ //if MS Global mode enabled, make sure we search by blog too so there's no cross-post confusion
352
+ if( !empty($this->event_id) ){
353
+ $event_array = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".EM_EVENTS_TABLE." WHERE event_id=%d",$this->event_id), ARRAY_A);
354
+ }else{
355
+ if( $this->blog_id == get_current_blog_id() || empty($this->blog_id) ){
356
+ $event_array = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".EM_EVENTS_TABLE." WHERE post_id=%d AND (blog_id=%d OR blog_id IS NULL)",$this->post_id, $this->blog_id), ARRAY_A);
357
+ }else{
358
+ $event_array = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".EM_EVENTS_TABLE." WHERE post_id=%d AND blog_id=%d",$this->post_id, $this->blog_id), ARRAY_A);
359
+ }
360
+ }
361
  }else{
362
  $event_array = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".EM_EVENTS_TABLE." WHERE post_id=%d",$this->post_id), ARRAY_A);
363
  }
740
  //unless events can be submitted by an anonymous user (and this is a new event), user must have permissions.
741
  return apply_filters('em_event_save', false, $this);
742
  }
 
 
 
 
743
  //start saving process
744
  do_action('em_event_save_pre', $this);
745
  $post_array = array();
819
 
820
  function save_meta(){
821
  global $wpdb;
822
+ //sort out multisite blog id if appliable
823
+ if( is_multisite() && empty($this->blog_id) ){
824
+ $this->blog_id = get_current_blog_id();
825
+ }
826
+ //continue with saving if permissions allow
827
  if( ( get_option('dbem_events_anonymous_submissions') && empty($this->event_id)) || $this->can_manage('edit_events', 'edit_others_events') ){
828
  do_action('em_event_save_meta_pre', $this);
829
  //first save location
1058
  }
1059
  if( !$result && !empty($this->orphaned_event) ){
1060
  //this is an orphaned event, so the wp delete posts would have never worked, so we just delete the row in our events table
1061
+ $result = $this->delete_meta();
1062
  }
1063
  }else{
1064
  $result = false;
events-manager.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: Events Manager
4
- Version: 5.7
5
  Plugin URI: http://wp-events-plugin.com
6
  Description: Event registration and booking management for WordPress. Recurring events, locations, google maps, rss, ical, booking registration and more!
7
  Author: Marcus Sykes
1
  <?php
2
  /*
3
  Plugin Name: Events Manager
4
+ Version: 5.7.2
5
  Plugin URI: http://wp-events-plugin.com
6
  Description: Event registration and booking management for WordPress. Recurring events, locations, google maps, rss, ical, booking registration and more!
7
  Author: Marcus Sykes
includes/js/admin-settings.js CHANGED
@@ -107,4 +107,11 @@ jQuery(document).ready(function($){
107
  el.val() == '1' ? $(el.attr('data-trigger')).show() : $(el.attr('data-trigger')).hide();
108
  });
109
  $('input.em-trigger:checked').trigger('change');
 
 
 
 
 
 
 
110
  });
107
  el.val() == '1' ? $(el.attr('data-trigger')).show() : $(el.attr('data-trigger')).hide();
108
  });
109
  $('input.em-trigger:checked').trigger('change');
110
+ //admin tools confirm
111
+ $('a.admin-tools-db-cleanup').click( function( e ){
112
+ if( !confirm(EM.admin_db_cleanup_warning) ){
113
+ e.preventDefault();
114
+ return false;
115
+ }
116
+ });
117
  });
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: bookings, calendar, tickets, events, buddypress, event management, google
5
  Text Domain: events-manager
6
  Requires at least: 3.5
7
  Tested up to: 4.7.4
8
- Stable tag: 5.7
9
 
10
  Fully featured event registration management including recurring events, locations management, calendar, Google map integration, booking management
11
 
@@ -99,6 +99,15 @@ See our [FAQ](http://wp-events-plugin.com/documentation/faq/) page, which is upd
99
  6. Manage attendees with various booking reports
100
 
101
  == Changelog ==
 
 
 
 
 
 
 
 
 
102
  = 5.7 =
103
  * added em_events_admin_args filter allowing modification of event search arguments
104
  * removed jQuery UI localize files for the datepicker in favor of WP 4.6 native localization
5
  Text Domain: events-manager
6
  Requires at least: 3.5
7
  Tested up to: 4.7.4
8
+ Stable tag: 5.7.2
9
 
10
  Fully featured event registration management including recurring events, locations management, calendar, Google map integration, booking management
11
 
99
  6. Manage attendees with various booking reports
100
 
101
  == Changelog ==
102
+ = 5.7.2 =
103
+ * fixed subsite events in MS Global mode not being able to save new events and resulting in orphaned entries in wp_em_events table
104
+ * added admin tool to allow removal of orphaned events in wp_em_events database table
105
+ * improved detection and handling of orphaned events when being displayed
106
+
107
+ = 5.7.1 =
108
+ * fix for wierd headers PHP error due to corrupted <?php on line 1 of admin/em-ms-options.php
109
+ * fixed minor PHP warning on settings page
110
+
111
  = 5.7 =
112
  * added em_events_admin_args filter allowing modification of event search arguments
113
  * removed jQuery UI localize files for the datepicker in favor of WP 4.6 native localization