-
Notifications
You must be signed in to change notification settings - Fork 6
Fix some issues with block pattern previews #152
Conversation
I will be attempting to replicate/fix this one next: |
…into try/fix-preview-issues
Reviewing this now 🚀 |
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.
); | ||
} | ||
} | ||
add_action( 'patternmanager_after_pattern_preview', __NAMESPACE__ . '\after_pattern_preview' ); |
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.
Good idea to create a module for this.
|
||
$this->assertSame( | ||
$the_expected_returned_content, | ||
do_the_content_things( $the_raw_content_to_test ) |
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.
Wow, great test!
* @param string $content The html content to run through the filters. | ||
* @return bool | ||
*/ | ||
function do_the_content_things( $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.
Does this need its own module, given that it's only called in wp-modules/pattern-preview-renderer/pattern-preview-renderer.php
?
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 moved it out because do_the_content_things was being used in 2 different modules, but since #148 I guess that's no longer the case.
I don't mind having some of these "module agnostic" functions in a dedicated module. It might perhaps make sense as part of @mike-day's work in #141 though. Maybe we leave it for now and look at moving it into his module once that's ready?
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.
That kind of thing could definitely live in patternmanager-common
(or equivalent)!
I would agree with leaving it for now and moving into the common module when that PR is ready.
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.
|
||
$pattern = \PatternManager\PatternDataHandlers\get_pattern_by_name( $pattern_name ); | ||
|
||
// Handle Genesis themes, who enqueue their stylesheets using genesis_meta. |
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.
Very useful comment 🚀
|
||
|
||
|
||
<p>🙂 <3</p> |
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 idea to test emoji rendering
<?php | ||
/** | ||
* Module Name: Pattern Preview Renderer | ||
* Description: This module makes a front-end render of a block pattern, useful inside iframes or other places you wish to preview a block pattern. |
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 idea to add 'useful inside iframes'
Nice work tackling this, @johnstonphilip! It was a tricky one. |
Extra points: this also fixes GF-3778 for Genesis themes (Resolve preview errors in PM) |
I had an odd hour this morning where generateblocks things weren't being styled right in the previews, but with no changes, it fixed itself. I'm leaving myself a breadcrumb here in case it happens again, but the styles from GenerateBlocks are output as an inline style in the tag like this: |
I've found that generateblocks seems to attach post meta to posts called Since we are not in a post context here (pattern only), there's no post meta, and thus, the CSS doesn't load. The reason why it worked unexpectedly is because while I was testing, I had created a new post in WP, and put generateblocks on that post. When I saved, it added that post meta to the post. In our preview, the global So to fix this, we'll have to mock that post meta, possibly in a compat file for generate blocks. |
I was able to mock the entire post object following this awesome tutorial (kudos @andykeith!): This fixes a few of the workarounds we had to do. By using the block pattern code as the post_content on the mocked post object, we can get rid of our entire |
Oh nice, that should make #153 not needed |
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.
@johnstonphilip I think this is good! Nice work!
Awesome, I shall merge now. |
$wp_query->is_single = false; | ||
$wp_query->is_attachment = false; | ||
$wp_query->is_archive = false; | ||
$wp_query->is_category = false; | ||
$wp_query->is_tag = false; | ||
$wp_query->is_tax = false; | ||
$wp_query->is_author = false; | ||
$wp_query->is_date = false; | ||
$wp_query->is_year = false; | ||
$wp_query->is_month = false; | ||
$wp_query->is_day = false; | ||
$wp_query->is_time = false; | ||
$wp_query->is_search = false; | ||
$wp_query->is_feed = false; | ||
$wp_query->is_comment_feed = false; | ||
$wp_query->is_trackback = false; | ||
$wp_query->is_home = false; | ||
$wp_query->is_embed = false; | ||
$wp_query->is_404 = false; | ||
$wp_query->is_paged = false; | ||
$wp_query->is_admin = false; | ||
$wp_query->is_preview = false; | ||
$wp_query->is_robots = false; | ||
$wp_query->is_posts_page = false; | ||
$wp_query->is_post_type_archive = false; |
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.
Sorry to comment after merge, but are these = false;
statements needed?
Many are false
by default.
$wp_query->is_post_type_archive = false; | ||
|
||
// Update globals. | ||
$GLOBALS['wp_query'] = $wp_query; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
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.
Is this needed? The lines above mutate the global $wp_query
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.
Sorry to comment after the fact.
Tasks
Summary of changes
This PR fixes some issues with block pattern previews, especially ones relating to Genesis Framework.
How to test
Notes & Screenshots
Before this branch (broken)
On this branched (fixed)