From 45da877f23e5709cf214bf77ee058a334e2e30be Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 21 Jun 2023 10:10:46 +0100 Subject: [PATCH 01/10] 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 abf94bcbe5aa9..b6800944127f0 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -491,6 +491,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( @@ -513,6 +521,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, @@ -552,7 +563,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)', @@ -566,7 +578,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)', @@ -580,7 +593,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)', @@ -595,7 +609,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)', @@ -610,7 +625,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)', @@ -624,7 +640,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)', @@ -659,7 +676,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)', @@ -674,7 +692,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)', @@ -689,7 +708,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)', @@ -704,7 +724,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 08c84c7167f94b2048b4cfbab8d2294a66e677a0 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 21 Jun 2023 10:10:56 +0100 Subject: [PATCH 02/10] 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 b59a30ad22b03..f4f7e557f85f7 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 beac183594269d1e617a9b79f59fcf9f81b4b0e6 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 21 Jun 2023 10:22:01 +0100 Subject: [PATCH 03/10] 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 b6800944127f0..c31277f2d172b 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -563,8 +563,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)', @@ -578,8 +577,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)', @@ -593,8 +591,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)', @@ -609,8 +606,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)', @@ -625,8 +621,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)', @@ -640,8 +635,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)', @@ -676,8 +670,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)', @@ -692,8 +685,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)', @@ -708,8 +700,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)', @@ -724,8 +715,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 58467becd33aa8188277c3d3f6917804a66ee064 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 21 Jun 2023 10:22:34 +0100 Subject: [PATCH 04/10] 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 c31277f2d172b..d92714a28571b 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -523,7 +523,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 95fd9ffbb1aa53701244cd2fafdb135ed9585b47 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 21 Jun 2023 10:23:01 +0100 Subject: [PATCH 05/10] 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 d92714a28571b..7f95b82340349 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -521,8 +521,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 f38e681e528ca8256fd7ac65e9efeb07ab63c854 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 21 Jun 2023 13:53:40 +0100 Subject: [PATCH 06/10] 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 f4f7e557f85f7..2d0ede8755ec2 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 520fcc217dd03cb4a431c0c1b603aabb36d29612 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 26 Jun 2023 12:14:22 +0100 Subject: [PATCH 07/10] 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 7f95b82340349..d6ab4db603a89 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -521,11 +521,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 a308a5e6c2c08e4ace889c88727f06d0e5c97a83 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 26 Jun 2023 12:41:47 +0100 Subject: [PATCH 08/10] 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 b16512a3facfebe6bb47e2922cc5d8b361116e52 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 26 Jun 2023 12:47:03 +0100 Subject: [PATCH 09/10] 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 ) ); From f8e4a85abe8811565e039725bfa6f728942cb59d Mon Sep 17 00:00:00 2001 From: ramon Date: Tue, 27 Jun 2023 12:26:47 +1000 Subject: [PATCH 10/10] updating annotations pre-commit --- src/wp-includes/link-template.php | 2 ++ tests/phpunit/tests/link/getEditPostLink.php | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index 2d0ede8755ec2..7fc107447056f 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -1438,6 +1438,8 @@ function get_preview_post_link( $post = null, $query_args = array(), $preview_li * pages, posts, attachments, revisions, global styles, templates, and template parts. * * @since 2.3.0 + * @since 6.3.0 Adds custom link for wp_navigation post types. + * Adds custom links for wp_template_part and wp_template post types. * * @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`. * @param string $context Optional. How to output the '&' character. Default '&'. diff --git a/tests/phpunit/tests/link/getEditPostLink.php b/tests/phpunit/tests/link/getEditPostLink.php index 8a1ad85953b23..2a17e69f75ebb 100644 --- a/tests/phpunit/tests/link/getEditPostLink.php +++ b/tests/phpunit/tests/link/getEditPostLink.php @@ -132,6 +132,11 @@ public function test_get_edit_post_link_for_wp_template_part_post_type() { $this->assertSame( $link_custom_context, get_edit_post_link( $template_part_post, 'something-else' ), 'Pass non-default value in second argument.' ); } + /** + * Tests getting the edit post link for a wp_navigation post type. + * + * @ticket 58589 + * */ public function test_get_edit_post_link_for_wp_navigation_post_type() { $navigation_post = self::factory()->post->create_and_get( array(