Skip to content

Instantly share code, notes, and snippets.

@rahularyan
Created November 12, 2017 12:14
Show Gist options
  • Save rahularyan/5fbe1977776c32637e9a1dd325147236 to your computer and use it in GitHub Desktop.
Save rahularyan/5fbe1977776c32637e9a1dd325147236 to your computer and use it in GitHub Desktop.
<?php
/**
* This hook will make question description field optional.
*
* @param array $form Form arguments.
* @return array
*/
function my_ap_make_question_description_optional( $form ) {
$validate = $form['fields']['post_content']['validate'];
//remove required from validation.
if ( is_array( $validate ) ) {
if ( ( $key = array_search( 'required', $validate ) ) !== false ) {
unset( $validate[ $key ] );
}
} else {
$validate = str_replace( 'required', '', $validate );
}
// Update existing value.
$form['fields']['post_content']['validate'] = $validate;
return $form;
}
add_filter( 'ap_question_form_fields', 'my_ap_make_question_description_optional' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment