Skip to content

Commit

Permalink
Turn ID into a unique slug when wp_navigation is created
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Nov 24, 2021
1 parent 8d258e5 commit 4c048f5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/navigation.php
Expand Up @@ -449,3 +449,29 @@ function gutenberg_hide_visibility_and_status_for_navigation_posts( $hook ) {
}

add_action( 'admin_enqueue_scripts', 'gutenberg_hide_visibility_and_status_for_navigation_posts' );

/**
* Sets a custom slug when creating auto-draft wp_navigatino posts.
* This is only needed for auto-drafts created by the regular WP editor.
* If this page is to be removed, this won't be necessary.
*
* @param int $post_id Post ID.
*/
function gutenberg_set_unique_slug_on_create_wp_navigation( $post_id ) {
// This is the core function with the same functionality.
if ( function_exists( 'gutenberg_set_unique_slug_on_create_wp_navigation' ) ) {
return;
}

$post = get_post( $post_id );
if ( ! $post->post_name ) {
wp_update_post(
array(
'ID' => $post_id,
'post_name' => $post_id . '',
)
);
}
}

add_action( 'save_post_wp_navigation', 'gutenberg_set_unique_slug_on_create_wp_navigation' );

0 comments on commit 4c048f5

Please sign in to comment.