Make WordPress Core

Opened 3 weeks ago

Last modified 9 days ago

#63653 new defect (bug)

map_meta_cap() fails in wp_refresh_post_lock() for custom post types not registered before init

Reported by: locke85's profile locke85 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.8
Component: Administration Keywords: needs-patch needs-testing dev-feedback reporter-feedback
Focuses: administration, multisite, performance Cc:

Description

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.

Change History (3)

#1 @mindctrl
3 weeks ago

  • Keywords reporter-feedback added

Hi @locke85,

Welcome to Trac and thanks for the report.

Could you provide more details about your environment? Which plugins do you have activated? Which theme? Can you show the code you're using to register the post type?

I did a quick test on a new vanilla site with a custom post type and was unable to reproduce the error.

#2 @locke85
10 days ago

Hi @mindctrl,

sorry for not getting back earlier.

Please find enclosed the system info file.

### Begin System Info (Generated at 2025-07-10 14:10:37) ###

-- Email Log Configuration --

Email Log Version:                  2.4.9
Number of Logs:                     455
Email Log DB Version:               0.3

-- Email Log Addon License --

- More Fields
- Resend Email
- Auto Delete Logs
- Forward Email
- Export Logs

-- Site Info --

Site URL:                 https://webgefaehrte.de
Home URL:                 https://webgefaehrte.de
Multisite:                Yes
Active Theme:             GeneratePress Child 0.1

-- WordPress Configuration --

Version:                  6.8.1
Language:                 en_US
Permalink Structure:      /%category%/%postname%/
WP Table Prefix:          wp_irpchfpaou_
GMT Offset:               1
Memory Limit:             1024M
Memory Max Limit:         1024M
ABSPATH:                  /home/wp/disk/wordpress/
WP_DEBUG:                 Enabled
WP_DEBUG_LOG:              Enabled
SAVEQUERIES:              Not set
WP_SCRIPT_DEBUG:          Not set
DISABLE_WP_CRON:          No
WP_CRON_LOCK_TIMEOUT:     60
EMPTY_TRASH_DAYS:         30

Registered Post types:    post, page, attachment, revision, nav_menu_item, custom_css, customize_changeset, oembed_cache, user_request, wp_block, wp_template, wp_template_part, wp_global_styles, wp_navigation, wp_font_family, wp_font_face, podcast, wg_seo_chat, wg_sharing_news, wpcf7_contact_form, gp_elements, gp_font, flamingo_contact, flamingo_inbound, mailpoet_page, mailpoet_email, gblocks_templates, gblocks_styles, gblocks_public_keys, wg_aktivitaet
post                      publish=17, future=0, draft=1, pending=0, private=0, trash=0, auto-draft=1, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
page                      publish=45, future=0, draft=0, pending=1, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
attachment                publish=0, future=0, draft=0, pending=0, private=1, trash=0, auto-draft=0, inherit=1005, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
revision                  publish=0, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=1484, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
nav_menu_item             publish=48, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
custom_css                publish=1, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
customize_changeset       publish=0, future=0, draft=0, pending=0, private=0, trash=3, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
oembed_cache              publish=6, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
user_request              publish=0, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
wp_block                  publish=29, future=0, draft=1, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
wp_template               publish=0, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
wp_template_part          publish=0, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
wp_global_styles          publish=3, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
wp_navigation             publish=4, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
wp_font_family            publish=0, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
wp_font_face              publish=0, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
podcast                   publish=49, future=0, draft=2, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
wg_seo_chat               publish=194, future=0, draft=8, pending=7, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
wg_sharing_news           publish=95, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
wpcf7_contact_form        publish=6, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
gp_elements               publish=67, future=0, draft=1, pending=0, private=0, trash=0, auto-draft=1, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
gp_font                   publish=2, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
flamingo_contact          publish=60, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
flamingo_inbound          publish=12, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
mailpoet_page             publish=2, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
mailpoet_email            publish=0, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
gblocks_templates         publish=0, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
gblocks_styles            publish=38, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
gblocks_public_keys       publish=1, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 
wg_aktivitaet             publish=1, future=0, draft=0, pending=0, private=0, trash=0, auto-draft=0, inherit=0, request-pending=0, request-confirmed=0, request-failed=0, request-completed=0, flamingo-spam=0, sent=0, 

