Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change edit links for templates and template parts #36294

Merged
merged 4 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/full-site-editing/template-parts.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ function gutenberg_register_template_part_post_type() {
}
add_action( 'init', 'gutenberg_register_template_part_post_type' );

/**
* Get the edit link for template parts.
*
* @param string $link The original link.
* @param int $post_id The custom post id.
*/
function gutenberg_get_edit_template_part_link( $link, $post_id ) {
$template_parts = gutenberg_get_block_templates(
array( 'wp_id' => $post_id ),
'wp_template_part'
);
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved
$template_part = $template_parts ? $template_parts[0] : null;

if ( ! $template_part ) {
return $link;
}

$id = urlencode( $template_part->id );

return "themes.php?page=gutenberg-edit-site&postId=$id&postType=wp_template_part";
}
add_filter( 'get_edit_post_link', 'gutenberg_get_edit_template_part_link', 10, 2 );

/**
* Registers the 'wp_template_part_area' taxonomy.
*/
Expand Down
23 changes: 23 additions & 0 deletions lib/full-site-editing/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,29 @@ function gutenberg_register_template_post_type() {
}
add_action( 'init', 'gutenberg_register_template_post_type' );

/**
* Get the edit link for templates.
*
* @param string $link The original link.
* @param int $post_id The custom post id.
*/
function gutenberg_get_edit_template_link( $link, $post_id ) {
$templates = gutenberg_get_block_templates(
array( 'wp_id' => $post_id ),
'wp_template'
);
$template = $templates ? $templates[0] : null;
draganescu marked this conversation as resolved.
Show resolved Hide resolved

if ( ! $template ) {
return $link;
}

$id = urlencode( $template->id );

return "themes.php?page=gutenberg-edit-site&postId=$id&postType=wp_template";
}
add_filter( 'get_edit_post_link', 'gutenberg_get_edit_template_link', 10, 2 );

/**
* Registers block editor 'wp_theme' taxonomy.
*/
Expand Down