Quick Edit: Undefined index _emnonce
-
The Issue
(EM version 5.2.6)
If in wp-config.php Idefine('WP_DEBUG', true);
then click ‘quick edit’ and ‘update’ in the manage posts screen for EM’s events or locations, I get aNotice: Undefined index: _emnonce in /…/events-manager/classes/em-location-post-admin.php on line 51.
My understanding is that it is best to adjust the code to prevent notices from displaying in “debug” mode. No problem would appear if not in debug mode.
I don’t see anything that EM needs to save from quick edit. Quick edit does trigger WP’s ‘save_post’ action hook, and EM hooks into ‘save_post’ for
EM_Event_Post_Admin::save_post()
andEM_Location_Post_Admin::save_post()
.
Both these methods usewp_verify_nonce($_REQUEST['_emnonce'], 'edit_event')
, but there is no _emnonce POSTed by quick edit, hence the “No Index” notice for _emnonce. I’m guessing EM didn’t intend thesesave_post()
methods to run from quick edit and so never POSTed a nonce.My Temporary Workaround
I think I resolved the issue by removing thesave_post()
functions when the user is on a manage posts admin screen with the quick edit option. Here’s the code:// If using quick edit in debug mode, we get a Notice: Undefined index _emnonce. Remove save_post() from pages with quick edit add_action('current_screen', 'my_remove_em_save_post'); function my_remove_em_save_post () { global $current_screen; if ( in_array($current_screen->id, array('edit-event', 'edit-location')) ) { remove_action('save_post',array('EM_Event_Post_Admin','save_post'),10,1); remove_action('save_post',array('EM_Location_Post_Admin','save_post')); } }
My Suggestion for Next Version of Plugin
I think the longer term resolution to the issue could involve two adjustments to each relevant file: em-event-post-admin.php and em-location-post-admin.php.First: Under
save_post()
, add$current_screen
to the list of globals so that it looks like this:
global $wpdb, $EM_Event, $EM_Location, $EM_Notices, $current_screen;
Second: On the big
if
statement for whethersave_post()
does anything at all, add a condition to ensure that ‘save_post’ wasn’t triggered from quick edit.
for events…
$current_screen->id != 'edit-event'
or for locations…
$current_screen->id != 'edit-location'
So, the revisedif
statement for events looks like this:
if(!defined('UNTRASHING_'.$post_id) && $is_post_type && $saving_status && $saving_status && $current_screen->id != 'edit-event'){
My Question
Any improvements to my understanding of the issue, or to the solutions above?
- The topic ‘Quick Edit: Undefined index _emnonce’ is closed to new replies.