我有一个多站点的博客,大约有300个站点。
我有一个想法,我想写一个插件,以便将所有博客管理员添加到邮件列表中。我只需要管理员,但我不想将编辑器和订阅者添加到此电子邮件列表。
我想捕获分配博客管理员的事件。然后,我会向我的邮件列表的订阅电子邮件地址发送一封电子邮件,以自动添加此人。
所以我想知道我应该用哪个钩子?我想每次有人被设置为管理员时,我都会发送一封电子邮件。我不在乎他们是否作为管理员被删除。
我有一个多站点的博客,大约有300个站点。
我有一个想法,我想写一个插件,以便将所有博客管理员添加到邮件列表中。我只需要管理员,但我不想将编辑器和订阅者添加到此电子邮件列表。
我想捕获分配博客管理员的事件。然后,我会向我的邮件列表的订阅电子邮件地址发送一封电子邮件,以自动添加此人。
所以我想知道我应该用哪个钩子?我想每次有人被设置为管理员时,我都会发送一封电子邮件。我不在乎他们是否作为管理员被删除。
你会陷入profile_update
和user_register
. 首先检查是否是新用户,以及她是否是管理员/编辑。
然后发送邮件。更新用户的情况也一样:查看角色是否已更改,以及新角色是admin还是editor。
<?php
add_action( \'profile_update\', \'wpse33949_profile_update\' );
add_action( \'user_register\', \'wpse33949_profile_update\' );
function wpse33949_profile_update( $user_id, $old_user_data = false )
{
// get the updated user data
$userdata = get_userdata( $user_id );
// whatever you need to send here
$message = "Sign up for my email!";
$subject = "Mailing List";
if( ! $old_user_data && in_array( $userdata->user_role, array( \'editor\', \'administrator\' ) ) )
{
// we\'re inserting a new user...
wp_mail( $userdata->user_email, $subject, $message );
}
elseif( in_array( $userdata->user_role, array( \'editor\', \'administrator\' ) ) && $userdata->user_role != $old_user_data->user_role )
{
// We\'re updating the role of an existing user, make sure they\'re
// becoming an admin or editor, then send the message.
wp_mail( $userdata->user_email, $subject, $message );
}
}
以上内容尚未测试。小心复制和粘贴。只是想让你开始。我这样问是因为我无法从我在第二个博客上创建的插件中找到选项。将此插件添加到主站点并显示选项。我很困惑,因为在wp_options 桌子blog_id 我希望那里会有不止一个值。