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

Feature/gutenberg deprecation fix #52

Merged
merged 16 commits into from
Jun 1, 2018

Conversation

jomurgel
Copy link
Contributor

Closes #51, #50, #49

DESCRIPTION

Reference: https://wordpress.org/gutenberg/handbook/reference/deprecated/

Resolves issues that arose during mass deprecation/improvements from the core Gutenberg build 2.9.2+

Relocates the following once in wp.blocks now in wp.editor. In our case:

  • ColorPalette
  • InspectorControls
  • BlockControls
  • BlockAlignmentToolbar
  • AlignmentToolbar
  • RichText
  • MediaUpload
  • PlainText
  • BlockIcon
  • UrlInput

Resolved issues with uses of this.props.focus or props.focus which no longer exist. Used, instead, more stable this.props.isSelected or props.isSelected where applicable.

Removed { description } = wp.blocks used in a few places related to the MediaUpload and SelectControl components. No longer a valid block, removes in favor of inline paragraph.

Resolved issue with the Related Posts block search parameter defaulting to users instead of posts.

Resolved issues with any RichText component which was throwing deprecation warning. Focus handlers no longer required with updates above.

Raw TinyMCE event handlers for RichText is deprecated and will be removed from gutenberg in 3.0. Please use Documented props, ancestor event handler, or onSetup access to the internal editor instance event hub instead.

I believe this also closes #51, as I can no longer replicate the issue described in the task, and resolves the width issues described in #50.

screenshot 2018-05-30 18 26 14

It also closes #49 which was missing the ability to remove and image or video once uploaded.

screenshot 2018-05-30 18 28 09
screenshot 2018-05-30 18 29 59

Note

There are still issue with media upload buttons rendering when ACF is active — a known issue documented here. This was fixed in ACF 5.7, but older versions may run into issues below that version.

Steps to Verify

Tested all blocks by adding to new page changing, updating and modifying block content, background options, block options and inline search/select options.

Everything works as initially intended except for a few issues noted in the issues here regarding a few blocks.

Copy link
Contributor

@gregrickaby gregrickaby left a comment

Choose a reason for hiding this comment

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

My only issue is the Recent Posts block. As soon as I add it, I get the "cannot update post" error, and then when I reload the page I see this in the dashboard: 😬
screenshot

  • Chrome 67
  • I just did a MigrateDB Pull from Lab
  • I have the latest versions of all themes/plugins and WP v4.9.6

I went ahead and bumped the versions and such in anticipation of this getting merged in. Thank you for your effort here @jomurgel! 🌮 ❤️

@jomurgel
Copy link
Contributor Author

@gregrickaby have the same chrome version, fresh MigrateDB pull from Lab and all of the latest versions of the plugins + repo and I don't have the same outcome. Might have to do a screen share on this to hopefully nail it down. I would bet it has something to do with the render.php file though given some similar behavior once upon a time during initial dev.

@jomurgel
Copy link
Contributor Author

The issue still appears to be around the use of the_excerpt() or get_the_excerpt() which is documented here: WordPress/gutenberg#5572

The issue also appears to affect the Related Posts block also depending on the posts that are pulled in. I'm unable to replicate the issue if I use older posts that contain any post_content.

In this case, the post_content of the "Test" post 243 is empty containing only the commented list of attributes to render the Recent Posts blocks.

Sort of two issue here, one is if there is no post content to display ( in this case it is since the Recent Posts block is dynamically relying on the render.php function ) it will error, and two if there is no manual excerpt AND no post content we error. Obviously, this isn't ideal and most people don't add manual excerpts. So we need to compensate for an instance where the excerpt doesn't exist.

One potential fix is to do something like this which makes sure we have an excerpt before trying to call either of those two functions.

<?php
// Make sure we have an excerpt.
if ( ! empty( $the_query->post->post_excerpt ) ) :
	the_excerpt();
endif;
?>

The downside to this is that the excerpt here in this case is an empty string '' where as the excerpt via the api is what appears on the admin editor screen so our admin looks like this:
screenshot 2018-05-31 09 41 07

and our front end looks like this:
screenshot 2018-05-31 09 41 11

Option two is to create an excerpt manually with post content. Something like (obviously would need refactored):

echo substr( strip_tags( strip_shortcodes( $the_query->post->post_content ) ), 0, 200 );

Which would output this
screenshot 2018-05-31 09 59 27

It's not the ideal solution either because it still differs from the API post.excerpt.rendered, what is shown in the admin.

Option three is to pull the excerpt directly from the API during render. There are a few issues I'm seeing with this other than that it could be expensive and that is that it may not work in every environment (certainly doesn't work with Local by Flywheel without some additional work.

Option four is to pass the excerpt in from the js into the $attributes and utilize that. A little more work required to get that working and I feel like a large undertaking for a small issue.

The solution I've come up with is a mixture of options 1 and 2 and I think might solve our problem which, if our excerpt is empty, generate one from post content. If we don't have post content return an empty string. Of course if we have a manual excerpt, return that.

Not the best solution as, again, it doesn't render the same as what's in the API's post.excerpt.rendered, but it also is actually a more accurate reflection of post content.

Added a new block-helpers.php file in template-tags and calls that in the Recent and Related Post Blocks.

Output ends up looking like this:
screenshot 2018-05-31 12 07 53

Test, in this case, has no post content and thus has no excerpt. It's not 100%, but more in line with what's in the admin.

Copy link
Contributor

@gregrickaby gregrickaby left a comment

Choose a reason for hiding this comment

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

@jomurgel This worked on the first try! 🥇

@gregrickaby gregrickaby merged commit ebc9b4d into master Jun 1, 2018
@gregrickaby gregrickaby deleted the feature/gutenberg-deprecation-fix branch August 24, 2020 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Something isn't working R4R Issue or PR ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Title/Subtitle no longer accept text Unable to remove/change background image on hero block
3 participants