Form::find( string $value, boolean|array $fields = false, string $key = 'original_name' )

Description #

Find a field object.

Parameters #

  • $value
    string (Required) Value for argument $key.
  • $fields
    boolean | array (Optional) List of field where to search. Default value: false
  • $key
    string (Optional) Search field by which property of a field object. Default value: 'original_name'

Source #

File: lib/class-form.php

	public function find( $value, $fields = false, $key = 'original_name' ) {
		if ( false === $this->prepared ) {
			$this->prepare();
		}

		$fields = false === $fields ? $this->fields : $fields;
		$found  = wp_filter_object_list( $fields, array( $key => $value ) );

		if ( empty( $found ) ) {
			foreach ( $fields as $field ) {
				if ( ! empty( $field->child ) && ! empty( $field->child->fields ) ) {
					$child_found = $this->find( $value, $field->child->fields );

					if ( ! empty( $child_found ) ) {
						$found = $child_found;
						break;
					}
				}
			}
		}

		return is_array( $found ) ? reset( $found ) : $found;
	}

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