我有一个功能,设计用于做两件事:1)在自定义程序中创建颜色选择器控件/设置,2)创建多维数组$customizeData
以标题样式输出,并用于本地化自定义程序的变量。js。
第一个目标是成功的。第二个把我逼到这里来了。我为添加了var\\u转储$customizerData
索引。php该数组在前端为空,但在我将其加载到自定义程序中时,会按预期填充该数组。
以下是所讨论的功能:
if (! function_exists(\'_sf_customzier_color_loop\') ) :
function _sf_customzier_color_loop($colors, $countStart = 10, $section) {
//Not sure why I have to do this first thing
global $wp_customize;
//declare $customizerData as a global variable
global $customizerData;
//start the counter at 10 or whatever was set.
$count = $countStart;
foreach ($colors as $things) {
$slug = $things[\'slug\'];
$id = "_sf[{$slug}]";
//If current array has a priority set, use it, if not use the counter.
if (! isset($things[\'priority\']) ) {
$priority = $count;
}
else {
$priority = $things[\'priority\'];
}
$wp_customize->add_setting( $id, array(
\'type\' => \'option\',
\'transport\' => \'postMessage\',
\'capability\' => \'edit_theme_options\',
\'default\' => $things[\'default\'],
) );
$control =
new WP_Customize_Color_Control(
$wp_customize, $slug,
array(
\'label\' => __( $things[\'label\'], \'_sf\' ),
\'section\' => $section,
\'priority\' => $priority,
\'settings\' => $id
)
);
$wp_customize->add_control($control);
//create array to be used for the outputting styles to wp_head and customizer.js
$customizerData [] = array(
\'id\' => $id,
\'slug\' => $slug,
\'selector\' => $things[\'selector\'],
\'property\' => $things[\'property\'],
);
//advance priority counter
$count++;
}
}
endif;
// ! _sf_customzier_color_loop exists
你可以在下面的网站上看到我给这个网站提供的内容的一个示例:
https://github.com/Shelob9/_sf_lib/blob/1.1-fancy-data/customizer/customizer-sidebar.php我需要做什么才能在前端填充阵列?