-
Notifications
You must be signed in to change notification settings - Fork 361
Conversation
2a8ccd1
to
c9e32e2
Compare
b35ae77
to
ea75607
Compare
/** | ||
* Class A8C_WP_Template_Data_Inserter | ||
*/ | ||
class A8C_WP_Template_Data_Inserter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if instead of including all of the logic in the theme, you instead keep the logic in the plugin and expose helper functions that the theme calls to register template parts, and provide the default block template content (or block template name to request from the API)?
Even though we are using one base theme that all child themes inherit from, that may not always be the case, and you're opening the possibility of future copy-pasta. Abstracting away the hard work, but providing helper functions matches the general philosophy of WordPress and theming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some discussion on this in the other PR, btw. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally I'd like to do that and prevent the need for copy-pasta in the future. On the other hand I'm also trying to avoid posing the requirement that FSE plugin needs to be installed/active prior to theme activation - which might be problematic if the plugin code it relies on is missing.
Ideally I'd like FSE theme to be able to operate entirely independent of FSE plugin - there should be a fallback non-FSE header, and data population should work. That way, if the plugin is activated at a later time, FSE functionality will kick in immediately.
* | ||
* @return string | ||
*/ | ||
public function get_header_content() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We talked about this in a call, but I think this data should be coming from an API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, that would be a lot better than hardcoding it here. I don't see any blockers to doing that atm. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work here, @vindl! I definitely think this is the approach we should head to.
Everything is working according to the testing instructions when paired with Automattic/wp-calypso#34640
I also tested on a WP.com site and the data is now automatically populated after switching to the Modern Business theme. Since the data is automatically created, the issue noted in #34689 is not reproducible anymore.
Apart from the already mentioned suggestions (code duplication, content from API), I found some other minor things we maybe want to improve in follow-ups:
- If I manually remove a template part, it is not created again automatically after switching back to Modern Business.
- Since the data is created after switching to the theme, any existing site currently using the Modern Business theme won't have FSE functionality. Might not be an issue if we want to target only new sites.
- For some reason, in my WP.com test site, the template/template parts has been created 5 times when switching to the theme. This doesn't affect the functionality, given we use the latest template created:
- In WP.com, the template types are created with a
pub
prefix, as you can see on the screenshot above.
Of course, none of them is a blocker!
*/ | ||
public function get_header_content() { | ||
// TODO: replace with header blocks once they are ready. | ||
return '<!-- wp:group {"className":"site-header site-branding"} -->' . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not found any specific doc indicating how many Gutenberg versions do we support in FSE, but given that we still use the older @wordpress/editor
package rather than @wordpress/block-editor
(#), it seems that we want to support at least the 2 most recent WP versions (currently 5.1 and 5.2) like Jetpack does.
Since the group block is not present yet in the current WP version (#), should we avoid using it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this part is required to make Modern Business header layout look as expected in the editor (cc @apeatling).
Since we are now targeting only Dotcom/Atomic, in the short term we can probably rely on the fact that we'll be running the latest version in both environments
Thanks for testing @mmtr!
I kind of relied here on the fact that template parts won't be exposed and hence deletable. I could improve it to check for entries based on taxonomy (instead of site option) and reinsert them when some part is missing.
That's a good point - this depends on how we want to handle existing Modern Business sites (cc @apeatling @gwwar). In case we need to populate data for all such sites, we could make data population execute on
Good catch! This is weird given that it's gated/marked by site option. Wondering if it's related to option caching or maybe the |
Seems this is caused by having the theme branch diverging from the calypso branch: Automattic/wp-calypso#34640 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems that folks like this idea and no blockers have been identified that can’t be addressed in follow ups, so giving my 👍to this.
After landing this, I think we should update the documentation (readme/FG) to make clear that we need now to switch to the Modern Business theme to get the FSE functionality.
this depends on how we want to handle existing Modern Business sites
I think is ok for now to focus on sites switching to the theme.
This adds required functionality to support rendering FSE header and footer on all site pages (static and dynamic). It's also includes the data population functionality, which has now been removed from the plugin and will be delegated to each theme for maximum flexibility.
FSE contant will always be defined due to the fact that this plugin bundles other functionality (SPT). Because of that we can't rely on it to determine if this feature has been activated.
ea75607
to
ffcc2e3
Compare
Since the corresponding Calypso PR has been merged, this should no longer be the case. I'm assuming this was occurring while testing this PR with Calypso master that tried to declare that class to with old FSE plugin approach. |
Lots of great feedback in the comments that I think should be incorporated. ✨ Thank you all for reviews and suggestions! |
Changes proposed in this Pull Request:
This adds required functionality to support rendering FSE header and
footer on all site pages (static and dynamic). It's also includes the
data population functionality, which has now been removed from the plugin
and will be delegated to each theme for maximum flexibility.
Testing instructions:
This PR requires its FSE counterpart PR to work properly. Please follow the testing instructions provided there: Automattic/wp-calypso#34640