From 9b500f5d8c55bc8dcea0e1026c6705ccd810d6cf Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Fri, 14 Jul 2023 10:31:03 +1000 Subject: [PATCH 1/5] Store and update post status in `dt` object. --- assets/js/gutenberg-plugin.js | 3 +++ assets/js/push.js | 4 +++- includes/push-ui.php | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/assets/js/gutenberg-plugin.js b/assets/js/gutenberg-plugin.js index 6d8306c24..7856bd093 100644 --- a/assets/js/gutenberg-plugin.js +++ b/assets/js/gutenberg-plugin.js @@ -187,8 +187,11 @@ const DistributorPlugin = () => { const post = useSelect( ( select ) => select( 'core/editor' ).getCurrentPost() ); + console.log( post ); // Make the post title available to the top menu. dt.postTitle = post.title; + // Make the post status available to the top menu. + dt.postStatus = post.status; // If we are on a non-supported post status, change what we show if ( diff --git a/assets/js/push.js b/assets/js/push.js index eb26e12db..8c8a51a07 100755 --- a/assets/js/push.js +++ b/assets/js/push.js @@ -401,6 +401,7 @@ jQuery( window ).on( 'load', () => { foundConnections: mustacheData.connections.length, showSearch: 5 < mustacheData.connections.length, postTitle: dt.postTitle, + postStatus: dt.postStatus, } ); @@ -409,6 +410,7 @@ jQuery( window ).on( 'load', () => { distributorPushWrapper.innerHTML = template( { connections: dtConnections, postTitle: dt.postTitle, + postStatus: dt.postStatus, } ); } @@ -516,7 +518,7 @@ jQuery( window ).on( 'load', () => { data.postStatus = null !== asDraftInput && asDraftInput.checked ? 'draft' - : postStatusInput.value; + : dt.postStatus; const xhr = dt.usexhr ? { withCredentials: true } : false; diff --git a/includes/push-ui.php b/includes/push-ui.php index b58a5ad7e..d883425ed 100644 --- a/includes/push-ui.php +++ b/includes/push-ui.php @@ -414,6 +414,7 @@ function enqueue_scripts( $hook ) { 'loadConnectionsNonce' => wp_create_nonce( 'dt-load-connections' ), 'postId' => (int) get_the_ID(), 'postTitle' => get_the_title(), + 'postStatus' => get_post_status(), 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ), /** From 5a76939cbec409a3dbbe8b68df95e64648eb02f0 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Fri, 14 Jul 2023 11:31:26 +1000 Subject: [PATCH 2/5] Remove unused `dt-post-status` input. --- assets/js/push.js | 2 -- templates/show-connections-amp.php | 1 - templates/show-connections.php | 1 - 3 files changed, 4 deletions(-) diff --git a/assets/js/push.js b/assets/js/push.js index 8c8a51a07..96290d47e 100755 --- a/assets/js/push.js +++ b/assets/js/push.js @@ -50,7 +50,6 @@ jQuery( window ).on( 'load', () => { let selectAllConnections = ''; let selectNoConnections = ''; let connectionsSearchInput = ''; - let postStatusInput = ''; let asDraftInput = ''; let errorDetails = ''; @@ -91,7 +90,6 @@ jQuery( window ).on( 'load', () => { connectionsSearchInput = document.getElementById( 'dt-connection-search' ); - postStatusInput = document.getElementById( 'dt-post-status' ); asDraftInput = document.getElementById( 'dt-as-draft' ); errorDetails = document.querySelector( '.dt-error ul.details' ); diff --git a/templates/show-connections-amp.php b/templates/show-connections-amp.php index 98cdda683..a50833b5d 100644 --- a/templates/show-connections-amp.php +++ b/templates/show-connections-amp.php @@ -55,7 +55,6 @@ class="add-connection{{#syndicated}} syndicated{{/syndicated}}"