| 1 |
<?php |
| 2 |
/** |
| 3 |
* Overrides Core's wp-includes/link-template.php for WP 6.3. |
| 4 |
* |
| 5 |
* @package gutenberg |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Updates the post edit link using the `_edit_link` property in wp_global_styles`, `wp_template`, |
| 10 |
* and `wp_template_part` custom post types. |
| 11 |
* |
| 12 |
* `_edit_link` for these custom post types is added by `gutenberg_update_templates_template_parts_rest_controller()` |
| 13 |
* in lib/compat/wordpress-6.3/rest-api.php. |
| 14 |
* |
| 15 |
* This functionality has already been ported to Core. See https://github.com/WordPress/gutenberg/issues/48065 |
| 16 |
* The following hook is a modified version that passes only 2 arguments to `sprintf()` to be compatible with WP <= 6.2. |
| 17 |
* |
| 18 |
* @param string $link The edit link. |
| 19 |
* @param int $post_id Post ID. |
| 20 |
* @return string|null The edit post link for the given post. Null if the post type does not exist |
| 21 |
* or does not allow an editing UI. |
| 22 |
*/ |
| 23 |
function gutenberg_update_get_edit_post_link( $link, $post_id ) { |
| 24 |
$post = get_post( $post_id ); |
| 25 |
|
| 26 |
if ( 'wp_template' === $post->post_type || 'wp_template_part' === $post->post_type ) { |
| 27 |
$post_type_object = get_post_type_object( $post->post_type ); |
| 28 |
$slug = urlencode( get_stylesheet() . '//' . $post->post_name ); |
| 29 |
$link = admin_url( sprintf( $post_type_object->_edit_link, $slug ) ); |
| 30 |
} |
| 31 |
|
| 32 |
return $link; |
| 33 |
} |
| 34 |
|
| 35 |
add_filter( 'get_edit_post_link', 'gutenberg_update_get_edit_post_link', 10, 2 ); |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
/** |
| 40 |
* Modifies the edit link for the `wp_navigation` custom post type. |
| 41 |
* |
| 42 |
* This has not been backported to Core. |
| 43 |
* |
| 44 |
* @param string $link The edit link. |
| 45 |
* @param int $post_id Post ID. |
| 46 |
* @return string|null The edit post link for the given post. Null if the post type does not exist |
| 47 |
* or does not allow an editing UI. |
| 48 |
*/ |
| 49 |
function gutenberg_update_navigation_get_edit_post_link( $link, $post_id ) { |
| 50 |
$post = get_post( $post_id ); |
| 51 |
|
| 52 |
if ( 'wp_navigation' === $post->post_type ) { |
| 53 |
$post_type_object = get_post_type_object( $post->post_type ); |
| 54 |
$id = $post->ID; |
| 55 |
$link = admin_url( sprintf( $post_type_object->_edit_link, $id ) ); |
| 56 |
} |
| 57 |
|
| 58 |
return $link; |
| 59 |
} |
| 60 |
add_filter( 'get_edit_post_link', 'gutenberg_update_navigation_get_edit_post_link', 10, 2 ); |
| 61 |
|