Image Upload Form is Disabling Comment Addition

Well, this is definitely a little hackish but what I ended up doing was changing the action on the form to “[mysite url]/wp-comments-post.php”. Then I took advantage of a few action hooks in wp-comments-post.php to hijack that page:

add_action('pre_comment_on_post', array($this, 'process_image_upload'));

And if anyone is curious as to how I wrote the process_image_upload function (which uploads an image), here it is:

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') );
            }
        }
    }

It’s still needs a little work, but this should at least get you started.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)