admin管理员组文章数量:1429575
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.
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.
Share Improve this question edited Dec 21, 2016 at 9:11 bueltge 17.1k7 gold badges62 silver badges97 bronze badges asked Dec 21, 2016 at 9:01 Alex CAlex C 1013 Answers
Reset to default 0While 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.
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.
There's absolutely nothing wrong with calling wp_mail()
in a theme. It's a core function that is meant to be used.
本文标签: theme developmentIs wpmail plugin territory
版权声明:本文标题:theme development - Is wp_mail plugin territory? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745486371a2660401.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论