AP_Form_Hooks::comment_form()

Description #

Register comment form.

Changelog #

VersionDescription
4.1.0Introduced.

Source #

File: includes/class-form-hooks.php

	public static function comment_form() {
		$form = array(
			'submit_label' => __( 'Submit Comment', 'anspress-question-answer' ),
			'fields'       => array(
				'content' => array(
					'type'        => 'textarea',
					'label'       => __( 'Comment', 'anspress-question-answer' ),
					'min_length'  => 5,
					'validate'    => 'required,min_string_length,badwords',
					'attr'        => array(
						'placeholder' => __( 'Write your comment here...', 'anspress-question-answer' ),
						'rows'        => 5,
					),
					'editor_args' => array(
						'quicktags'     => true,
						'textarea_rows' => 5,
					),
				),
			),
		);

		// Add name fields if anonymous is allowed.
		if ( ! is_user_logged_in() ) {
			$form['fields']['author'] = array(
				'label'      => __( 'Your Name', 'anspress-question-answer' ),
				'attr'       => array(
					'placeholder' => __( 'Enter your name to display.', 'anspress-question-answer' ),
				),
				'validate'   => 'required,max_string_length,badwords',
				'max_length' => 64,
			);

			$form['fields']['email'] = array(
				'label'      => __( 'Your Email', 'anspress-question-answer' ),
				'attr'       => array(
					'placeholder' => __( 'Enter your email to get follow up notifications.', 'anspress-question-answer' ),
				),
				'subtype'    => 'email',
				'validate'   => 'required,is_email',
				'max_length' => 254,
			);

			$form['fields']['url'] = array(
				'label'      => __( 'Your Website', 'anspress-question-answer' ),
				'attr'       => array(
					'placeholder' => __( 'Enter link to your website.', 'anspress-question-answer' ),
				),
				'subtype'    => 'url',
				'validate'   => 'is_url',
				'max_length' => 254,
			);
		}

		/**
		 * Filter for modifying comment form `$args`.
		 *
		 * @param   array $fields   Comment form fields.
		 * @since   4.1.0
		 */
		$form = apply_filters( 'ap_comment_form_fields', $form );

		return $form;
	}

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