PHP Warning missing Argument 1 for __()
Question
I am getting this error in my server error logs:
[Thu Dec 11 10:06:30 2014] [error] [client 11.111.111.111] PHP Warning: Missing argument 1 for __(), called in /var/www/vhosts/mysite.org/public_html/wp-content/themes/mysite_v2.2/functions-cpt-projects.php on line 15 and defined in /var/www/vhosts/mysite.org/public_html/wp-includes/l10n.php on line 146, referer: http://www.mysite.org/wp-admin/edit.php
I've never encountered this before and I'm wondering what might be causing it. The line of code it refers to in the l10n.php
file is:
function __( $text, $domain = 'default' ) {
return translate( $text, $domain );
}
I'm wondering if anyone knows how I might go about debugging this? I read somewhere that it could be related to a plugin and to disable them one by one to find out if the issue is resolved but this has not worked for me as of yet.
Solution
you get this error if you passed empty string or did not pass any argument to the __()
function.
You should check where you've used the __()
function and check what value is being passed as argument.
OTHER TIPS
I had a similar problem.
The issue was with a Custom Post Type and the solution was that the _x() translation function needed context (the 'missing argument') for a single word that has multiple meanings.
Example: Custom Post Type "Members" threw this error:
Warning: Missing argument 2 for _x(), called in /wp-content/plugins/my-cpt/posttypes.php on line 29 and defined in /Users/SITE-NAME/Sites/THEME-NAME/wp-includes/l10n.php on line 294
Without context, my Custom Post Type looked like this:
The 'Members' name/s were throwing all the errors because without context, (the second argument taken by the _x() function), translators might not know which Member I was referring to.
For Example:
- Member - Someone or something that belongs to a group or an organization?
- Member - A part of a structure?
- Member - A body part, such as an arm or a leg?
So I added context:
And the error messages went away.