本文整理汇总了PHP中WP_Customize_Control::add_control方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Customize_Control::add_control方法的具体用法?PHP WP_Customize_Control::add_control怎么用?PHP WP_Customize_Control::add_control使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Customize_Control
的用法示例。
在下文中一共展示了WP_Customize_Control::add_control方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ya_customize_register
/**
* Adds sections to the customizer
* @param WP_Customize_Control $wp_customize
*/
function ya_customize_register($wp_customize)
{
$priority = 200;
$sections = array();
$ya_options = ya_options();
$i = 0;
foreach ($ya_options->sections as $section) {
if (isset($section['fields']) && is_array($section['fields'])) {
foreach ($section['fields'] as $field) {
$customize = $field['id'] . '_customize_allow';
if ($ya_options->get($customize)) {
if (isset($field['options'])) {
$field['choices'] = $field['options'];
}
if ($field['type'] == 'upload') {
$field['type'] = 'image';
}
if ($field['type'] == 'radio_img') {
$field['type'] = 'select';
$field['choices'] = array();
foreach ($field['options'] as $key => $choices) {
$field['choices'][$key] = $choices['title'];
}
}
$field['label'] = $field['title'];
$field['section'] = sanitize_title($section['title']);
$field['settings'] = $ya_options->args['opt_name'] . '[' . $field['id'] . ']';
$field['priority'] = $priority++;
$sections[$i]['fields'][] = $field;
}
}
if (isset($sections[$i]['fields'])) {
$sections[$i]['title'] = $section['title'];
$sections[$i]['priority'] = $priority++;
$sections[$i]['capability'] = 'edit_theme_options';
$i++;
}
}
}
foreach ($sections as $section) {
// Add Section
$wp_customize->add_section(sanitize_title($section['title']), $section);
foreach ($section['fields'] as $field) {
//Add Setting
$wp_customize->add_setting($ya_options->args['opt_name'] . '[' . $field['id'] . ']', array('default' => $ya_options->get($field['id']), 'type' => 'option', 'transport' => 'postMessage', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'customize_option'));
// Add Control
switch ($field['type']) {
case 'color':
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, $field['id'], $field));
break;
case 'image':
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, $field['id'], $field));
break;
case 'textarea':
$wp_customize->add_control(new WP_Customize_Textarea_Control($wp_customize, $field['id'], $field));
break;
default:
$wp_customize->add_control($field['id'], $field);
}
//$wp_customize->get_setting($ya_options->args['opt_name'].'['.$field['id'].']')->transport = 'postMessage';
}
}
$wp_customize->get_setting('blogname')->transport = 'postMessage';
$wp_customize->get_setting('blogdescription')->transport = 'postMessage';
}