Skip to content

Conversation

brandonpayton
Copy link
Member

@brandonpayton brandonpayton commented Nov 10, 2018

Description

This is a change to avoid problems due to changing the default wpautop priority.

Fixes #11691.

How has this been tested?

Some text above
https://www.youtube.com/watch?v=3V9QHBgrPNY

https://www.youtube.com/watch?v=f5KyMNDJE6o
  • Tested that block content opened in the classic editor retains its paragraphs.
  • Tested that non-block content is autop'd.
  • Unit tests.

Types of changes

Take a similar approach to core by removing the wpautop filter when block content is detected and subsequently restore it for later applications of the the_content filter.

The core changeset used for reference:
https://core.trac.wordpress.org/changeset/43879

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@brandonpayton brandonpayton added [Type] Bug An existing feature does not function as intended [Status] In Progress Tracking issues with work in progress labels Nov 10, 2018
@brandonpayton brandonpayton added this to the 4.4 milestone Nov 10, 2018
@brandonpayton brandonpayton self-assigned this Nov 10, 2018
lib/compat.php Outdated
*/
function gutenberg_wpautop( $content ) {
if ( has_blocks( $content ) ) {
return $content;
// If there are blocks in this content, we shouldn't run wpautop() on it later.
Copy link
Member

Choose a reason for hiding this comment

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

In Core, this block of code is run at the top of do_blocks(), there is no equivalent of gutenberg_wpautop(). Any particular reason why you chose to do it this way?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's no good reason.

I may have made a mental mistake and avoided do_blocks because it is only defined conditionally by this plugin, but actually, we only need to worry about avoiding wpautop when we define do_blocks. Thanks for asking.

lib/compat.php Outdated
*
* @access private
*
* @since 4.4
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @since 4.4
* @since 4.4.0

@brandonpayton brandonpayton force-pushed the fix/broken-wpautop-priority branch from e116708 to bd83c88 Compare November 12, 2018 21:12
lib/blocks.php Outdated
$priority = has_filter( 'the_content', 'wpautop' );
if ( false !== $priority && doing_filter( 'the_content' ) && has_blocks( $content ) ) {
remove_filter( 'the_content', 'wpautop', $priority );
add_filter( 'the_content', 'wpautop', $priority + 1 );
Copy link
Member Author

Choose a reason for hiding this comment

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

Immediately re-adding wpautop here. 🤦‍♂️ Good example of why one shouldn't work during time set aside for recharging.

@brandonpayton brandonpayton removed the [Status] In Progress Tracking issues with work in progress label Nov 12, 2018
@brandonpayton brandonpayton requested a review from a team November 12, 2018 23:09
@youknowriad youknowriad modified the milestones: 4.4, 4.5 Nov 15, 2018
lib/blocks.php Outdated
@@ -187,6 +194,29 @@ function do_blocks( $content ) {
add_filter( 'the_content', 'do_blocks', 7 ); // BEFORE do_shortcode() and oembed.
}

if ( ! function_exists( '_restore_wpautop_hook' ) ) {
/**
* If do_blocks() needs to remove wp_autop() from the `the_content` filter,
Copy link

Choose a reason for hiding this comment

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

wp_autop ~> wpautop

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for catching that. It's fixed now.

@brandonpayton brandonpayton force-pushed the fix/broken-wpautop-priority branch from ae40f6d to 46b6887 Compare November 16, 2018 18:57
@mtias mtias modified the milestones: 4.5, 4.6 Nov 19, 2018
@catehstn
Copy link

This looks like it's ready for another pass, @brandonpayton?

@brandonpayton brandonpayton force-pushed the fix/broken-wpautop-priority branch from 46b6887 to e5ecd4a Compare November 21, 2018 17:19
@brandonpayton
Copy link
Member Author

This looks like it's ready for another pass, @brandonpayton?

Yep. It just needs a review.

@mtias mtias added [Type] Task Issues or PRs that have been broken down into an individual action to take and removed [Type] Bug An existing feature does not function as intended labels Nov 22, 2018
@brandonpayton
Copy link
Member Author

Hi @mtias, why are we changing this from a Bug to a Task? Loading Gutenberg in 4.9 breaks auto embeds as mentioned in #11691. That is buggy behavior.

Copy link
Member

@noisysocks noisysocks left a comment

Choose a reason for hiding this comment

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

Confirmed that this fixes #11691 👍

Could we include the unit test that's in https://core.trac.wordpress.org/changeset/43879?

Will be good to remove all of these workarounds once the Gutenberg plugin relies on having WordPress 5.0 installed.

@noisysocks
Copy link
Member

This should go into the next plugin release. My understanding is that that will be 4.7, not 4.6.

@mtias
Copy link
Member

mtias commented Nov 28, 2018

@brandonpayton changed it to task because this is retrofitting the plugin with behaviour present in core, and since we are not doing another plugin release yet.

@brandonpayton
Copy link
Member Author

ah, maybe I shouldn't be tagging PRs with "bug" at all. thanks for explaining @mtias

@mtias
Copy link
Member

mtias commented Nov 28, 2018

It's fine :) I just wanted to have a clear overview in the milestone to figure out what needs to be merged before release and what can be added after release but before 5.0.1, if that makes sense.

@youknowriad youknowriad merged commit 2a66db0 into master Nov 29, 2018
@youknowriad youknowriad deleted the fix/broken-wpautop-priority branch November 29, 2018 12:48
daniloercoli added a commit that referenced this pull request Nov 29, 2018
…rnmobile/danilo-try-to-fix-undo-redo

* 'master' of https://github.com/WordPress/gutenberg:
  Avoid changing default wpautop priority (#11722)
  Try fixing the tab navigation issue (#12390)
  Polish editor style documentation (#12381)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants