Skip to content
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

Plugin: Remove jQuery heartbeat-to-hooks proxying #13576

Merged
merged 1 commit into from
Feb 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 1 addition & 36 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -851,48 +851,13 @@ function gutenberg_get_available_image_sizes() {
* @param string $hook Screen name.
*/
function gutenberg_editor_scripts_and_styles( $hook ) {
global $wp_scripts, $wp_meta_boxes;

// Add "wp-hooks" as dependency of "heartbeat".
$heartbeat_script = $wp_scripts->query( 'heartbeat', 'registered' );
if ( $heartbeat_script && ! in_array( 'wp-hooks', $heartbeat_script->deps ) ) {
$heartbeat_script->deps[] = 'wp-hooks';
}
global $wp_meta_boxes;

// Enqueue heartbeat separately as an "optional" dependency of the editor.
// Heartbeat is used for automatic nonce refreshing, but some hosts choose
// to disable it outright.
wp_enqueue_script( 'heartbeat' );

// Transforms heartbeat jQuery events into equivalent hook actions. This
// avoids a dependency on jQuery for listening to the event.
$heartbeat_hooks = <<<JS
( function() {
jQuery( document ).on( [
'heartbeat-send',
'heartbeat-tick',
'heartbeat-error',
'heartbeat-connection-lost',
'heartbeat-connection-restored',
'heartbeat-nonces-expired',
].join( ' ' ), function( event ) {
var actionName = event.type.replace( /-/g, '.' ),
args;

// Omit the event argument in applying arguments to the hook callback.
// The remaining arguments are passed to the hook.
args = Array.prototype.slice.call( arguments, 1 );

wp.hooks.doAction.apply( null, [ actionName ].concat( args ) );
} );
} )();
JS;
wp_add_inline_script(
'heartbeat',
$heartbeat_hooks,
'after'
);

wp_enqueue_script( 'wp-edit-post' );
wp_enqueue_script( 'wp-format-library' );
wp_enqueue_style( 'wp-format-library' );
Expand Down