$this->WP_Widget() syntax (5 posts)

  1. Ryan
    Posted 5 years ago #

    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.

  2. Ryan
    Posted 5 years ago #

    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?

  3. Mark / t31os

    Posted 5 years ago #

    - 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 name

    If 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' ); ?>


    $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).

  4. Ryan
    Posted 5 years ago #

    Got it Mark. That was fast!! Many thanks for the info.

  5. Mark / t31os

    Posted 5 years ago #

    You're welcome.. ;)

Topic Closed

This topic has been closed to new replies.

About this Topic