I'm working on the Wordpress Customizer in my theme. Now suppose i want to create a kind of item with 3 options (in this case, an image and 2 inputs), and i want to let the user to create many of these. I know how to create the text inputs:
$wp_customizer->add_setting('fantastic-input', array(
'type' => 'theme_mod',
'default' => 'Make something fantastic!'
));
$wp_customizer->add_control('fantastic-input-opt', array(
'type' => 'input',
'section' => 'fantastic-section',
'settings' => 'fantastic-input',
'label' => _('Input something fantastic here'),
'description' => 'This input is fantastic!'
));
and to add an Image selector:
$wp_customizer->add_setting('fantastic-image', array(
'type' => 'theme_mod',
'default' => ''
));
$wp_customizer->add_control(new WP_Customize_Image_Control (
$wp_customizer,
'fantastic-image',
array(
'label' => _('Best image ever'),
'section' => 'fantastic-section',
)
));
But what if i don't want this to be the only one of its kind? Thank you.
EDIT
I'm thinking about a possible solution being to create a custom control with all the needed fields inside, extending WP_Customize_Control
. I could think about some way to encode all of them in a json string, or something that makes them easy to manage together.
Possible code for custom control:
class Custom_Control extends WP_Customize_Control {
public $type = 'my-custom-control';
//As seen by admin
public function render_content() {
$picture = new WP_Customize_Image_Control();
$picture->render_content();
?>
<input type="text" name="title" placeholder="" />
<input type="text" name="cta" placeholder="" />
<textarea name="textbody"></textarea>
<?php
}
//Load js to handle this
public function enqueue () {
wp_enqueue_script('something.js', 'somepath', array( 'jquery' ));
}
}
Is this ok? And what about the picture control? How to include it?