dozent_get_attachments( int $post_ID )
Get attachments from Dozent PostType like course | lecture | assignments
Description
Get all attachments in array from the Dozent LMS post types Pass Post id as parameter
Example usage:
dozent_get_attachments();
dozent_get_attachments( $post_id );
See also
Parameters
- $post_ID
-
(int) (Required) Post ID
Return
(array)
Source
File: includes/core-functions.php
function dozent_get_attachments( $post_ID = 0 ) { $post_ID = dozent_get_post_id( $post_ID ); $attachments = (array) maybe_unserialize( get_post_meta( $post_ID, '_attachments', true ) ); $attachments = array_filter( $attachments ); $attachmentsArr = []; $font_icons = apply_filters( 'dozent_file_type_icons', [ 'dicon-file-archive', 'dicon-file-audio', 'dicon-file-code', 'dicon-file-default', 'dicon-file-document', 'dicon-file-interactive', 'dicon-file-spreadsheet', 'dicon-file-text', 'dicon-file-video', 'dicon-file-image', ] ); if ( dozent_count( $attachments ) ) { foreach ( $attachments as $attachment ) { $url = wp_get_attachment_url( $attachment ); $file_type = wp_check_filetype( $url ); $ext = $file_type['ext']; $title = get_the_title( $attachment ); $file_path = get_attached_file( $attachment ); $size_bytes = file_exists( $file_path ) ? filesize( $file_path ) : 0; $size = size_format( $size_bytes, 2 ); $type = wp_ext2type( $ext ); $type = 'dicon-file-' . $type; $icon = dozent_array_get( $type, $font_icons, 'dicon-file-default' ); $data = array( 'post_ID' => $post_ID, 'id' => $attachment, 'url' => $url, 'name' => $title . '.' . $ext, 'title' => $title, 'ext' => $ext, 'size_readable' => $size, 'size_bytes' => $size_bytes, 'icon' => $icon, ); /** * Filter attachments output of dozent_get_attachments() function * * @since DozentLMS 1.0.0 * * @param array $data Attachments */ $attachmentsArr[] = (object) apply_filters( 'dozent/posts/attachments', $data ); } return $attachmentsArr; } return $attachmentsArr; }
Changelog
Version | Description |
---|---|
DozentLMS 1.0.0 | Introduced. |