Skip to content

Method

Create a new instance.

__construct( Theme_My_Login_Form $form, string $name, array $args = array() )

public

Parameters

$form Theme_My_Login_Form
The field's parent form.
$name string
The field name.
$args array Default array()
Optional. An array of arguments.
$type string
The field type.
$value string
The field value.
$label string
The field label.
$description string
The field description.
$error string
The field error message.
$content string
The field content. Used if type is set to "custom".
$options array
The field options. Used if type is set to "dropdown" or "radio-group".
$attributes array
The field attributes.

Source

public function __construct( Theme_My_Login_Form $form, $name, $args = array() ) {
    $this->set_form( $form );
    $this->set_name( $name );

    $args = wp_parse_args(
        $args,
        array(
            'type'        => 'text',
            'value'       => '',
            'label'       => '',
            'description' => '',
            'error'       => '',
            'content'     => '',
            'options'     => array(),
            'attributes'  => array(),
        )
    );

    $this->set_type( $args['type'] );
    $this->set_value( $args['value'] );
    $this->set_label( $args['label'] );
    $this->set_description( $args['description'] );
    $this->set_error( $args['error'] );
    $this->set_content( $args['content'] );
    $this->set_options( $args['options'] );

    if ( ! empty( $args['id'] ) ) {
        $this->add_attribute( 'id', $args['id'] );
    }

    if ( ! empty( $args['class'] ) ) {
        $this->add_class( $args['class'] );
    } elseif ( 'hidden' !== $this->get_type() ) {
        if ( in_array( $args['type'], array( 'button', 'submit', 'reset' ), true ) ) {
            $class = 'tml-button';
        } elseif ( in_array( $args['type'], array( 'checkbox', 'radio', 'radio-group' ), true ) ) {
            $class = 'tml-checkbox';
        } else {
            $class = 'tml-field';
        }
        $this->add_class( $class );
    }

    if ( 'checkbox' === $args['type'] && ! empty( $args['checked'] ) ) {
        $this->add_attribute( 'checked', 'checked' );
    }

    foreach ( (array) $args['attributes'] as $key => $value ) {
        $this->add_attribute( $key, $value );
    }

    if ( isset( $args['priority'] ) ) {
        $this->set_priority( $args['priority'] );
    }

    if ( ! empty( $args['render_args'] ) ) {
        $this->render_args = $args['render_args'];
    }
}

Uses

Used by

Changelog

VersionDescription
7.0 Introduced.