Skip to content

Commit

Permalink
Editor: Extend PostTrashCheck with canUser() check for delete action (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ocean90 authored Jun 22, 2020
1 parent 3cbf030 commit 149a1e1
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/editor/src/components/post-trash/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
*/
import { withSelect } from '@wordpress/data';

function PostTrashCheck( { isNew, postId, children } ) {
if ( isNew || ! postId ) {
function PostTrashCheck( { isNew, postId, canUserDelete, children } ) {
if ( isNew || ! postId || ! canUserDelete ) {
return null;
}

return children;
}

export default withSelect( ( select ) => {
const { isEditedPostNew, getCurrentPostId } = select( 'core/editor' );
const { isEditedPostNew, getCurrentPostId, getCurrentPostType } = select(
'core/editor'
);
const { getPostType, canUser } = select( 'core' );
const postId = getCurrentPostId();
const postType = getPostType( getCurrentPostType() );
const resource = postType?.[ 'rest_base' ] || '';

return {
isNew: isEditedPostNew(),
postId: getCurrentPostId(),
postId,
canUserDelete:
postId && resource ? canUser( 'delete', resource, postId ) : false,
};
} )( PostTrashCheck );

0 comments on commit 149a1e1

Please sign in to comment.