示例#1
0
/**
 * shopp_rmv_image
 *
 * remove an image record from the database
 *
 * @api
 * @since 1.2
 *
 * @param int $image the image id
 * @param string $context the object type the image asset is attached to.  This can be product or category
 * @return mixed false on failure, int image asset id on success.
 **/
function shopp_rmv_image($image, $context)
{
    if (empty($image) || empty($context)) {
        shopp_debug(__FUNCTION__ . " failed: Missing parameters");
        return false;
    }
    if ('product' == $context) {
        $Image = new ProductImage($image);
    } else {
        if ('category' == $context) {
            $Image = new CategoryImage($image);
        } else {
            shopp_debug(__FUNCTION__ . " failed: Invalid context {$context}.");
            return false;
        }
    }
    if (empty($Image->id)) {
        shopp_debug(__FUNCTION__ . " failed: No such {$context} image with id {$image}");
        return false;
    }
    return $Image->delete();
}