Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to prevent output of <img> in mail notifications for media attachments #521

Open
ginocremer opened this issue Feb 22, 2021 · 1 comment

Comments

@ginocremer
Copy link

ginocremer commented Feb 22, 2021

Hello Sven, a customer asked us to customize the email notifications. Specifically, there should be no direct tags within the email. Instead, only the URL to the image should be linked (instead of outputting a whole image). The output of the image apparently causes problems in various email clients.

In the file src/db-objects/elements/element-types/base/media.php on line 106 you will find the hardcoded entry with

$output = '<img src="' . $image_url . '" style="max-width:300px;height:auto;" />';

How can we specifically change the output there without having to touch the plugin code?

@ginocremer
Copy link
Author

We got it working by using this code

function pix_filter_attachment_torro( $value, $element ){

        if (strpos($value, '<img') !== false) {
                $doc = new DOMDocument();
                $doc->loadHTML($value);
                $imageTags = $doc->getElementsByTagName('img');

                foreach($imageTags as $tag) {
                    $value = '<a href="'.$tag->getAttribute('src').'">'.$tag->getAttribute('src').'</a>';
                    break;
                }
        }


        return $value;
}
add_filter( 'torro_export_value', 'pix_filter_attachment_torro' , 10, 2 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant