add_action('wp_insert_attachment', 'send_image_to_remote_server', 10, 3);
function send_image_to_remote_server($attachment_id, $post_data, $update) {
// Get the API address of the uploaded image
$api_address = ''; // Replace with your logic to retrieve the API address
// Make sure the API address is available
if (!empty($api_address)) {
// Call your remote server and send the API address
// Replace this with your code to send the API address to the remote server
}
}
1条答案
按热度按时间pvabu6sv1#
如果你想触发一个动作,并将新上传的图片的API地址发送到远程服务器进行编辑,你可以使用WordPress中的add_attachment钩子。但是,add_attachment钩子在附件元数据保存到数据库之前触发,因此此时API地址可能不可用。
为了确保API地址在钩子被触发时可用,可以使用wp_insert_attachment钩子。在将附件元数据保存到数据库后,将触发此挂接。下面是如何修改代码的示例:
在
send_image_to_remote_server
函数中,您可以使用自己的逻辑检索上传图像的API地址。获得API地址后,可以继续将其发送到远程服务器进行编辑。请确保将占位符''替换为您的逻辑,以检索映像的实际API地址。此外,用您自己的代码替换注解,将API地址发送到远程服务器进行编辑。
通过使用
wp_insert_attachment
钩子,您可以确保API地址可用,并且在将附件元数据保存到数据库后,可以将其发送到远程服务器。