ampproject / ampproject/amp-wp
AMP error if admin bar styles are removed
- Dominant language
- PHP
- Stars
- 1.8k
- Forks
- 378
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 10
Description
### Bug Description
If visiting a wordpress page where I removed admin bar styles, AMP throws
`Warning: Undefined array key "admin-bar" in XXX/wp-content/plugins/amp/includes/class-amp-theme-support.php on line 1382`
I removed the styles (and the whole admin bar) with
```
add_filter( 'show_admin_bar', '__return_false' );
wp_deregister_style( 'admin-bar' );
```
If I take out `wp_deregister_style( 'admin-bar' );` it works again.
### Expected Behaviour
Should not throw warning
### Screenshots
_No response_
### PHP Version
8.2
### Plugin Version
2.5.3
### AMP plugin template mode
Standard
### WordPress Version
_No response_
### 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
on line 1382 includes/class-amp-theme-support.php you should replace
`is_array( wp_styles()->registered['admin-bar']->deps ) && in_array( $handle, wp_styles()->registered['admin-bar']->deps, true ) ? [..]
`
by
`isset( wp_styles()->registered['admin-bar']->deps ) && is_array( wp_styles()->registered['admin-bar']->deps ) && in_array( $handle, wp_styles()->registered['admin-bar']->deps, true ) ? [..]`
(add an isset())
### QA Testing Instructions
_No response_
### Demo
_No response_
### Changelog Entry
_No response_
Contributor guide
Research direction
Start in includes/class-amp-theme-support.php around line 1382, where the admin-bar dependency is accessed. Guard that dependency lookup when the admin-bar style has been deregistered, then verify that an AMP page with the provided WordPress filters no longer emits the undefined-array-key warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100