是的,是的,你可以
您将需要连接到add_attachment
行动,尽管还有其他更合适的方法。然后抓取管理员列表并发送电子邮件。
以下是我为您创建的示例插件:
<?php
/*
Plugin Name: Notify on Attachment Creation
Plugin URI: http://www.tomjn.com
Description: Send a notification when an attachment is created
Version: 1.03
Author: Tom J Nowell
Author URI: http://www.tomjn.com
*/
function new_attachment_email($att_id){
$recipients = array();
// who should it be sent to?
global $wpdb;
$key = $wpdb->prefix."user_level";
$admins = $wpdb->get_results($wpdb->prepare("SELECT user_id from $wpdb->usermeta AS um WHERE um.meta_key =\'". $key."\' AND um.meta_value = 10"));
if(!empty($admins)){
foreach($admins as $admin){
$userdata = get_userdata($admin->user_id);
$recipients[] = $userdata->user_email;
}
} else {
wp_die(\'nicht\');
}
if(is_multisite()){
$superadmins = get_super_admins();
if(!empty($superadmins)){
foreach($superadmins as $superadmin){
$u = get_userdatabylogin($superadmin);
if($u != false){
if(!in_array($u->user_email,$recipients)){
$recipients[] = $u->user_email;
}
}
}
}
}
// send the email
if(empty($recipients)){
// there is nobody to send this to? Abort!
wp_die(\'oh dear god\');
return;
}
$admin_email = get_option(\'admin_email\');
$headers= "From:$admin_email\\r\\n";
$headers .= "Reply-To:$admin_email\\r\\n";
$headers .= "X-Mailer: PHP/".phpversion()."\\r\\n";
$headers .= "content-type: text/html";
$subject = \'New Attachment upload\';
$template = \'<p>new attachment uploaded to WordPress with the ID: \'.$att_id.\'.</p>\'. wp_get_attachment_link( $att_id,\'\',true,false,\'click here to view this attachment\' );
foreach($recipients as $to){
@wp_mail($to, $subject, $template, $headers);
}
}
add_action(\'add_attachment\',\'new_attachment_email\',1,1);
创建新附件时,这将向wordpress站点/网络的管理员和超级管理员发送电子邮件。