[wp-trac] [WordPress Trac] #21515: No custom header support in theme == Fatal error: Call to a member function process_default_headers() on a non-object

WordPress Trac noreply at wordpress.org
Tue Dec 10 08:43:58 UTC 2024


#21515: No custom header support in theme == Fatal error: Call to a member function
process_default_headers() on a non-object
------------------------------+---------------------
 Reporter:  c3mdigital        |       Owner:  ryan
     Type:  defect (bug)      |      Status:  closed
 Priority:  normal            |   Milestone:  3.4.2
Component:  Customize         |     Version:
 Severity:  normal            |  Resolution:  fixed
 Keywords:  has-patch commit  |     Focuses:
------------------------------+---------------------

Comment (by salmankhan0909):

 Replying to [comment:9 salmankhan0909]:
 > Replying to [comment:8 bloomhejm]:
 > > WordPress. The error message you provided indicates that there is an
 issue with the WP_Customize_Header_Image_Control class and its
 process_default_headers() method being called on a non-object. This error
 typically occurs when you attempt to use the Customizer with a theme that
 doesn't support custom headers.
 > > Here's a possible solution to handle this error by checking whether
 the WP_Customize_Header_Image_Control object exists before calling its
 methods:
 > >
 > >
 > > {{{#!php
 > > <?php
 > > if ( class_exists( 'WP_Customize_Header_Image_Control' ) ) {
 > >     $custom_image_header = new WP_Customize_Header_Image_Control(
 $wp_customize );
 > >     if ( is_object( $custom_image_header ) ) {
 > >         // Process custom header controls here
 > >     }
 > > }
 > > }}}
 > >
 > > This code snippet checks if the WP_Customize_Header_Image_Control
 class exists, and if it does, it attempts to create an instance of it.
 Then, it checks if the instance is a valid object before proceeding to
 process custom header controls.
 >
 > Use the following snippet to prevent errors and handle the situation
 gracefully:
 >
 > {{{#!php
 > <?php
 > <?php
 > if ( class_exists( 'WP_Customize_Header_Image_Control' ) ) {
 >     // Check if $wp_customize is available
 >     if ( isset( $wp_customize ) && is_object( $wp_customize ) ) {
 >         $custom_image_header = new WP_Customize_Header_Image_Control(
 $wp_customize, 'header_image', array(
 >             'label'    => __( 'Header Image', 'your-textdomain' ),
 >             'section'  => 'header_image_section',
 >             'settings' => 'header_image_setting',
 >         ) );
 >
 >         if ( is_object( $custom_image_header ) ) {
 >             // Add your custom header controls logic here
 >         }
 >     } else {
 >         error_log( 'Customizer object is not available.' );
 >     }
 > } else {
 >     error_log( 'WP_Customize_Header_Image_Control class is missing.
 Ensure the theme supports custom headers.' );
 > }
 >
 > }}}

 **''Verify $wp_customize Object''******
 Before creating an instance of WP_Customize_Header_Image_Control, ensure
 $wp_customize is correctly passed into the context (it’s usually available
 in the customize_register action).

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


More information about the wp-trac mailing list