WordPress.org

Forums

JSON API
Extending save features: thumbnail and scheduled posts (4 posts)

  1. aspratley
    Member
    Posted 5 years ago #

    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.

    http://wordpress.org/extend/plugins/json-api/

  2. fgrs
    Member
    Posted 4 years ago #

    which file need to be changed?

  3. fgrs
    Member
    Posted 4 years ago #

    any idea? i tried this mod but no luck, help please!

  4. dphiffer
    Member
    Plugin Author

    Posted 4 years ago #

    Interesting, I think I'll include this in a future release. The next one about to go up is just bugfixes.

    Thanks,
    -Dan

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • JSON API
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags