Make WordPress Core

Changeset 55743


Ignore:
Timestamp:
05/10/2023 05:34:13 PM (19 months ago)
Author:
davidbaumwald
Message:

Revisions: Add edit link functionality for the wp_template and wp_template_part post types.

In preparation for viewing revisions of templates and template parts in the editor, this set changes adds the _edit_link argument when registering the wp_template and wp_template_part post types. This commit also updates get_edit_post_link to account for the unique edit URLs for these post types.

Finally, this commit also adds new unit tests for the get_edit_post_link function, including tests for the post, wp_template, and wp_template_part post types.

Fixes #57709.
Props andraganescu, spacedmonkey, antonvlasenko, youknowriad, ramonopoly, ironprogrammer, annezazu.

Location:
trunk
Files:
1 added
2 edited

Legend:

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

    r55703 r55743  
    14361436 *
    14371437 * Can be used within the WordPress loop or outside of it. Can be used with
    1438  * pages, posts, attachments, and revisions.
     1438 * pages, posts, attachments, revisions, global styles, templates, and template parts.
    14391439 *
    14401440 * @since 2.3.0
     
    14701470    }
    14711471
    1472     if ( $post_type_object->_edit_link ) {
     1472    $link = '';
     1473
     1474    if ( 'wp_template' === $post->post_type || 'wp_template_part' === $post->post_type ) {
     1475        $slug = urlencode( get_stylesheet() . '//' . $post->post_name );
     1476        $link = admin_url( sprintf( $post_type_object->_edit_link, $post->post_type, $slug ) );
     1477    } elseif ( $post_type_object->_edit_link ) {
    14731478        $link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) );
    1474     } else {
    1475         $link = '';
    14761479    }
    14771480
  • trunk/src/wp-includes/post.php

    r55732 r55743  
    333333    );
    334334
     335    $template_edit_link = 'site-editor.php?' . build_query(
     336        array(
     337            'postType' => '%s',
     338            'postId'   => '%s',
     339            'canvas'   => 'edit',
     340        )
     341    );
     342
    335343    register_post_type(
    336344        'wp_template',
     
    359367            'public'                => false,
    360368            '_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
     369            '_edit_link'            => $template_edit_link, /* internal use only. don't use this when registering your own post type. */
    361370            'has_archive'           => false,
    362371            'show_ui'               => false,
     
    419428            'public'                => false,
    420429            '_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
     430            '_edit_link'            => $template_edit_link, /* internal use only. don't use this when registering your own post type. */
    421431            'has_archive'           => false,
    422432            'show_ui'               => false,
     
    459469            'public'       => false,
    460470            '_builtin'     => true, /* internal use only. don't use this when registering your own post type. */
     471            '_edit_link'   => '/site-editor.php?canvas=edit', /* internal use only. don't use this when registering your own post type. */
    461472            'show_ui'      => false,
    462473            'show_in_rest' => false,
Note: See TracChangeset for help on using the changeset viewer.