如何处理“WP_Customize_Cropt_Image_Control”回调?

时间:2015-11-11 作者:Elidrissi simo

我想在Customizer中创建一个徽标管理器,但是如何使用WP_Customize_Cropped_Image_Control

示例来自Make WordPress Core:

$wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, \'cropped_image\', array(
    \'section\'     => \'background_image\',
    \'label\'       => __( \'Croppable Image\' ),
    \'flex_width\'  => true, // Allow any width, making the specified value recommended. False by default.
    \'flex_height\' => false, // Require the resulting image to be exactly as tall as the height attribute (default).
    \'width\'       => 1920,
    \'height\'      => 1080,
) ) );

2 个回复
SO网友:bueltge

我想您为每个徽标添加了一个设置字段?如果没有,请加强您的问题。

如果是,则还经常添加对裁剪图像控件的调用。下面的示例为徽标选项添加一个部分和一个字段,并获得裁剪图像的可能性。

add_action( \'customize_register\', \'fb_logo_customize_register\' );
function fb_logo_customize_register( $wp_customize ) {

    /* Add the logo section. */
    $wp_customize->add_section(
        \'logo\',
        array(
            \'title\'       => esc_html__( \'Logo\', \'textdomain\' ),
            \'description\' => __( \'Manage User List\', \'textdomain\' ),
            \'priority\'    => 10,
            //\'panel\'       => \'fb_panel\' // not inside the example code, 
        )
    );

    /* Add the setting for our logo value. */
    $wp_customize->add_setting(
        \'site_logo\',
        array(
            \'default\'           => \'\',
            \'sanitize_callback\' => \'absint\'
        )
    );

    /* Add our image uploader. */
    $wp_customize->add_control(
        new WP_Customize_Cropped_Image_Control(
            $wp_customize,
                \'site_logo\',
                array(
                    \'label\'       => __( \'Site Logo\', \'textdomain\' ),
                    \'section\'     => \'logo\',
                    \'flex_width\'  => true,
                    \'flex_height\' => true,
                    \'width\'       => 240,
                    \'height\'      => 80,
                )
        )
    );

}

SO网友:Jeff W

我们就是这样做的-我们的目标是创建一个圆形的个人资料图片,所以我们在上传时强制进行方形裁剪-您应该能够对徽标上传执行类似的操作。

您定义的大小将决定显示的最终结果的尺寸,因此在我的示例中,如果用户要裁剪矩形,最终结果仍将渲染为正方形,从而扭曲图像。为了避免这种情况,您可能应该记住什么类型的徽标最适合您在主题中考虑的区域,无论是徽章类型的徽标、矩形徽标、无定形徽标等,并将flex设置保持为“false”-任何用户都不希望他们的徽标最终显示不稳定。

无论如何,我希望这对你有帮助!

$wp_customize->add_setting( \'theme_profile_picture\', array(
    \'transport\' => \'refresh\',
    \'sanitize_callback\' => \'theme_sanitize_profile_picture\',
));

$wp_customize->add_section(\'theme_profile_picture_section\', array(
    \'title\' => __(\'Profile Picture\', \'theme\'),
    \'priority\' => 10,
));

$wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, \'theme_profile_picture\', array(
    \'label\'    => __( \'Upload Profile Picture\', \'theme\' ),
    \'section\' => \'title_tagline\',
    \'settings\' => \'theme_profile_picture\',
    \'flex_width\'  => false, // Allow any width, making the specified value recommended. False by default.
    \'flex_height\' => false,
    \'width\'       => 250,
    \'height\'      => 250,
) ) );

相关推荐

如何在LOGO下显示二十一六个他们的菜单?

我试着把WordPress改成216。我仔细检查了CSS,不知道主菜单怎么会显示在徽标(和网站名称)的右侧。无浮点,无内联块。我试图在菜单和徽标中添加浮动或显示为块,但根本不起作用。他们是怎么做到的?