好吧,这肯定有点黑客化,但我最终将表单上的操作更改为“[mysite url]/wp comments post.php”。然后,我利用了wp评论帖子中的几个动作挂钩。php劫持该页面:
add_action(\'pre_comment_on_post\', array($this, \'process_image_upload\'));
如果有人想知道我是如何编写process\\u image\\u upload函数(上传图像)的,请看这里:
private function process_image_upload($comment_post_ID){
//see which submit button was pressed
$comment = ( isset($_POST[\'submit\']) ) ? trim(strip_tags($_POST[\'submit\'])) : null;
//if it wasn\'t the comment submit button then...
if($comment != \'Post Comment\'){
if(current_user_can(\'upload_files\')){
if ($_FILES) {
foreach ($_FILES as $file => $array) {
$newupload = $this->insert_attachment($file,$comment_post_ID);
// $newupload returns the attachment id of the file that was just uploaded. Do whatever you want with that now.
}
if($newupload){
$location = get_permalink( $comment_post_ID );
wp_redirect($location);
exit;
}
}
}else {
wp_die( __(\'You do not have permission to upload files\') );
}
}
}
它仍然需要一些工作,但这至少应该让你开始。