-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- adds an `_edit_link` property to `wp_global_styles`, `wp_template`, and `wp_template-part` custom post type schemata via filter - uses the `_edit_link` value to create an edit link via the `get_edit_post_link` hook
- Loading branch information
Showing
3 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* Overrides Core's wp-includes/link-template.php for WP 6.3. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Updates the post edit link using the `_edit_link` property in wp_global_styles`, `wp_template`, | ||
* and `wp_template_part` custom post types. | ||
* | ||
* `_edit_link` for these custom post types is added by `gutenberg_update_templates_template_parts_rest_controller()` | ||
* in lib/compat/wordpress-6.3/rest-api.php. | ||
* | ||
* This functionality has already been ported to Core. See https://github.com/WordPress/gutenberg/issues/48065 | ||
* The following hook is a modified version that passes only 2 arguments to `sprintf()` to be compatible with WP <= 6.2. | ||
* | ||
* @param string $link The edit link. | ||
* @param int $post_id Post ID. | ||
* @return string|null The edit post link for the given post. Null if the post type does not exist | ||
* or does not allow an editing UI. | ||
*/ | ||
function gutenberg_update_get_edit_post_link( $link, $post_id ) { | ||
$post = get_post( $post_id ); | ||
|
||
if ( 'wp_template' === $post->post_type || 'wp_template_part' === $post->post_type ) { | ||
$post_type_object = get_post_type_object( $post->post_type ); | ||
$slug = urlencode( get_stylesheet() . '//' . $post->post_name ); | ||
$link = admin_url( sprintf( $post_type_object->_edit_link, $slug ) ); | ||
} | ||
return $link; | ||
} | ||
|
||
add_filter( 'get_edit_post_link', 'gutenberg_update_get_edit_post_link', 10, 2 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters