Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Need a quick explanation... WordPress


echo '<input type="hidden" name="myplugin_noncename" id="myplugin_noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';

echo '<label for="myplugin_new_field">' . __("Description for this field", 'myplugin_textdomain' ) . '</label> ';

Ok, so these bits were taken from the example provided on:

What does <strong>"__FILE__"</strong> and <strong>"__("Description for this field", 'myplugin_textdomain' )"</strong> do? What does the "__" do or signify?


So what is the second parameter ('myplugin_textdomain') of the __() function?

Answers (4)


Ron Rennick answers:

__FILE__ is the full path to the currently executing PHP file.

__ does the same as _e except it returns the translated string instead of echoing it. So, __ translates the string to the current language.


Brian Richards answers:

The second parameter of the localization string provides a reference point for translation, as in, what dictionary to use for translating the text.

If supplied, this GetText will return the translations only from the dictionary that you supply with that domain name. Although optional, specifying the translation domain is highly recommended. Without it, GetText might return a different translation, if the same string also appears in a different plugin, or in WordPress.


Brian Richards answers:

__("Description for this field", 'myplugin_textdomain' ) is a localization string, helpful for translating. You can learn more about that here: [[LINK href=""]][[/LINK]]

__FILE__ contains the current file name of the script

Bonus points:
__LINE__ contails the current line number in the script
__PATH__ contains the path to the current script


Ron Rennick answers:

There is a function you can use to register the language files for you plugin. The call looks like this:

load_textdomain( $domain, $mofile )

The domain would match the second parameter in the __( call.