• Resolved bisdanner

    (@bisdanner)


    Hi,

    first, thanks for this great plugin.

    I try to execute my own shortcode (in function.php of child-theme) in forminator fields, but the shortcode isn’t replaced or processed.

    I use a form where an user can put name and email to generate a personal certificate. This certificate, created by e2pdf, is attached to the email by e2pdf-shortcode. This works very well.

    Now I would like to add a second attachment to the email, namely the featured image of the post in which the form is embedded. I tried a shortcode [add_feature_image post={embed_id}]:

    function insert_featuredimage_url( $atts , $content = null ) {
        $output='';
        $a = shortcode_atts([
            'post' => '',
            ], $atts);
        $post_id = isset($atts['post']) ? (int) $atts['post'] : false;
        if($post_id) {
            $output = get_the_post_thumbnail_url((int) $post_id, 'full');
        }
        return $output;
    }
    add_shortcode( 'add_feature_image', 'insert_featuredimage_url' );

    But all I get is [add_feature_image post=12345]. The embed-id is replaced but the shortcode isn’t processed, I guess.

    The shortcode is working btw, I added the [add_feature_image post=12345] to the post and the url is showing.

    Do you have any ideas?

    • This topic was modified 2 years, 6 months ago by bisdanner.
    • This topic was modified 2 years, 6 months ago by bisdanner.
    • This topic was modified 2 years, 6 months ago by bisdanner.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hello @bisdanner

    I am sorry to hear about the issue you’re experiencing. Thank you for the elaborate information.

    I have pinged our SLS team so that they can review your query and see what can be possible in this case. We will post an update here as soon as more information is available.

    Kind Regards,
    Saurabh

    Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hello @bisdanner

    I have an update from the SLS team and instead of using the shortcode, can you please use the below snippet as a “mu-plugin” and check if that helps, please try this on the staging/dev site first if possible.

    <?php
    add_filter( 'forminator_custom_form_mail_admin_message', 'wpmudev_send_post_image_mail', 10, 5 );
    function wpmudev_send_post_image_mail( $message, $custom_form, $data, $entry, $cls_mail ) {
        if ( $custom_form->id != 6 ) { //Please change the form ID
            return $message;
        }
    
        $thumbnail = '';
    
        if ( ! empty( $data['page_id'] ) ) {
            $thumbnail = get_the_post_thumbnail_url($data['page_id']);
        }
    
        if ( $thumbnail ) {
            $replaced_img = "<img src='$thumbnail'/>";
            if ( strpos( $message, '{post_image}' ) !== false ) {
                $message = str_replace( '{post_image}', $replaced_img, $message );
            }       
        }
    
        return $message;
    }

    However, before you directly add it, you will need to update the form ID 6 in the line ( $custom_form->id != 6 ) with your Forminator form ID.

    Save the file and then add it as a mu-plugin inside the /wp-content/mu-plugins/ directory. Here is a guide about how you can add mu-plugins: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Once added, you can place the {post_image} macro in your email notification content to add the post thumbnail where you want it.

    Hope this helps.

    Kind Regards,
    Saurabh

    Thread Starter bisdanner

    (@bisdanner)

    Hello Saurabh,

    thanks for reply and the update from SLS.
    I’ve added the code in mu-plugins and used {post_image} macro in my email notification.
    Now it works pretty well. The image is embedded into the email message and not into the attachment, but that’s okay with me.

    Thanks a lot for the fast reply and offering a solution. Great work, great plugin, great support.

    Best regards
    Bisdanner

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

The topic ‘Shortcode not working in HTML or Email notification’ is closed to new replies.