Make WordPress Core


Ignore:
Timestamp:
01/30/2025 09:17:04 PM (2 weeks ago)
Author:
flixos90
Message:

Editor: Fix block template registration failing for custom post types containing underscore characters.

Custom post types may contain underscores, however block template registration has been using a regular expression that disallows underscores. Since the block template name for certain templates is directly associated with which post type it applies to, this regular expression was causing unexpected failures. This changeset adjusts the regular expression to allow block template names with underscore characters, effectively allowing block templates to be registered for any custom post type.

Props alexandrebuffet, ankitkumarshah, gaambo, jorbin, karthickmurugan, oglekler, poena, sukhendu2002.
Fixes #62523.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block-templates-registry.php

    r59073 r59742  
    5151            $error_message = __( 'Template names must not contain uppercase characters.' );
    5252            $error_code    = 'template_name_no_uppercase';
    53         } elseif ( ! preg_match( '/^[a-z0-9-]+\/\/[a-z0-9-]+$/', $template_name ) ) {
     53        } elseif ( ! preg_match( '/^[a-z0-9_\-]+\/\/[a-z0-9_\-]+$/', $template_name ) ) {
    5454            $error_message = __( 'Template names must contain a namespace prefix. Example: my-plugin//my-custom-template' );
    5555            $error_code    = 'template_no_prefix';
Note: See TracChangeset for help on using the changeset viewer.