Skip to content

Instantly share code, notes, and snippets.

@rahularyan
Last active December 3, 2017 11:01
Show Gist options
  • Save rahularyan/aac5c8f5a52318919f2989726e30d85a to your computer and use it in GitHub Desktop.
Save rahularyan/aac5c8f5a52318919f2989726e30d85a to your computer and use it in GitHub Desktop.
Add a PDF upload field in AnsPress questions
<?php
/**
* Adds a PDF field to AnsPress question form.
*
* @param array $form Form arguments.
* @return void
*/
function my_custom_question_field( $form ) {
// Upload field.
$form['fields']['screenshot'] = array(
'fields' => array(
'pdf' => array( // This is a unique key for field.
'label' => __( 'PDF File' ),
'desc' => __( 'Allow single PDF file upload.' ),
'type' => 'upload',
'upload_options' => array(
'multiple' => false, // Only allow single image upload.
'allowed_mimes' => array(
'pdf' => 'application/pdf', // This will allow uploading of PDF file.
),
),
),
),
);
return $form;
}
add_filter( 'ap_question_form_fields', 'my_custom_question_field' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment