-
Notifications
You must be signed in to change notification settings - Fork 466
feat: introduce new fields for getting mediaItem files and filePaths #3294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: introduce new fields for getting mediaItem files and filePaths #3294
Conversation
…iaItem and allows a size to be specified. - update resolver for MediaDetails.file to return just the filename as the description states. Previously it was returning a path such as /2022/02/filename.jpg which doesn't match the description of the field. This is a bugfix but could be a breaking change for users that were expecting the path. - introduce a MediaSize.filePath field which returns the path to the file for the referenced size (default is full) - add tests for the new and updated fields
…sizes-file-field # Conflicts: # tests/wpunit/MediaItemQueriesTest.php
…rectory - update tests to accomondate for the change
| $metadata = wp_get_attachment_metadata( $source->databaseId ); | ||
|
|
||
| if ( ! empty( $metadata['sizes'][ $size ]['file'] ) ) { | ||
| return $metadata['sizes'][ $size ]['file']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid too many return statements within this method.
|
|
||
| // Default to original file | ||
| $attached_file = get_post_meta( $source->databaseId, '_wp_attached_file', true ); | ||
| return ! empty( $attached_file ) ? basename( $attached_file ) : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid too many return statements within this method.
|
|
||
| if ( ! empty( $metadata['sizes'][ $size ]['file'] ) ) { | ||
| $file_path = $metadata['file']; | ||
| return path_join( $relative_upload_path, dirname( $file_path ) . '/' . $metadata['sizes'][ $size ]['file'] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid too many return statements within this method.
| return null; | ||
| } | ||
|
|
||
| return path_join( $relative_upload_path, $attached_file ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid too many return statements within this method.
|
Code Climate has analyzed commit 90d6ca5 and detected 9 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
What does this implement/fix? Explain your changes.
This introduces some new fields for retrieving MediaItem file values:
MediaDetails.filePath: The path to the mediaItem relative to the uploads directoryMediaItem.file: The filename of the mediaItem for the specified size (default size is full)MediaItem.filePath: The path to the original file relative to the uploads directoryMediaSize.filePathThe path of the file for the referenced size (default size is full)Does this close any currently open issues?
related: #2982
Any other comments?
In #3293 we fixed a bug in how the MediaDetails.file field resolved. This introduces some new fields to access both the filename and filePath to accommodate various use cases.
ex:
Standard site with standard uploads directory
Bedrock site with a different uploads directory