我很难找到线索。
我有一个函数,它接受一个 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');