From bfbfd2dc3e15683ee4e5acda512f6f5e19efe924 Mon Sep 17 00:00:00 2001
From: Erick Hitter <git-contrib@ethitter.com>
Date: Sat, 27 Mar 2021 14:59:09 -0700
Subject: [PATCH] Exclude metabox from Gutenberg-enabled posts

---
 inc/class-wp-revisions-control.php | 83 ++++++++++++++++--------------
 1 file changed, 45 insertions(+), 38 deletions(-)

diff --git a/inc/class-wp-revisions-control.php b/inc/class-wp-revisions-control.php
index ead01d0..3ca4d90 100644
--- a/inc/class-wp-revisions-control.php
+++ b/inc/class-wp-revisions-control.php
@@ -275,48 +275,55 @@ class WP_Revisions_Control {
 	/**
 	 * Override Core's revisions metabox.
 	 *
-	 * @param string $post_type Post type.
-	 * @param object $post      Post object.
+	 * @param string   $post_type Post type.
+	 * @param \WP_Post $post      Post object.
 	 */
 	public function action_add_meta_boxes( $post_type, $post ) {
-		if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' !== get_post_status() && count( wp_get_post_revisions( $post ) ) > 1 ) {
-			// Replace the metabox.
-			remove_meta_box( 'revisionsdiv', null, 'normal' );
-			add_meta_box(
-				'revisionsdiv-wp-rev-ctl',
-				__(
-					'Revisions',
-					'wp_revisions_control'
-				),
-				array(
-					$this,
-					'revisions_meta_box',
-				),
-				null,
-				'normal',
-				'core'
-			);
+		if (
+			use_block_editor_for_post( $post )
+			|| ! post_type_supports( $post_type, 'revisions' )
+			|| 'auto-draft' === get_post_status()
+			|| count( wp_get_post_revisions( $post ) ) < 1
+		) {
+			return;
+		}
 
-			// A bit of JS for us.
-			$handle = 'wp-revisions-control-post';
-			wp_enqueue_script( $handle, plugins_url( 'js/post.js', __DIR__ ), array( 'jquery' ), '20131205', true );
-			wp_localize_script(
-				$handle,
-				$this->settings_section,
-				array(
-					'namespace'       => $this->settings_section,
-					'action_base'     => $this->settings_section,
-					'processing_text' => __( 'Processing&hellip;', 'wp_revisions_control' ),
-					'ays'             => __( 'Are you sure you want to remove revisions from this post?', 'wp_revisions_control' ),
-					'autosave'        => __( 'Autosave', 'wp_revisions_control' ),
-					'nothing_text'    => wpautop( __( 'There are no revisions to remove.', 'wp_revisions_control' ) ),
-					'error'           => __( 'An error occurred. Please refresh the page and try again.', 'wp_revisions_control' ),
-				)
-			);
+		// Replace the metabox.
+		remove_meta_box( 'revisionsdiv', null, 'normal' );
+		add_meta_box(
+			'revisionsdiv-wp-rev-ctl',
+			__(
+				'Revisions',
+				'wp_revisions_control'
+			),
+			array(
+				$this,
+				'revisions_meta_box',
+			),
+			null,
+			'normal',
+			'core'
+		);
 
-			// Add some styling to our metabox additions.
-			add_action( 'admin_head', array( $this, 'action_admin_head' ), 999 );
-		}
+		// A bit of JS for us.
+		$handle = 'wp-revisions-control-post';
+		wp_enqueue_script( $handle, plugins_url( 'js/post.js', __DIR__ ), array( 'jquery' ), '20131205', true );
+		wp_localize_script(
+			$handle,
+			$this->settings_section,
+			array(
+				'namespace'       => $this->settings_section,
+				'action_base'     => $this->settings_section,
+				'processing_text' => __( 'Processing&hellip;', 'wp_revisions_control' ),
+				'ays'             => __( 'Are you sure you want to remove revisions from this post?', 'wp_revisions_control' ),
+				'autosave'        => __( 'Autosave', 'wp_revisions_control' ),
+				'nothing_text'    => wpautop( __( 'There are no revisions to remove.', 'wp_revisions_control' ) ),
+				'error'           => __( 'An error occurred. Please refresh the page and try again.', 'wp_revisions_control' ),
+			)
+		);
+
+		// Add some styling to our metabox additions.
+		add_action( 'admin_head', array( $this, 'action_admin_head' ), 999 );
 	}
 
 	/**
-- 
GitLab