diff --git a/js/block-editor.js b/js/block-editor.js new file mode 100644 index 0000000..b03f7bd --- /dev/null +++ b/js/block-editor.js @@ -0,0 +1,26 @@ +var editPost = wp.data.select( 'core/edit-post' ), lastIsSaving = false; + +wp.data.subscribe( + function() { + var isSaving = editPost.isSavingMetaBoxes(); + if ( isSaving !== lastIsSaving && ! isSaving ) { + lastIsSaving = isSaving; + // Gutenberg Post Saving has finished! + var data = { + 'action': 'update_post_meta_inspector', + 'nonce': pmi_data.nonce, + 'post': pmi_data.post + }; + + jQuery.get( + ajaxurl, + data, + function( response ) { + jQuery( '#post_meta_inspector' ).html( response ); + } + ); + } + + lastIsSaving = isSaving; + } +); diff --git a/post-meta-inspector.php b/post-meta-inspector.php index d39ecbe..b239e26 100644 --- a/post-meta-inspector.php +++ b/post-meta-inspector.php @@ -62,6 +62,8 @@ private function __construct() { private static function setup_actions() { add_action( 'init', array( self::$instance, 'action_init' ) ); add_action( 'add_meta_boxes', array( self::$instance, 'action_add_meta_boxes' ) ); + add_action( 'wp_ajax_update_post_meta_inspector', array( self::$instance, 'ajax_render_table' ) ); + add_action( 'enqueue_block_editor_assets', array( self::$instance, 'enqueue_block_editor_assets' ) ); } /** @@ -91,9 +93,12 @@ public function action_add_meta_boxes() { * @return void */ public function post_meta_inspector() { - $toggle_length = apply_filters( 'pmi_toggle_long_value_length', 0 ); - $toggle_length = max( intval( $toggle_length ), 0 ); - $toggle_el = '' . __( 'Click to show…', 'post-meta-inspector' ) . ''; + // Data for Block Editor AJAX call. + $pmi_data = array( + 'nonce' => wp_create_nonce( 'update_post_meta_inspector' ), + 'post' => get_the_ID(), + ); + ?> + + + -
| - | + | + | |
|---|---|---|---|
| - - | +