[wp-trac] [WordPress Trac] #63653: map_meta_cap() fails in wp_refresh_post_lock() for custom post types not registered before init

WordPress Trac noreply at wordpress.org
Wed Jul 2 13:02:23 UTC 2025


#63653: map_meta_cap() fails in wp_refresh_post_lock() for custom post types not
registered before init
-------------------------------------+-------------------------------------
 Reporter:  locke85                  |      Owner:  (none)
     Type:  defect (bug)             |     Status:  new
 Priority:  normal                   |  Milestone:  Awaiting Review
Component:  Administration           |    Version:  6.8
 Severity:  normal                   |   Keywords:  needs-patch needs-
  Focuses:  administration,          |  testing dev-feedback
  multisite, performance             |
-------------------------------------+-------------------------------------
 When editing a custom post type (CPT) post that is registered during the
 `init` hook (standard practice), the following warning is thrown:

 > map_meta_cap was called incorrectly. The post type "podcast" is not
 registered. This may cause unreliable behavior when checking the
 "edit_post" capability for this post type.

 This occurs because `wp_refresh_post_lock()` is hooked to
 `heartbeat_received`, which runs **before** `init`. As a result,
 capability checks using `current_user_can('edit_post', $post_id)` fail
 when the post type has not yet been registered.

 This results in:
 - Debug notices in logs
 - In some environments, the editor freezing ("Page is unresponsive")
 - Inconsistent behavior for CPTs, especially in AJAX contexts

 ### Steps to reproduce:
 1. Register a custom post type (e.g., `podcast`) via
 `register_post_type()` inside an `init` callback.
 2. Create and save a post of that type.
 3. Edit the post in the Block Editor and monitor `debug.log`.

 ### Expected behavior:
 WordPress should not evaluate capabilities for unregistered post types
 during heartbeat.

 ### Suggested solutions:
 - Delay the execution of `wp_refresh_post_lock()` until after `init`
 - Or, safely skip capability checks for unregistered CPTs

 Let me know if you need further logs or a patch draft. I'd be happy to
 assist.

 Reported using WP 6.8.1.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63653>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list