Skip to content
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

Merged
merged 1 commit into from
Jun 26, 2020

Conversation

kasparsd
Copy link
Collaborator

Fixes #361.

*/
public function login_enqueue_assets() {
Copy link
Collaborator Author

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',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wp_enqueue_script( 'fido-u2f-login' );
public static function enqueue_scripts() {
wp_register_script(
'fido-u2f-api',
Copy link
Collaborator Author

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 );
Copy link
Collaborator Author

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.

@rinatkhaziev
Copy link

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 wp_enqueue_script call.

@kasparsd
Copy link
Collaborator Author

@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.

@rinatkhaziev
Copy link

Ah I see, thanks!

@kasparsd kasparsd merged commit 536678d into master Jun 26, 2020
@kasparsd kasparsd deleted the fix/enqueue-u2f-assets branch June 26, 2020 22:42
@kasparsd kasparsd mentioned this pull request Aug 3, 2020
@jeffpaul jeffpaul added this to the 0.7.0 milestone Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wp_register_script causes a PHP Notice
3 participants