|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
new WPCOM_JSON_API_Render_Embed_Endpoint( array( |
|
4
|
|
|
'description' => "Get a rendered embed for a site. Note: The current user must have publishing access.", |
|
5
|
|
|
'group' => 'sites', |
|
6
|
|
|
'stat' => 'embeds:render', |
|
7
|
|
|
'method' => 'GET', |
|
8
|
|
|
'path' => '/sites/%s/embeds/render', |
|
9
|
|
|
'path_labels' => array( |
|
10
|
|
|
'$site' => '(int|string) Site ID or domain', |
|
11
|
|
|
), |
|
12
|
|
|
'query_parameters' => array( |
|
13
|
|
|
'embed_url' => '(string) The query-string encoded embed URL to render. Required. Only accepts one at a time.', |
|
14
|
|
|
), |
|
15
|
|
|
'response_format' => array( |
|
16
|
|
|
'embed_url' => '(string) The embed_url that was passed in for rendering.', |
|
17
|
|
|
'result' => '(html) The rendered HTML result of the embed.', |
|
18
|
|
|
), |
|
19
|
|
|
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/apiexamples.wordpress.com/embeds/render?embed_url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DSQEQr7c0-dw', |
|
20
|
|
|
'example_request_data' => array( |
|
21
|
|
|
'headers' => array( |
|
22
|
|
|
'authorization' => 'Bearer YOUR_API_TOKEN' |
|
23
|
|
|
), |
|
24
|
|
|
) |
|
25
|
|
|
) ); |
|
26
|
|
|
|
|
27
|
|
|
class WPCOM_JSON_API_Render_Embed_Endpoint extends WPCOM_JSON_API_Render_Endpoint { |
|
28
|
|
|
// /sites/%s/embeds/render -> $blog_id |
|
29
|
|
|
function callback( $path = '', $blog_id = 0 ) { |
|
30
|
|
|
$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); |
|
31
|
|
|
if ( is_wp_error( $blog_id ) ) { |
|
32
|
|
|
return $blog_id; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
if ( ! current_user_can( 'edit_posts' ) ) { |
|
36
|
|
|
return new WP_Error( 'unauthorized', __( 'Your token must have permission to post on this blog.', 'jetpack' ), 403 ); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$args = $this->query_args(); |
|
40
|
|
|
$embed_url = trim( $args['embed_url'] ); |
|
41
|
|
|
|
|
42
|
|
|
// quick validation |
|
43
|
|
|
if ( ! preg_match_all( '|^\s*(https?://[^\s"]+)\s*$|im', $embed_url, $matches ) ) { |
|
44
|
|
|
return new WP_Error( 'invalid_embed_url', __( 'The embed_url parameter must be a valid URL.', 'jetpack' ), 400 ); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if ( count( $matches[1] ) > 1 ) { |
|
48
|
|
|
return new WP_Error( 'invalid_embed', __( 'Only one embed can be rendered at a time.', 'jetpack' ), 400 ); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$embed_url = array_shift( $matches[1] ); |
|
52
|
|
|
$parts = wp_parse_url( $embed_url ); |
|
53
|
|
|
if ( ! $parts ) { |
|
|
|
|
|
|
54
|
|
|
return new WP_Error( 'invalid_embed_url', __( 'The embed_url parameter must be a valid URL.', 'jetpack' ), 400 ); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
global $wp_embed; |
|
58
|
|
|
$render = $this->process_render( array( $this, 'do_embed' ), $embed_url ); |
|
59
|
|
|
|
|
60
|
|
|
// if nothing happened, then the shortcode does not exist. |
|
61
|
|
|
$is_an_embed = ( $embed_url != $render['result'] && $wp_embed->maybe_make_link( $embed_url ) != $render['result'] ); |
|
62
|
|
|
if ( ! $is_an_embed ) { |
|
63
|
|
|
return new WP_Error( 'invalid_embed', __( 'The requested URL is not an embed.', 'jetpack' ), 400 ); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
// our output for this endpoint.. |
|
67
|
|
|
$return['embed_url'] = $embed_url; |
|
|
|
|
|
|
68
|
|
|
$return['result'] = $render['result']; |
|
69
|
|
|
|
|
70
|
|
|
$return = $this->add_assets( $return, $render['loaded_scripts'], $render['loaded_styles'] ); |
|
71
|
|
|
|
|
72
|
|
|
return $return; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.