PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.1-a.3
Jetpack – WP Security, Backup, Speed, & Growth v16.1-a.3
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-shortcodes-endpoint.php
class.wpcom-json-api-list-shortcodes-endpoint.php
71 lines 1.9 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 shortcodes endpoint.
9 */
10 new WPCOM_JSON_API_List_Shortcodes_Endpoint(
11 array(
12 'description' => 'Get a list of shortcodes available on a site. Note: The current user must have publishing access.',
13 'group' => 'sites',
14 'stat' => 'shortcodes',
15 'method' => 'GET',
16 'path' => '/sites/%s/shortcodes',
17 'path_labels' => array(
18 '$site' => '(int|string) Site ID or domain',
19 ),
20 'response_format' => array(
21 'shortcodes' => '(array) A list of supported shortcodes by their handle.',
22 ),
23 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/82974409/shortcodes',
24 'example_request_data' => array(
25 'headers' => array(
26 'authorization' => 'Bearer YOUR_API_TOKEN',
27 ),
28 ),
29 )
30 );
31
32 /**
33 * List shortcodes endpoint class
34 *
35 * /sites/%s/shortcodes -> $blog_id
36 *
37 * @phan-constructor-used-for-side-effects
38 */
39 class WPCOM_JSON_API_List_Shortcodes_Endpoint extends WPCOM_JSON_API_Endpoint {
40 /**
41 * API callback.
42 *
43 * @param string $path - the path.
44 * @param string $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 global $shortcode_tags;
59 $output = array( 'shortcodes' => array() );
60
61 foreach ( $shortcode_tags as $tag => $class ) {
62 if ( '__return_false' === $class ) {
63 continue;
64 }
65 $output['shortcodes'][] = $tag;
66 }
67
68 return $output;
69 }
70 }
71