Deprecated

This function has been deprecated.

ap_get_answer_form_fields( integer|boolean $question_id = false, integer|boolean $answer_id = false )

Description #

Get all answer form fields.

Parameters #

  • $question_id
    integer | boolean (Optional) Post ID. Default value: false
  • $answer_id
    integer | boolean (Optional) Answer ID. Default value: false

Changelog #

VersionDescription
4.1.0This function has been deprecated.
3.0.0Introduced.

Source #

File: includes/deprecated.php

function ap_get_answer_form_fields( $question_id = false, $answer_id = false ) {
	_deprecated_function( __FUNCTION__, '4.1.0' );

	global $editing_post;
	$editing = false;

	if ( $answer_id && ap_user_can_edit_answer( (int) $answer_id ) ) {
		$editing      = true;
		$editing_post = ap_get_post( (int) $answer_id, 'OBJECT', 'edit' );
	}

	$is_private = false;

	if ( $editing ) {
		$is_private = $editing_post->post_status == 'private_post' ? true : false;
	}

	$fields = array(
		array(
			'name'        => 'description',
			'type'        => is_question() ? 'textarea' : 'editor',
			'value'       => ( $editing ? $editing_post->post_content : wp_kses_post( ap_isset_post_value( 'description', '' ) ) ),
			'placeholder' => __( 'Your answer..', 'anspress-question-answer' ),
			'settings'    => ap_tinymce_editor_settings( 'answer' ),
			'sanitize'    => array( 'sanitize_description' ),
			'validate'    => array(
				'required'     => true,
				'length_check' => ap_opt( 'minimum_ans_length' ),
			),
		),
		array(
			'name'  => 'form_question_id',
			'type'  => 'hidden',
			'value' => ( $editing ? $editing_post->post_parent : $question_id ),
			'order' => 20,
		),
	);

	// Add name fields if anonymous is allowed.
	if ( ! is_user_logged_in() && ap_opt( 'allow_anonymous' ) ) {
		$fields[] = array(
			'name'        => 'anonymous_name',
			'label'       => __( 'Name', 'anspress-question-answer' ),
			'type'        => 'text',
			'placeholder' => __( 'Enter your name to display', 'anspress-question-answer' ),
			'value'       => ap_isset_post_value( 'name', '' ),
			'order'       => 12,
			'sanitize'    => array( 'strip_tags', 'sanitize_text_field' ),
		);
	}

	// Add private field checkbox if enabled.
	if ( ap_opt( 'allow_private_posts' ) ) {
		$fields[] = array(
			'name'          => 'is_private',
			'type'          => 'checkbox',
			'desc'          => __( 'Only visible to admin and moderator.', 'anspress-question-answer' ),
			'value'         => $is_private,
			'order'         => 12,
			'show_desc_tip' => false,
			'sanitize'      => array( 'only_boolean' ),
		);
	}

	$fields[] = array(
		'name'  => 'ap_upload',
		'type'  => 'custom',
		'html'  => ap_post_upload_form( $editing ? $editing_post->ID : false ),
		'order' => 11,
	);

	$fields[] = array(
		'name'  => 'action',
		'type'  => 'hidden',
		'value' => 'ap_ajax',
		'order' => 20,
	);

	$fields[] = array(
		'name'  => 'ap_ajax_action',
		'type'  => 'hidden',
		'value' => 'answer_form',
		'order' => 20,
	);

	if ( $editing ) {
		$fields[] = array(
			'name'     => 'edit_post_id',
			'type'     => 'hidden',
			'value'    => $editing_post->ID,
			'order'    => 20,
			'sanitize' => array( 'only_int' ),
		);
	}

	/** This filter is documented in includes/class-form-hooks.php */
	$fields = apply_filters( 'ap_answer_form_fields', array( 'fields' => $fields ), $editing );
	return $fields['fields'];
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment