Created
June 5, 2020 19:38
-
-
Save Oceas/29db8dfec1b290154c653acd707e6a64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Upload photo to site. | |
* | |
* @author Scott Anderson <[email protected]> | |
* @since NEXT | |
* @param Request $request Request form date to format for api. | |
* @return int Id of image uploaded. | |
*/ | |
public function upload_photo( Request $request ) : int { | |
$this->new_construct(); | |
$file = file_get_contents( $request->file( 'featured_image_upload' ) ); | |
$response = json_decode( $this->client->post( "{$this->site_url}/wp-json/wp/v2/media", [ 'headers' => $this->image_header( $request ), 'body' => $file ] )->getBody() ); | |
return $response->id; | |
} | |
/** | |
* Specialized image header. | |
* | |
* @author Scott Anderson <[email protected]> | |
* @since NEXT | |
* @param Request $request Request form date to format for api. | |
* @return array | |
*/ | |
private function image_header( Request $request ) : array { | |
return array_merge( $this->headers, [ | |
'Content-Disposition' => 'attachment; filename=testing.jpeg', | |
'Content-Type' => 'image/png', | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment