{"action":"created","comment":{"url":"https://api.github.com/repos/WordPress/gutenberg/pulls/comments/173861773","pull_request_review_id":103119586,"id":173861773,"diff_hunk":"@@ -0,0 +1,189 @@\n+<?php\n+/**\n+ * Shortcode Blocks REST API: WP_REST_Shortcodes_Controller class\n+ *\n+ * @package gutenberg\n+ * @since 2.0.0\n+ */\n+\n+/**\n+ * Controller which provides a REST endpoint for Gutenberg to preview shortcode blocks.\n+ *\n+ * @since 2.0.0\n+ *\n+ * @see WP_REST_Controller\n+ */\n+class WP_REST_Shortcodes_Controller extends WP_REST_Controller {\n+\t/**\n+\t * Constructs the controller.\n+\t *\n+\t * @since 2.0.0\n+\t * @access public\n+\t */\n+\tpublic function __construct() {\n+\t\t// @codingStandardsIgnoreLine - PHPCS mistakes $this->namespace for the namespace keyword\n+\t\t$this->namespace = 'gutenberg/v1';\n+\t\t$this->rest_base = 'shortcodes';\n+\t}\n+\n+\t/**\n+\t * Registers the necessary REST API routes.\n+\t *\n+\t * @since 0.10.0\n+\t * @access public\n+\t */\n+\tpublic function register_routes() {\n+\t\t// @codingStandardsIgnoreLine - PHPCS mistakes $this->namespace for the namespace keyword\n+\t\t$namespace = $this->namespace;\n+\n+\t\tregister_rest_route( $namespace, '/' . $this->rest_base, array(\n+\t\t\tarray(\n+\t\t\t\t'methods'             => WP_REST_Server::READABLE,\n+\t\t\t\t'callback'            => array( $this, 'get_shortcode_output' ),\n+\t\t\t\t'permission_callback' => array( $this, 'get_shortcode_output_permissions_check' ),\n+\t\t\t),\n+\t\t\t'schema' => array( $this, 'get_public_item_schema' ),\n+\t\t) );\n+\t}\n+\n+\t/**\n+\t * Checks if a given request has access to read shortcode blocks.\n+\t *\n+\t * @since 2.0.0\n+\t * @access public\n+\t *\n+\t * @param  WP_REST_Request $request Full details about the request.\n+\t * @return true|WP_Error True if the request has read access, WP_Error object otherwise.\n+\t */\n+\tpublic function get_shortcode_output_permissions_check( $request ) {\n+\t\tif ( ! current_user_can( 'edit_posts' ) ) {","path":"lib/class-wp-rest-shortcodes-controller.php","position":59,"original_position":59,"commit_id":"777b304633d7973954ab196a1d0d1ce44adbb291","original_commit_id":"777b304633d7973954ab196a1d0d1ce44adbb291","user":{"login":"westonruter","id":134745,"avatar_url":"https://avatars2.githubusercontent.com/u/134745?v=4","gravatar_id":"","url":"https://api.github.com/users/westonruter","html_url":"https://github.com/westonruter","followers_url":"https://api.github.com/users/westonruter/followers","following_url":"https://api.github.com/users/westonruter/following{/other_user}","gists_url":"https://api.github.com/users/westonruter/gists{/gist_id}","starred_url":"https://api.github.com/users/westonruter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/westonruter/subscriptions","organizations_url":"https://api.github.com/users/westonruter/orgs","repos_url":"https://api.github.com/users/westonruter/repos","events_url":"https://api.github.com/users/westonruter/events{/privacy}","received_events_url":"https://api.github.com/users/westonruter/received_events","type":"User","site_admin":false},"body":"If `$args['postId']` is not empty, then it should also check if `current_user_can( 'edit_post', $args['postId'] )`.","created_at":"2018-03-12T16:33:11Z","updated_at":"2018-03-12T16:47:15Z","html_url":"https://github.com/WordPress/gutenberg/pull/4710#discussion_r173861773","pull_request_url":"https://api.github.com/repos/WordPress/gutenberg/pulls/4710","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/WordPress/gutenberg/pulls/comments/173861773"},"html":{"href":"https://github.com/WordPress/gutenberg/pull/4710#discussion_r173861773"},"pull_request":{"href":"https://api.github.com/repos/WordPress/gutenberg/pulls/4710"}}},"pull_request":{"url":"https://api.github.com/repos/WordPress/gutenberg/pulls/4710","id":165540906,"html_url":"https://github.com/WordPress/gutenberg/pull/4710","diff_url":"https://github.com/WordPress/gutenberg/pull/4710.diff","patch_url":"https://github.com/WordPress/gutenberg/pull/4710.patch","issue_url":"https://api.github.com/repos/WordPress/gutenberg/issues/4710","number":4710,"state":"open","locked":false,"title":"Enhance the shortcode block to support previewing of shortcodes","user":{"login":"niranjan-uma-shankar","id":1269602,"avatar_url":"https://avatars1.githubusercontent.com/u/1269602?v=4","gravatar_id":"","url":"https://api.github.com/users/niranjan-uma-shankar","html_url":"https://github.com/niranjan-uma-shankar","followers_url":"https://api.github.com/users/niranjan-uma-shankar/followers","following_url":"https://api.github.com/users/niranjan-uma-shankar/following{/other_user}","gists_url":"https://api.github.com/users/niranjan-uma-shankar/gists{/gist_id}","starred_url":"https://api.github.com/users/niranjan-uma-shankar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niranjan-uma-shankar/subscriptions","organizations_url":"https://api.github.com/users/niranjan-uma-shankar/orgs","repos_url":"https://api.github.com/users/niranjan-uma-shankar/repos","events_url":"https://api.github.com/users/niranjan-uma-shankar/events{/privacy}","received_events_url":"https://api.github.com/users/niranjan-uma-shankar/received_events","type":"User","site_admin":false},"body":"## Description\r\n<!-- Please describe your changes -->\r\nThis PR adds the capability to preview shortcodes entered in the Shortcode block. This is similar to previews rendered by the embed block and custom HTML block. Work done in this PR references the issue #1054 \r\n\r\n## Summary of changes\r\n\r\n- I've  added a new REST API endpoint that converts the shortcode to its output filtered through its hooks\r\n    - `GET /gutenberg/v1/shortcodes` - get the filtered output for a given shortcode\r\n\r\n- I've changed the UI of the shortcode block to a tabbed component (identical to the custom HTML block).  I've posted a [comment](https://github.com/WordPress/gutenberg/issues/1054#issuecomment-360271233) on my thoughts behind this design consideration. The comment has screenshots of the UI, please check there. \r\n\r\n- The shortcode preview is embedded in a `Sandbox` component. This component (which is essentially creating an iframe) needed to support injection of custom JS and styles, since some shortcodes such as [gallery] and [playlist] need  additional styles and scripts, such as the theme style or mediaelement JS. I've made the necessary changes to support this.\r\n\r\n## How to test\r\n\r\n1. Test with all the default shortcodes - `[audio]`, `[video]`, `[caption]`, `[wp_caption]`, `[embed]`, `[gallery]`, `[playlist type=\"audio\"]`, `[playlist type=\"video\"]`.\r\n2. Add various attributes to the shortcodes and check if they get applied. To note, shortcodes entered without any src attributes will try to automatically render an attached media  file of the corresponding type. For eg. : \r\n           (a) [audio] will render the attached audio vs [audio src=\"audio-source.mp3\"]\r\n           (b) [gallery] will render all attached images, whereas [gallery ids=\"10,11,12\"] will render those specific image ids.\r\n3. Create a custom shortcode via add_shortcode and use it in the shortcode block. Also, get a little fancy with [Shortcode-ception](https://developer.wordpress.org/plugins/shortcodes/enclosing-shortcodes/#shortcode-ception).\r\n4. Edit/modify/replace shortcodes in the block - clicking preview after every such action should render the most recent version of the shortcode\r\n5. Non-existent shortcodes will be treated as a normal text and displayed\r\n6. If there's no attached media/photo to a post, then using just [gallery] or [audio] (without \"src\" or \"ids\" attributes) will give an error message that the preview cannot be rendered\r\n7. Giving incompatible \"ids\" - for example, in [gallery ids=\"11\"], if 11 refers to an audio file, or in [playlist ids=\"12\" type=\"video\"], \"12\" refers to an audio file, then a message will be flashed \"Sorry, couldn't render preview\" \r\n\r\n## Screenshot\r\n\r\nBelow is an example of a preview for [caption]\r\n\r\n![giphy](https://user-images.githubusercontent.com/1269602/35482917-96a141a0-0461-11e8-9afb-af58e584ce0b.gif)\r\n\r\n## <del>Known issue</del>\r\n\r\n<del>1. Preview for [wp-playlist] does not work. I'm trying to inject all the necessary JS into the Sandbox component (the js is fetched by the rest endpoint and can be seen in these [lines of code](https://github.com/niranjan-uma-shankar/gutenberg/blob/master/lib/class-wp-rest-shortcodes-controller.php#L110)). I get an error `Uncaught TypeError: Cannot read property 'replace' of undefined` in `underscore.min.js`. Any pointers here would be appreciated.</del>","created_at":"2018-01-27T22:51:52Z","updated_at":"2018-03-12T16:47:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4d3b95ab02c1c220cf418fa7c4a8bae809728367","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/WordPress/gutenberg/pulls/4710/commits","review_comments_url":"https://api.github.com/repos/WordPress/gutenberg/pulls/4710/comments","review_comment_url":"https://api.github.com/repos/WordPress/gutenberg/pulls/comments{/number}","comments_url":"https://api.github.com/repos/WordPress/gutenberg/issues/4710/comments","statuses_url":"https://api.github.com/repos/WordPress/gutenberg/statuses/777b304633d7973954ab196a1d0d1ce44adbb291","head":{"label":"niranjan-uma-shankar:master","ref":"master","sha":"777b304633d7973954ab196a1d0d1ce44adbb291","user":{"login":"niranjan-uma-shankar","id":1269602,"avatar_url":"https://avatars1.githubusercontent.com/u/1269602?v=4","gravatar_id":"","url":"https://api.github.com/users/niranjan-uma-shankar","html_url":"https://github.com/niranjan-uma-shankar","followers_url":"https://api.github.com/users/niranjan-uma-shankar/followers","following_url":"https://api.github.com/users/niranjan-uma-shankar/following{/other_user}","gists_url":"https://api.github.com/users/niranjan-uma-shankar/gists{/gist_id}","starred_url":"https://api.github.com/users/niranjan-uma-shankar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niranjan-uma-shankar/subscriptions","organizations_url":"https://api.github.com/users/niranjan-uma-shankar/orgs","repos_url":"https://api.github.com/users/niranjan-uma-shankar/repos","events_url":"https://api.github.com/users/niranjan-uma-shankar/events{/privacy}","received_events_url":"https://api.github.com/users/niranjan-uma-shankar/received_events","type":"User","site_admin":false},"repo":{"id":118829297,"name":"gutenberg","full_name":"niranjan-uma-shankar/gutenberg","owner":{"login":"niranjan-uma-shankar","id":1269602,"avatar_url":"https://avatars1.githubusercontent.com/u/1269602?v=4","gravatar_id":"","url":"https://api.github.com/users/niranjan-uma-shankar","html_url":"https://github.com/niranjan-uma-shankar","followers_url":"https://api.github.com/users/niranjan-uma-shankar/followers","following_url":"https://api.github.com/users/niranjan-uma-shankar/following{/other_user}","gists_url":"https://api.github.com/users/niranjan-uma-shankar/gists{/gist_id}","starred_url":"https://api.github.com/users/niranjan-uma-shankar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niranjan-uma-shankar/subscriptions","organizations_url":"https://api.github.com/users/niranjan-uma-shankar/orgs","repos_url":"https://api.github.com/users/niranjan-uma-shankar/repos","events_url":"https://api.github.com/users/niranjan-uma-shankar/events{/privacy}","received_events_url":"https://api.github.com/users/niranjan-uma-shankar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/niranjan-uma-shankar/gutenberg","description":"Printing since 1440. Development hub for the editor focus in core. Beta plugin is available from the official WordPress repository.","fork":true,"url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg","forks_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/forks","keys_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/teams","hooks_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/hooks","issue_events_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/issues/events{/number}","events_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/events","assignees_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/assignees{/user}","branches_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/branches{/branch}","tags_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/tags","blobs_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/git/refs{/sha}","trees_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/statuses/{sha}","languages_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/languages","stargazers_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/stargazers","contributors_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/contributors","subscribers_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/subscribers","subscription_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/subscription","commits_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/commits{/sha}","git_commits_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/git/commits{/sha}","comments_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/comments{/number}","issue_comment_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/issues/comments{/number}","contents_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/contents/{+path}","compare_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/merges","archive_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/downloads","issues_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/issues{/number}","pulls_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/pulls{/number}","milestones_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/milestones{/number}","notifications_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/labels{/name}","releases_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/releases{/id}","deployments_url":"https://api.github.com/repos/niranjan-uma-shankar/gutenberg/deployments","created_at":"2018-01-24T22:18:13Z","updated_at":"2018-01-24T22:18:17Z","pushed_at":"2018-03-06T12:10:27Z","git_url":"git://github.com/niranjan-uma-shankar/gutenberg.git","ssh_url":"git@github.com:niranjan-uma-shankar/gutenberg.git","clone_url":"https://github.com/niranjan-uma-shankar/gutenberg.git","svn_url":"https://github.com/niranjan-uma-shankar/gutenberg","homepage":"https://wordpress.org/plugins/gutenberg/ ","size":10555,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"WordPress:master","ref":"master","sha":"07dbbb0e97948c118eed1f711cf800bac4924994","user":{"login":"WordPress","id":276006,"avatar_url":"https://avatars0.githubusercontent.com/u/276006?v=4","gravatar_id":"","url":"https://api.github.com/users/WordPress","html_url":"https://github.com/WordPress","followers_url":"https://api.github.com/users/WordPress/followers","following_url":"https://api.github.com/users/WordPress/following{/other_user}","gists_url":"https://api.github.com/users/WordPress/gists{/gist_id}","starred_url":"https://api.github.com/users/WordPress/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WordPress/subscriptions","organizations_url":"https://api.github.com/users/WordPress/orgs","repos_url":"https://api.github.com/users/WordPress/repos","events_url":"https://api.github.com/users/WordPress/events{/privacy}","received_events_url":"https://api.github.com/users/WordPress/received_events","type":"Organization","site_admin":false},"repo":{"id":80862584,"name":"gutenberg","full_name":"WordPress/gutenberg","owner":{"login":"WordPress","id":276006,"avatar_url":"https://avatars0.githubusercontent.com/u/276006?v=4","gravatar_id":"","url":"https://api.github.com/users/WordPress","html_url":"https://github.com/WordPress","followers_url":"https://api.github.com/users/WordPress/followers","following_url":"https://api.github.com/users/WordPress/following{/other_user}","gists_url":"https://api.github.com/users/WordPress/gists{/gist_id}","starred_url":"https://api.github.com/users/WordPress/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WordPress/subscriptions","organizations_url":"https://api.github.com/users/WordPress/orgs","repos_url":"https://api.github.com/users/WordPress/repos","events_url":"https://api.github.com/users/WordPress/events{/privacy}","received_events_url":"https://api.github.com/users/WordPress/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/WordPress/gutenberg","description":"Printing since 1440. Development hub for the editor focus in core. Beta plugin is available from the official WordPress repository.","fork":false,"url":"https://api.github.com/repos/WordPress/gutenberg","forks_url":"https://api.github.com/repos/WordPress/gutenberg/forks","keys_url":"https://api.github.com/repos/WordPress/gutenberg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WordPress/gutenberg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WordPress/gutenberg/teams","hooks_url":"https://api.github.com/repos/WordPress/gutenberg/hooks","issue_events_url":"https://api.github.com/repos/WordPress/gutenberg/issues/events{/number}","events_url":"https://api.github.com/repos/WordPress/gutenberg/events","assignees_url":"https://api.github.com/repos/WordPress/gutenberg/assignees{/user}","branches_url":"https://api.github.com/repos/WordPress/gutenberg/branches{/branch}","tags_url":"https://api.github.com/repos/WordPress/gutenberg/tags","blobs_url":"https://api.github.com/repos/WordPress/gutenberg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WordPress/gutenberg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WordPress/gutenberg/git/refs{/sha}","trees_url":"https://api.github.com/repos/WordPress/gutenberg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WordPress/gutenberg/statuses/{sha}","languages_url":"https://api.github.com/repos/WordPress/gutenberg/languages","stargazers_url":"https://api.github.com/repos/WordPress/gutenberg/stargazers","contributors_url":"https://api.github.com/repos/WordPress/gutenberg/contributors","subscribers_url":"https://api.github.com/repos/WordPress/gutenberg/subscribers","subscription_url":"https://api.github.com/repos/WordPress/gutenberg/subscription","commits_url":"https://api.github.com/repos/WordPress/gutenberg/commits{/sha}","git_commits_url":"https://api.github.com/repos/WordPress/gutenberg/git/commits{/sha}","comments_url":"https://api.github.com/repos/WordPress/gutenberg/comments{/number}","issue_comment_url":"https://api.github.com/repos/WordPress/gutenberg/issues/comments{/number}","contents_url":"https://api.github.com/repos/WordPress/gutenberg/contents/{+path}","compare_url":"https://api.github.com/repos/WordPress/gutenberg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WordPress/gutenberg/merges","archive_url":"https://api.github.com/repos/WordPress/gutenberg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WordPress/gutenberg/downloads","issues_url":"https://api.github.com/repos/WordPress/gutenberg/issues{/number}","pulls_url":"https://api.github.com/repos/WordPress/gutenberg/pulls{/number}","milestones_url":"https://api.github.com/repos/WordPress/gutenberg/milestones{/number}","notifications_url":"https://api.github.com/repos/WordPress/gutenberg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WordPress/gutenberg/labels{/name}","releases_url":"https://api.github.com/repos/WordPress/gutenberg/releases{/id}","deployments_url":"https://api.github.com/repos/WordPress/gutenberg/deployments","created_at":"2017-02-03T19:34:19Z","updated_at":"2018-03-12T16:35:07Z","pushed_at":"2018-03-12T16:38:48Z","git_url":"git://github.com/WordPress/gutenberg.git","ssh_url":"git@github.com:WordPress/gutenberg.git","clone_url":"https://github.com/WordPress/gutenberg.git","svn_url":"https://github.com/WordPress/gutenberg","homepage":"https://wordpress.org/plugins/gutenberg/ ","size":11293,"stargazers_count":2114,"watchers_count":2114,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":485,"mirror_url":null,"archived":false,"open_issues_count":773,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":485,"open_issues":773,"watchers":2114,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/WordPress/gutenberg/pulls/4710"},"html":{"href":"https://github.com/WordPress/gutenberg/pull/4710"},"issue":{"href":"https://api.github.com/repos/WordPress/gutenberg/issues/4710"},"comments":{"href":"https://api.github.com/repos/WordPress/gutenberg/issues/4710/comments"},"review_comments":{"href":"https://api.github.com/repos/WordPress/gutenberg/pulls/4710/comments"},"review_comment":{"href":"https://api.github.com/repos/WordPress/gutenberg/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/WordPress/gutenberg/pulls/4710/commits"},"statuses":{"href":"https://api.github.com/repos/WordPress/gutenberg/statuses/777b304633d7973954ab196a1d0d1ce44adbb291"}},"author_association":"NONE"}}
{"actor":{"display_login":"westonruter"}}