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

Call to _admin_bar_bump_cb causes deprecation error in WordPress 6.4+ #7619

Closed
tofumatt opened this issue Sep 29, 2023 · 3 comments · Fixed by #7635
Closed

Call to _admin_bar_bump_cb causes deprecation error in WordPress 6.4+ #7619

tofumatt opened this issue Sep 29, 2023 · 3 comments · Fixed by #7635
Assignees
Labels
Bug Something isn't working Changelogged Whether the issue/PR has been added to release notes.
Milestone

Comments

@tofumatt
Copy link

tofumatt commented Sep 29, 2023

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

CleanShot 2023-09-29 at 11 50 33

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

@tofumatt tofumatt added the Bug Something isn't working label Sep 29, 2023
@tofumatt tofumatt changed the title Call to _admin_bar_bump_cb causes deprecation error in WordPress 8+ Call to _admin_bar_bump_cb causes deprecation error in WordPress 6.4+ Sep 29, 2023
@westonruter westonruter added this to the v2.4.3 milestone Sep 29, 2023
@westonruter
Copy link
Member

westonruter commented Sep 29, 2023

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:

remove_action( 'wp_head', $header_callback );
if ( '__return_false' !== $header_callback ) {
ob_start();
$header_callback();
$style = ob_get_clean();
$data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $style ) ); // See wp_add_inline_style().
// 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 );
}

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 ); 
 }

@westonruter
Copy link
Member

cc @spacedmonkey

@pavanpatil1
Copy link

QA Passed ✅

Cross-verified the issue and the applied solution is functioning correctly. Now, the deprecation warning related to the _admin_bar_bump_cb is not visible.

Before After
image image

@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Nov 6, 2023
@github-project-automation github-project-automation bot moved this to QA Passed in Ongoing Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Changelogged Whether the issue/PR has been added to release notes.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants