Completed
Push — fix/normalize-www-in-site-url-... ( e67e76 )
by
unknown
13:13 queued 02:59
created

class.wpcom-json-api-list-embeds-endpoint.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
class WPCOM_JSON_API_List_Embeds_Endpoint extends WPCOM_JSON_API_Endpoint {
3
	// /sites/%s/embeds -> $blog_id
4
	function callback( $path = '', $blog_id = 0 ) {
5
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
0 ignored issues
show
Consider using a different name than the parameter $blog_id. This often makes code more readable.
Loading history...
6
		if ( is_wp_error( $blog_id ) ) {
7
			return $blog_id;
8
		}
9
10
		// permissions check
11
		if ( ! current_user_can( 'edit_posts' ) ) {
12
			return new WP_Error( 'unauthorized', 'Your token must have permission to post on this blog.', 403 );
13
		}
14
15
		// list em
16
		$output = array( 'embeds' => array() );
17
	
18
		if ( ! function_exists( '_wp_oembed_get_object' ) ) {
19
			require_once( ABSPATH . WPINC . '/class-oembed.php' );
20
		}
21
				
22
		global $wp_embed;
23
		$oembed = _wp_oembed_get_object();
24
25
		foreach( $wp_embed->handlers as $priority => $handlers ) {
26
			foreach( $handlers as $handler ) {
27
				if ( ! empty( $handler['regex'] ) )
28
					$output['embeds'][] = $handler['regex'];
29
			}
30
		}
31
32
		foreach ( $oembed->providers as $regex => $oembed_info ) {
33
			if ( ! empty( $regex ) )
34
				$output['embeds'][] = $regex;
35
		}
36
37
		return $output;
38
	}
39
}