Method
Create a new instance.
__construct( Theme_My_Login_Form $form, string $name, array $args = array() )
public
Parameters
-
$formTheme_My_Login_Form - The field's parent form.
-
$namestring - The field name.
-
$argsarray Defaultarray() -
Optional. An array of arguments.
-
$typestring - The field type.
-
$valuestring - The field value.
-
$labelstring - The field label.
-
$descriptionstring - The field description.
-
$errorstring - The field error message.
-
$contentstring - The field content. Used if type is set to "custom".
-
$optionsarray - The field options. Used if type is set to "dropdown" or "radio-group".
-
$attributesarray - 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'];
}
} View src/includes/class-theme-my-login-form-field.php, line 132 on GitHub
Uses
Used by
Changelog
| Version | Description |
|---|---|
| 7.0 | Introduced. |