bool, 'message' => string] */ public static function validate_image_dimensions($image) { if (empty($image)) { return ['valid' => false, 'message' => 'Image is empty.']; } $width = 0; $height = 0; if (is_numeric($image)) { // It's an attachment ID $meta = wp_get_attachment_metadata($image); if ($meta) { $width = $meta['width']; $height = $meta['height']; } } else { // It's a URL. Hard to check dimensions without fetching or ID. // If it's a local URL, we might be able to map to ID. // For MVP/Phase 2, if URL is provided, we might assume it's valid or try to get ID. // PRD 1.3 says "Use WordPress Media Library only". // So we should encourage storing IDs in options for validation, but for output we use URL. // If $image is a URL, try to get ID? $id = attachment_url_to_postid($image); if ($id) { $meta = wp_get_attachment_metadata($id); if ($meta) { $width = $meta['width']; $height = $meta['height']; } } } if ($width === 0 || $height === 0) { // Cannot determine dimensions. Warn? return ['valid' => true, 'message' => 'Could not verify dimensions.']; } if ($width < self::MIN_WIDTH || $height < self::MIN_HEIGHT) { return ['valid' => false, 'message' => sprintf('Image is too small (%dx%d). Minimum %dx%d required.', $width, $height, self::MIN_WIDTH, self::MIN_HEIGHT)]; } if ($width < self::REC_WIDTH || $height < self::REC_HEIGHT) { // Valid but sub-optimal return ['valid' => true, 'message' => sprintf('Image is smaller than recommended (%dx%d). Recommended %dx%d.', $width, $height, self::REC_WIDTH, self::REC_HEIGHT)]; } return ['valid' => true, 'message' => 'OK']; } }