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

Avoid doing-it-wrong notices with direct calls #8

Merged
merged 2 commits into from
May 3, 2024

Conversation

lucatume
Copy link
Contributor

@lucatume lucatume commented May 3, 2024

This PR fixes an issue where the wp_script_is, wp_style_is, wp_register_script and wp_register_style functions would be called too early, triggering a doint-it-wrong PHP notice.

Calling those functions before at least one of the init, wp_enqueue_scripts, admin_enqueue_scripts or login_enqueue_scripts actions has fire, will trigger a doing-it-wrong notice.

The change consists in running the same checks those functions would call to know if the registration would happen too early, if that is the case, the asset will be queued later.
I think the library API should abstract away the "is it too early?" concern, and just do it when it's right.

@lucatume lucatume self-assigned this May 3, 2024
@lucatume lucatume marked this pull request as ready for review May 3, 2024 11:31
@lucatume lucatume requested review from bordoni and borkweb May 3, 2024 11:36
@borkweb
Copy link
Member

borkweb commented May 3, 2024

This looks like a good change! I dug around a bit to ensure that the auto-registering happened and it looks like it does nicely. That being said, there's no tests for that (my bad)

I think it'd be a good idea to add some Acceptance tests that ensures assets still get registered and enqueued if registered earlier than init.

@lucatume
Copy link
Contributor Author

lucatume commented May 3, 2024

I think it'd be a good idea to add some Acceptance tests that ensures assets still get registered and enqueued if registered earlier than init.

Done.

@lucatume lucatume merged commit c5cbed2 into main May 3, 2024
3 checks passed
@lucatume lucatume deleted the fix/too-early-checks branch May 3, 2024 13:01
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.

None yet

2 participants