Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/wp-includes/link-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,8 @@ function get_edit_post_link( $post = 0, $context = 'display' ) {
if ( 'wp_template' === $post->post_type || 'wp_template_part' === $post->post_type ) {
$slug = urlencode( get_stylesheet() . '//' . $post->post_name );
$link = admin_url( sprintf( $post_type_object->_edit_link, $post->post_type, $slug ) );
} elseif ( 'wp_navigation' === $post->post_type ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could add an annotation in the get_edit_post_link() PHP doc, e.g., something like

* @since 6.3.0 Adds custom link for wp_navigation post types.

$link = admin_url( sprintf( $post_type_object->_edit_link, (string) $post->ID ) );
} elseif ( $post_type_object->_edit_link ) {
$link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) );
}
Expand Down
9 changes: 9 additions & 0 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,14 @@ function create_initial_post_types() {
)
);

$navigation_post_edit_link = 'site-editor.php?' . build_query(
array(
'postId' => '%s',
'postType' => 'wp_navigation',
'canvas' => 'edit',
)
);

register_post_type(
'wp_navigation',
array(
Expand All @@ -516,6 +524,7 @@ function create_initial_post_types() {
'description' => __( 'Navigation menus that can be inserted into your site.' ),
'public' => false,
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
'_edit_link' => $navigation_post_edit_link, /* internal use only. don't use this when registering your own post type. */
'has_archive' => false,
'show_ui' => true,
'show_in_menu' => false,
Expand Down
20 changes: 20 additions & 0 deletions tests/phpunit/tests/link/getEditPostLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,24 @@ public function test_get_edit_post_link_for_wp_template_part_post_type() {
$this->assertSame( $link_default_context, get_edit_post_link( $template_part_post ), 'Second argument `$context` has a default context of `"display"`.' );
$this->assertSame( $link_custom_context, get_edit_post_link( $template_part_post, 'something-else' ), 'Pass non-default value in second argument.' );
}

public function test_get_edit_post_link_for_wp_navigation_post_type() {
$navigation_post = self::factory()->post->create_and_get(
array(
'post_type' => 'wp_navigation',
'post_name' => 'my_navigation',
'post_title' => 'My Navigation',
'post_content' => '<!-- wp:navigation-link {"label":"WordPress","type":"custom","url":"http://www.wordpress.org/","kind":"custom"} /-->',
'post_excerpt' => 'Description of my Navigation',
)
);

$post_type_object = get_post_type_object( $navigation_post->post_type );

$link_default_context = admin_url( sprintf( $post_type_object->_edit_link, $navigation_post->ID ) );
$link_custom_context = admin_url( sprintf( $post_type_object->_edit_link, $navigation_post->ID ) );

$this->assertSame( $link_default_context, get_edit_post_link( $navigation_post ), 'Second argument `$context` has a default context of `"display"`.' );
$this->assertSame( $link_custom_context, get_edit_post_link( $navigation_post, 'something-else' ), 'Pass non-default value in second argument.' );
}
}