Automattic\WooCommerce\Internal\ProductDownloads
DownloadableFileAttachments::is_downloadable_file
Check whether an attachment is stored in the woocommerce_uploads directory.
Метод класса: DownloadableFileAttachments{}
Хуков нет.
Возвращает
bool.
Использование
// private - только в коде основоного (родительского) класса $result = $this->is_downloadable_file( $attachment_id ): bool;
- $attachment_id(int) (обязательный)
- Attachment ID.
Код DownloadableFileAttachments::is_downloadable_file() DownloadableFileAttachments::is downloadable file WC 11.3.0
private function is_downloadable_file( int $attachment_id ): bool {
// Checking the post type first skips a meta lookup for the posts that comment and GUID hooks run on.
if ( $this->in_progress || $attachment_id <= 0 || 'attachment' !== get_post_type( $attachment_id ) ) {
return false;
}
// Plugins can filter the meta read below with a function that fires these hooks again, such as get_the_guid().
$this->in_progress = true;
try {
// Case-insensitive to match the SQL LIKE used for REST API collections.
return 0 === stripos( (string) get_post_meta( $attachment_id, '_wp_attached_file', true ), self::DIRECTORY );
} finally {
$this->in_progress = false;
}
}