PluginProbe
Gutenberg / 16.2.0
Gutenberg v16.2.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / lib / compat / wordpress-6.3 / link-template.php

link-template.php in Gutenberg 16.2.0, at lib/compat/wordpress-6.3/link-template.php

61 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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