Skip to content

Commit

Permalink
Navigation block: create draft posts and don't render links to drafts (
Browse files Browse the repository at this point in the history
…#27207)

* create draft and don't render drafts on the server

* check for ID existing for excluding just content not external links

* linting
  • Loading branch information
draganescu authored Jan 12, 2021
1 parent 289b7f7 commit 1936a04
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ function NavigationLinkEdit( {

const page = await saveEntityRecord( 'postType', postType, {
title: pageTitle,
status: 'publish',
status: 'draft',
} );

return {
Expand Down Expand Up @@ -389,12 +389,12 @@ function NavigationLinkEdit( {
if ( type === 'post' ) {
/* translators: %s: search term. */
format = __(
'Create post: <mark>%s</mark>'
'Create draft post: <mark>%s</mark>'
);
} else {
/* translators: %s: search term. */
format = __(
'Create page: <mark>%s</mark>'
'Create draft page: <mark>%s</mark>'
);
}
return createInterpolateElement(
Expand Down
8 changes: 8 additions & 0 deletions packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ function block_core_navigation_link_render_submenu_icon() {
* @return string Returns the post content with the legacy widget added.
*/
function render_block_core_navigation_link( $attributes, $content, $block ) {
// Don't render the block's subtree if it is a draft.
if ( is_numeric( $attributes['id'] ) ) {
$post = get_post( $attributes['id'] );
if ( 'publish' !== $post->post_status ) {
return '';
}
}

// Don't render the block's subtree if it has no label.
if ( empty( $attributes['label'] ) ) {
return '';
Expand Down

0 comments on commit 1936a04

Please sign in to comment.