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. Built from https://develop.svn.wordpress.org/trunk@55743 git-svn-id: http://core.svn.wordpress.org/trunk@55255 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9e840bbc8d
commit
fe27bb8d0b
|
@ -1435,7 +1435,7 @@ function get_preview_post_link( $post = null, $query_args = array(), $preview_li
|
|||
* Retrieves the edit post link for post.
|
||||
*
|
||||
* Can be used within the WordPress loop or outside of it. Can be used with
|
||||
* pages, posts, attachments, and revisions.
|
||||
* pages, posts, attachments, revisions, global styles, templates, and template parts.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*
|
||||
|
@ -1469,10 +1469,13 @@ function get_edit_post_link( $post = 0, $context = 'display' ) {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( $post_type_object->_edit_link ) {
|
||||
$link = '';
|
||||
|
||||
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 ( $post_type_object->_edit_link ) {
|
||||
$link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) );
|
||||
} else {
|
||||
$link = '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -332,6 +332,14 @@ function create_initial_post_types() {
|
|||
)
|
||||
);
|
||||
|
||||
$template_edit_link = 'site-editor.php?' . build_query(
|
||||
array(
|
||||
'postType' => '%s',
|
||||
'postId' => '%s',
|
||||
'canvas' => 'edit',
|
||||
)
|
||||
);
|
||||
|
||||
register_post_type(
|
||||
'wp_template',
|
||||
array(
|
||||
|
@ -358,6 +366,7 @@ function create_initial_post_types() {
|
|||
'description' => __( 'Templates to include in your theme.' ),
|
||||
'public' => false,
|
||||
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
|
||||
'_edit_link' => $template_edit_link, /* internal use only. don't use this when registering your own post type. */
|
||||
'has_archive' => false,
|
||||
'show_ui' => false,
|
||||
'show_in_menu' => false,
|
||||
|
@ -418,6 +427,7 @@ function create_initial_post_types() {
|
|||
'description' => __( 'Template parts to include in your templates.' ),
|
||||
'public' => false,
|
||||
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
|
||||
'_edit_link' => $template_edit_link, /* internal use only. don't use this when registering your own post type. */
|
||||
'has_archive' => false,
|
||||
'show_ui' => false,
|
||||
'show_in_menu' => false,
|
||||
|
@ -458,6 +468,7 @@ function create_initial_post_types() {
|
|||
'description' => __( 'Global styles to include in themes.' ),
|
||||
'public' => false,
|
||||
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
|
||||
'_edit_link' => '/site-editor.php?canvas=edit', /* internal use only. don't use this when registering your own post type. */
|
||||
'show_ui' => false,
|
||||
'show_in_rest' => false,
|
||||
'rewrite' => false,
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.3-alpha-55742';
|
||||
$wp_version = '6.3-alpha-55743';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue