Form_Settings_Page::add_field( string $id, string $type, array $args = array() )

Adds a field to the settings page.

Description

Parameters

$id

(string) (Required) Field identifier.

$type

(string) (Required) Identifier of the type.

$args

(array) (Optional) Field arguments. See the field class constructor for further arguments.

  • 'section'
    (string) Section identifier this field belongs to.
  • 'label'
    (string) Field label.
  • 'description'
    (string) Field description.
  • 'default'
    (mixed) Default value for the field. Default null.
  • 'input_classes'
    (array) Array of CSS classes for the field input.
  • 'label_classes'
    (array) Array of CSS classes for the field label.
  • 'input_attrs'
    (array) Array of additional input attributes as $key => $value pairs.

Default value: array()

Source

File: src/db-objects/forms/form-settings-page.php

	public function add_field( $id, $type, $args = array() ) {
		if ( ! isset( $args['section'] ) ) {
			return;
		}

		if ( ! isset( $this->sections[ $args['section'] ] ) ) {
			return;
		}

		if ( ! isset( $this->subtabs[ $this->sections[ $args['section'] ]['subtab'] ] ) ) {
			return;
		}

		if ( ! isset( $this->tabs[ $this->subtabs[ $this->sections[ $args['section'] ]['subtab'] ]['tab'] ] ) ) {
			return;
		}

		$tab_args = $this->tabs[ $this->subtabs[ $this->sections[ $args['section'] ]['subtab'] ]['tab'] ];
		$tab_args['field_manager']->add( $id, $type, $args );
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.