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 before being enqueued #356

Closed

Conversation

cojennin
Copy link

@cojennin cojennin commented May 13, 2020

Registering the fido-u2f-api and fido-u2f-login scripts in the __constructor is generating the following notice:
Notice: wp_register_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks.

It seems like these wp_register_script calls should be moved to login_enqueue_assets as that's where they're utilized.

(Props @scottnelle for tracking this down)

Copy link
Collaborator

@kasparsd kasparsd left a comment

Choose a reason for hiding this comment

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

This looks great, thank you!

@@ -130,6 +114,23 @@ public function get_label() {
* @since 0.1-dev
*/
public function login_enqueue_assets() {

wp_register_script(
'fido-u2f-api',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like this is also referenced here:

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

so we need to make sure this script is registered before it is enqueued there.

Copy link
Author

@cojennin cojennin May 13, 2020

Choose a reason for hiding this comment

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

Ah yea, made a change to the PR to register on admin_enqueue_scripts with a lower priority to make sure it gets registered prior to this. But when does login_enqueue_assets get called?

@cojennin cojennin force-pushed the fix/register-scripts-fido-u2f branch from 7f2f616 to de6d035 Compare May 13, 2020 15:26
@kasparsd kasparsd self-requested a review May 13, 2020 15:31
@rinatkhaziev
Copy link

Hi @kasparsd ,

Any plans to get this merged in the next release?

@kasparsd
Copy link
Collaborator

Fixes #361.

@kasparsd
Copy link
Collaborator

There appear to be a few code style issues reported here https://travis-ci.com/github/WordPress/two-factor/jobs/333298974 and a merge conflict with the latest changes introduced by the latest worked merged into master.

Is it OK if I open a new pull request to fix these and also make sure the scripts are available on the login screen?

@kasparsd
Copy link
Collaborator

Replacing this with #368 if that's OK.

@rinatkhaziev, @cojennin Could you please code review #368?

@kasparsd kasparsd closed this Jun 26, 2020
@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.

4 participants