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

Add Interactivity API hooks to wp_admin #6453

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ public function register_script_modules() {
public function add_hooks() {
add_action( 'wp_enqueue_scripts', array( $this, 'register_script_modules' ) );
add_action( 'wp_footer', array( $this, 'print_client_interactivity_data' ) );

add_action( 'admin_enqueue_scripts', array( $this, 'register_script_modules' ) );
Copy link
Member

Choose a reason for hiding this comment

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

The question is which hook fits better here as there are two possibilities in contrast to the front end:

  • admin_footer - Prints scripts or data before the default footer scripts.
  • admin_print_footer_scripts - Prints any scripts and data queued for the footer.

Copy link
Member

Choose a reason for hiding this comment

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

It's the configs and initial state for stores so it probably needs to be printer earlier 👍🏻

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, good question! I think I'd print this as late as possible. @wordpress/interactivity is what will use this when it initializes, and because that's a module the DOM should have finished parsing before it runs.

I think we can switch this to admin_print_footer_scripts to print it as late as possible.

Copy link
Member

Choose a reason for hiding this comment

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

I was exploring that part of the codebase for the first time today. I still don't know what should be the order of printing when taking into account also 3rd party plugins that depend on Interactivity API. My initial thinking was that 3rd party plugins would use admin_enqueue_scripts to register/enqueue their scripts. I'm not sure how folks would use wp_interactivity_store.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've pushed that change, I can see the script moved after the footer scripts and it continues to work as expected.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's @wordpress/interactivity itself that reads data from the printed store data. And because these are modules (which implies defer) there shouldn't be any problem pushing the printed script tag to be later. The module that depends on it will not execute until the DOM has been parsed completely, so the script tag it looks for will be there.

add_action( 'admin_footer', array( $this, 'print_client_interactivity_data' ) );
}

/**
Expand Down
Loading