Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#38271 closed defect (bug) (fixed)

`wp-remove-post-lock` Ajax request generates notice in `wp_ajax_wp_remove_post_lock()`

Reported by: dlh's profile dlh Owned by: adamsilverstein's profile adamsilverstein
Milestone: 4.7 Priority: normal
Severity: normal Version: 4.7
Component: Editor Keywords:
Focuses: javascript, administration Cc:

Description

Before [38425], when no #active_post_lock was in the DOM, the POST request from post.js with the wp-remove-post-lock action would not include an active_post_lock key, and wp_ajax_wp_remove_post_lock() would return immediately.

After [38425], when no #active_post_lock is in the DOM, active_post_lock is converted to the string "undefined" when formData is supported (I'm using Chrome 53.0.2785.143).

wp_ajax_wp_remove_post_lock() tries to process that value, leading to Undefined offset: 1 after array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) ).

To replicate, visit post-new.php and refresh the page after it loads.

The attached patch would return before the Ajax request occurs in post.js if data.active_post_lock is undefined.

Attachments (2)

38271.diff (442 bytes) - added by dlh 8 years ago.
38271.2.diff (682 bytes) - added by adamsilverstein 8 years ago.
use yoda conditional

Download all attachments as: .zip

Change History (6)

@dlh
8 years ago

#1 @adamsilverstein
8 years ago

@dlh thanks for the patch! This looks reasonable, I tested before and after, verified the error you mentioned and see it is solved by the patch. I am attaching a slightly updated version switching to a Yoda conditional.

@adamsilverstein
8 years ago

use yoda conditional

#2 @adamsilverstein
8 years ago

  • Milestone changed from Awaiting Review to 4.7
  • Owner set to adamsilverstein
  • Status changed from new to assigned

#3 @azaozz
8 years ago

The attached patch would return before the Ajax request occurs in post.js

Right, the first thing wp_ajax_wp_remove_post_lock() does is to return early when either post_ID or active_post_lock is empty. Can do the same in JS and not send the request.

Last edited 8 years ago by azaozz (previous) (diff)

#4 @azaozz
8 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 38772:

Editor: do not send the request for releasing the post lock on unload when post_ID or active_post_lock is missing.

Props dlh, adamsilverstein.
Fixes #38271.

Note: See TracTickets for help on using tickets.