Skip to content

Commit

Permalink
Preload: parse post ID from p (path) (#67465)
Browse files Browse the repository at this point in the history
Co-authored-by: ellatrix <[email protected]>
Co-authored-by: youknowriad <[email protected]>
  • Loading branch information
3 people authored Dec 2, 2024
1 parent 141e9cd commit e07fe5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions backport-changelog/6.8/7695.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
https://github.com/WordPress/wordpress-develop/pull/7695

* https://github.com/WordPress/gutenberg/pull/66631
* https://github.com/WordPress/gutenberg/pull/67465
12 changes: 10 additions & 2 deletions lib/compat/wordpress-6.8/preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@
*/
function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) {
if ( 'core/edit-site' === $context->name ) {
if ( ! empty( $_GET['postId'] ) ) {
$route_for_post = rest_get_route_for_post( $_GET['postId'] );
$post_id = null;
if ( isset( $_GET['postId'] ) && is_numeric( $_GET['postId'] ) ) {
$post_id = (int) $_GET['postId'];
}
if ( isset( $_GET['p'] ) && preg_match( '/^\/page\/(\d+)$/', $_GET['p'], $matches ) ) {
$post_id = (int) $matches[1];
}

if ( $post_id ) {
$route_for_post = rest_get_route_for_post( $post_id );
if ( $route_for_post ) {
$paths[] = add_query_arg( 'context', 'edit', $route_for_post );
}
Expand Down

0 comments on commit e07fe5c

Please sign in to comment.