{"action":"created","comment":{"url":"https://api.github.com/repos/WP-API/WP-API/pulls/comments/25141242","id":25141242,"diff_hunk":"@@ -0,0 +1,338 @@\n+<?php\n+\n+class WP_JSON_Attachments_Controller extends WP_JSON_Posts_Controller {\n+\n+\t/**\n+\t * Create a single attachment\n+\t *\n+\t * @param WP_JSON_Request $request Full details about the request\n+\t * @return WP_Error|WP_HTTP_ResponseInterface\n+\t */\n+\tpublic function create_item( $request ) {\n+\n+\t\t// Permissions check - Note: \"upload_files\" cap is returned for an attachment by $post_type_obj->cap->create_posts\n+\t\t$post_type_obj = get_post_type_object( $this->post_type );\n+\t\tif ( ! current_user_can( $post_type_obj->cap->create_posts ) || ! current_user_can( $post_type_obj->cap->edit_posts ) ) {\n+\t\t\treturn new WP_Error( 'json_cannot_create', __( 'Sorry, you are not allowed to post on this site.' ), array( 'status' => 400 ) );\n+\t\t}\n+\n+\t\t// If a user is trying to attach to a post make sure they have permissions. Bail early if post_id is not being passed\n+\t\tif ( ! empty( $request['post_id'] ) ) {\n+\t\t\t$parent = get_post( (int) $request['post_id'] );\n+\t\t\t$post_parent_type = get_post_type_object( $parent->post_type );\n+\t\t\tif ( ! current_user_can( $post_parent_type->cap->edit_post, $request['post_id'] ) ) {\n+\t\t\t\treturn new WP_Error( 'json_cannot_edit', __( 'Sorry, you are not allowed to edit this post.' ), array( 'status' => 401 ) );\n+\t\t\t}\n+\t\t}\n+\n+\t\t// Get the file via $_FILES or raw data\n+\t\t$files = $request->get_file_params();\n+\t\t$headers = $request->get_headers();\n+\t\tif ( ! empty( $files ) ) {\n+\t\t\t$file = $this->upload_from_file( $files, $headers );\n+\t\t} else {\n+\t\t\t$file = $this->upload_from_data( $request->get_body(), $headers );\n+\t\t}\n+\n+\t\tif ( is_wp_error( $file ) ) {\n+\t\t\treturn $file;\n+\t\t}\n+\n+\t\t$name       = basename( $file['file'] );\n+\t\t$name_parts = pathinfo( $name );\n+\t\t$name       = trim( substr( $name, 0, -(1 + strlen( $name_parts['extension'] ) ) ) );\n+\n+\t\t$url     = $file['url'];\n+\t\t$type    = $file['type'];\n+\t\t$file    = $file['file'];\n+\t\t$title   = $name;\n+\t\t$caption = '';\n+\n+\t\t// use image exif/iptc data for title and caption defaults if possible\n+\t\tif ( $image_meta = @wp_read_image_metadata( $file ) ) {\n+\t\t\tif ( empty( $request['title'] ) && trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) {\n+\t\t\t\t$title = $image_meta['title'];\n+\t\t\t}\n+\n+\t\t\tif ( empty( $request['caption'] ) && trim( $image_meta['caption'] ) ) {\n+\t\t\t\t$caption = $image_meta['caption'];\n+\t\t\t}\n+\t\t}\n+\n+\t\t$attachment = $this->prepare_item_for_database( $request );\n+\t\t$attachment->post_type = $this->post_type; // Currently defaults to 'post'","path":"lib/endpoints/class-wp-json-attachments-controller.php","position":63,"original_position":63,"commit_id":"b6fc1293e513c90d6e0aaaf6e7895d2b2f6fe92e","original_commit_id":"b6fc1293e513c90d6e0aaaf6e7895d2b2f6fe92e","user":{"login":"danielbachhuber","id":36432,"avatar_url":"https://avatars.githubusercontent.com/u/36432?v=3","gravatar_id":"","url":"https://api.github.com/users/danielbachhuber","html_url":"https://github.com/danielbachhuber","followers_url":"https://api.github.com/users/danielbachhuber/followers","following_url":"https://api.github.com/users/danielbachhuber/following{/other_user}","gists_url":"https://api.github.com/users/danielbachhuber/gists{/gist_id}","starred_url":"https://api.github.com/users/danielbachhuber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielbachhuber/subscriptions","organizations_url":"https://api.github.com/users/danielbachhuber/orgs","repos_url":"https://api.github.com/users/danielbachhuber/repos","events_url":"https://api.github.com/users/danielbachhuber/events{/privacy}","received_events_url":"https://api.github.com/users/danielbachhuber/received_events","type":"User","site_admin":false},"body":"This hack is because of #913","created_at":"2015-02-23T02:15:53Z","updated_at":"2015-02-23T02:15:53Z","html_url":"https://github.com/WP-API/WP-API/pull/904#discussion_r25141242","pull_request_url":"https://api.github.com/repos/WP-API/WP-API/pulls/904","_links":{"self":{"href":"https://api.github.com/repos/WP-API/WP-API/pulls/comments/25141242"},"html":{"href":"https://github.com/WP-API/WP-API/pull/904#discussion_r25141242"},"pull_request":{"href":"https://api.github.com/repos/WP-API/WP-API/pulls/904"}}},"pull_request":{"url":"https://api.github.com/repos/WP-API/WP-API/pulls/904","id":29773715,"html_url":"https://github.com/WP-API/WP-API/pull/904","diff_url":"https://github.com/WP-API/WP-API/pull/904.diff","patch_url":"https://github.com/WP-API/WP-API/pull/904.patch","issue_url":"https://api.github.com/repos/WP-API/WP-API/issues/904","number":904,"state":"open","locked":false,"title":"Convert /media to new controller pattern","user":{"login":"danielbachhuber","id":36432,"avatar_url":"https://avatars.githubusercontent.com/u/36432?v=3","gravatar_id":"","url":"https://api.github.com/users/danielbachhuber","html_url":"https://github.com/danielbachhuber","followers_url":"https://api.github.com/users/danielbachhuber/followers","following_url":"https://api.github.com/users/danielbachhuber/following{/other_user}","gists_url":"https://api.github.com/users/danielbachhuber/gists{/gist_id}","starred_url":"https://api.github.com/users/danielbachhuber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielbachhuber/subscriptions","organizations_url":"https://api.github.com/users/danielbachhuber/orgs","repos_url":"https://api.github.com/users/danielbachhuber/repos","events_url":"https://api.github.com/users/danielbachhuber/events{/privacy}","received_events_url":"https://api.github.com/users/danielbachhuber/received_events","type":"User","site_admin":false},"body":"Related #605","created_at":"2015-02-22T17:43:43Z","updated_at":"2015-02-23T02:15:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e7f47e9bf0aaa248f3e5e7be75857065a8a80085","assignee":null,"milestone":{"url":"https://api.github.com/repos/WP-API/WP-API/milestones/10","labels_url":"https://api.github.com/repos/WP-API/WP-API/milestones/10/labels","id":844496,"number":10,"title":"2.0","description":null,"creator":{"login":"danielbachhuber","id":36432,"avatar_url":"https://avatars.githubusercontent.com/u/36432?v=3","gravatar_id":"","url":"https://api.github.com/users/danielbachhuber","html_url":"https://github.com/danielbachhuber","followers_url":"https://api.github.com/users/danielbachhuber/followers","following_url":"https://api.github.com/users/danielbachhuber/following{/other_user}","gists_url":"https://api.github.com/users/danielbachhuber/gists{/gist_id}","starred_url":"https://api.github.com/users/danielbachhuber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielbachhuber/subscriptions","organizations_url":"https://api.github.com/users/danielbachhuber/orgs","repos_url":"https://api.github.com/users/danielbachhuber/repos","events_url":"https://api.github.com/users/danielbachhuber/events{/privacy}","received_events_url":"https://api.github.com/users/danielbachhuber/received_events","type":"User","site_admin":false},"open_issues":90,"closed_issues":130,"state":"open","created_at":"2014-10-29T00:12:18Z","updated_at":"2015-02-23T02:13:38Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/WP-API/WP-API/pulls/904/commits","review_comments_url":"https://api.github.com/repos/WP-API/WP-API/pulls/904/comments","review_comment_url":"https://api.github.com/repos/WP-API/WP-API/pulls/comments{/number}","comments_url":"https://api.github.com/repos/WP-API/WP-API/issues/904/comments","statuses_url":"https://api.github.com/repos/WP-API/WP-API/statuses/b6fc1293e513c90d6e0aaaf6e7895d2b2f6fe92e","head":{"label":"WP-API:media-controller","ref":"media-controller","sha":"b6fc1293e513c90d6e0aaaf6e7895d2b2f6fe92e","user":{"login":"WP-API","id":5706008,"avatar_url":"https://avatars.githubusercontent.com/u/5706008?v=3","gravatar_id":"","url":"https://api.github.com/users/WP-API","html_url":"https://github.com/WP-API","followers_url":"https://api.github.com/users/WP-API/followers","following_url":"https://api.github.com/users/WP-API/following{/other_user}","gists_url":"https://api.github.com/users/WP-API/gists{/gist_id}","starred_url":"https://api.github.com/users/WP-API/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WP-API/subscriptions","organizations_url":"https://api.github.com/users/WP-API/orgs","repos_url":"https://api.github.com/users/WP-API/repos","events_url":"https://api.github.com/users/WP-API/events{/privacy}","received_events_url":"https://api.github.com/users/WP-API/received_events","type":"Organization","site_admin":false},"repo":{"id":10420996,"name":"WP-API","full_name":"WP-API/WP-API","owner":{"login":"WP-API","id":5706008,"avatar_url":"https://avatars.githubusercontent.com/u/5706008?v=3","gravatar_id":"","url":"https://api.github.com/users/WP-API","html_url":"https://github.com/WP-API","followers_url":"https://api.github.com/users/WP-API/followers","following_url":"https://api.github.com/users/WP-API/following{/other_user}","gists_url":"https://api.github.com/users/WP-API/gists{/gist_id}","starred_url":"https://api.github.com/users/WP-API/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WP-API/subscriptions","organizations_url":"https://api.github.com/users/WP-API/orgs","repos_url":"https://api.github.com/users/WP-API/repos","events_url":"https://api.github.com/users/WP-API/events{/privacy}","received_events_url":"https://api.github.com/users/WP-API/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/WP-API/WP-API","description":"WP REST API - a JSON-based REST API for WordPress.","fork":false,"url":"https://api.github.com/repos/WP-API/WP-API","forks_url":"https://api.github.com/repos/WP-API/WP-API/forks","keys_url":"https://api.github.com/repos/WP-API/WP-API/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WP-API/WP-API/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WP-API/WP-API/teams","hooks_url":"https://api.github.com/repos/WP-API/WP-API/hooks","issue_events_url":"https://api.github.com/repos/WP-API/WP-API/issues/events{/number}","events_url":"https://api.github.com/repos/WP-API/WP-API/events","assignees_url":"https://api.github.com/repos/WP-API/WP-API/assignees{/user}","branches_url":"https://api.github.com/repos/WP-API/WP-API/branches{/branch}","tags_url":"https://api.github.com/repos/WP-API/WP-API/tags","blobs_url":"https://api.github.com/repos/WP-API/WP-API/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WP-API/WP-API/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WP-API/WP-API/git/refs{/sha}","trees_url":"https://api.github.com/repos/WP-API/WP-API/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WP-API/WP-API/statuses/{sha}","languages_url":"https://api.github.com/repos/WP-API/WP-API/languages","stargazers_url":"https://api.github.com/repos/WP-API/WP-API/stargazers","contributors_url":"https://api.github.com/repos/WP-API/WP-API/contributors","subscribers_url":"https://api.github.com/repos/WP-API/WP-API/subscribers","subscription_url":"https://api.github.com/repos/WP-API/WP-API/subscription","commits_url":"https://api.github.com/repos/WP-API/WP-API/commits{/sha}","git_commits_url":"https://api.github.com/repos/WP-API/WP-API/git/commits{/sha}","comments_url":"https://api.github.com/repos/WP-API/WP-API/comments{/number}","issue_comment_url":"https://api.github.com/repos/WP-API/WP-API/issues/comments{/number}","contents_url":"https://api.github.com/repos/WP-API/WP-API/contents/{+path}","compare_url":"https://api.github.com/repos/WP-API/WP-API/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WP-API/WP-API/merges","archive_url":"https://api.github.com/repos/WP-API/WP-API/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WP-API/WP-API/downloads","issues_url":"https://api.github.com/repos/WP-API/WP-API/issues{/number}","pulls_url":"https://api.github.com/repos/WP-API/WP-API/pulls{/number}","milestones_url":"https://api.github.com/repos/WP-API/WP-API/milestones{/number}","notifications_url":"https://api.github.com/repos/WP-API/WP-API/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WP-API/WP-API/labels{/name}","releases_url":"https://api.github.com/repos/WP-API/WP-API/releases{/id}","created_at":"2013-06-01T10:52:43Z","updated_at":"2015-02-23T00:08:20Z","pushed_at":"2015-02-23T02:12:52Z","git_url":"git://github.com/WP-API/WP-API.git","ssh_url":"git@github.com:WP-API/WP-API.git","clone_url":"https://github.com/WP-API/WP-API.git","svn_url":"https://github.com/WP-API/WP-API","homepage":"http://wp-api.org","size":7853,"stargazers_count":1556,"watchers_count":1556,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":285,"mirror_url":null,"open_issues_count":214,"forks":285,"open_issues":214,"watchers":1556,"default_branch":"develop"}},"base":{"label":"WP-API:develop","ref":"develop","sha":"6bad1a0ddd0b4dd950b9c01d6206f4d16430f01c","user":{"login":"WP-API","id":5706008,"avatar_url":"https://avatars.githubusercontent.com/u/5706008?v=3","gravatar_id":"","url":"https://api.github.com/users/WP-API","html_url":"https://github.com/WP-API","followers_url":"https://api.github.com/users/WP-API/followers","following_url":"https://api.github.com/users/WP-API/following{/other_user}","gists_url":"https://api.github.com/users/WP-API/gists{/gist_id}","starred_url":"https://api.github.com/users/WP-API/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WP-API/subscriptions","organizations_url":"https://api.github.com/users/WP-API/orgs","repos_url":"https://api.github.com/users/WP-API/repos","events_url":"https://api.github.com/users/WP-API/events{/privacy}","received_events_url":"https://api.github.com/users/WP-API/received_events","type":"Organization","site_admin":false},"repo":{"id":10420996,"name":"WP-API","full_name":"WP-API/WP-API","owner":{"login":"WP-API","id":5706008,"avatar_url":"https://avatars.githubusercontent.com/u/5706008?v=3","gravatar_id":"","url":"https://api.github.com/users/WP-API","html_url":"https://github.com/WP-API","followers_url":"https://api.github.com/users/WP-API/followers","following_url":"https://api.github.com/users/WP-API/following{/other_user}","gists_url":"https://api.github.com/users/WP-API/gists{/gist_id}","starred_url":"https://api.github.com/users/WP-API/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WP-API/subscriptions","organizations_url":"https://api.github.com/users/WP-API/orgs","repos_url":"https://api.github.com/users/WP-API/repos","events_url":"https://api.github.com/users/WP-API/events{/privacy}","received_events_url":"https://api.github.com/users/WP-API/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/WP-API/WP-API","description":"WP REST API - a JSON-based REST API for WordPress.","fork":false,"url":"https://api.github.com/repos/WP-API/WP-API","forks_url":"https://api.github.com/repos/WP-API/WP-API/forks","keys_url":"https://api.github.com/repos/WP-API/WP-API/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WP-API/WP-API/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WP-API/WP-API/teams","hooks_url":"https://api.github.com/repos/WP-API/WP-API/hooks","issue_events_url":"https://api.github.com/repos/WP-API/WP-API/issues/events{/number}","events_url":"https://api.github.com/repos/WP-API/WP-API/events","assignees_url":"https://api.github.com/repos/WP-API/WP-API/assignees{/user}","branches_url":"https://api.github.com/repos/WP-API/WP-API/branches{/branch}","tags_url":"https://api.github.com/repos/WP-API/WP-API/tags","blobs_url":"https://api.github.com/repos/WP-API/WP-API/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WP-API/WP-API/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WP-API/WP-API/git/refs{/sha}","trees_url":"https://api.github.com/repos/WP-API/WP-API/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WP-API/WP-API/statuses/{sha}","languages_url":"https://api.github.com/repos/WP-API/WP-API/languages","stargazers_url":"https://api.github.com/repos/WP-API/WP-API/stargazers","contributors_url":"https://api.github.com/repos/WP-API/WP-API/contributors","subscribers_url":"https://api.github.com/repos/WP-API/WP-API/subscribers","subscription_url":"https://api.github.com/repos/WP-API/WP-API/subscription","commits_url":"https://api.github.com/repos/WP-API/WP-API/commits{/sha}","git_commits_url":"https://api.github.com/repos/WP-API/WP-API/git/commits{/sha}","comments_url":"https://api.github.com/repos/WP-API/WP-API/comments{/number}","issue_comment_url":"https://api.github.com/repos/WP-API/WP-API/issues/comments{/number}","contents_url":"https://api.github.com/repos/WP-API/WP-API/contents/{+path}","compare_url":"https://api.github.com/repos/WP-API/WP-API/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WP-API/WP-API/merges","archive_url":"https://api.github.com/repos/WP-API/WP-API/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WP-API/WP-API/downloads","issues_url":"https://api.github.com/repos/WP-API/WP-API/issues{/number}","pulls_url":"https://api.github.com/repos/WP-API/WP-API/pulls{/number}","milestones_url":"https://api.github.com/repos/WP-API/WP-API/milestones{/number}","notifications_url":"https://api.github.com/repos/WP-API/WP-API/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WP-API/WP-API/labels{/name}","releases_url":"https://api.github.com/repos/WP-API/WP-API/releases{/id}","created_at":"2013-06-01T10:52:43Z","updated_at":"2015-02-23T00:08:20Z","pushed_at":"2015-02-23T02:12:52Z","git_url":"git://github.com/WP-API/WP-API.git","ssh_url":"git@github.com:WP-API/WP-API.git","clone_url":"https://github.com/WP-API/WP-API.git","svn_url":"https://github.com/WP-API/WP-API","homepage":"http://wp-api.org","size":7853,"stargazers_count":1556,"watchers_count":1556,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":285,"mirror_url":null,"open_issues_count":214,"forks":285,"open_issues":214,"watchers":1556,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/WP-API/WP-API/pulls/904"},"html":{"href":"https://github.com/WP-API/WP-API/pull/904"},"issue":{"href":"https://api.github.com/repos/WP-API/WP-API/issues/904"},"comments":{"href":"https://api.github.com/repos/WP-API/WP-API/issues/904/comments"},"review_comments":{"href":"https://api.github.com/repos/WP-API/WP-API/pulls/904/comments"},"review_comment":{"href":"https://api.github.com/repos/WP-API/WP-API/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/WP-API/WP-API/pulls/904/commits"},"statuses":{"href":"https://api.github.com/repos/WP-API/WP-API/statuses/b6fc1293e513c90d6e0aaaf6e7895d2b2f6fe92e"}}}}