Extend the Ask Form to include file uploads
It can be achieved. Have a look at ask form source code and you can get idea how AnsPress process upload. As I remember I have answered before to allow custom file type, please search.
Rahul Aryan commented
Please create a gist of your actual file, then I will show you which hooks can be used.
scolling commented
Thanks for getting back to me and I’m happy to do that, but I’m not sure what you mean 🙂
Hi Rahul
I have made the following solution for this, however I’m not sure if there are any plugins or callbacks I can use because at the moment it will be overwritten with the next anspress update, Is there any way I could change what I’ve done to override the plug in without modifying it’s own code?
Anyway here’s what I did to allow my users, and those answering, to upload documents as well as images:
/* —————————————————————————————————–
* In \wp-content\plugins\anspress-question-answer\includes\functions.php make the following changes:
* /
function function ap_responce_message()
// I know this message can be overridden but I’m not sure how??
Change message text for ‘post_image_uploaded’ to say ‘File uploaded successfully’
function ap_upload_user_file()
add the additional types of files you want to allow, e.g.:
// it would be good if this could be one of the plugin options?
‘pdf’ => ‘application/pdf’,
‘doc’ => ‘application/msword’,
‘xls’ => ‘application/vnd.ms-excel’,
/* —————————————————————————————————–
* In \wp-content\plugins\anspress-question-answer\includes\process-form.php
*/
function upload_post_image()
Find the code that currently looks like this:
$attachment_id = ap_upload_user_file( $file );
if ( $attachment_id !== false ) {
ap_send_json( ap_ajax_responce( array( ‘action’ => ‘upload_post_image’, ‘html’ => wp_get_attachment_image( $attachment_id, ‘full’ ), ‘message’ => ‘post_image_uploaded’, ‘attachment_id’ => $attachment_id ) ) ); }
and extend it so it becomes this:
$attachment_id = ap_upload_user_file( $file );
$attachment_html = wp_get_attachment_image( $attachment_id, ‘full’ );
if (empty($attachment_html)) {
$attachment_link = wp_get_attachment_link( $attachment_id, ‘thumbnail’, false, true );
$attachment_file = basename( get_attached_file( $attachment_id ) );
$attachment_html = sprintf(__(‘%s %s %s %s %s’, ‘anspress-question-answer’), ”, $attachment_link, ”, $attachment_file, ”);
}
if ( $attachment_id !== false ) {
ap_send_json( ap_ajax_responce( array( ‘action’ => ‘upload_post_image’, ‘html’ => $attachment_html, ‘message’ => ‘post_image_uploaded’, ‘attachment_id’ => $attachment_id ) ) );
}