Home>Support>Seeking Clarity: Extending existing widgets Tutorial

Seeking Clarity: Extending existing widgets Tutorial


I am struggling to understand an item in the first code block of this tutorial.

function mytheme_extend_button_form( $form_options, $widget ){
    // Lets add a new theme option
    if( !empty($form_options['design']['fields']['theme']['options']) ) {
        $form_options['design']['fields']['theme']['options']['test'] = __('Test Style', 'mytheme');

    return $form_options;
add_filter('siteorigin_widgets_form_options_sow-button', 'mytheme_extend_button_form', 10, 2);

What is the ‘mytheme’ string argument on the 4th line? What is it pointing to? `mytheme` isn’t mentioned anywhere else in the tutorial, and I certainly haven’t named anything `mytheme` in my code. Yet, the hook still works and still adds the new `Test Style` option to the widget. I understand that, in this 4th line, we are accessing the `options` array, and adding a fourth item, `’test’ => ‘Test Style’`. I *think* that the `__( $arg1, $arg2 )` portion is some sort of shorthand that alters the constructor (please correct me if I’m wrong and provide a resource so I can learn). But what that second argument does completely eludes me – what is it?

Thanks for the clarity.

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 4 months, 12 days ago Andrew Misplon Hi, I Work Here

    Hi Timothy

    Thanks for reaching out.

    You can replace mytheme with your theme prefix, for example, if this function was in SiteOrigin Corp we’d change the function to:

    function siteorigin_corp_extend_button_form

    The same would apply if you were using the function in a plugin.

    The second argument is the text domain for translation purposes:

  2. 4 months, 12 days ago Andrew Misplon Hi, I Work Here

    Hopefully, the above helps. If you have any follow-up questions, please, let us know.

  3. 4 months, 11 days ago Timothy Andes

    This is great, thank you. This question may be my lack of experience with OOP and/or PHP, but if you didn’t need to set this up for internationalization, would line 4 just be

    $form_options['design']['fields']['theme']['options']['test'] = 'Test Style'

    , or

    $form_options['design']['fields']['theme']['options']['test'] = __('Test Style');

    ? Still not sure if the __( ) is a gettext- or constructor-related syntax

  4. 4 months, 11 days ago Alex S Hi, I Work Here

    Hi Timothy,

    Both are fine. If you don’t intend to offer additional language support I would personally not use __() as It’s easier just to output the text directly.

    __() is a PHP function, and it’s an indirect method of using gettext. For more information, please refer to this page.

    Kind regards,

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More