Skip to content

Function

Get the settings fields.

tml_admin_get_settings_fields( )

Return

array The settings fields.

Source

function tml_admin_get_settings_fields() {
    $fields = array();

    // General
    $fields['tml_settings_general'] = array(
        // AJAX
        'tml_ajax' => array(
            'title'             => __( 'AJAX', 'theme-my-login' ),
            'callback'          => 'tml_admin_setting_callback_checkbox_field',
            'sanitize_callback' => 'sanitize_text_field',
            'args'              => array(
                'label_for' => 'tml_ajax',
                'label'     => __( 'Enable AJAX requests', 'theme-my-login' ),
                'value'     => '1',
                'checked'   => get_site_option( 'tml_ajax', '0' ),
            ),
        ),
    );

    // Login
    $fields['tml_settings_login'] = array(
        // Login type
        'tml_login_type' => array(
            'title'             => __( 'Login Type', 'theme-my-login' ),
            'callback'          => 'tml_admin_setting_callback_radio_group_field',
            'sanitize_callback' => 'sanitize_text_field',
            'args'              => array(
                'description' => tml_admin_get_extension_suggestion( '2fa', '2FA', __( 'Add authenticator-app two-factor authentication to logins.', 'theme-my-login' ) ),
                'label_for'   => 'tml_login_type',
                'legend'      => __( 'Login Type', 'theme-my-login' ),
                'options'     => array(
                    'default'  => __( 'Default', 'theme-my-login' ),
                    'username' => __( 'Username only', 'theme-my-login' ),
                    'email'    => __( 'Email only', 'theme-my-login' ),
                ),
                'checked'     => get_site_option( 'tml_login_type', 'default' ),
            ),
        ),
    );

    // Registration
    $fields['tml_settings_registration'] = array();

    // Anyone can register. On multisite, the network's registration setting overrides this option.
    if ( ! is_multisite() ) {
        $fields['tml_settings_registration']['users_can_register'] = array(
            'title'    => __( 'Membership' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- reusing WP core's translated "Membership" string (see wp-admin/options-general.php).
            'callback' => 'tml_admin_setting_callback_checkbox_field',
            'args'     => array(
                'label_for' => 'users_can_register',
                'label'     => __( 'Anyone can register' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- reusing WP core's translated "Anyone can register" string (see wp-admin/options-general.php).
                'value'     => '1',
                'checked'   => get_option( 'users_can_register' ),
            ),
        );
    }

    $fields['tml_settings_registration'] += array(
        // Registration type
        'tml_registration_type' => array(
            'title'             => __( 'Registration Type', 'theme-my-login' ),
            'callback'          => 'tml_admin_setting_callback_radio_group_field',
            'sanitize_callback' => 'sanitize_text_field',
            'args'              => array(
                'description' => implode(
                    '<br />',
                    array_filter(
                        array(
                            tml_admin_get_extension_suggestion( 'moderation', 'Moderation', __( 'Require email confirmation or admin approval for new users.', 'theme-my-login' ) ),
                            tml_admin_get_extension_suggestion( 'recaptcha', 'reCAPTCHA', __( 'Block spam bots on login, registration and lost password forms.', 'theme-my-login' ) ),
                        )
                    )
                ),
                'label_for'   => 'tml_registration_type',
                'legend'      => __( 'Registration Type', 'theme-my-login' ),
                'options'     => array(
                    'default' => __( 'Default', 'theme-my-login' ),
                    'email'   => __( 'Email only', 'theme-my-login' ),
                ),
                'checked'     => get_site_option( 'tml_registration_type', 'default' ),
            ),
        ),
        // User passwords
        'tml_user_passwords'    => array(
            'title'             => __( 'Passwords', 'theme-my-login' ),
            'callback'          => 'tml_admin_setting_callback_checkbox_field',
            'sanitize_callback' => 'sanitize_text_field',
            'args'              => array(
                'description' => tml_admin_get_extension_suggestion( 'security', 'Security', __( 'Set password rules and lock out brute-force attacks.', 'theme-my-login' ) ),
                'label_for'   => 'tml_user_passwords',
                'label'       => __( 'Allow users to set their own password', 'theme-my-login' ),
                'value'       => '1',
                'checked'     => get_site_option( 'tml_user_passwords' ),
            ),
        ),
        // Auto-login
        'tml_auto_login'        => array(
            'title'             => __( 'Auto-Login', 'theme-my-login' ),
            'callback'          => 'tml_admin_setting_callback_checkbox_field',
            'sanitize_callback' => 'sanitize_text_field',
            'args'              => array(
                'description' => tml_admin_get_extension_suggestion( 'redirection', 'Redirection', __( 'Choose where users land after they register or log in, by role.', 'theme-my-login' ) ),
                'label_for'   => 'tml_auto_login',
                'label'       => __( 'Automatically log in users after registration', 'theme-my-login' ),
                'value'       => '1',
                'checked'     => get_site_option( 'tml_auto_login' ),
            ),
        ),
    );

    // Slugs
    $fields['tml_settings_slugs'] = array();
    foreach ( tml_get_actions() as $action ) {
        if ( ! $action->show_in_slug_settings ) {
            continue;
        }

        $slug_option = 'tml_' . $action->get_name() . '_slug';

        $fields['tml_settings_slugs'][ $slug_option ] = array(
            'title'             => $action->get_title(),
            'callback'          => 'tml_admin_setting_callback_input_field',
            'sanitize_callback' => 'sanitize_title',
            'args'              => array(
                'label_for'   => $slug_option,
                'value'       => get_site_option( $slug_option, $action->get_slug() ),
                'attributes'  => array(
                    'checked'  => true,
                    'class'    => 'regular-text code',
                    'required' => true,
                ),
                'description' => sprintf( '<a href="%1$s">%1$s</a>', $action->get_url() ),
            ),
        );
    }

    /**
     * Filters the settings fields.
     *
     * @since 7.0
     *
     * @param array $fields The settings fields.
     */
    return (array) apply_filters( 'tml_admin_get_settings_fields', $fields );
}

Uses

Used by

Changelog

VersionDescription
7.0 Introduced.