PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 15.4.1
Jetpack – WP Security, Backup, Speed, & Growth v15.4.1
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 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 All 500 releases
jetpack / json-endpoints / class.wpcom-json-api-list-embeds-endpoint.php
class.wpcom-json-api-list-embeds-endpoint.php
84 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit( 0 );
5 }
6
7 /**
8 * List Embeds endpoint.
9 */
10 new WPCOM_JSON_API_List_Embeds_Endpoint(
11 array(
12 'description' => 'Get a list of embeds available on a site. Note: The current user must have publishing access.',
13 'group' => 'sites',
14 'stat' => 'embeds',
15 'method' => 'GET',
16 'path' => '/sites/%s/embeds',
17 'path_labels' => array(
18 '$site' => '(int|string) Site ID or domain',
19 ),
20 'response_format' => array(
21 'embeds' => '(array) A list of supported embeds by their regex pattern.',
22 ),
23 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/82974409/embeds',
24 'example_request_data' => array(
25 'headers' => array(
26 'authorization' => 'Bearer YOUR_API_TOKEN',
27 ),
28 ),
29 )
30 );
31
32 /**
33 * List Embeds Endpoint class.
34 *
35 * /sites/%s/embeds -> $blog_id
36 *
37 * @phan-constructor-used-for-side-effects
38 */
39 class WPCOM_JSON_API_List_Embeds_Endpoint extends WPCOM_JSON_API_Endpoint {
40 /**
41 * API Callback.
42 *
43 * @param string $path - the path.
44 * @param int $blog_id - the blog ID.
45 */
46 public function callback( $path = '', $blog_id = 0 ) {
47 $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
48 if ( is_wp_error( $blog_id ) ) {
49 return $blog_id;
50 }
51
52 // permissions check.
53 if ( ! current_user_can( 'edit_posts' ) ) {
54 return new WP_Error( 'unauthorized', 'Your token must have permission to post on this blog.', 403 );
55 }
56
57 // list em.
58 $output = array( 'embeds' => array() );
59
60 if ( ! function_exists( '_wp_oembed_get_object' ) ) {
61 require_once ABSPATH . WPINC . '/class-oembed.php';
62 }
63
64 global $wp_embed;
65 $oembed = _wp_oembed_get_object();
66
67 foreach ( $wp_embed->handlers as $handlers ) {
68 foreach ( $handlers as $handler ) {
69 if ( ! empty( $handler['regex'] ) ) {
70 $output['embeds'][] = $handler['regex'];
71 }
72 }
73 }
74
75 foreach ( $oembed->providers as $regex => $oembed_info ) {
76 if ( ! empty( $regex ) ) {
77 $output['embeds'][] = $regex;
78 }
79 }
80
81 return $output;
82 }
83 }
84