-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register scripts during *_enqueue_scripts hook instead #368
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' ) ); | ||
|
||
|
@@ -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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wasn't used anywhere. |
||
wp_enqueue_script( 'fido-u2f-login' ); | ||
public static function enqueue_scripts() { | ||
wp_register_script( | ||
'fido-u2f-api', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a dependency for |
||
plugins_url( 'includes/Google/u2f-api.js', dirname( __FILE__ ) ), | ||
null, | ||
self::asset_version(), | ||
true | ||
); | ||
|
||
wp_register_script( | ||
'fido-u2f-login', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is used during our custom "login" page https://github.com/wordpress/two-factor/blob/a97c32b6639a3557fd149725b973615246549ffe/class-two-factor-core.php#L581-L726 |
||
plugins_url( 'js/fido-u2f-login.js', __FILE__ ), | ||
array( 'jquery', 'fido-u2f-api' ), | ||
self::asset_version(), | ||
true | ||
); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use action priority 5 to ensure the scripts have been registered before they're enqueued later at priority 10.