Returns the settings fields for the API’s authentication data.
Description
See also
Return
(array) Associative array of <code>$field_slug => $field_args</code> pairs.
Source
File: src/modules/actions/api-action.php
protected function get_authentication_fields() { $authenticator = $this->api()->get_authenticator(); // TODO: Use authentication data to detect what has been set programmatically. $authenticator_defaults = $this->api()->get_authentication_data_defaults(); $title = $this->api()->get_title(); $fields = array(); switch ( $authenticator ) { case 'oauth1': $fields = array( 'consumer_key' => array( 'type' => 'text', 'label' => __( 'API Consumer Key', 'torro-forms' ), /* translators: %s: an API title */ 'description' => sprintf( __( 'Enter the consumer key for the %s API.', 'torro-forms' ), $title ), ), 'consumer_secret' => array( 'type' => 'text', 'label' => __( 'API Consumer Secret', 'torro-forms' ), /* translators: %s: an API title */ 'description' => sprintf( __( 'Enter the consumer secret for the %s API.', 'torro-forms' ), $title ), ), ); break; case 'x': if ( empty( $authenticator_defaults['header_name'] ) ) { $fields['header_name'] = array( 'type' => 'text', 'label' => __( 'Authorization Header Name', 'torro-forms' ), /* translators: %s: an API title */ 'description' => sprintf( __( 'Enter the name of the authorization header that is sent to verify %s API requests. It will be prefixed with “X-”.', 'torro-forms' ), $title ), 'default' => 'Authorization', ); } $fields['token'] = array( 'type' => 'text', 'label' => __( 'Authorization Token', 'torro-forms' ), /* translators: %s: an API title */ 'description' => sprintf( __( 'Enter the authorization token for the %s API.', 'torro-forms' ), $title ), ); break; case 'x-account': if ( empty( $authenticator_defaults['placeholder_name'] ) ) { $fields['placeholder_name'] = array( 'type' => 'text', 'label' => __( 'Account Placeholder Name', 'torro-forms' ), /* translators: %s: an API title */ 'description' => sprintf( __( 'Enter the name of the placeholder in the URI used to verify %s API requests.', 'torro-forms' ), $title ), 'default' => 'account', ); } $fields['account'] = array( 'type' => 'text', 'label' => __( 'Account Identifier', 'torro-forms' ), /* translators: %s: an API title */ 'description' => sprintf( __( 'Enter the account identifier for the %s API.', 'torro-forms' ), $title ), ); if ( empty( $authenticator_defaults['header_name'] ) ) { $fields['header_name'] = array( 'type' => 'text', 'label' => __( 'Authorization Header Name', 'torro-forms' ), /* translators: %s: an API title */ 'description' => sprintf( __( 'Enter the name of the authorization header that is sent to verify %s API requests. It will be prefixed with “X-”.', 'torro-forms' ), $title ), 'default' => 'Authorization', ); } $fields['token'] = array( 'type' => 'text', 'label' => __( 'Authorization Token', 'torro-forms' ), /* translators: %s: an API title */ 'description' => sprintf( __( 'Enter the authorization token for the %s API.', 'torro-forms' ), $title ), ); break; case 'basic': $fields = array( 'username' => array( 'type' => 'text', 'label' => __( 'API Username', 'torro-forms' ), /* translators: %s: an API title */ 'description' => sprintf( __( 'Enter the username for the %s API.', 'torro-forms' ), $title ), ), 'password' => array( 'type' => 'text', 'label' => __( 'API Password', 'torro-forms' ), /* translators: %s: an API title */ 'description' => sprintf( __( 'Enter the password for the %s API.', 'torro-forms' ), $title ), ), ); break; case 'key': if ( empty( $authenticator_defaults['parameter_name'] ) ) { $fields['parameter_name'] = array( 'type' => 'text', 'label' => __( 'API Key Parameter Name', 'torro-forms' ), /* translators: %s: an API title */ 'description' => sprintf( __( 'Enter the name of the request parameter that is sent to verify %s API requests.', 'torro-forms' ), $title ), 'default' => 'key', ); } $fields['key'] = array( 'type' => 'text', 'label' => __( 'API Key', 'torro-forms' ), /* translators: %s: an API title */ 'description' => sprintf( __( 'Enter the API key for the %s API.', 'torro-forms' ), $title ), ); break; } return $fields; }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |