Skip to content

Commit

Permalink
Register scripts during *_enqueue_scripts hook instead
Browse files Browse the repository at this point in the history
Fixes #361
  • Loading branch information
kasparsd committed Jun 26, 2020
1 parent d7da73c commit a97c32b
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions providers/class-two-factor-fido-u2f.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,10 @@ protected function __construct() {
require_once TWO_FACTOR_DIR . 'providers/class-two-factor-fido-u2f-admin.php';
Two_Factor_FIDO_U2F_Admin::add_hooks();

wp_register_script(
'fido-u2f-api',
plugins_url( 'includes/Google/u2f-api.js', dirname( __FILE__ ) ),
null,
self::asset_version(),
true
);

wp_register_script(
'fido-u2f-login',
plugins_url( 'js/fido-u2f-login.js', __FILE__ ),
array( 'jquery', 'fido-u2f-api' ),
self::asset_version(),
true
);
// Ensure the script dependencies have been registered before they're enqueued at a later priority.
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ), 5 );
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ), 5 );
add_action( 'login_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ), 5 );

add_action( 'two_factor_user_options_' . __CLASS__, array( $this, 'user_options' ) );

Expand Down Expand Up @@ -131,12 +120,27 @@ public function get_label() {
}

/**
* Enqueue assets for login form.
* Register script dependencies used during login and when
* registering keys in the WP admin.
*
* @since 0.1-dev
* @return void
*/
public function login_enqueue_assets() {
wp_enqueue_script( 'fido-u2f-login' );
public static function enqueue_scripts() {
wp_register_script(
'fido-u2f-api',
plugins_url( 'includes/Google/u2f-api.js', dirname( __FILE__ ) ),
null,
self::asset_version(),
true
);

wp_register_script(
'fido-u2f-login',
plugins_url( 'js/fido-u2f-login.js', __FILE__ ),
array( 'jquery', 'fido-u2f-api' ),
self::asset_version(),
true
);
}

/**
Expand Down

0 comments on commit a97c32b

Please sign in to comment.