-- WordPress Active Plugins --

Chained Quiz: 1.3.3
Email Log: 2.4.9
Flamingo: 2.5
Font Awesome: 5.0.2
GenerateBlocks Pro: 2.2.0
GenerateCloud: 1.1.0
Loco Translate: 2.8.0
MailPoet: 5.12.10
Matomo Analytics - Ethical Stats. Powerful Insights.: 5.3.1
Seriously Simple Podcasting: 3.10.4
Seriously Simple Stats: 1.7.0
Simple Local Avatars: 2.8.3
webGefährte Custom Functionality Plugin: 1.6.3
WG SEO Chat: 2.0
WG Sharing News: 1.0
WordPress Importer: 0.8.4
WP Mail SMTP: 4.5.0
Yoast SEO: 25.4
Yoast SEO Premium: 25.4
Yoast Test Helper: 1.18


-- Network Active Plugins --Better Search Replace :1.4.10
Contact Form 7 :6.1
Lightbox for Gallery & Image Block :1.16
GenerateBlocks Pro :2.2.0
GenerateBlocks :2.1.0
GenerateCloud :1.1.0
GP Premium :2.5.4
WP Armour - Honeypot Anti Spam :2.2.12
Zapier for WordPress :1.5.2

-- User Browser --

User Agent String:        Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36

-- Webserver Configuration --

PHP Version:              8.1.32
MySQL Version:            10.11.11
Web Server Info:          nginx/1.24.0
Platform:                 Linux

-- PHP Configuration --

PHP Memory Limit:         1024M
PHP Safe Mode:            No
PHP Upload Max Size:      2000M
PHP Post Max Size:        2000M
PHP Upload Max Filesize:  2000M
PHP Time Limit:           300
PHP Max Input Vars:       10000
Display Errors:           N/A
PHP Arg Separator:        &
PHP Allow URL File Open:  Yes

-- PHP Extensions --

fsockopen:                Your server supports fsockopen.
cURL:                     Your server supports cURL.
SOAP Client:              Your server has the SOAP Client enabled.
SUHOSIN:                  Your server does not have SUHOSIN installed.

### End System Info ###

As far as the code for CPT registration, please consult the following threat which I have created to clarify the issue with the plugin/ CPT developer: https://wordpress.org/support/topic/map_meta_cap-warning-custom-post-type-podcast-not-registered-in-time/

Thanks,
Jan

#3 @mindctrl
9 days ago

@locke85 thanks for the extra details. I tried to reproduce this again, with just WP, Seriously Simple Podcasting, and the default 2025 theme, and I'm still unable to reproduce it.

=== Environment
- WordPress: 6.8.1
- PHP: 8.2.27
- Server: nginx/1.26.1
- Database: mysqli (Server: 8.0.35 / Client: mysqlnd 8.2.27)
- Browser: Chrome 138.0.0.0
- OS: macOS
- Theme: Twenty Twenty-Five 1.2
- MU Plugins: None activated
- Plugins:
  * Query Monitor 3.18.0
  * Seriously Simple Podcasting 3.10.4
  * Test Reports 1.2.0

I'm wondering if some other plugin or the theme is conflicting. Also, the podcast plugin registers its podcast post type on init at priority 11, whereas the default of 10 is most common. I wonder if, in your setup, changing that priority to 10 would make any difference. Either way, I don't think this is a WP core bug, unless it only surfaces with a certain configuration.

Are you able to deactivate plugins, switch to the default theme, and see if it still happens? If it does not happen, start reactivating plugins one by one and see when it starts showing up again.

Note: See TracTickets for help on using tickets.