{"id":70756,"date":"2017-06-22T19:26:29","date_gmt":"2017-06-22T19:26:29","guid":{"rendered":"https:\/\/wordpress.org\/plugins\/raw-post-mod\/"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-30T00:00:00","slug":"raw-post-mod","status":"closed","type":"plugin","link":"https:\/\/wordpress.org\/plugins\/raw-post-mod\/","author":15471653,"comment_status":"closed","ping_status":"closed","template":"","meta":{"version":"1.0.0","stable_tag":"","tested":"","requires":"","requires_php":"","requires_plugins":"","header_name":"Raw Post mod","header_author":"Joshua Purcell","header_description":"Modifies WP REST-API post GET response to include a JSON version of the raw content","assets_banners_color":"","last_updated":"2017-06-22 19:26:29","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"https:\/\/github.com\/vuldin\/raw-post-mod","header_author_uri":"https:\/\/github.com\/vuldin","rating":0,"author_block_rating":0,"active_installs":0,"downloads":1351,"num_ratings":0,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description"],"tags":[],"upgrade_notice":[],"ratings":[],"assets_icons":[],"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":[],"block_files":[],"assets_screenshots":[],"screenshots":[]},"plugin_section":[],"plugin_tags":[],"plugin_category":[],"plugin_contributors":[],"plugin_business_model":[],"class_list":["post-70756","plugin","type-plugin","status-closed","hentry","plugin_committers-vuldin"],"banners":[],"icons":{"svg":false,"icon":"https:\/\/s.w.org\/plugins\/geopattern-icon\/raw-post-mod.svg","icon_2x":false,"generated":true},"screenshots":[],"raw_content":"\n\n<!--section=description-->\n<h3>Install<\/h3>\n\n<p>This plugin will be available from the <a href=\"https:\/\/wordpress.org\/plugins\/\">Wordpress plugin directory<\/a> once it has gone through the approval process.\nInstead you can follow the steps below:\n    <code>bash\ngit clone https:\/\/github.com\/vuldin\/raw-post-mod.git\nzip -x *.git* -r raw-post-mod raw-post-mod\/<\/code>\nThen upload this <code>raw-post-mod.zip<\/code> file from the plugins page of your wordpress admin portal.\nOnce uploaded, select <code>enable<\/code>.<\/p>\n\n<h3>Purpose<\/h3>\n\n<p>While making a site using React\/Next\/Mobx and other javascript libraries, I wanted to get posts from wordpress and then render them as components in the app.\nThe issue is that Wordpress by default only returned a rendered version of the post content when making an unauthenticated request.\nThe raw content is a little closer to what is needed for being able to get the type of data I need, but it is only one step in the right direction.<\/p>\n\n<p>Here is an example of what an unauthenticated post GET request returns by default:\n    <code>json\n{\n  \"id\":19,\n  \"date\":\"2017-06-22T10:03:07\",\n  \"date_gmt\":\"2017-06-22T17:03:07\",\n  \"guid\":{\n    \"rendered\":\"http:\/\/jlpwptest.localtunnel.me\/?p=19\"\n  },\n  \"modified\":\"2017-06-22T10:03:07\",\n  \"modified_gmt\":\"2017-06-22T17:03:07\",\n  \"slug\":\"title\",\n  \"status\":\"publish\",\n  \"type\":\"post\",\n  \"link\":\"http:\/\/jlpwptest.localtunnel.me\/2017\/06\/22\/title\/\",\n  \"title\":{\n    \"rendered\":\"Title\"\n  },\n  \"content\":{\n    \"rendered\":\"&lt;p&gt;First sentence of first paragraph. Second sentence of first paragraph.&lt;\/p&gt;n&lt;p&gt;First sentence of second paragraph. Second sentence of second paragraph.&lt;\/p&gt;n&lt;p&gt;&lt;img class=\"alignnone size-medium wp-image-20\" src=\"http:\/\/jlpwptest.localtunnel.me\/wp-content\/uploads\/2017\/06\/Test_card-300x169.png\" alt=\"\" width=\"300\" height=\"169\" srcset=\"http:\/\/jlpwptest.localtunnel.me\/wp-content\/uploads\/2017\/06\/Test_card-300x169.png 300w, http:\/\/jlpwptest.localtunnel.me\/wp-content\/uploads\/2017\/06\/Test_card.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/&gt;&lt;\/p&gt;n&lt;p&gt;First sentence of third paragraph. Second sentence of third paragraph.&lt;\/p&gt;n\",\n    \"protected\":false\n  },\"excerpt\":{\n    \"rendered\":\"&lt;p&gt;First sentence of first paragraph. Second sentence of first paragraph. First sentence of second paragraph. Second sentence of second paragraph. First sentence of third paragraph. Second sentence of third paragraph.&lt;\/p&gt;n\",\n    \"protected\":false\n  },\n  \"author\":1,\n  \"featured_media\":0,\n  \"comment_status\":\"open\",\n  \"ping_status\":\"open\",\n  \"sticky\":false,\n  \"template\":\"\",\n  \"format\":\"standard\",\n  \"meta\":[],\n  \"categories\":[1],\n  \"tags\":[],\n  \"_links\":{\n    \"self\":[{\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/posts\/19\"}],\n    \"collection\":[{\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/posts\"}],\n    \"about\":[{\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/types\/post\"}],\n    \"author\":[{\"embeddable\":true,\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/users\/1\"}],\n    \"replies\":[{\"embeddable\":true,\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/comments?post=19\"}],\n    \"version-history\":[{\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/posts\/19\/revisions\"}],\n    \"wp:attachment\":[{\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/media?parent=19\"}],\n    \"wp:term\":[{\"taxonomy\":\"category\",\"embeddable\":true,\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/categories?post=19\"},{\"taxonomy\":\"post_tag\",\"embeddable\":true,\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/tags?post=19\"}],\n    \"curies\":[{\"name\":\"wp\",\"href\":\"https:\/\/api.w.org\/{rel}\",\"templated\":true}]\n  }\n}<\/code>\nThe <code>guid<\/code>, <code>title<\/code>, <code>content<\/code>, and <code>excerpt<\/code> only return a rendered version of that object's data.\nFor external webapps using the REST API this makes it difficult to determine for themselves how to best render this content.\nThis is especially the case with the <code>content<\/code> and <code>excerpt<\/code> objects.<\/p>\n\n<h3>Feature<\/h3>\n\n<p>This mod reads the raw content and generates a JSON array.\nEach entry in the array is the contents of the post's paragraph.<\/p>\n\n<p>Here is an example of the same request above after this plugin is installed (see the <code>content_rawmod<\/code> property):\n    <code>json\n{\n  \"id\":19,\n  \"date\":\"2017-06-22T10:03:07\",\n  \"date_gmt\":\"2017-06-22T17:03:07\",\n  \"guid\":{\n    \"rendered\":\"http:\/\/jlpwptest.localtunnel.me\/?p=19\"\n  },\n  \"modified\":\"2017-06-22T10:03:07\",\n  \"modified_gmt\":\"2017-06-22T17:03:07\",\n  \"slug\":\"title\",\n  \"status\":\"publish\",\n  \"type\":\"post\",\n  \"link\":\"http:\/\/jlpwptest.localtunnel.me\/2017\/06\/22\/title\/\",\n  \"title\":{\n    \"rendered\":\"Title\"\n  },\n  \"content\":{\n    \"rendered\":\"&lt;p&gt;First sentence of first paragraph. Second sentence of first paragraph.&lt;\/p&gt;n&lt;p&gt;First sentence of second paragraph. Second sentence of second paragraph.&lt;\/p&gt;n&lt;p&gt;&lt;img class=\"alignnone size-medium wp-image-20\" src=\"http:\/\/jlpwptest.localtunnel.me\/wp-content\/uploads\/2017\/06\/Test_card-300x169.png\" alt=\"\" width=\"300\" height=\"169\" srcset=\"http:\/\/jlpwptest.localtunnel.me\/wp-content\/uploads\/2017\/06\/Test_card-300x169.png 300w, http:\/\/jlpwptest.localtunnel.me\/wp-content\/uploads\/2017\/06\/Test_card.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/&gt;&lt;\/p&gt;n&lt;p&gt;First sentence of third paragraph. Second sentence of third paragraph.&lt;\/p&gt;n\",\n    \"protected\":false\n  },\"excerpt\":{\n    \"rendered\":\"&lt;p&gt;First sentence of first paragraph. Second sentence of first paragraph. First sentence of second paragraph. Second sentence of second paragraph. First sentence of third paragraph. Second sentence of third paragraph.&lt;\/p&gt;n\",\n    \"protected\":false\n  },\n  \"author\":1,\n  \"featured_media\":0,\n  \"comment_status\":\"open\",\n  \"ping_status\":\"open\",\n  \"sticky\":false,\n  \"template\":\"\",\n  \"format\":\"standard\",\n  \"meta\":[],\n  \"categories\":[1],\n  \"tags\":[],\n  \"content_rawmod\":[\n    \"First sentence of first paragraph. Second sentence of first paragraph.\",\n    \"First sentence of second paragraph. Second sentence of second paragraph.\",\n    \"[caption id=\"attachment_20\" align=\"alignnone\" width=\"300\"]&lt;img class=\"wp-image-20 size-medium\" src=\"http:\/\/jlpwptest.localtunnel.me\/wp-content\/uploads\/2017\/06\/Test_card-300x169.png\" alt=\"alternative text\" width=\"300\" height=\"169\" \/&gt; caption[\/caption]\",\n    \"First sentence of third paragraph. Second sentence of third paragraph.\"\n  ],\n  \"_links\":{\n    \"self\":[{\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/posts\/19\"}],\n    \"collection\":[{\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/posts\"}],\n    \"about\":[{\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/types\/post\"}],\n    \"author\":[{\"embeddable\":true,\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/users\/1\"}],\n    \"replies\":[{\"embeddable\":true,\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/comments?post=19\"}],\n    \"version-history\":[{\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/posts\/19\/revisions\"}],\n    \"wp:attachment\":[{\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/media?parent=19\"}],\n    \"wp:term\":[{\"taxonomy\":\"category\",\"embeddable\":true,\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/categories?post=19\"},{\"taxonomy\":\"post_tag\",\"embeddable\":true,\"href\":\"http:\/\/jlpwptest.localtunnel.me\/wp-json\/wp\/v2\/tags?post=19\"}],\n    \"curies\":[{\"name\":\"wp\",\"href\":\"https:\/\/api.w.org\/{rel}\",\"templated\":true}]\n  }\n}<\/code><\/p>\n\n<h3>Future plans<\/h3>\n\n<p>The rawmod content is better than either the rendered or raw content, but it still has issues.\nThe main issue is the format that images and captions are in.\nI'll be looking into how this plugin can modify this content so that it is in a more usable JSON format.\nThis could be solved by returning objects that gave details as to what type of block the content should be.<\/p>\n\n<p>For example:\n    <code>json\n{\n  \"content_rawmod\": [\n    {\n      \"type\": \"text\",\n      \"value\": \"First sentence of first paragraph. Second sentence of first paragraph.\"\n    }\n    {\n      \"type\": \"image\",\n      \"link\": \"http:\/\/jlpwptest.localtunnel.me\/wp-content\/uploads\/2017\/06\/Test_card-300x169.png\",\n      \"caption\": \"caption text\",\n      \"alttext\": \"alternate text\"\n    }\n  ]\n}<\/code><\/p>","raw_excerpt":"Modifies WP REST-API post GET response to include a JSON version of the raw content","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/70756","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=70756"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/vuldin"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=70756"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=70756"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=70756"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=70756"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=70756"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=70756"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}