Completed
Push — add/videopress-gutenberg-exten... ( 296eaa...5df94e )
by
unknown
06:49
created

WPCOM_REST_API_V2_Sites_Media_VideoPress   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A add_videopress_data() 0 9 1
A get_videopress_data() 0 13 2
1
<?php
2
3
/*
4
 * Plugin Name: WPCOM Media VideoPress
5
 *
6
 * Adds `jetpack_videopress` to media responses
7
 */
8
9
class WPCOM_REST_API_V2_Sites_Media_VideoPress {
10
	function __construct() {
11
		add_action( 'rest_api_init', array( $this, 'add_videopress_data' ) );
12
	}
13
14
	function add_videopress_data() {
15
		register_rest_field( 'attachment', 'jetpack_videopress',
16
			array(
17
				'get_callback'    => array( $this, 'get_videopress_data' ),
18
				'update_callback' => null,
19
				'schema'          => null,
20
			)
21
		);
22
	}
23
24
	function get_videopress_data( $object, $field_name, $request ) {
25
		$videopress_data = null;
26
27
		$blog_id = get_current_blog_id();
28
		$post_id = absint( $object['id'] );
29
		$videopress_id = video_get_info_by_blogpostid( $blog_id, $post_id )->guid;
30
31
		if ( $videopress_id ) {
32
			$videopress_data = videopress_get_video_details( $videopress_id );
33
		}
34
35
		return $videopress_data;
36
	}
37
}
38
39
wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Sites_Media_VideoPress' );
40