Skip to content

Add actions for plugins to register frontend and editor assets#1717

Merged
nylen merged 8 commits intomasterfrom
add/plugin-assets-hook
Jul 5, 2017
Merged

Add actions for plugins to register frontend and editor assets#1717
nylen merged 8 commits intomasterfrom
add/plugin-assets-hook

Conversation

@nylen
Copy link
Copy Markdown
Member

@nylen nylen commented Jul 5, 2017

Adds actions so that someone can hook into where Gutenberg styles and scripts are loaded and bring in styles and scripts of their own, for both the frontend and the editor.

This modifies functionality added in #1418, adding a Gutenberg-specific action intended for plugin use in enqueuing front-end assets. It also adds a corresponding action for plugins to enqueue editor assets.

See also #422, #514, and #1420.

@nylen nylen changed the title Add actions for frontend and plugin styles Add actions for plugins to register frontend and editor assets Jul 5, 2017
nylen added 2 commits July 5, 2017 12:23
...and fire this action in both admin context and on the frontend.
@nylen
Copy link
Copy Markdown
Member Author

nylen commented Jul 5, 2017

As of 00e7c3a there are two actions here:

  • enqueue_block_assets - fires in both editor and admin contexts to allow enqueuing assets common to both. If enqueuing scripts here, plugin authors should use an if ( ! is_admin() ) check to ensure that they are only loaded on the frontend. We may want a third enqueue_block_frontend_assets action instead, but this should be added later if necessary.
  • enqueue_block_editor_assets - fires in the editor context to allow enqueuing scripts and styles specific to the editor (register the block, build and style its editing controls, etc.)

@swissspidy
Copy link
Copy Markdown
Member

We may want a third enqueue_block_frontend_assets action instead, but this should be added later if necessary.

Then gutenberg_frontend_scripts_and_styles is not an ideal function name when it's called in the admin as well.

@nylen
Copy link
Copy Markdown
Member Author

nylen commented Jul 5, 2017

Then gutenberg_frontend_scripts_and_styles is not an ideal function name when it's called in the admin as well.

👍 Changed to common in 214e177 [and further improved in def57fc].

Copy link
Copy Markdown
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

LGTM 👍

// Enqueue block styles built through plugins. This lives in a separate
// action for a couple of reasons: (1) we want to load these assets
// (usually stylesheets) in *both* frontend and editor contexts, and (2)
// one day we may need to be smarter about whether assets are included
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be a multi-line comment, e.g.

/*
 * ddd
 */

(with one asterisk on the first line)

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