WordPress.org

Support

Support » Plugins and Hacks » Hacks » $this->WP_Widget() syntax

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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 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' ); ?>

    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.wordpress.org/I18n_for_WordPress_Developers

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

    You’re welcome.. 😉

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘$this->WP_Widget() syntax’ is closed to new replies.