$this->WP_Widget() syntax
-
This may be a dumb question but I have been unable to find a reasonable description in the Codex or online…
In the Widget example there is in the constructor function the following line…
$this->WP_Widget( 'example-widget', __('Example Widget', 'example'), $widget_ops, $control_ops );I am wondering what the ‘example-widget’ and __(‘Example Widget’, ‘example’) are for. The $widget_ops and $control_ops I have been able to decipher from online material but the first two I am not sure about. It seems that sometimes these are included and other times they are not.
If anyone could provide information, a link to the the codex where this is covered or anything at all please let me know.
All the best.
-
UPDATE: I found some information in trunk/wp-includes/widgets.php but I am not sure I am interpreting it correctly.
the ‘example-widget’ part is a Base-ID?
the __(‘Example Widget’, ‘example’) is the Name of the widget?
example-widget
– the slug for the widget__('Example Widget', 'example')– the value in this case is the widget display name (slugs are for reference, all lowercase and hyphens in place of spaces)
– a translatable string
– first part is the string/text
– second part is the text domain nameIf my theme registered a text domain(what you register to make a theme or plugin translation ready) with the name
bob(for example), i’d wrap all pieces of text like this..<?php _e( 'some text i\'m echoing and making translatable', 'bob' ); ?>or
<?php $var = __( 'some text being stored in a var for translation', 'bob' ); ?>If you have no need for translation, just drop the translation wrapper/function-call..
__('Example Widget', 'example')Can be..
'Example Widget'More on translation here (if it’s of interest).
http://codex.ww.wp.xz.cn/I18n_for_WordPress_DevelopersGot it Mark. That was fast!! Many thanks for the info.
You’re welcome.. 😉
The topic ‘$this->WP_Widget() syntax’ is closed to new replies.