Skip to content

Function

Enqueue scripts for TML.

tml_enqueue_scripts( )

Source

function tml_enqueue_scripts() {
    $suffix = SCRIPT_DEBUG ? '' : '.min';

    $dependencies = array( 'jquery' );
    if ( tml_is_action( 'resetpass' ) || ( tml_is_action( 'register' ) && tml_allow_user_passwords() ) ) {
        $dependencies[] = 'password-strength-meter';
    }

    /**
     * Filter the dependencies of the main TML script.
     *
     * @since 7.0.15
     *
     * @param array $dependencies The dependencies of the main TML script.
     */
    $dependencies = apply_filters( 'tml_script_dependencies', $dependencies );

    wp_enqueue_script( 'theme-my-login', THEME_MY_LOGIN_URL . "assets/scripts/theme-my-login$suffix.js", $dependencies, THEME_MY_LOGIN_VERSION, true );

    /**
     * Filter whether to autofocus the primary field on TML forms.
     *
     * @since 7.2.0
     *
     * @param bool $autofocus Whether to autofocus the primary field. Default true.
     */
    $autofocus = (bool) apply_filters( 'tml_autofocus', true );

    /**
     * Filter the main TML script data.
     *
     * @since 7.0.15
     *
     * @param array $data The main TML script data.
     */
    $data = apply_filters(
        'tml_script_data',
        array(
            'action'            => tml_is_action() ? tml_get_action()->get_name() : '',
            'errors'            => tml_get_errors()->get_error_codes(),
            'autofocus'         => $autofocus,
            // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- reuses WP core's translated wp-login.php strings verbatim.
            'showPasswordLabel' => __( 'Show password' ),
            // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- reuses WP core's translated wp-login.php strings verbatim.
            'hidePasswordLabel' => __( 'Hide password' ),
            // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- reuses WP core's translated wp-ajax-response string verbatim.
            'ajaxErrorMessage'  => __( 'An error occurred while processing your request. Please try again later.' ),
        )
    );

    wp_localize_script( 'theme-my-login', 'themeMyLogin', $data );

    if ( tml_is_action() ) {
        /** This action is documented in wp-login.php */
        do_action( 'login_enqueue_scripts' );
    }
}

Uses

Changelog

VersionDescription
7.0 Introduced.