From b2ef2fc2f629a5bdfd3f4f1a0dbde93ebae7bfa2 Mon Sep 17 00:00:00 2001 From: Kiril Zhelyazkov Date: Mon, 13 Apr 2020 11:28:21 +0300 Subject: [PATCH] fix: [#20954] Scheduled posts display the correct url --- .../post-publish-panel/postpublish.js | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/packages/editor/src/components/post-publish-panel/postpublish.js b/packages/editor/src/components/post-publish-panel/postpublish.js index 21ea2144d052f0..c7aa69bddb20cd 100644 --- a/packages/editor/src/components/post-publish-panel/postpublish.js +++ b/packages/editor/src/components/post-publish-panel/postpublish.js @@ -23,6 +23,26 @@ import { decodeEntities } from '@wordpress/html-entities'; */ import PostScheduleLabel from '../post-schedule/label'; +const POSTNAME = '%postname%'; + +/** + * Returns URL for a future post. + * + * @param {Object} post Post object. + * + * @return {string} PostPublish URL. + */ + +const getFuturePostUrl = ( post ) => { + const { slug } = post; + + if ( post.permalink_template.includes( POSTNAME ) ) { + return post.permalink_template.replace( POSTNAME, slug ); + } + + return post.permalink_template; +}; + class PostPublishPanelPostpublish extends Component { constructor() { super( ...arguments ); @@ -65,6 +85,8 @@ class PostPublishPanelPostpublish extends Component { const { children, isScheduled, post, postType } = this.props; const postLabel = get( postType, [ 'labels', 'singular_name' ] ); const viewPostLabel = get( postType, [ 'labels', 'view_item' ] ); + const link = + post.status === 'future' ? getFuturePostUrl( post ) : post.link; const postPublishNonLinkHeader = isScheduled ? ( <> @@ -78,7 +100,7 @@ class PostPublishPanelPostpublish extends Component { return (
- + { decodeEntities( post.title ) || __( '(no title)' ) } { ' ' } { postPublishNonLinkHeader } @@ -95,19 +117,19 @@ class PostPublishPanelPostpublish extends Component { __( '%s address' ), postLabel ) } - value={ safeDecodeURIComponent( post.link ) } + value={ safeDecodeURIComponent( link ) } onFocus={ this.onSelectInput } />
{ ! isScheduled && ( - ) } { this.state.showCopyConfirmation