Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command for publish post types #66820

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions packages/editor/src/components/commands/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { useSelect, useDispatch, dispatch } from '@wordpress/data';
import { __, isRTL, sprintf } from '@wordpress/i18n';
import {
blockDefault,
Expand All @@ -14,6 +14,7 @@ import {
external,
keyboard,
symbol,
check,
page,
layout,
rotateRight,
Expand Down Expand Up @@ -280,10 +281,16 @@ const getEditorCommandLoader = () =>

const getEditedEntityContextualCommands = () =>
function useEditedEntityContextualCommands() {
const { postType } = useSelect( ( select ) => {
const { getCurrentPostType } = select( editorStore );
const { postType, isViewable, status } = useSelect( ( select ) => {
const { getCurrentPostType, getEditedPostAttribute } =
select( editorStore );
const { getPostType } = select( coreStore );

return {
postType: getCurrentPostType(),
isViewable:
getPostType( getCurrentPostType() )?.viewable ?? false,
status: getEditedPostAttribute( 'status' ),
};
}, [] );
const { openModal } = useDispatch( interfaceStore );
Expand All @@ -310,6 +317,25 @@ const getEditedEntityContextualCommands = () =>
} );
}

if ( postType !== 'page' && status !== 'publish' && isViewable ) {
commands.push( {
name: 'core/publish-' + postType,
label: sprintf(
/* translators: %s: Post type name (e.g., "Page", "Product") */
__( 'Publish %s' ),
postType.charAt( 0 ).toUpperCase() + postType.slice( 1 )
),
scope: 'core/edit-post',
icon: check,
callback: async ( { close } ) => {
close();
await dispatch( editorStore ).editPost( {
status: 'publish',
} );
await dispatch( editorStore ).savePost();
},
} );
}
return { isLoading: false, commands };
};

Expand Down
Loading