Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ private function to_wp_post( $post ) {
$obj->ping_status = $post['ping_status'];

// Use raw content if both remote and local are using Gutenberg.
$obj->post_content = \Distributor\Utils\is_using_gutenberg( new \WP_Post( $obj ) ) && isset( $post['is_using_gutenberg'] ) ?
$obj->post_content = Utils\is_using_gutenberg( new \WP_Post( $obj ) ) && isset( $post['is_using_gutenberg'] ) ?
$post['content']['raw'] :
Utils\get_processed_content( $post['content']['raw'] );

Expand Down
30 changes: 23 additions & 7 deletions includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,40 @@ function is_vip_com() {
* @return boolean
*/
function is_using_gutenberg( $post ) {
if ( empty( $post->post_content ) ) {
return false;
}

global $wp_version;

$gutenberg_available = function_exists( 'the_gutenberg_project' );
$version_5_plus = version_compare( $wp_version, '5', '>=' );

if ( ! $gutenberg_available && ! $version_5_plus ) {
return false;
}

if ( function_exists( 'use_block_editor_for_post' ) ) {
return use_block_editor_for_post( $post );
} else {
if ( ! empty( $post->post_content ) ) {
if ( function_exists( 'use_block_editor_for_post' ) ) {
return use_block_editor_for_post( $post );
}

// This duplicates the check from `has_blocks()` as of WP 5.2.
return false !== strpos( (string) $post->post_content, '<!-- wp:' );
}

$use_block_editor = true;

if ( ! function_exists( 'is_plugin_active' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}

if ( is_plugin_active( 'classic-editor/classic-editor.php' ) ) {
$use_block_editor = ( get_option( 'classic-editor-replace' ) === 'no-replace' );
}

if ( $use_block_editor && is_a( $post, '\WP_Post' ) && class_exists( '\Gutenberg_Ramp' ) ) {
$gutenberg_ramp = \Gutenberg_Ramp::get_instance();
$use_block_editor = $gutenberg_ramp->gutenberg_should_load( $post );
}

return $use_block_editor;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/wpacceptance/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ public function testAuthorBylineSetting() {
// Verify byline is normal
$I->moveTo( $post_info['distributed_front_url'] );

$I->seeText( 'wpsnapshots', '.byline .author' );
$I->seeText( 'admin', '.byline .author' );
}
}