@@ 163-191 (lines=29) @@ | ||
160 | * |
|
161 | * @return int|object |
|
162 | */ |
|
163 | function create_local_media_library_for_videopress_guid( $guid, $parent_id = 0 ) { |
|
164 | $vp_data = videopress_get_video_details( $guid ); |
|
165 | if ( ! $vp_data || is_wp_error( $vp_data ) ) { |
|
166 | return $vp_data; |
|
167 | } |
|
168 | ||
169 | $args = array( |
|
170 | 'post_date' => $vp_data->upload_date, |
|
171 | 'post_title' => wp_kses( $vp_data->title, array() ), |
|
172 | 'post_content' => wp_kses( $vp_data->description, array() ), |
|
173 | 'post_mime_type' => 'video/videopress', |
|
174 | 'guid' => sprintf( 'https://videopress.com/v/%s', $guid ), |
|
175 | ); |
|
176 | ||
177 | $attachment_id = wp_insert_attachment( $args, null, $parent_id ); |
|
178 | ||
179 | if ( ! is_wp_error( $attachment_id ) ) { |
|
180 | update_post_meta( $attachment_id, 'videopress_guid', $guid ); |
|
181 | wp_update_attachment_metadata( $attachment_id, array( |
|
182 | 'width' => $vp_data->width, |
|
183 | 'height' => $vp_data->height, |
|
184 | ) ); |
|
185 | ||
186 | $thumbnail_id = videopress_download_poster_image( $vp_data->poster, $attachment_id ); |
|
187 | update_post_meta( $attachment_id, '_thumbnail_id', $thumbnail_id ); |
|
188 | } |
|
189 | ||
190 | return $attachment_id; |
|
191 | } |
|
192 | ||
193 | /** |
|
194 | * Helper that will look for VideoPress media items that are more than 30 minutes old, |
@@ 146-174 (lines=29) @@ | ||
143 | * |
|
144 | * @return int|object |
|
145 | */ |
|
146 | function create_local_media_library_for_videopress_guid( $guid, $parent_id = 0 ) { |
|
147 | $vp_data = videopress_get_video_details( $guid ); |
|
148 | if ( ! $vp_data || is_wp_error( $vp_data ) ) { |
|
149 | return $vp_data; |
|
150 | } |
|
151 | ||
152 | $args = array( |
|
153 | 'post_date' => $vp_data->upload_date, |
|
154 | 'post_title' => wp_kses( $vp_data->title, array() ), |
|
155 | 'post_content' => wp_kses( $vp_data->description, array() ), |
|
156 | 'post_mime_type' => 'video/videopress', |
|
157 | 'guid' => sprintf( 'https://videopress.com/v/%s', $guid ), |
|
158 | ); |
|
159 | ||
160 | $attachment_id = wp_insert_attachment( $args, null, $parent_id ); |
|
161 | ||
162 | if ( ! is_wp_error( $attachment_id ) ) { |
|
163 | update_post_meta( $attachment_id, 'videopress_guid', $guid ); |
|
164 | wp_update_attachment_metadata( $attachment_id, array( |
|
165 | 'width' => $vp_data->width, |
|
166 | 'height' => $vp_data->height, |
|
167 | ) ); |
|
168 | ||
169 | $thumbnail_id = videopress_download_poster_image( $vp_data->poster, $attachment_id ); |
|
170 | update_post_meta( $attachment_id, '_thumbnail_id', $thumbnail_id ); |
|
171 | } |
|
172 | ||
173 | return $attachment_id; |
|
174 | } |
|
175 | ||
176 | if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
177 | /** |