isComputingMissingImageSubsizes()) { return $data; } // Resolve the local original path without wp_get_original_image_path(), // which calls wp_get_attachment_metadata() and would re-enter this // filter. Unfiltered on purpose: we want the real local path, not one // rewritten by 'get_attached_file' filters. $attached_file = get_attached_file($attachment_id, true); if (empty($attached_file)) { return $data; } $original_image = path_join(dirname($attached_file), $data['original_image']); if (file_exists($original_image)) { return $data; } unset($data['original_image']); return $data; } /** * Whether the current metadata fetch originates from * wp_get_missing_image_subsizes(). * * @return bool */ private function isComputingMissingImageSubsizes(): bool { // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 8); foreach ($trace as $frame) { if (isset($frame['function']) && 'wp_get_missing_image_subsizes' === $frame['function'] && empty($frame['class'])) { return true; } } return false; } }