我很难找到线索。
我有一个函数,它接收JSON数据列表并将其形成为php多维数组。我正在尝试将此数组插入到wordpress的add_theme_support函数中,以添加一些颜色选项。
由于某种原因,我正在创建的数组不会被添加到add_theme_support函数中。
$json_data = file_get_contents(); // url here
$decodey = json_decode($json_data, true);
$new_palette = array();
$palette_colors = array_values($new_palette);
//loop through JSON to get php arrays
for ($i = 0; $i < sizeof($decodey['list']['colors'][0]['colors']); $i++){
$colorName = $decodey['list']['colors'][0]['colors'][$i]['name'];
$colorName = trim($colorName);
$pattern = '/!/';
$replacement = '';
$colorName = preg_replace($pattern, $replacement, $colorName);
//echo $colorName;
$colorSlug = str_replace(' ', '-', strtolower($colorName));
//echo $colorSlug;
$colorCode = $decodey['list']['colors'][0]['colors'][$i]['value'];
//echo $colorCode;
//create new array for each color
$newColorItem = array( 'name' => $colorName,
'slug' => $colorSlug,
'color' => $colorCode,
);
//push color arrays to empty array
$new_palette[] = array( 'name' => $colorName,
'slug' => $colorSlug,
'color' => $colorCode,
);
} //end loop
function addNewColors(){
add_theme_support('editor-color-palette',
array(
//this doesn't work
$new_palette
)
);
}
add_action( 'after_setup_theme', 'addNewColors');
答案 0 :(得分:0)
问题来自于addNewColors()函数。不需要它,现在在Gutenberg中的选项似乎很好。不需要变量。
add_theme_support('editor-color-palette', $new_palette);