The Two Percent

Hire Me

[Solved] Warning: Parameter 1 to wp_default_scripts() expected to be a reference

Are you seeing a warning message in WordPress admin via Query Monitor?

Warning: Parameter 1 to wp_default_scripts() expected to be a reference, value given in /wp-includes/class-wp-hook.php on line 286

Warning: Parameter 1 to wp_default_styles() expected to be a reference, value given in /wp-includes/class-wp-hook.php on line 286

I’m going to take a wild guess and say you’re hosting on WP Engine?

What causes it?

This error is caused because WP Engine turn off the WordPress heartbeat on Admin pages that are not editable.

This thread covers a few different ways of dealing with the problem:

1) Editing wp-config.php

define( ‘WP_DEBUG_DISPLAY’, false );
@ini_set( ‘display_errors’, 0 );

2) Editing htaccess

php_flag display_errors off

3) Add to functions.php to squelch these particular errors

function warning_squelch_wpe(int $errno , string $errstr , string $errfile , int $errline , array $errcontext) {
if(strstr($errstr, "expected to be a reference")) {
return true; // squelch matching warnings
}
// allow normal handling for non-matching warnings
return false;
}
set_error_handler("warning_squelch_wpe", E_WARNING);

None of these are very good ways of dealing with this issue. As you’re just hiding the message.

So, what’s the answer.

Ask WP Engine to turn off an internal-only setting that saves resources by not allowing heartbeat on any non-editing pages, specifically:

Please turn ON heartbeat_autosave_only

You can then combine this with a custom heartbeat setting to reduce resources in your config.php

#custom heartbeat - stop the warning from WPE
# see https://www.thetwopercent.co.uk/solved-warning-parameter-1-to-wp_default_scripts/
define( 'WPE_HEARTBEAT_INTERVAL', 15 );