• Resolved TheRealMikeD

    (@therealmiked)


    Hi Everyone,

    Very cool plug-in. It works just fine when pasting the shortcode into post content. But when trying to call do_shortcode() from within PHP code in the theme, I get the following error message:
    Notice: Undefined index: dae_settings in /(full path redacted)/wp-content/plugins/download-after-email/includes/shortcodes.php on line 334.

    Line 334 contains the following code:
    $dae_settings = $GLOBALS['dae_settings'][ $download_id ];

    So it looks like that global variable does not get initialized prior to usage in this case. In addition to the error message, an incomplete version of the form is displayed, which makes sense, looking at the plugin code surrounding the line where the error was reported. Only the title and primary content text are filled in. Everything else is empty HTML elements.

    Please let me know if this is something that I can work around or if it requires an update to the plugin.

    Thanks!

    • This topic was modified 4 years, 11 months ago by TheRealMikeD.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter TheRealMikeD

    (@therealmiked)

    So I was able to patch this issue by augmenting the problematic code as follows:

    if (isset($GLOBALS['dae_settings'])) {
        $dae_settings = $GLOBALS['dae_settings'][ $download_id ];
    } else {
        $dae_settings = get_post_meta( $download_id, 'dae_settings', true );
    }

    With this patch, all the HTML gets output correctly when calling do_shortcode() from the theme’s PHP code. The inline CSS does NOT get output in this case, but as a theme developer, I actually like it better this way. It allows me to write my own CSS that will be consistent throughout the theme without having to use !important to override a lot of styles.

    Plugin Author mkscripts

    (@mkscripts)

    Hi there,

    Good to hear that you like our plug-in.

    This is the right way to work around it, but we will adjust this behaviour with the next update, so this patch is no longer needed. That way it’s easier to implement the shortcode by using do_shortcode().

    The CSS is indeed not loaded via the shortcode function. We will leave it this way so that you always have the possibility to write the CSS yourself.

    Thanks for noticing. If you have any more questions, feel free to ask.

    Best regards,
    Team Download After Email

    Thread Starter TheRealMikeD

    (@therealmiked)

    Cool. I will leave my patch in place until you release an updated version that includes this fix.

    Thanks!

    Plugin Author mkscripts

    (@mkscripts)

    Since version 2.0.3 the CSS styling options are loaded via the do_shortcode() function by default. To disable the CSS styling options, you can use a new shortcode attribute: css=”off”.

    Thread Starter TheRealMikeD

    (@therealmiked)

    The new attribute works well. Thanks for letting me know!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Error When Using do_shortcode’ is closed to new replies.