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

PHP Warning: Undefined array key (probably Windows-only issue) #866

Open
siliconforks opened this issue May 6, 2024 · 2 comments
Open

Comments

@siliconforks
Copy link

When running Query Monitor with the Twenty Twenty-Four theme on Windows I get these warnings:

PHP Warning:  Undefined array key "O:/Apache24/htdocs/wordpress/wp-content/themes/twentytwentyfour/parts/header.html" in O:\\Apache24\\htdocs\\wordpress\\wp-content\\plugins\\query-monitor\\output\\html\\theme.php on line 163
PHP Warning:  Undefined array key "O:/Apache24/htdocs/wordpress/wp-content/themes/twentytwentyfour/parts/post-meta.html" in O:\\Apache24\\htdocs\\wordpress\\wp-content\\plugins\\query-monitor\\output\\html\\theme.php on line 163
PHP Warning:  Undefined array key "O:/Apache24/htdocs/wordpress/wp-content/themes/twentytwentyfour/parts/footer.html" in O:\\Apache24\\htdocs\\wordpress\\wp-content\\plugins\\query-monitor\\output\\html\\theme.php on line 163

I believe the cause of the issue is here:

https://github.com/johnbillion/query-monitor/blob/3.16.0/collectors/theme.php#L473-L500

Note the following:

  • $this->data->count_template_parts[ $file ] uses $file before calling QM_Util::standard_dir
  • $this->data->template_parts[ $file ] and $this->data->theme_template_parts[ $file ] use $file after calling QM_Util::standard_dir

So, $this->data->count_template_parts does not have the same keys as the other arrays.

@LoranRendel
Copy link

LoranRendel commented May 16, 2024

Also encountered this error.

The problem is that target array items on Windows actual value is not
O:/Apache24/htdocs/wordpress/wp-content/themes/twentytwentyfour/parts/header.html, but
O:\Apache24\htdocs\wordpress/wp-content/themes/twentytwentyfour/parts/header.html

The plugin should use wp_normalize_path when forming this array.

@siliconforks
Copy link
Author

The plugin should use wp_normalize_path when forming this array.

That's what QM_Util::standard_dir does (among other things). Query Monitor performs

$file = QM_Util::standard_dir( $file );

but it does it too late, because it has already used $file before then.

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

No branches or pull requests

2 participants