• Resolved sarahtopfstaedt

    (@sarahtopfstaedt)


    Hi there,

    I used custom tabs to extend the profiles. I integrated the newsletter forms from the Newsletter plugin. Every shortcode is working fine, except the subscription form with the shortcode [newsletter_form].

    Can you tell me what I’m doing wrong?

    /* Add multiple new tabs */
    add_filter('um_account_page_default_tabs_hook', 'custom_tabs_in_um', 100);
    function custom_tabs_in_um($tabs) {
    // Newsletter Tab
    $tabs[800]['newsletter'] = array(
    'icon' => 'um-faicon-newspaper-o',
    'title' => 'Newsletter neu/erstmals abonnieren',
    'custom' => true,
    'show_button' => false
    );

    // Newsletter-Abo Tab
    $tabs[801]['newslettersettings'] = array(
    'icon' => 'um-faicon-cog',
    'title' => 'Newsletter-Abo verwalten',
    'custom' => true,
    'show_button' => false
    );

    // Newsletter-Abmelden Tab
    $tabs[802]['unsubscribe'] = array(
    'icon' => 'um-icon-android-cancel',
    'title' => 'Newsletter abmelden',
    'custom' => true,
    'show_button' => false
    );

    // Weitere Tabs können hier hinzugefügt werden
    return $tabs;
    }

    /* Make our new tabs hookable */
    add_action('um_account_tab__newsletter', 'um_account_tab__newsletter');
    add_action('um_account_tab__newslettersettings', 'um_account_tab__newslettersettings');
    add_action('um_account_tab__unsubscribe', 'um_account_tab__unsubscribe');

    function um_account_tab__newsletter($info) {
    global $ultimatemember;
    echo $ultimatemember->account->get_tab_output('newsletter');
    }

    function um_account_tab__newslettersettings($info) {
    global $ultimatemember;
    echo $ultimatemember->account->get_tab_output('newslettersettings');
    }

    function um_account_tab__unsubscribe($info) {
    global $ultimatemember;
    echo $ultimatemember->account->get_tab_output('unsubscribe');
    }

    /* Content for "Newsletter" tab */
    add_filter('um_account_content_hook_newsletter', 'um_account_content_hook_newsletter');
    function um_account_content_hook_newsletter($output) {
    ob_start();
    ?>
    <div class="um-field">
    <p>Hier können Sie unseren Newsletter abonnieren. Bitte füllen Sie dieses Formular nur aus, wenn Sie bisher keinen Newsletter über unsere Webseite abonniert haben. Zum Verwalten eines bestehenden Abos klicken Sie bitte auf den Tab "Newsletter-Abo verwalten".</p>
    <?php echo do_shortcode('[newsletter_form /]'); ?>
    </div>
    <?php
    return $output . ob_get_clean();
    }

    /* Content for "Settings" tab */
    add_filter('um_account_content_hook_newslettersettings', 'um_account_content_hook_newslettersettings');
    function um_account_content_hook_newslettersettings($output) {
    ob_start();
    ?>
    <div class="um-field">
    <p>Hier können Sie Ihr bestehendes Newsletter-Abo verwalten.</p>
    <?php echo do_shortcode('[newsletter_profile]'); ?>
    </div>
    <?php
    return $output . ob_get_clean();
    }

    /* Content for "Unsubscribe" tab */
    add_filter('um_account_content_hook_unsubscribe', 'um_account_content_hook_unsubscribe');
    function um_account_content_hook_unsubscribe($output) {
    ob_start();
    ?>
    <div class="um-field">
    <p>Hier können Sie sich von Ihrem Newsletter abmelden. Sie erhalten dann keinen Newsletter mehr.</p>
    <br>
    <?php echo do_shortcode('[newsletter_unsubscribe_button label="Abmelden" /]'); ?>
    </div>
    <?php
    return $output . ob_get_clean();
    }

Viewing 7 replies - 1 through 7 (of 7 total)
  • @sarahtopfstaedt

    From WP version 5.4.0 we are using the apply_shortcodes function.

    https://developer.wordpress.org/reference/functions/apply_shortcodes/

    Code example

           if ( version_compare( get_bloginfo( 'version' ), '5.4', '<' ) ) {
                echo do_shortcode( '[ultimatemember form_id="' . $login_form_id . '"/]' );
            } else {
                echo apply_shortcodes( '[ultimatemember form_id="' . $login_form_id . '"/]' );
            }
    Thread Starter sarahtopfstaedt

    (@sarahtopfstaedt)

    Actually, the code works fine. Only the [newsletter_form /] only works if I add the tab twice – and then only the second tab is working. I tested it with apply_shortcodes – the issue is the same.

    @sarahtopfstaedt

    When testing I get the “Newsletter neu/erstmals abonnieren” OK
    with email field and a send button.

    Applying for membership will give this PHP error
    and you must add a nonce hidden field to your newsletter form.

    Undefined array key "um_account_nonce_newsletter" in .../wp-content/plugins/ultimate-member/includes/core/um-actions-account.php on line 20

    Turn on debug logging when you develop new code.

    https://docs.ultimatemember.com/article/1751-enable-debug-logging

    Thread Starter sarahtopfstaedt

    (@sarahtopfstaedt)

    The shortcode on frontend is not the problem – as I said, only if I add the custom tab twice, I can subscribe for the newsletter without an error. And that’s what is strange for me. I used the custom code for extend the Ultimate Member Tabs from the documentation and wonder what’s the problem in my specific case.

    Plugin Support Yurii

    (@yuriinalivaiko)

    Hello @sarahtopfstaedt

    The code you use does not extend the profiles. This code extends the accounts. There is no way to add forms into account because HTML does not allow placing a form into another form.

    I recommend you add a form you need into the custom profile tab. This should work. See example here: Extending Ultimate Member Profile Menu using Hooks

    Regards

    Thread Starter sarahtopfstaedt

    (@sarahtopfstaedt)

    Thanks a lot! Now it`s working and it clearify a lot for me 🙂

    Plugin Support Yurii

    (@yuriinalivaiko)

    Hi @sarahtopfstaedt

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. 🙂

    Regards

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Custom tabs for Newsletter forms’ is closed to new replies.