PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
← All changes | jetpack_vendor/automattic/jetpack-videopress/src/class-attachment-handler.php +100 -5 13.5.2 → 16.3 View file →
@@ -43,8 +43,12 @@
43 43 add_filter( 'ajax_query_attachments_args', array( __CLASS__, 'ajax_query_attachments_args' ) );
44 44 add_action( 'pre_get_posts', array( __CLASS__, 'media_list_table_query' ) );
45 45
46 46 add_filter( 'user_has_cap', array( __CLASS__, 'disable_delete_if_disconnected' ), 10, 3 );
47 +
48 + add_action( 'admin_print_scripts-upload.php', array( __CLASS__, 'enqueue_media_library_poll' ) );
49 + add_action( 'admin_print_styles-upload.php', array( __CLASS__, 'enqueue_media_library_styles' ) );
50 + add_filter( 'heartbeat_received', array( __CLASS__, 'heartbeat_received' ), 10, 2 );
47 51 }
48 52
49 53 /**
50 54 * Returns the VideoPress URL for the give post id, otherwise returns the provided default.
@@ -117,9 +121,10 @@
117 121 // Phone home and have wp.com delete the VideoPress entry and files.
118 122 $wpcom_response = Client::wpcom_json_api_request_as_blog(
119 123 sprintf( '/videos/%s/delete', $guid ),
120 124 '1.1',
121 - array( 'method' => 'POST' )
125 + array( 'method' => 'POST' ),
126 + array( 'user_id' => get_current_user_id() )
122 127 );
123 128
124 129 if ( is_wp_error( $wpcom_response ) ) {
125 130 return $wpcom_response;
@@ -189,16 +194,21 @@
189 194
190 195 /**
191 196 * Make sure that any Video that has a VideoPress GUID passes that data back.
192 197 *
193 - * @param WP_Post $post Attachment object.
198 + * @param array $post Attachment data array.
199 + * @return array
194 200 */
195 201 public static function prepare_attachment_for_js( $post ) {
196 202 if ( 'video' === $post['type'] ) {
197 - $guid = get_post_meta( $post['id'], 'videopress_guid' );
203 + $guid = get_post_meta( $post['id'], 'videopress_guid', true );
198 204 if ( $guid ) {
199 205 $post['videopress_guid'] = $guid;
200 206 }
207 + $status = get_post_meta( $post['id'], 'videopress_status', true );
208 + if ( $status ) {
209 + $post['videopress_status'] = $status;
210 + }
201 211 }
202 212 return $post;
203 213 }
204 214
@@ -274,14 +284,14 @@
274 284 */
275 285 public static function disable_delete_if_disconnected( $allcaps, $cap, $args ) {
276 286
277 287 // Only apply this filter to `delete_post` checks
278 - if ( 'delete_post' !== $args[0] ) {
288 + if ( ! isset( $args[0] ) || 'delete_post' !== $args[0] ) {
279 289 return $allcaps;
280 290 }
281 291
282 292 // Only apply this filter to VideoPress attachments
283 - if ( ! is_videopress_attachment( $args[2] ) ) {
293 + if ( ! isset( $args[2] ) || ! is_videopress_attachment( $args[2] ) ) {
284 294 return $allcaps;
285 295 }
286 296
287 297 // Set the capability to false if the user can't perform the actions
@@ -289,6 +299,91 @@
289 299 $allcaps[ $cap[0] ] = false;
290 300 }
291 301
292 302 return $allcaps;
303 + }
304 +
305 + /**
306 + * Enqueues the script that hooks into WP Heartbeat to refresh
307 + * processing VideoPress video data in the media library grid.
308 + *
309 + * @since 0.35.4
310 + *
311 + * @return void
312 + */
313 + public static function enqueue_media_library_poll() {
314 + wp_enqueue_script(
315 + 'videopress-media-library-poll',
316 + plugins_url( 'js/media-library-poll.js', __FILE__ ),
317 + array( 'jquery', 'heartbeat', 'media-grid' ),
318 + Package_Version::PACKAGE_VERSION,
319 + true
320 + );
321 +
322 + add_filter( 'heartbeat_settings', array( __CLASS__, 'heartbeat_settings' ) );
323 + }
324 +
325 + /**
326 + * Adds inline styles for the media library grid on the upload page.
327 + *
328 + * @since 0.35.4
329 + *
330 + * @return void
331 + */
332 + public static function enqueue_media_library_styles() {
333 + // Constrain poster images so they fit within the media library grid cell.
334 + wp_add_inline_style(
335 + 'media-views',
336 + '.attachment-preview.type-video .thumbnail .centered img.thumbnail { max-width: 100%; max-height: 100%; }'
337 + );
338 + }
339 +
340 + /**
341 + * Lowers the Heartbeat minimum interval on the media library page
342 + * so the polling script can request a faster tick rate.
343 + *
344 + * @since 0.35.4
345 + *
346 + * @param array $settings Heartbeat settings.
347 + * @return array
348 + */
349 + public static function heartbeat_settings( $settings ) {
350 + $settings['minimalInterval'] = 5;
351 +
352 + return $settings;
353 + }
354 +
355 + /**
356 + * Heartbeat API handler that checks the processing status of VideoPress videos.
357 + *
358 + * @since 0.35.4
359 + *
360 + * @param array $response The Heartbeat response.
361 + * @param array $data The data sent with the Heartbeat request.
362 + * @return array
363 + */
364 + public static function heartbeat_received( $response, $data ) {
365 + if ( empty( $data['videopress_processing_ids'] ) || ! is_array( $data['videopress_processing_ids'] ) ) {
366 + return $response;
367 + }
368 +
369 + $statuses = array();
370 + foreach ( $data['videopress_processing_ids'] as $id ) {
371 + $id = (int) $id;
372 +
373 + if ( ! current_user_can( 'edit_post', $id ) ) {
374 + continue;
375 + }
376 +
377 + $status = get_post_meta( $id, 'videopress_status', true );
378 + if ( $status ) {
379 + $statuses[ $id ] = $status;
380 + }
381 + }
382 +
383 + if ( ! empty( $statuses ) ) {
384 + $response['videopress_processing_status'] = $statuses;
385 + }
386 +
387 + return $response;
293 388 }
294 389 }