Skip to content

Method

Create a new instance.

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

public

Parameters

$name string
The form name.
$args array Default array()
Optional. An array of arguments.
$action string
The form action. Default empty.
$method string
The form method. Default 'post'.
$attributes array
The form attributes. Default empty array.

Source

public function __construct( $name, $args = array() ) {

    $this->set_name( $name );

    $args = wp_parse_args(
        $args,
        array(
            'action'     => '',
            'method'     => 'post',
            'attributes' => array(),
        )
    );

    $this->set_action( $args['action'] );
    $this->set_method( $args['method'] );

    $this->errors = new WP_Error();

    // Add the default links
    foreach ( tml_get_actions() as $action ) {
        if ( $action->show_on_forms && $action->get_name() !== $this->get_name() ) {
            $this->add_link(
                $action->get_name(),
                array(
                    'text' => true === $action->show_on_forms ? $action->get_title() : $action->show_on_forms,
                    'url'  => $action->get_url(),
                )
            );
        }
    }

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

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

Uses

Used by

Changelog

VersionDescription
7.0 Introduced.