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

Comments - missing argument in comments.php function #2107

Open
mleathem opened this issue Mar 16, 2023 · 9 comments
Open

Comments - missing argument in comments.php function #2107

mleathem opened this issue Mar 16, 2023 · 9 comments

Comments

@mleathem
Copy link

Fatal error - is generated from line 37 of understrap\comments.php

**Understrap seems to be missing an argument - post with comment displays error message **

Wordpress new install (v. 6.1.1 ) - the default post with comment (vanilla install), after activating the theme, an error message is shown instead of the comment. (applies also to a child theme of course).

Fatal error: Uncaught ArgumentCountError: 3 arguments are required, 2 given in [localpath-to-wordpress]\wp-content\themes\understrap\comments.php:37 S tack trace: #0 [localpath-to-wordpress]\wp-content\themes\understrap\comments.php(37): printf('Ein Gedanke zu ...', '<span>Hallo Wel...') #1 [localpath-to-wordpress]\wp-includes\comment-template.php(1550): require('[localpath-to-server]\...') #2 [localpath-to-wordpress]\wp-content\themes\understrap\single.php(36): comments_template() #3 [localpath-to-wordpress]\wp-includes\template-loader.php(106): include('[localpath-to-server]\...') #4 [localpath-to-wordpress]\wp-blog-header.php(19): require_once('[localpath-to-server]\...') #5 [localpath-to-wordpress]\index.php(17): require('[localpath-to-server]\...') #6 {main} thrown in [localpath-to-wordpress]\wp-content\themes\understrap\comments.php on line 37

PS - In my case: comments will be deactivated (so no error will be shown) - HOWEVER relevant for any site using comments.

To Reproduce
Steps to reproduce the behavior:

  1. Install WP
  2. install and activate theme Understrap
  3. view frontend - page with comment.

Expected behavior
Comment should be shown

The Environment

  • WordPress Version: 6.1.1
  • OS Version: Laragon (windows)
  • Browser: all
  • Language: German (DE)
@IanDelMar
Copy link
Contributor

Thank you for reporting. Can you please share line 33-39 of your comments.php?

@IanDelMar
Copy link
Contributor

Also which PHP version are you using?

@mleathem
Copy link
Author

mleathem commented Mar 20, 2023

PHP version = 8.1.10

the comments.php file is unchanged Understrap Version: 1.2.2

this is lines 32 - 39 ( line 33 then starts with the if )


			$comments_number = get_comments_number();
			if ( 1 === (int) $comments_number ) {
				printf(
					/* translators: %s: post title */
					esc_html_x( 'One thought on “%s”', 'comments title', 'understrap' ),
					'' . get_the_title() . ''
				);
			} else {

@IanDelMar
Copy link
Contributor

I can't replicate the issue. Also, the error message Fatal error: Uncaught ArgumentCountError: 3 arguments are required, 2 given in [localpath-to-wordpress]\wp-content\themes\understrap\comments.php:37 is strange. comments.php does not call any function that requires 3 arguments.

Are you using a translation plugin? Does this happen with the Understrap theme (no child theme activated) and no plugins activated?

@1qubitde
Copy link

1qubitde commented Jun 6, 2023

Hi,

I have the same problem / error.

I testet on my staging system and the problem is also there with the Understrap theme activated (instead of child theme) and with all plugins disabled.

But it is only there if you have only one approved comment. Is the comment not approved the page is rendered without the error if you open it as an logged in administrator and see the comment.

If you set all comments except for one to not approved the error is shown again.

  • Wordpress 6.2.2
  • Understrap 1.2.2
  • PHP 8.1.19 / 64 Bit OS

Fatal error: Uncaught ArgumentCountError: 3 arguments are required, 2 given in [localpath-to-wordpress]/wp-content/themes/understrap/comments.php:37 Stack trace: #0 [localpath-to-wordpress]/wp-content/themes/understrap/comments.php(37): printf() #1 [localpath-to-wordpress]/wp-includes/comment-template.php(1591): require('[localpath]/...') #2 [localpath-to-wordpress]/wp-content/themes/understrap/single.php(36): comments_template() #3 [localpath-to-wordpress]/wp-includes/template-loader.php(106): include('[localpath]/...') #4 [localpath-to-wordpress]/wp-blog-header.php(19): require_once('[localpath]/...') #5 [localpath-to-wordpress]/index.php(17): require('[localpath]/...') #6 {main} thrown in [localpath-to-wordpress]/wp-content/themes/understrap/comments.php on line 37

@1qubitde
Copy link

1qubitde commented Jun 6, 2023

Hi again,

in line 36 of comments.php I changed

esc_html_x( 'One thought on &ldquo;%s&rdquo;', 'comments title', 'understrap' ),

to

esc_html_x( 'One thought on &ldquo;%1$s&rdquo;', 'comments title', 'understrap' ),

%s to %1$s

like in the else part for more than one comment.

With this change it is working.

@IanDelMar
Copy link
Contributor

comments.php does not call any function that requires 3 arguments.

except for esc_html_x() 😆 But it is called with 3 arguments.

But it is only there if you have only one approved comment. Is the comment not approved the page is rendered without the error if you open it as an logged in administrator and see the comment.

Still, I can't replicate this. I tested a post with exactly one comment and it works just fine. It also works for me with a post that has 1 comment approved and 1 comment unapproved.

%s to %1$s

This shouldn't do anything but breaking the translations because there are translations for 'One thought on &ldquo;%s&rdquo;' but not for 'One thought on &ldquo;%1$s&rdquo;'. Also, if you only replace %s by %1$s, you're not changing the number of arguments passed to esc_html_x().

@bacoords I have no idea what causes this. Do you have any idea?

@bacoords bacoords self-assigned this Oct 9, 2023
@bacoords
Copy link
Member

bacoords commented Oct 9, 2023

Just adding here that I've also been unable to replicate this error either. Wondering if anyone else is having it.

@bacoords bacoords removed their assignment Oct 9, 2023
@sheol77
Copy link

sheol77 commented Jan 2, 2024

Probably the error lies in the German translation file de_DE.po, where on line 89, placeholder 2$s is used instead of placeholder %s.

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

5 participants