PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.1.5
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.1.5
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Controllers / Rest / ProductMediaController.php
ProductMediaController.php
53 lines 971 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Controllers\Rest;
4
5 use SureCart\Models\ProductMedia;
6
7 /**
8 * Handle ProductMedia requests through the REST API
9 */
10 class ProductMediaController extends RestController {
11 /**
12 * Always fetch with these subcollections.
13 *
14 * @var array
15 */
16 protected $with = [ 'media' ];
17
18 /**
19 * Class to make the requests.
20 *
21 * @var string
22 */
23 protected $class = ProductMedia::class;
24
25 /**
26 * Download a media file.
27 *
28 * @param \WP_REST_Request $request Request object.
29 *
30 * @return integer|\WP_Error
31 */
32 public function download( \WP_REST_Request $request ) {
33 $model = $this->middleware( new $this->class(), $request );
34 if ( is_wp_error( $model ) ) {
35 return $model;
36 }
37
38 $media = $model->with( [ 'media' ] )->find( $request['id'] );
39
40 if ( is_wp_error( $media ) ) {
41 return $media;
42 }
43
44 $attachment_id = $media->download();
45
46 if ( is_wp_error( $attachment_id ) ) {
47 return $attachment_id;
48 }
49
50 return $attachment_id;
51 }
52 }
53