0

I recently stumbled upon this and was wondering if calling wp_mail() in a theme is allowed or not as per WordPress standards. I should clarify that I'm not overriding it as a pluggable function in the theme, I am just calling it if it exists.

I'm asking here because I've been searching for this but did not find any clear answer stating anything like this.

0

While wp_mail() is not exactly forbidden in a theme, it is very likely misplaced there. The purpose of a theme is presentation. It should not change existing data, and it should always be easy to replace.

That's the reason why contact forms, polls, shops, tracking and similar functionality is pure plugin territory. There is no context for wp_mail() in a theme.

|improve this answer|||||
  • It's interesting, since this wordpress author who seems reputable writes the contrary: code.tutsplus.com/tutorials/…: "Pluggable functions are something you code into your parent theme, so they won't be any use to you if you're working with an existing parent theme that doesn't have them." – Alex C Dec 21 '16 at 9:20
  • @AlexC I am talking about wp_mail() only, not about pluggable functions in general. Albeit that is a terrible concept. – fuxia Dec 21 '16 at 9:22
0

WordPress provides a lot of functions you can use, including the wp_mail() function. The function is not only a plugin territory, the core uses it often.

If you will change the behavior, use the filter and actions hooks that are inside the core to influence the behavior of the function. As example for this function give it the filter hook wp_mail, see here in the source. That is a possibility to change the behavior of wp_mail().

The wp_mail() function is also pluggable and can be replaced by a new function with the same name. All functions in wp-includes/pluggable.php have a check if the function exists. That gives developers the chance to replace the function with changes to the functionality.

|improve this answer|||||
0

There's absolutely nothing wrong with calling wp_mail() in a theme. It's a core function that is meant to be used.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.