AnsPress::form_exists( string $name )

Description #

Check if a form exists in AnsPress, if not then tries to register.

Parameters #

  • $name
    string (Required) Name of form.

Changelog #

VersionDescription
4.1.0Introduced.

Source #

File: anspress-question-answer.php

		public function form_exists( $name ) {
			$name = preg_replace( '/^form_/i', '', $name );

			if ( isset( $this->forms[ $name ] ) ) {
				return true;
			}

			/**
			 * Register a form in AnsPress.
			 *
			 * @param array $form {
			 *      Form options and fields. Check @see `AnsPress\Form` for more detail.
			 *
			 *      @type string  $submit_label Custom submit button label.
			 *      @type boolean $editing      Pass true if currently in editing mode.
			 *      @type integer $editing_id   If editing then pass editing post or comment id.
			 *      @type array   $fields       Fields. For more detail on field option check documentations.
			 * }
			 * @since 4.1.0
			 * @todo  Add detailed docs for `$fields`.
			 */
			$args = apply_filters( 'ap_form_' . $name, null );

			if ( ! is_null( $args ) && ! empty( $args ) ) {
				$this->forms[ $name ] = new AnsPress\Form( 'form_' . $name, $args );

				return true;
			}

			return false;
		}

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