From 8fecfbf47cbe762fe5d02b7c9352fb0dd8c4e957 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 21 Jun 2023 10:10:46 +0100 Subject: [PATCH 1/9] Use custom edit link definition on Navigation Post type --- src/wp-includes/post.php | 41 ++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 1d543fe9860e5..12f2d603fb116 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -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( @@ -512,6 +520,9 @@ function create_initial_post_types() { 'filter_items_list' => __( 'Filter Navigation Menu list' ), 'items_list_navigation' => __( 'Navigation Menus list navigation' ), 'items_list' => __( 'Navigation Menus list' ), + /* internal use only. don't use this when registering your own post type. */ + '_edit_link' => $navigation_post_edit_link, + ), 'description' => __( 'Navigation menus that can be inserted into your site.' ), 'public' => false, @@ -551,7 +562,8 @@ function create_initial_post_types() { array( 'label' => _x( 'Published', 'post status' ), 'public' => true, - '_builtin' => true, /* internal use only. */ + '_builtin' => true, /* + internal use only. */ /* translators: %s: Number of published posts. */ 'label_count' => _n_noop( 'Published (%s)', @@ -565,7 +577,8 @@ function create_initial_post_types() { array( 'label' => _x( 'Scheduled', 'post status' ), 'protected' => true, - '_builtin' => true, /* internal use only. */ + '_builtin' => true, /* + internal use only. */ /* translators: %s: Number of scheduled posts. */ 'label_count' => _n_noop( 'Scheduled (%s)', @@ -579,7 +592,8 @@ function create_initial_post_types() { array( 'label' => _x( 'Draft', 'post status' ), 'protected' => true, - '_builtin' => true, /* internal use only. */ + '_builtin' => true, /* + internal use only. */ /* translators: %s: Number of draft posts. */ 'label_count' => _n_noop( 'Draft (%s)', @@ -594,7 +608,8 @@ function create_initial_post_types() { array( 'label' => _x( 'Pending', 'post status' ), 'protected' => true, - '_builtin' => true, /* internal use only. */ + '_builtin' => true, /* + internal use only. */ /* translators: %s: Number of pending posts. */ 'label_count' => _n_noop( 'Pending (%s)', @@ -609,7 +624,8 @@ function create_initial_post_types() { array( 'label' => _x( 'Private', 'post status' ), 'private' => true, - '_builtin' => true, /* internal use only. */ + '_builtin' => true, /* + internal use only. */ /* translators: %s: Number of private posts. */ 'label_count' => _n_noop( 'Private (%s)', @@ -623,7 +639,8 @@ function create_initial_post_types() { array( 'label' => _x( 'Trash', 'post status' ), 'internal' => true, - '_builtin' => true, /* internal use only. */ + '_builtin' => true, /* + internal use only. */ /* translators: %s: Number of trashed posts. */ 'label_count' => _n_noop( 'Trash (%s)', @@ -658,7 +675,8 @@ function create_initial_post_types() { array( 'label' => _x( 'Pending', 'request status' ), 'internal' => true, - '_builtin' => true, /* internal use only. */ + '_builtin' => true, /* + internal use only. */ /* translators: %s: Number of pending requests. */ 'label_count' => _n_noop( 'Pending (%s)', @@ -673,7 +691,8 @@ function create_initial_post_types() { array( 'label' => _x( 'Confirmed', 'request status' ), 'internal' => true, - '_builtin' => true, /* internal use only. */ + '_builtin' => true, /* + internal use only. */ /* translators: %s: Number of confirmed requests. */ 'label_count' => _n_noop( 'Confirmed (%s)', @@ -688,7 +707,8 @@ function create_initial_post_types() { array( 'label' => _x( 'Failed', 'request status' ), 'internal' => true, - '_builtin' => true, /* internal use only. */ + '_builtin' => true, /* + internal use only. */ /* translators: %s: Number of failed requests. */ 'label_count' => _n_noop( 'Failed (%s)', @@ -703,7 +723,8 @@ function create_initial_post_types() { array( 'label' => _x( 'Completed', 'request status' ), 'internal' => true, - '_builtin' => true, /* internal use only. */ + '_builtin' => true, /* + internal use only. */ /* translators: %s: Number of completed requests. */ 'label_count' => _n_noop( 'Completed (%s)', From 15d48377e9bcc8972ba1c7f2fc8a277498a80599 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 21 Jun 2023 10:10:56 +0100 Subject: [PATCH 2/9] Amend link template for Navigation post type --- src/wp-includes/link-template.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index 28c65c8d0a434..404a4a5437b68 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -1474,6 +1474,9 @@ 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 ) { + $id = $post->ID; + $link = admin_url( sprintf( $post_type_object->_edit_link, $id ) ); } elseif ( $post_type_object->_edit_link ) { $link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) ); } From 33c24661ad30906d97278527b5c5878d082f166f Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 21 Jun 2023 10:22:01 +0100 Subject: [PATCH 3/9] Revert unintended reformatting --- src/wp-includes/post.php | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 12f2d603fb116..3cfcb9a071a95 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -562,8 +562,7 @@ function create_initial_post_types() { array( 'label' => _x( 'Published', 'post status' ), 'public' => true, - '_builtin' => true, /* - internal use only. */ + '_builtin' => true, /* internal use only. */ /* translators: %s: Number of published posts. */ 'label_count' => _n_noop( 'Published (%s)', @@ -577,8 +576,7 @@ function create_initial_post_types() { array( 'label' => _x( 'Scheduled', 'post status' ), 'protected' => true, - '_builtin' => true, /* - internal use only. */ + '_builtin' => true, /* internal use only. */ /* translators: %s: Number of scheduled posts. */ 'label_count' => _n_noop( 'Scheduled (%s)', @@ -592,8 +590,7 @@ function create_initial_post_types() { array( 'label' => _x( 'Draft', 'post status' ), 'protected' => true, - '_builtin' => true, /* - internal use only. */ + '_builtin' => true, /* internal use only. */ /* translators: %s: Number of draft posts. */ 'label_count' => _n_noop( 'Draft (%s)', @@ -608,8 +605,7 @@ function create_initial_post_types() { array( 'label' => _x( 'Pending', 'post status' ), 'protected' => true, - '_builtin' => true, /* - internal use only. */ + '_builtin' => true, /* internal use only. */ /* translators: %s: Number of pending posts. */ 'label_count' => _n_noop( 'Pending (%s)', @@ -624,8 +620,7 @@ function create_initial_post_types() { array( 'label' => _x( 'Private', 'post status' ), 'private' => true, - '_builtin' => true, /* - internal use only. */ + '_builtin' => true, /* internal use only. */ /* translators: %s: Number of private posts. */ 'label_count' => _n_noop( 'Private (%s)', @@ -639,8 +634,7 @@ function create_initial_post_types() { array( 'label' => _x( 'Trash', 'post status' ), 'internal' => true, - '_builtin' => true, /* - internal use only. */ + '_builtin' => true, /* internal use only. */ /* translators: %s: Number of trashed posts. */ 'label_count' => _n_noop( 'Trash (%s)', @@ -675,8 +669,7 @@ function create_initial_post_types() { array( 'label' => _x( 'Pending', 'request status' ), 'internal' => true, - '_builtin' => true, /* - internal use only. */ + '_builtin' => true, /* internal use only. */ /* translators: %s: Number of pending requests. */ 'label_count' => _n_noop( 'Pending (%s)', @@ -691,8 +684,7 @@ function create_initial_post_types() { array( 'label' => _x( 'Confirmed', 'request status' ), 'internal' => true, - '_builtin' => true, /* - internal use only. */ + '_builtin' => true, /* internal use only. */ /* translators: %s: Number of confirmed requests. */ 'label_count' => _n_noop( 'Confirmed (%s)', @@ -707,8 +699,7 @@ function create_initial_post_types() { array( 'label' => _x( 'Failed', 'request status' ), 'internal' => true, - '_builtin' => true, /* - internal use only. */ + '_builtin' => true, /* internal use only. */ /* translators: %s: Number of failed requests. */ 'label_count' => _n_noop( 'Failed (%s)', @@ -723,8 +714,7 @@ function create_initial_post_types() { array( 'label' => _x( 'Completed', 'request status' ), 'internal' => true, - '_builtin' => true, /* - internal use only. */ + '_builtin' => true, /* internal use only. */ /* translators: %s: Number of completed requests. */ 'label_count' => _n_noop( 'Completed (%s)', From a3ba3f63da310fac645f9779412a78837925035c Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 21 Jun 2023 10:22:34 +0100 Subject: [PATCH 4/9] Remove new line --- src/wp-includes/post.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 3cfcb9a071a95..7ffd0c4989eb8 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -522,7 +522,6 @@ function create_initial_post_types() { 'items_list' => __( 'Navigation Menus list' ), /* internal use only. don't use this when registering your own post type. */ '_edit_link' => $navigation_post_edit_link, - ), 'description' => __( 'Navigation menus that can be inserted into your site.' ), 'public' => false, From a7bd0f102cef80813ec7827a269969b32b34d4d2 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 21 Jun 2023 10:23:01 +0100 Subject: [PATCH 5/9] Inline comment --- src/wp-includes/post.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 7ffd0c4989eb8..998c421feae19 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -520,8 +520,7 @@ function create_initial_post_types() { 'filter_items_list' => __( 'Filter Navigation Menu list' ), 'items_list_navigation' => __( 'Navigation Menus list navigation' ), 'items_list' => __( 'Navigation Menus list' ), - /* internal use only. don't use this when registering your own post type. */ - '_edit_link' => $navigation_post_edit_link, + '_edit_link' => $navigation_post_edit_link, /* internal use only. don't use this when registering your own post type. */ ), 'description' => __( 'Navigation menus that can be inserted into your site.' ), 'public' => false, From c5ac355b4f2df16589775952a766a7a160e5d001 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 21 Jun 2023 13:53:40 +0100 Subject: [PATCH 6/9] Coerce to string Co-authored-by: Jonny Harris --- src/wp-includes/link-template.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index 404a4a5437b68..35697b72ed434 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -1475,8 +1475,7 @@ function get_edit_post_link( $post = 0, $context = 'display' ) { $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 ) { - $id = $post->ID; - $link = admin_url( sprintf( $post_type_object->_edit_link, $id ) ); + $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 ) ); } From 40db7c19e9bdcb0234fd3ffc7f988a450095573e Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 26 Jun 2023 12:14:22 +0100 Subject: [PATCH 7/9] Move arg to correct place --- src/wp-includes/post.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 998c421feae19..66a6ffd97d3a7 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -520,11 +520,11 @@ function create_initial_post_types() { 'filter_items_list' => __( 'Filter Navigation Menu list' ), 'items_list_navigation' => __( 'Navigation Menus list navigation' ), 'items_list' => __( 'Navigation Menus list' ), - '_edit_link' => $navigation_post_edit_link, /* internal use only. don't use this when registering your own post type. */ ), '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, From 58d9bca948a22c9bd587f8db8f06d58b76002f6f Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 26 Jun 2023 12:41:47 +0100 Subject: [PATCH 8/9] Update tests --- tests/phpunit/tests/link/getEditPostLink.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/phpunit/tests/link/getEditPostLink.php b/tests/phpunit/tests/link/getEditPostLink.php index 4236e7a335acf..85d21d1a1f5f5 100644 --- a/tests/phpunit/tests/link/getEditPostLink.php +++ b/tests/phpunit/tests/link/getEditPostLink.php @@ -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' => '', + '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.' ); + } } From 8b0c77a7a704b5f2cc744c4ad134e12bc256ba52 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 26 Jun 2023 12:47:03 +0100 Subject: [PATCH 9/9] PHPCS --- tests/phpunit/tests/link/getEditPostLink.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/link/getEditPostLink.php b/tests/phpunit/tests/link/getEditPostLink.php index 85d21d1a1f5f5..8a1ad85953b23 100644 --- a/tests/phpunit/tests/link/getEditPostLink.php +++ b/tests/phpunit/tests/link/getEditPostLink.php @@ -143,7 +143,7 @@ public function test_get_edit_post_link_for_wp_navigation_post_type() { ) ); - $post_type_object = get_post_type_object( $navigation_post->post_type ); + $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 ) );