WordPress.org

Ready to get started?Download WordPress

Forums

Possible to add filter based on if statement? (email - wordpress@) (2 posts)

  1. Norbert McDorbert
    Member
    Posted 1 year ago #

    I understand filters on a basic level. I can replace the from email option

    However, is it possible to apply a filter in a functions.php or mu plugin when its conditional.

    Ie, I want to allow plugins to give people the option on modifying the from address, and I only wish to replace the from of wordpress@domain.com if from == wordpress

    Is that an option?

  2. bcworkz
    Member
    Posted 1 year ago #

    Not sure if mu mail address filters differ, but something along this line.

    function mcd_mail_from($from) {
      if ('wordpress@domain.com' == $from) $from = 'norbert@domain.com';
      return $from
    }
    add_filter( 'wp_mail_from', 'mcd_mail_from' );

    Depending on what order the filters are added from various plugins, a different plugin could still change what you have set. Unfortunately, not all plugins are as polite as you and will arbitrarily change things no matter what. Kudos for being considerate of others.

Topic Closed

This topic has been closed to new replies.

About this Topic