-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a shim to override wp.apiRequest, allowing HTTP/1.0 emulation #5741
Changes from 4 commits
c3c7f97
543bb37
3154754
7c7ada0
7ba2dda
a7abd50
d22b177
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,37 @@ function gutenberg_shim_fix_api_request_plain_permalinks( $scripts ) { | |
} | ||
add_action( 'wp_default_scripts', 'gutenberg_shim_fix_api_request_plain_permalinks' ); | ||
|
||
/** | ||
* Shims support for emulating HTTP/1.0 requests in wp.apiRequest | ||
* | ||
* @see https://core.trac.wordpress.org/ticket/43605 | ||
* | ||
* @param WP_Scripts $scripts WP_Scripts instance (passed by reference). | ||
*/ | ||
function gutenberg_shim_api_request_emulate_http( $scripts ) { | ||
$api_request_fix = <<<JS | ||
( function( wp ) { | ||
var oldApiRequest = wp.apiRequest; | ||
wp.apiRequest = function ( options ) { | ||
if ( options.method ) { | ||
if( [ 'GET', 'PUT', 'DELETE' ].indexOf( options.method.toUpperCase() ) >= 0 ) { | ||
if ( ! options.headers ) { | ||
options.headers = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be assigned as an object, not array. http://api.jquery.com/jquery.ajax/ ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missed that, but array is also an object in JS... so might work, but obviously should be updated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏻 |
||
} | ||
options.headers['X-HTTP-Method-Override'] = options.method; | ||
options.method = 'POST'; | ||
} | ||
} | ||
|
||
return oldApiRequest( options ); | ||
} | ||
} )( window.wp ); | ||
JS; | ||
|
||
$scripts->add_inline_script( 'wp-api-request', $api_request_fix, 'after' ); | ||
} | ||
add_action( 'wp_default_scripts', 'gutenberg_shim_api_request_emulate_http' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous shim was called inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No practical difference, I just copy/pasta-ed from the |
||
|
||
/** | ||
* Disables wpautop behavior in classic editor when post contains blocks, to | ||
* prevent removep from invalidating paragraph blocks. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space after
if
is missing :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙃