From 44add0bb8b0e4b1f16c01783eda9b1e39307e782 Mon Sep 17 00:00:00 2001 From: Renatho De Carli Rosa Date: Mon, 17 Jul 2023 15:50:51 -0300 Subject: [PATCH] Check if a job is being published --- assets/js/admin/job-editor.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/assets/js/admin/job-editor.js b/assets/js/admin/job-editor.js index e69de29bb..121e6bbca 100644 --- a/assets/js/admin/job-editor.js +++ b/assets/js/admin/job-editor.js @@ -0,0 +1,23 @@ +/** + * WordPress dependencies + */ +import { select } from '@wordpress/data'; +import { store as editorStore } from '@wordpress/editor'; + +/** + * Internal dependencies + */ +import editorLifecycle from './editor-lifecycle'; + +const coreEditorSelector = select( editorStore ); + +editorLifecycle( { + onSaveStart: () => { + // Check if status is being changed to publish. + if ( 'publish' === coreEditorSelector.getEditedPostAttribute( 'status' ) && 'publish' !== coreEditorSelector.getCurrentPostAttribute( 'status' ) ) { + const jobId = coreEditorSelector.getCurrentPostId(); + + console.log( jobId ); + } + } +} );