Make WordPress Core

Changeset 56053


Ignore:
Timestamp:
06/27/2023 06:00:59 AM (12 months ago)
Author:
isabel_brison
Message:

Editor: fix post edit navigation link.

Adds a custom link for navigation post types.

Props get_dave, spacedmonkey, ramonopoly.
Fixes #58589.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/link-template.php

    r56021 r56053  
    14391439 *
    14401440 * @since 2.3.0
     1441 * @since 6.3.0 Adds custom link for wp_navigation post types.
     1442 *              Adds custom links for wp_template_part and wp_template post types.
    14411443 *
    14421444 * @param int|WP_Post $post    Optional. Post ID or post object. Default is the global `$post`.
     
    14751477        $slug = urlencode( get_stylesheet() . '//' . $post->post_name );
    14761478        $link = admin_url( sprintf( $post_type_object->_edit_link, $post->post_type, $slug ) );
     1479    } elseif ( 'wp_navigation' === $post->post_type ) {
     1480        $link = admin_url( sprintf( $post_type_object->_edit_link, (string) $post->ID ) );
    14771481    } elseif ( $post_type_object->_edit_link ) {
    14781482        $link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) );
  • trunk/src/wp-includes/post.php

    r56043 r56053  
    492492    );
    493493
     494    $navigation_post_edit_link = 'site-editor.php?' . build_query(
     495        array(
     496            'postId'   => '%s',
     497            'postType' => 'wp_navigation',
     498            'canvas'   => 'edit',
     499        )
     500    );
     501
    494502    register_post_type(
    495503        'wp_navigation',
     
    518526            'public'                => false,
    519527            '_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
     528            '_edit_link'            => $navigation_post_edit_link, /* internal use only. don't use this when registering your own post type. */
    520529            'has_archive'           => false,
    521530            'show_ui'               => true,
  • trunk/tests/phpunit/tests/link/getEditPostLink.php

    r55743 r56053  
    132132        $this->assertSame( $link_custom_context, get_edit_post_link( $template_part_post, 'something-else' ), 'Pass non-default value in second argument.' );
    133133    }
     134
     135    /**
     136     * Tests getting the edit post link for a wp_navigation post type.
     137     *
     138     * @ticket 58589
     139     * */
     140    public function test_get_edit_post_link_for_wp_navigation_post_type() {
     141        $navigation_post = self::factory()->post->create_and_get(
     142            array(
     143                'post_type'    => 'wp_navigation',
     144                'post_name'    => 'my_navigation',
     145                'post_title'   => 'My Navigation',
     146                'post_content' => '<!-- wp:navigation-link {"label":"WordPress","type":"custom","url":"http://www.wordpress.org/","kind":"custom"} /-->',
     147                'post_excerpt' => 'Description of my Navigation',
     148            )
     149        );
     150
     151        $post_type_object = get_post_type_object( $navigation_post->post_type );
     152
     153        $link_default_context = admin_url( sprintf( $post_type_object->_edit_link, $navigation_post->ID ) );
     154        $link_custom_context  = admin_url( sprintf( $post_type_object->_edit_link, $navigation_post->ID ) );
     155
     156        $this->assertSame( $link_default_context, get_edit_post_link( $navigation_post ), 'Second argument `$context` has a default context of `"display"`.' );
     157        $this->assertSame( $link_custom_context, get_edit_post_link( $navigation_post, 'something-else' ), 'Pass non-default value in second argument.' );
     158    }
    134159}
Note: See TracChangeset for help on using the changeset viewer.