-
Notifications
You must be signed in to change notification settings - Fork 802
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
API: Add File Attachment & Parent Details to Media Endpoint #20408
base: trunk
Are you sure you want to change the base?
Conversation
'post_type' => 'any', | ||
); | ||
|
||
$content_query = new WP_Query( $args ); |
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.
What if we use an OR operator instead of doing a query for each file size? 🤔
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.
I've tried doing some research and testing this, but my understanding is that this doesn't work with the search parameter. I haven't been able to get it to work, so I feel like it might be necessary to do individual queries for each size?
); | ||
} | ||
|
||
return $data; |
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.
I think we should filter the array by unique URLs. I guess there are cases when both sizes are present in the same post, in which case I think we'll have duplicate entries, right? 🤔
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.
Yep, I'll fix that!
@Aurorum, many thanks for the contribution! I've had a look and I've made a few suggestions about the implementation. One thing that I think we could look into is the performance impact. Since we are doing a search in all post types, what if we could make this operation on demand? For example, what if we change a bit the UI in Calypso and add a button in the UI asking something like "Refresh/Retrieve the occurrences of this media"? When pressed, we'll make an API call that executes that method call and stores the result in the attachment metadata. I think we could explore this and maybe get some feedback on it from other folks. :) Thanks again for taking the time to look into this. :) |
Thanks @BogdanUngureanu! That sounds like a good approach - I've started work on some of it, but I'll need to add the Calypso-side at some point later this week. |
Hi @BogdanUngureanu! I'm trying to implement the button you recommended in Calypso, but I'm struggling to understand how to store the media query. Generally, my understanding is it should look something like this: this.props.requestMedia( this.props.siteId, { query_attached_files: 1 } ).then( ( mediaData ) =>
this.setState( {
mediaData,
} )
); Although that successfully makes the API request, it doesn't store the response. Would you have any idea how to do that? |
Hi @Aurorum, that looks ok, I think. You could check if the promise is rejected or not, maybe that's why the state is not persisted. |
@Aurorum @BogdanUngureanu Any chance you could take another stab at this? Looks like Automattic/wp-calypso#54691 is blocked by its progress |
Hi @obenland - sorry for the late response, sure, I think I could work on it in some of my 20% time. About the Calypso part, I'm not 100% confident about the design, because there are cases when a image would be used in a lot of post types, in which case that list would be huge and might break the modal layout. |
Thank you! Yeah we could probably limit that list to five posts or something, but that is probably best discussed in the Calypso ticket itself |
Required for Automattic/wp-calypso#54691
Changes proposed in this Pull Request:
Adds two pieces of information to the Media endpoint:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions: