From 46f900eb4a433984f450e3166349155270c4e294 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Fri, 28 Jun 2024 19:32:36 +0530 Subject: [PATCH 1/2] add filter to delay saving post --- assets/js/editor/editor.js | 4 +++- includes/ConvertToBlocks/MigrationAgent.php | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/assets/js/editor/editor.js b/assets/js/editor/editor.js index 187b6a3..a483b83 100644 --- a/assets/js/editor/editor.js +++ b/assets/js/editor/editor.js @@ -66,7 +66,9 @@ class ConvertToBlocksEditorSupport { return null; } - client.save(); + setTimeout(() => { + client.save(); + }, config.agent.save_delay); return null; }, 500); diff --git a/includes/ConvertToBlocks/MigrationAgent.php b/includes/ConvertToBlocks/MigrationAgent.php index 2aaadbc..1d2f1b6 100644 --- a/includes/ConvertToBlocks/MigrationAgent.php +++ b/includes/ConvertToBlocks/MigrationAgent.php @@ -24,12 +24,18 @@ public function register() { return; } + $posts_to_update = get_option( 'ctb_posts_to_update' ); + $cursor = get_option( 'ctb_cursor' ); + $posts_to_update = is_array( $posts_to_update ) ? $posts_to_update : []; + $post_id = $posts_to_update[ $cursor ] ?? 0; + wp_localize_script( 'convert_to_blocks_editor', 'convert_to_blocks_agent', [ 'agent' => [ - 'next' => $this->next(), + 'next' => $this->next(), + 'save_delay' => apply_filters( 'convert_to_blocks_save_delay', 500, $post_id ) ], ] ); From 352d73a36a6954caa78be8d8ad713e6e50fbeb65 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Tue, 2 Jul 2024 13:32:06 +0530 Subject: [PATCH 2/2] code review changes --- assets/js/editor/editor.js | 10 ++++++++-- includes/ConvertToBlocks/MigrationAgent.php | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/assets/js/editor/editor.js b/assets/js/editor/editor.js index a483b83..bee0280 100644 --- a/assets/js/editor/editor.js +++ b/assets/js/editor/editor.js @@ -66,9 +66,15 @@ class ConvertToBlocksEditorSupport { return null; } - setTimeout(() => { + const saveDelay = config?.agent?.save_delay || 0; + + if (saveDelay > 0) { + setTimeout(() => { + client.save(); + }, saveDelay); + } else { client.save(); - }, config.agent.save_delay); + } return null; }, 500); diff --git a/includes/ConvertToBlocks/MigrationAgent.php b/includes/ConvertToBlocks/MigrationAgent.php index 1d2f1b6..a859a31 100644 --- a/includes/ConvertToBlocks/MigrationAgent.php +++ b/includes/ConvertToBlocks/MigrationAgent.php @@ -35,7 +35,7 @@ public function register() { [ 'agent' => [ 'next' => $this->next(), - 'save_delay' => apply_filters( 'convert_to_blocks_save_delay', 500, $post_id ) + 'save_delay' => apply_filters( 'convert_to_blocks_save_delay', 0, $post_id ) ], ] );