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

Fix check for empty dependencies on admin bar style loader tag filter #7920

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

Takshil-Kunadia
Copy link
Contributor

Summary

Fixes #7766

  • Added check for empty since deps is a non-nullable property of WP_Styles.

Checklist

  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@Takshil-Kunadia Takshil-Kunadia marked this pull request as ready for review November 13, 2024 11:08
Comment on lines 1381 to 1384
if (
is_array( wp_styles()->registered['admin-bar']->deps ) && in_array( $handle, wp_styles()->registered['admin-bar']->deps, true ) ?
! empty( wp_styles()->registered['admin-bar']->deps ) && is_array( wp_styles()->registered['admin-bar']->deps ) && in_array( $handle, wp_styles()->registered['admin-bar']->deps, true ) ?
self::is_exclusively_dependent( wp_styles(), $handle, 'admin-bar' ) :
self::has_dependency( wp_styles(), $handle, 'admin-bar' )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively:

		$admin_bar_dep = wp_styles()->query( 'admin-bar', 'registered' );
		if (
			$admin_bar_dep && in_array( $handle, $admin_bar_dep->deps, true ) ?
				self::is_exclusively_dependent( wp_styles(), $handle, 'admin-bar' ) :
				self::has_dependency( wp_styles(), $handle, 'admin-bar' )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, much better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we don't need to pass status param in query() as the default value is 'registered'.

@Takshil-Kunadia
Copy link
Contributor Author

Takshil-Kunadia commented Nov 14, 2024

Should we add the same checks here as well?

public static function filter_customize_preview_style_loader_tag( $tag, $handle ) {
$customize_preview = 'customize-preview';
if (
is_array( wp_styles()->registered[ $customize_preview ]->deps ) && in_array( $handle, wp_styles()->registered[ $customize_preview ]->deps, true )
? self::is_exclusively_dependent( wp_styles(), $handle, $customize_preview )
: self::has_dependency( wp_styles(), $handle, $customize_preview )
) {
$tag = preg_replace( '/(?<=<link)(?=\s|>)/i', ' ' . AMP_Rule_Spec::DEV_MODE_ATTRIBUTE, $tag );
}
return $tag;

public static function filter_admin_bar_script_loader_tag( $tag, $handle ) {
if (
is_array( wp_scripts()->registered['admin-bar']->deps ) && in_array( $handle, wp_scripts()->registered['admin-bar']->deps, true ) ?
self::is_exclusively_dependent( wp_scripts(), $handle, 'admin-bar' ) :
self::has_dependency( wp_scripts(), $handle, 'admin-bar' )
) {
$tag = preg_replace( '/(?<=<script)(?=\s|>)/i', ' ' . AMP_Rule_Spec::DEV_MODE_ATTRIBUTE, $tag );
}
return $tag;
}

@westonruter
Copy link
Member

@Takshil-Kunadia sure, sounds good!

@westonruter westonruter added this to the v2.5.6 milestone Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AMP error if admin bar styles are removed
2 participants