-
Notifications
You must be signed in to change notification settings - Fork 814
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
Add new media endpoints #5281
Add new media endpoints #5281
Conversation
get
and update
media endpoints
cc @mcsf @gravityrail if we're missing anything major for a Jetpack enpoint |
Something that we have to achieve is to be able to upload a new image without creating a new record into of dB. As far as I see we should split the request into two requests. First one to upload the new image and the second one to update the image-post record. For this reason, I think we should create a new Jetpack action, for instance, So the |
I wonder if we can modify |
😅 Sorry about that Miguel |
Removing the milestone until this is completed-- please feel free to move it back into the appropriate milestone when it's out of "In Progress" |
Closing this for now, feel free to reopen if it ever gets fresh attention |
Starting to work on this again. |
d3ffed6
to
f89ed2f
Compare
_inc/lib/class.media.php
Outdated
|
||
if ( ! empty( $original_media ) ) { | ||
$original_file_parts = pathinfo( $original_media['file'] ); | ||
$original_file_ext = $original_file_parts['filename']; |
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.
This var is not used anywhere?
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.
No. removing ...
_inc/lib/class.media.php
Outdated
} | ||
|
||
// hook: clean revision history when the media item is deleted | ||
$clean_revision_history = function( $media_id ) { |
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.
Unfortunately we need to support PHP 5.2.4 :(
Anonymous functions were introduced in 5.3
} | ||
} | ||
|
||
return $post_update_action; |
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.
Looks like this may not be defined if there's no $attrs['alt']
set.
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.
Yes, that's right. I've decided to implement the same behavior that we already do with other endpoints which is silence these errors when these metadata aren't updated, like here: https://github.com/Automattic/jetpack/blob/master/json-endpoints/class.wpcom-json-api-update-media-v1-1-endpoint.php#L41
We still returning an error when the media item updating (post) fails.
* @param {String} $url - image URL to save locally | ||
* @return {Array|WP_Error} An array with information about the new file saved or a WP_Error is something went wrong. | ||
*/ | ||
private function build_file_array_from_url( $media_id, $url ) { |
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.
do we need $media_id param?
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.
yup, If I'm not wrong it's needed to update the media item (post object).
$insert['ID'] = $media_id;
$update_action = wp_update_post( (object) $insert );
* WARNING: This file is distributed verbatim in Jetpack. | ||
* There should be nothing WordPress.com specific in this file. | ||
* | ||
* @hide-in-jetpack |
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.
You can remove this block -- it should only be added to wpcom as it tells our syncing script to omit it when building out the commits.
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.
Yeah, it's confusing. tl;dr this @hide-in-jetpack
tells a script that we use to hide this block from Jetpack and it's safe to remove from this PR.
Anyway, it's fine to leave it in too. Not a blocker.
_inc/lib/class.media.php
Outdated
/** | ||
* Class to handle different actions related to media. | ||
*/ | ||
class Media { |
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.
Let's namespace this Jetpack_
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.
cool. done
_inc/lib/class.media.php
Outdated
|
||
// hook: clean revision history when the media item is deleted | ||
function clean_revision_history( $media_id ) { | ||
error_log( 'mas se perdio en la guerra ' ); |
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 this may have been left in...
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.
🤦♂️ already removed
a3e2408
to
8b882c6
Compare
8b882c6
to
9941c20
Compare
This is working well for me. And although github says changes requested, it looks like the changes @dereksmart asked for are handled. So if it looks good to him, I think this is good to 🚢 |
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'm happy :) merging!
I'm happy too. :-D |
* Changelog: update stable tag and move changelog to changelog.txt Also remove old releases from readme.txt to keep the changelog tab short. * Changelog: add #5883 Also update the filter's docblock to match new version. * Changelog: add #5938 * Changelog: add #6298 * Changelog: add #3405 * Changelog: add #5941 * Changelog: add #6239 * Changelog: add #6281 * Changelog: add #6303 * Changelog: add #6018 * Changelog: add #6300 * Changelog: add #6296 * Changelog: add #6130 * Changelog: add #6292 * Readme: remove extra "on". * Changelog: add #6307 * Changelog: add #3297 * Changelog: add #6275 * Changelog: add #6321 * Changelog: add #6297 * Readme: update the support forum link anchor. Anchor changed when WordPress.org forums were updated to bbPress 2 * Readme: update list of a12s, it wasn't up to date anymore! * Changelog: add #6338 * Changelog: add #6337 * Changelog: add #6335 * Changelog: add #6333 * Testing List: first version of the 4.7 testing list. * Changelog: add #6332 * Changelog: add #6325 * Changelog: add #6326 * Changelog: add #6339 * Changelog: add #6342 * Changelog: add #6343 * Changelog: add #6346 * Changelog: add #6347 * Changelog: add #6279 * Changelog: add #6306 * Changelog: add #6312 * Changelog: add #6316 * Changelog: add #6171 * Changelog: add #6317 * Changelog: add #6246 * Changelog: add #6263 * Changelog: add #4220 * Changelog: add #5888 * Changelog: add #3406 * Changelog: add #3637 * Changelog: add #6320 * Changelog: add #5992 * Changelog: add #6322 * Changelog: add #6324 * Changelog: add #6352 * Changelog: add #6355 * Changelog: add #6360 * Changelog: add #6362 * Changelog: add #6369, #6382 * Changelog: add #6370 * Changelog: add #6375 * Changelog: add #6383 * Changelog: add #6384 * Changelog: add #6386 * Changelog: add #6395 * Changelog: add #6403 * Changelog: add #6406 * Changelog: add #6418 * Changelog: add #6419 * Changelog: add #6434 * Changelog: add #6446 * Changelog: add #6006 * Changelog: add #6096 * Changelog: add #6399 * Changelog: fix typo. @see #6331 (comment) * Changelog: add #6440 * Changelog: add #6443 * Changelog: add #6445 * Changelog: add #6463 * Changelog: add #6468 * Changelog: add #6471 * Changelog: add #6474 * Changelog: add #6480 * Changelog: add #6497 * Changelog: add #6499 * Changelog: add #6514 * Changelog: add #6267 * Changelog: add #5940 * Changelog: add #6492 * Changelog: add #5281 * Changelog: add #6327 * Changelog: add #6451 * Changelog: add #6525 * Changelog: add #6530
yay! |
This PR adds new versions of
get-media
endpoint and add the newedit-media
endpoint to the WP COM API.Changes proposed in this Pull Request:
Add v1.2
[POST]
/sites/$site/media/$mediaID/edit
The
edit-media
endpoint was added into the WP COM API a while ago. This patch adds the needed code to support theedit-media
endpoint now for Jetpack sites.The hardest part of this process is to detect when a media item should be added (
new-media
endpoint) or when it should be updated (edit-media
endpoint).The right action to take depends on the action parameter into the request body. it could be
jetpack_upload_action
(the only one action used at the moment) andjetpack_update_action
. When the action is the last one, the attached metadata of the media item is updated according to the new uploaded media file instead of creating a new media item.Also, other tasks are done in this editing process, such as store the original media file, keep the revision history, clean the remaining files when the media item is deleted, etc.
Add v1.2
[GET]
/sites/$site/media/$mediaID
There aren't significant changes in this endpoint. It just adds some fields to the response body.