WordPress.org

Forums

WP Mail From breaks Contact Form 7 (4 posts)

  1. shinerweb
    Member
    Posted 5 years ago #

    I'm using [WP Mail From] (ver 0.5) plugin to change the default "From" as used by the WordPress installation.

    Unfortunately, this interacts with [Contact Form 7] in that when I use a From field set with [your-name] <[your-email]> , (assuming variables your-name and your-email are set), these get overridden by [WP Mail From] plugin.

    The [WP Mail From] uses the filter hooks wp_mail_from and wp_mail_from_name and a priority of 1.

    I am assuming that [Contact Form 7] is also using the same filter hooks (wp_mail_from and wp_mail_from_name) to override the WP Default settings (with the values set in [your-name] <[your-email]> in this case).

    What I am after is a method of changing the priority of [Contact Form 7] to a higher value than that of [WP Mail From]

    This will allow [Contact Form 7] to take priority over the default system settings. (It will also allow [Contact Form 7] to function alongside [WP Mail From] plugin.

    I think changes are required in function compose_and_send_mail( $mail_template ) (in classes.php).
    It already uses wp_mail, but it does not use the filter hooks wp_mail_from and wp_mail_from_name to set the sender.
    If it set the filter hooks wp_mail_from and wp_mail_from_name with a priority >1 it would take prescendance over [WP Mail From] and function correctly.

    erm.. I hope that makes sense...

    Regards

    Chris

    http://wordpress.org/extend/plugins/contact-form-7/

  2. Takayuki Miyoshi
    Member
    Posted 5 years ago #

    Chris, thanks, but I don't think its a good solution. I afraid it can make it more complicated.

  3. shinerweb
    Member
    Posted 5 years ago #

    But since WordPress 1.5.1+ you should (and) have been using the add_filter function to change the value of wp_mail_from and wp_mail_from_name

    This allows your plugin to safely interact with other plugins that may also alter the same variable(s).

    Like so:

    add_filter('wp_mail_from','site_mail_from',x);
    add_filter('wp_mail_from_name','site_mail_from_name',x);

    where x is the priority.

    The 3rd parameter is the priority. This is important as it allows the interaction with other plugins.

    see:
    http://phpdoc.wordpress.org/trunk/WordPress/Plugin/_wp-includes---plugin.php.html#functionadd_filter

    Because your plugin uses wp_mail, you are therefore using wp_mail_from and wp_mail_from_name, so you should really use the methods which allow the rest of the system to use it too.
    What you are doing at the moment is in fact over riding the default system settings when you call wp_mail ignoring any other 'modules'

    By ignoring the priority of the other parts of the system, I'd argue it's your plugin at fault.

    See wp_mail info at http://phpdoc.wordpress.org/trunk/WordPress/_wp-includes---pluggable.php.html#functionwp_mail

    Note:

    uses: apply_filters() - Calls 'wp_mail_from' hook to get the from email address.

    uses: apply_filters() - Calls 'wp_mail_from_name' hook to get the from address name.
    You already do call apply_filters:

    extract( apply_filters( 'wpcf7_mail_components',
    compact( 'subject', 'sender', 'body', 'recipient', 'additional_headers' ) ) );

    But you are not allowing the changing of the priority.
    This means your plugin isn't compatible with other plugins that also change those variables.
    At the moment, because you don't set the priority, it defaults to '0'
    This means that what ever you set it to using apply_filters is then overridden by other plugins.

    As for making it more complicated, all you need to do is have a default priority >1 and perhaps allow users to change it via settings if required.

  4. Takayuki Miyoshi
    Member
    Posted 5 years ago #

    I suppose it's a misunderstanding.

    What you are doing at the moment is in fact over riding the default system settings when you call wp_mail ignoring any other 'modules'

    But you are not allowing the changing of the priority.

    I can't get why you think so. Contact Form 7 never override default system settings nor block the changing of priorities.

    Please check the source codes carefully.

    You can't control the priority on the apply_filters().

    http://core.trac.wordpress.org/browser/tags/2.8.4/wp-includes/plugin.php#L134

    While you can set it with the add_filter(). And its default priority is 10, not 0.

    http://core.trac.wordpress.org/browser/tags/2.8.4/wp-includes/plugin.php#L65

    If you need to apply or add any filters, do so. Nothing blocks you.

    The 'wpcf7_mail_components' hook you mentioned is completely different thing from 'wp_mail_from' and 'wp_mail_from_name'. There is no relation between them.

    What I want to say is that, I don't think it makes sense changing priority of filter just for getting around a conflict with a specific plugin (in this case WP Mail From). If you change the priority for plugin A, it can make another conflict with plugin B. I meant it by making it more complicated.

Topic Closed

This topic has been closed to new replies.

About this Topic