Call to `_admin_bar_bump_cb` causes deprecation error in WordPress 6.4+
tofumatt opened this issue · 3 comments
Bug Description
The call to _admin_bar_bump_cb
at https://github.com/ampproject/amp-wp/blob/2c4df9e1dec74c798e11f06cd02e470f1f988705/includes/class-amp-theme-support.php#L1226C9-L1226C9 causes PHP Deprecation notices to appear when using the AMP plugin with WordPress 6.4+.
The entire notice is:
PHP Deprecated: Function _admin_bar_bump_cb is deprecated since version 6.4.0! Use wp_enqueue_admin_bar_bump_styles instead. in /var/www/html/wp-includes/functions.php on line 6032
It seems using wp_enqueue_admin_bar_bump_styles
instead will fix the issue, when the version of WordPress is equal-to/above 6.4.0
.
Expected Behaviour
No deprecation errors appear in the WordPress debug log/elsewhere when using the AMP plugin with WordPress 6.4+.
Screenshots
PHP Version
7.4
Plugin Version
2.4.2
AMP plugin template mode
Standard
WordPress Version
6.4.0 (Nightly)
Site Health
No response
Gutenberg Version
No response
OS(s) Affected
No response
Browser(s) Affected
No response
Device(s) Affected
No response
Acceptance Criteria
No response
Implementation Brief
No response
QA Testing Instructions
No response
Demo
No response
Changelog Entry
No response
Yes, this is result of https://core.trac.wordpress.org/ticket/58775
We'll need to fix by the time WordPress 6.4 is released.
As for the fix, the code in question is:
amp-wp/includes/class-amp-theme-support.php
Lines 1228 to 1241 in 2c4df9e
I believe it can be rewritten as follows, or something like it:
if ( ! function_exists( 'wp_enqueue_admin_bar_header_styles' ) ) {
remove_action( 'wp_head', $header_callback );
}
if ( '__return_false' !== $header_callback ) {
if ( ! function_exists( 'wp_enqueue_admin_bar_header_styles' ) ) {
ob_start();
$header_callback();
$style = ob_get_clean();
$data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $style ) ); // See wp_add_inline_style().
} else {
$data = '';
}
// Override AMP's position:relative on the body for the sake of the AMP viewer, which is not relevant an an Admin Bar context.
if ( amp_is_dev_mode() ) {
$data .= 'html:not(#_) > body { position:unset !important; }';
}
wp_add_inline_style( 'admin-bar', $data );
}