[wp-trac] [WordPress Trac] #51081: Fatal Error - Undefined get_page_templates() in Customizer

WordPress Trac noreply at wordpress.org
Thu Aug 20 23:29:34 UTC 2020


#51081: Fatal Error - Undefined get_page_templates() in Customizer
---------------------------+---------------------------------------
 Reporter:  Howdy_McGee    |       Owner:  (none)
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  5.5.1
Component:  Customize      |     Version:  5.5
 Severity:  normal         |  Resolution:
 Keywords:  needs-testing  |     Focuses:  administration, template
---------------------------+---------------------------------------

Comment (by SergeyBiryukov):

 Related:
 * [47763] / #46829.
 * [48620] / #49374.

 This appears to be caused by the fact that `get_post_states()` (along with
 the `display_post_states` filter) is now used in the Customizer to denote
 special pages (per [47763] above), but does not have all of the admin
 context.

 Per [48620] above, the Customizer requires `wp-
 admin/includes/template.php` if `get_post_states()` does not exist.
 However, `get_page_templates()` is defined in another file: `wp-
 admin/includes/theme.php`.

 The easiest workaround for the example from the ticket description would
 be to check if the function exists:
 {{{
 function prefix_page_template_labels( $post_states ) {
         if ( function_exists( 'get_page_templates' ) ) {
                 $page_templates = get_page_templates();
         }

         return $post_states;

 }
 add_filter( 'display_post_states', 'prefix_page_template_labels' );
 }}}

 I don't think we realistically can (or need to) require all of the admin
 files in the Customizer, so I'm not sure if anything needs changing here.

 We could, however add some documentation for the `display_post_states` to
 explain that it is now also applied in the Customizer context, so if any
 admin functions are used, they need to be checked for existence.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51081#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list