我需要为此函数添加一些错误检查,以确保 imagegif() 和 imagecolorset() 函数成功。失败的常见原因是 spot2.gif 文件不可写的权限问题。
但是,当我将 spot2.gif 更改为只读时,应该触发“其他”条件的条件,回显的 javascript 警报不会触发。
function set_theme_color_spot2($hex)
{
$info = hexToRGB($hex);
$token = "../wp-content/themes/".get_option('template')."/styles/".get_option('myTheme')."/spot2.gif";
$token2 = "../wp-content/themes/".get_option('template')."/styles/".get_option('myTheme')."/spot2-template.gif";
if (file_exists($token2) && is_writable($token))
{
$img = imagecreatefromgif("../wp-content/themes/".get_option('template')."/styles/".get_option('myTheme')."/spot2-template.gif");
$color = imagecolorallocate($img, $info["red"], $info["green"], $info["blue"]);
imagecolorset($img, 0, $info["red"], $info["green"], $info["blue"]);
imagegif($img, $token);
$themecolor = get_option('myTheme').'_color4';
update_option($themecolor, $hex);
}
else
{
echo "<script type='text/javascript'>alert('The template colors could not be changed because your current file permissions are too restrictive. Make sure the files in the styles directory are set to 644');</script>";
}
}