Deprecated strlen() issued during `wp_head` processing when `core/query` block doesn't include core/query-pagination-next or previous
- [x] I've read and understood the contribution guidelines.
- [x] I've searched for any related issues and avoided creating a duplicate issue.
Please give us a description of what happened
For PHP 8.1 and above, for WordPress 6.2 and higher, if your content includes a core/query block that doesn't inherit the main query, and if there isn't a core/query-pagination-next or core/query-pagination-previous block then the following deprecated message is issued.
Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated
in C:\apache\htdocs\wp55\wp-includes\html-api\class-wp-html-tag-processor.php on line 544
In my case, the Deprecated message is issued twice; once each for prev and next.
To Reproduce
Step-by-step reproduction instructions
- Create a page containing the following query block
<!-- wp:query {"queryId":7,"query":{"perPage":3,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"exclude","inherit":false},"displayLayout":{"type":"flex","columns":3},"layout":{"type":"flex","columns":3}} -->
<div class="wp-block-query"><!-- wp:post-template -->
<!-- wp:group {"tagName":"main","style":{"spacing":{"padding":{"top":"30px","right":"30px","bottom":"30px","left":"30px"}}},"layout":{"inherit":false}} -->
<main class="wp-block-group" style="padding-top:30px;padding-right:30px;padding-bottom:30px;padding-left:30px"><!-- wp:post-title {"isLink":true} /-->
<!-- wp:post-excerpt {"wordCount":20} /-->
<!-- wp:post-date /-->
<!-- wp:post-featured-image /--></main>
<!-- /wp:group -->
<!-- /wp:post-template --></div>
<!-- /wp:query -->
- Save.
- View.
- The Deprecated messages are displayed.
Expected results
- No Deprecated messages
Actual results
Two deprecated messages are displayed.
Screenshots, screen recording, code snippet
Technical info
Output from the oik-bwtrace plugin.
C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\includes\bwtrace-actions.php(286:2) bw_trace_error_handler(1) 125 1 2023-12-07T11:30:50+00:00 1.216485 0.042415 cf=wp_head,wpseo_head,wpseo_adjacent_rel_url 29690 93 781 58720256/58720256 256M F=1116 err Array
[0] => (integer) 8192
[1] => (string) "Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated"
[2] => (string) "C:\apache\htdocs\wp55\wp-includes\html-api\class-wp-html-tag-processor.php"
[3] => (integer) 544
@#:0 33 0
0. bw_lazy_backtrace C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\libs\bwtrace.php:108 0
1. bw_backtrace C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\includes\bwtrace-actions.php:293 0
2. bw_trace_error_handler(8192,strlen(): Passing null to parameter #1 ($string) of type string is deprecated,C:\apache\htdocs\wp55\wp-includes\html-api\class-wp-html-tag-processor.php,544) C:\apache\htdocs\wp55\wp-includes\html-api\class-wp-html-tag-processor.php:544 4
3. next_tag(array) C:\apache\htdocs\wordpress\wp-content\plugins\wordpress-seo\src\integrations\front-end-integration.php:327 1
4. adjacent_rel_url(,prev,object) C:\apache\htdocs\wp55\wp-includes\class-wp-hook.php:324 3
5. apply_filters(,array) C:\apache\htdocs\wp55\wp-includes\plugin.php:205 2
6. apply_filters(wpseo_adjacent_rel_url,,prev,object) C:\apache\htdocs\wordpress\wp-content\plugins\wordpress-seo\src\presenters\rel-prev-presenter.php:70 4
7. get C:\apache\htdocs\wordpress\wp-content\plugins\wordpress-seo\src\presenters\abstract-indexable-tag-presenter.php:37 0
8. present C:\apache\htdocs\wordpress\wp-content\plugins\wordpress-seo\src\presenters\rel-prev-presenter.php:39 0
9. present C:\apache\htdocs\wordpress\wp-content\plugins\wordpress-seo\src\integrations\front-end-integration.php:409 0
10. present_head() C:\apache\htdocs\wp55\wp-includes\class-wp-hook.php:324 1
11. apply_filters(,array) C:\apache\htdocs\wp55\wp-includes\class-wp-hook.php:348 2
12. do_action(array) C:\apache\htdocs\wp55\wp-includes\plugin.php:517 1
13. do_action(wpseo_head) C:\apache\htdocs\wordpress\wp-content\plugins\wordpress-seo\src\integrations\front-end-integration.php:383 1
14. call_wpseo_head() C:\apache\htdocs\wp55\wp-includes\class-wp-hook.php:324 1
15. apply_filters(null,array) C:\apache\htdocs\wp55\wp-includes\class-wp-hook.php:348 2
16. do_action(array) C:\apache\htdocs\wp55\wp-includes\plugin.php:517 1
17. do_action(wp_head) C:\apache\htdocs\wp55\wp-includes\general-template.php:3052 1
18. wp_head C:\apache\htdocs\wp55\wp-includes\template-canvas.php:17 0
19. include(C:\apache\htdocs\wp55\wp-includes\template-canvas.php) C:\apache\htdocs\wp55\wp-includes\template-loader.php:106 1
20. require_once(C:\apache\htdocs\wp55\wp-includes\template-loader.php) C:\apache\htdocs\wp55\wp-blog-header.php:19 1
21. require(C:\apache\htdocs\wp55\wp-blog-header.php) C:\apache\htdocs\wp55\index.php:17 1
Analysis
wpseo_adjacent_rel_url is being invoked with parameters
[0] => (string) ""
[1] => (string) "prev"
[2] => Yoast\WP\SEO\Presentations\Indexable_Static_Home_Page_Presentation Object
and is implemented by Yoast\WP\SEO\Integrations\Front_End_Integration::adjacent_rel_url
In class Front_End_Integration both $this->next and $this->prev are null.
The page contains a core/query block, which does not inherit the main query block, but neither core/query-pagination-next nor core/query-pagination-previous. The code in query_loop_next_prev seems to assume that since there's a core/query block that isn't the main query then there'll be core/query-pagination-next and core/query-pagination-previous blocks that can be used to create adjacent rel links.
Since neither $this->next or $this-prev are initialised to empty strings, I suggest that the filter function adjacent_rel_url should be changed to return early when either $this->next or $this->prev are null.
public function adjacent_rel_url( $link, $rel, $presentation = null ) {
if ( $link === \home_url( '/' ) ) {
return $link;
}
if ( $rel === 'next' || $rel === 'prev' ) {
if ( null === $this->$rel ) {
return '';
}
...
- If relevant, which editor is affected (or editors):
- [x] Block Editor
- [x] Gutenberg Editor
- [ ] Elementor Editor
- [ ] Classic Editor
- [ ] Other:
- Which browser is affected (or browsers):
- [ ] Chrome
- [ ] Firefox
- [ ] Safari
- [ ] Other:
Used versions
- Device you are using: WIndows laptop
- Operating system: Windows 11
- PHP version: 8.1, 8.2 and 8.3
- WordPress version: 6.4.2 - but problem started with 6.2
- WordPress Theme: thisis
- Yoast SEO version: 21.6
- Gutenberg plugin version:
- Elementor plugin version:
- Classic Editor plugin version:
- Relevant plugins in case of a bug:
Hi @bobbingwide
Thanks for using the Yoast SEO plugin and creating an issue.
I tried to reproduce this on my lab site using the Query Loop block. However I was not able to see the deprecated message on the logs. I also tried the code you have shared on my site, but it causes an error when trying to change to the Block. So can you please confirm whether you have tested with the default theme Twenty Twenty Two or Twenty Twenty Three and only with the Yoast SEO plugin as activated?
We look forward to hearing from you.
Closing this issue due to inactivity. If the issue persists, please provide additional information so that we can investigate it further.
@josevarghese I have seen this also, and just tried to reproduce it in a couple of clean, new environments. I created an empty site on WP Engine, PHP 8.2.14, with the default theme, only Yoast SEO enabled, enabled WP_DEBUG, and added a posts query (not inheriting the query) to a page. No deprecation warning.
I then created the closest environment in LocalWP on my Windows desktop (PHP 8.2.10, nginx, mysql8). The deprecation warning is present. The warning is present on other LocalWP sites as well.
Just a plus one from me. I'm seeing this on php 8.2.17, plugin version 22.3, WP 6.4.3.
To add to this, Xdebug is giving me the following:
PHP Debug has encountered an exception:
Yoast\WP\SEO\Exceptions\Indexable\Author_Not_Built_Exception: Indexable for author with id 1 is not being built, since author archives are disabled.
And after that the error that we're talking about (times two):
PHP Debug has encountered an exception:
Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated
PHP Debug has encountered an exception:
Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated
Followed by another
PHP Debug has encountered an exception:
Yoast\WP\SEO\Exceptions\Indexable\Author_Not_Built_Exception: Indexable for author with id 1 is not being built, since author archives are disabled.
I'm thinking they're related, but am not knowledgeable about this plugin to know much about it.
Hi @bhdd and @mevanloon
This issue you both have mentioned is already opened at here: https://github.com/Yoast/wordpress-seo/issues/21256
Thanks for that. This original issue stems from December 2023, the issue you linked is two weeks old. But happy to see it's being worked on.
If you look at my block https://github.com/Yoast/wordpress-seo/issues/20922#issue-2030780058 you'll see I didn't have query pagination either.
Please hurry up and fix #21256