admin管理员组文章数量:1332660
I’m creating and developing a new plugin for some of my private clients and I do want to see if my clients are sharing my plugin with other people (I asked them not to do that).
How can I do something in my plugin every time plugin is activated, his website sends an email from ‘[email protected]’ to one or more emails I want ‘[email protected]’ and ‘[email protected]’.
By the way, does this include if they update the plugin? Or I just would be able to see who activates only? And does it include the current activated plugin?
I’m creating and developing a new plugin for some of my private clients and I do want to see if my clients are sharing my plugin with other people (I asked them not to do that).
How can I do something in my plugin every time plugin is activated, his website sends an email from ‘[email protected]’ to one or more emails I want ‘[email protected]’ and ‘[email protected]’.
By the way, does this include if they update the plugin? Or I just would be able to see who activates only? And does it include the current activated plugin?
Share Improve this question asked Jul 18, 2020 at 12:51 SaeedSaeed 1091 gold badge1 silver badge5 bronze badges2 Answers
Reset to default 2I offer you an idea that I have already used something like this. I wanted to know the sites that my plugin uses, I created a cron job allow me to send me an email every week :
add_action('init', function() {
$time = wp_next_scheduled('dro_cron_hook');
wp_unschedule_event($time, 'dro_cron_hook');
if (!wp_next_scheduled('dro_cron_hook')) {
wp_schedule_event(time(), 'everyweek', 'dro_cron_hook');
}
});
add_filter('cron_schedules', function($schedules) {
$schedules['everyweek'] = array(
'interval' => 604800
);
return $schedules;
});
add_action('dro_cron_hook', function() {
// Here you can send the email using wp_mail() and some additional data
});
So there are two parts to your question:
- How to run code when your plugin is activated
- How to send an email
For item 1 I searched for 'wordpress plugin activation hook' and found https://developer.wordpress/plugins/plugin-basics/activation-deactivation-hooks/ which describes this hook so you can call your own fucntion when a plugin is activated:
register_activation_hook( __FILE__, 'pluginprefix_function_to_run' );
It is documented here: https://developer.wordpress/reference/functions/register_activation_hook/
For item 2, there are many examples of online of how to send email from PHP and/or inside the Wordpress infrastructure. As you are using this for a notification, I would suggest that you think about sending this notification with a very simple REST API style call instead. E.g. you could make a URL like yoursite/plugin/ping
and your plugin could call that URL whenever it's activated, attaching extra information as required in e.g. the request parameters.
Note that however you send the notification, collecting identifiable information about people without their consent is immoral and also illegal in e.g. the EU under GDPR so you need to be very careful with what information you collect. You may want to consider licensing your software and having users agree to a license rather than what you're doing, however that subject is way off topic here.
本文标签: How to send email when my plugin is activated
版权声明:本文标题:How to send email when my plugin is activated? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742251342a2440818.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论