-
Notifications
You must be signed in to change notification settings - Fork 156
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
Conversation
*/ | ||
public function login_enqueue_assets() { |
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.
This wasn't used anywhere.
); | ||
|
||
wp_register_script( | ||
'fido-u2f-login', |
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.
This is used during our custom "login" page https://github.com/wordpress/two-factor/blob/a97c32b6639a3557fd149725b973615246549ffe/class-two-factor-core.php#L581-L726
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This is a dependency for fido-u2f-admin
and fido-u2f-login
.
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 ); |
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.
This looks good, however, is there a particular reason why we do script registration and enqueueing separately? I may be missing some context, but it seems to me that the complexity might be reduced a bit if combined into a single |
@rinatkhaziev That's a good question. I think the reason for that is that both admin and login screens rely on the same JS dependencies so we're able to reference those dependencies without having to enqueue them two multiple times and potentially mess up the file paths, versions, etc. |
Ah I see, thanks! |
Fixes #361.