I want to make a logo manager in the Customizer, but how do I set different image sizes with the WP_Customize_Cropped_Image_Control
class?
Example from 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 Answers
I think you add for each logo a settings field? If no, please enhance your question.
If yes, then add also often the call for the cropped image control. The follow example add an section, an field for a logo option and get the possibility for cropping image.
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,
)
)
);
}