[Plugin: JSON API] Extending save features: thumbnail and scheduled posts
-
I needed to mark the uploaded image as the post thumbnail so altered the save method with this:
if (!empty($_FILES['attachment'])) { include_once ABSPATH . '/wp-admin/includes/file.php'; include_once ABSPATH . '/wp-admin/includes/media.php'; include_once ABSPATH . '/wp-admin/includes/image.php'; $attachment_id = media_handle_upload('attachment', $this->id); $this->attachments[] = new JSON_API_Attachment($attachment_id); if (isset($values['thumbnail'])) { if($values['thumbnail'] == 'TRUE'){ $thumbnail_html = wp_get_attachment_image( $attachment_id, 'thumbnail' ); if ( !empty( $thumbnail_html ) ) { update_post_meta( $this->id, '_thumbnail_id', $attachment_id ); } } } unset($_FILES['attachment']); }
I also added scheduled posts with:
if (!empty($values['status'])) { $wp_values['post_status'] = $values['status']; if (!empty($values['date']) && $values['status'] == 'publish') { $wp_values['post_date'] = $values['date']; } }
Thanks for a fantastic plugin Dan.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘[Plugin: JSON API] Extending save features: thumbnail and scheduled posts’ is closed to new replies.