[wp-trac] [WordPress Trac] #62523: Can't register Block Templates for CPTs with an underscore "_" character in the key

WordPress Trac noreply at wordpress.org
Fri Nov 22 11:22:44 UTC 2024


#62523: Can't register Block Templates for CPTs with an underscore "_" character in
the key
-----------------------------+-----------------------------
 Reporter:  alexandrebuffet  |      Owner:  (none)
     Type:  defect (bug)     |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Editor           |    Version:  6.7
 Severity:  major            |   Keywords:  needs-patch
  Focuses:  template         |
-----------------------------+-----------------------------
 After several days of using the new Block Templates API, I’ve noticed that
 we can’t register a template for a CPT that has underscore "_" in its key,
 it displays the error "Template names must contain a namespace prefix.
 Example: my-plugin//my-custom-template".

 For example, I have a plugin that declares a CPT "school_course" and if I
 declare its associated templates "my-plugin//archive-school_course" and/or
 "my-plugin//single-school_course" I get the error.

 This error seems to be displayed because the test on the template name via
 the RegEx "/^[a-z0-9-]+\/\/[a-z0-9-]+$/" returns false in register method
 from WP_Block_Templates_Registry class.

 Related issue in Gutenberg:
 https://github.com/WordPress/gutenberg/issues/67066

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


More information about the wp-trac mailing list