在WordPress 3.4中使用‘ADD_TIME_SUPPORT’代替‘ADD_CUSTOM_IMAGE_HEADER’

时间:2012-06-16 作者:its_me

我正在使用调试我的主题Debug Bar 插件,它向我显示了此错误(除其他几个错误外):

注意事项:add_custom_image_header 自版本3.4以来已弃用!使用add_theme_support( \'custom-header\', $args ) 相反

好吧,很明显,上面说我需要use this 而不是this. 问题是,add_custom_image_header 有三个参数,即:

$header\\u callback

  • $admin\\u header\\u callback
  • $admin\\u image\\u div\\u callback
  • add_theme_support 作用像这样?

    $aahan_custom_header_args = array(
        \'wp-head-callback\'       => \'\',
        \'admin-head-callback\'    => \'\',
        \'admin-preview-callback\' => \'\',
    );
    add_theme_support( \'custom-header\', $aahan_custom_header_args );
    
    此外,还有wp-head-callback, admin-head-callback, 和admin-preview-callback, 完全替代$header_callback, $admin_header_callback, 和$admin_image_div_callback 分别地

    1 个回复
    最合适的回答,由SO网友:Chip Bennett 整理而成

    请阅读Updating Custom Backgrounds and Custom Headers for WordPress 3.4.

    自定义标题

    旧方法:

    // Define default header image constant
    define( \'HEADER_IMAGE\', get_template_directory_uri() . \'/images/headers/default.jpg\' );
    // Define header image width constant
    define( \'HEADER_IMAGE_WIDTH\', 1000 );
    // Define header image height constant
    define( \'HEADER_IMAGE_HEIGHT\', 198 );
    // Define header text constant
    define( \'NO_HEADER_TEXT\', false );
    // Define header text color constant
    define( \'HEADER_TEXTCOLOR\', \'000\' );
    // Turn on random header image rotation by default.
    // Requires HEADER_IMAGE to be null
    add_theme_support( \'custom-header\', array( \'random-default\' => true ) );
    
    // Add Theme support
    add_custom_image_header( $wphead_cb, $adminhead_cb, $adminpreview_cb );
    新方法:

    add_theme_support( \'custom-header\', array(
        // Header image default
        \'default-image\'         => get_template_directory_uri() . \'/images/headers/default.jpg\',
        // Header text display default
        \'header-text\'           => false,
        // Header text color default
        \'default-text-color\'        => \'000\',
        // Header image width (in pixels)
        \'width\'             => 1000,
        // Header image height (in pixels)
        \'height\'            => 198,
        // Header image random rotation default
        \'random-default\'        => false,
        // Template header style callback
        \'wp-head-callback\'      => $wphead_cb,
        // Admin header style callback
        \'admin-head-callback\'       => $adminhead_cb,
        // Admin preview style callback
        \'admin-preview-callback\'    => $adminpreview_cb
    ) );
    再说一遍:那很容易,不是吗?

    为了澄清,以下是旧的常量/新的数组键等价物:

    HEADER_IMAGE       => \'default-image\'
    HEADER_IMAGE_WIDTH  => \'width\'
    HEADER_IMAGE_HEIGHT => \'height\'
    NO_HEADER_TEXT      => \'header-text\'
    HEADER_TEXTCOLOR    => \'default-text-color\'
    与之前一样,支持所有相同的回调。

    以下是完整的默认值数组供参考:

    $defaults = array(
        \'default-image\' => \'\',
        \'random-default\' => false,
        \'width\' => 0,
        \'height\' => 0,
        \'flex-height\' => false,
        \'flex-width\' => false,
        \'default-text-color\' => \'\',
        \'header-text\' => true,
        \'uploads\' => true,
        \'wp-head-callback\' => \'\',
        \'admin-head-callback\' => \'\',
        \'admin-preview-callback\' => \'\',
    );

    结束