WordPress.org

Ready to get started?Download WordPress

Forums

remove_theme_support() generates array index error (6 posts)

  1. Mike Walsh
    Member
    Posted 2 years ago #

    I am updating a Twenty-Eleven child theme to 3.4 (actually 3.4.1) and had used remove_custom_background() and remove_custom_image_header() to disable custom headers as the child theme defines a fixed header and background.

    I am trying to address the deprecated warning messages for remove_custom_background() and remove_custom_image_header() by using remove_theme_support('custom-background') and remove_theme_support('custom-header') but both generate a warnings:

    Notice:  Undefined index: wp-head-callback in C:\inetpub\wwwroot\wordpress\wp-includes\theme.php on line 1458
    Notice: Undefined index: custom_background in C:\inetpub\wwwroot\wordpress\wp-includes\theme.php on line 1460
    Notice: Undefined index: custom_image_header in C:\inetpub\wwwroot\wordpress\wp-includes\theme.php on line 1452

    Looking at the wordpress\wp-includes\theme.php code, it appears that the code checks for the array element before trying to use it in one case but not all!

    switch ( $feature ) {
    		case 'custom-header' :
    			$support = get_theme_support( 'custom-header' );
    			if ( $support[0]['wp-head-callback'] )
    				remove_action( 'wp_head', $support[0]['wp-head-callback'] );
    			remove_action( 'admin_menu', array( $GLOBALS['custom_image_header'], 'init' ) );
    			unset( $GLOBALS['custom_image_header'] );
    			break;
    
    		case 'custom-background' :
    			$support = get_theme_support( 'custom-background' );
    			remove_action( 'wp_head', $support[0]['wp-head-callback'] );
    			remove_action( 'admin_menu', array( $GLOBALS['custom_background'], 'init' ) );
    			unset( $GLOBALS['custom_background'] );
    			break;
    	}

    The only way I've been able to remove these theme features in 3.4 is to do this:

    global $_wp_theme_features;
    	unset($_wp_theme_features['custom-header']);
    	unset($_wp_theme_features['custom-background']);

    Is anyone else successfully calling remove_theme_support()? If so, what am I doing wrong?

  2. global_1981
    Member
    Posted 1 year ago #

    I second this question!

  3. codingpet
    Member
    Posted 1 year ago #

    Hi,

    It works. You need to use add_action to add them to after_setup_theme.
    Try below codes:

    add_action('after_setup_theme','custom_remove_function');
    function custom_remove_function(){
    remove_theme_support( 'custom-header' );
    remove_theme_support( 'custom-background' );
    }
    For detailed features, you can check http://codex.wordpress.org/Function_Reference/current_theme_supports

  4. global_1981
    Member
    Posted 1 year ago #

    @codingpet.com yes It does work but the problem is it still throws PHP notices.

  5. codingpet
    Member
    Posted 1 year ago #

    @global_1981, if you just installed a new wordpress 3.4.1 without any plugins activated, there will still be some PHP notices. These undefined index or deprecated notices are caused by some wordpress core codes. So I can only assume these notices are allowed by the core wordpress developer(compatible with outdated themes or plugins). For me, I will not enable the debug mode to try to fix these notices.

    Any other ideas?

  6. Silvan Hagen
    Member
    Posted 1 year ago #

    You still have this problem? I have the same thing: http://wordpress.org/support/topic/undefined-index-custom_image_header-in-after_setup_theme-of-child-theme

    There is somehow a few approaches to fix this, see pastebin im my post and http://wordpress.stackexchange.com/questions/9490/removing-custom-background-and-header-feature-in-child-theme but both of them aren't really nice.

Topic Closed

This topic has been closed to new replies.

About this Topic