Skip to content
Snippets Groups Projects

Introduce native Gutenberg controls

Merged Erick Hitter requested to merge add/gutenberg-native-meta into master
Compare and
1 file
+ 45
38
Compare changes
  • Side-by-side
  • Inline
@@ -275,48 +275,55 @@ class WP_Revisions_Control {
@@ -275,48 +275,55 @@ class WP_Revisions_Control {
/**
/**
* Override Core's revisions metabox.
* Override Core's revisions metabox.
*
*
* @param string $post_type Post type.
* @param string $post_type Post type.
* @param object $post Post object.
* @param \WP_Post $post Post object.
*/
*/
public function action_add_meta_boxes( $post_type, $post ) {
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 ) {
if (
// Replace the metabox.
use_block_editor_for_post( $post )
remove_meta_box( 'revisionsdiv', null, 'normal' );
|| ! post_type_supports( $post_type, 'revisions' )
add_meta_box(
|| 'auto-draft' === get_post_status()
'revisionsdiv-wp-rev-ctl',
|| count( wp_get_post_revisions( $post ) ) < 1
__(
) {
'Revisions',
return;
'wp_revisions_control'
}
),
array(
$this,
'revisions_meta_box',
),
null,
'normal',
'core'
);
// A bit of JS for us.
// Replace the metabox.
$handle = 'wp-revisions-control-post';
remove_meta_box( 'revisionsdiv', null, 'normal' );
wp_enqueue_script( $handle, plugins_url( 'js/post.js', __DIR__ ), array( 'jquery' ), '20131205', true );
add_meta_box(
wp_localize_script(
'revisionsdiv-wp-rev-ctl',
$handle,
__(
$this->settings_section,
'Revisions',
array(
'wp_revisions_control'
'namespace' => $this->settings_section,
),
'action_base' => $this->settings_section,
array(
'processing_text' => __( 'Processing&hellip;', 'wp_revisions_control' ),
$this,
'ays' => __( 'Are you sure you want to remove revisions from this post?', 'wp_revisions_control' ),
'revisions_meta_box',
'autosave' => __( 'Autosave', 'wp_revisions_control' ),
),
'nothing_text' => wpautop( __( 'There are no revisions to remove.', 'wp_revisions_control' ) ),
null,
'error' => __( 'An error occurred. Please refresh the page and try again.', 'wp_revisions_control' ),
'normal',
)
'core'
);
);
// Add some styling to our metabox additions.
// A bit of JS for us.
add_action( 'admin_head', array( $this, 'action_admin_head' ), 999 );
$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 );
}
}
/**
/**
Loading