Skip to content

Commit

Permalink
Allow resetting the permalink by saving it as empty (#6615)
Browse files Browse the repository at this point in the history
Fixes #6603.
  • Loading branch information
pento committed May 8, 2018
1 parent 4dc4c7b commit 3d93ac6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
3 changes: 1 addition & 2 deletions editor/components/post-permalink/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PostPermalinkEditor extends Component {

this.props.onSave();

if ( ! postName || postName === this.props.postName ) {
if ( postName === this.props.postName ) {
return;
}

Expand Down Expand Up @@ -63,7 +63,6 @@ class PostPermalinkEditor extends Component {
value={ editedPostName }
onChange={ ( event ) => this.setState( { editedPostName: event.target.value } ) }
type="text"
required
autoFocus
/>
<span className="editor-post-permalink-editor__suffix">
Expand Down
2 changes: 1 addition & 1 deletion editor/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,7 @@ export function getPermalink( state ) {
*/
export function getPermalinkParts( state ) {
const permalinkTemplate = getEditedPostAttribute( state, 'permalink_template' );
const postName = getEditedPostAttribute( state, 'slug' ) || getEditedPostAttribute( state, 'draft_slug' );
const postName = getEditedPostAttribute( state, 'slug' ) || getEditedPostAttribute( state, 'generated_slug' );

const [ prefix, suffix ] = permalinkTemplate.split( PERMALINK_POSTNAME_REGEX );

Expand Down
7 changes: 2 additions & 5 deletions lib/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,10 @@ function gutenberg_add_permalink_template_to_posts( $response, $post, $request )
require_once ABSPATH . '/wp-admin/includes/post.php';
}

$sample_permalink = get_sample_permalink( $post->ID );
$sample_permalink = get_sample_permalink( $post->ID, $post->post_title, '' );

$response->data['permalink_template'] = $sample_permalink[0];

if ( 'draft' === $post->post_status && ! $post->post_name ) {
$response->data['draft_slug'] = $sample_permalink[1];
}
$response->data['generated_slug'] = $sample_permalink[1];

return $response;
}
Expand Down

0 comments on commit 3d93ac6

Please sign in to comment.