{"id":19388500,"url":"https://github.com/vuldin/raw-post-mod","last_synced_at":"2025-02-24T19:58:48.304Z","repository":{"id":146506863,"uuid":"95134840","full_name":"vuldin/raw-post-mod","owner":"vuldin","description":"Modifies WP REST-API post GET response to include a JSON version of the raw content","archived":false,"fork":false,"pushed_at":"2017-06-23T06:22:58.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-07T08:47:30.455Z","etag":null,"topics":["plugin","wordpress","wp-api"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vuldin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-22T16:22:42.000Z","updated_at":"2024-12-13T07:12:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"80ba79a4-4800-4166-a6e9-3b4fe804c74f","html_url":"https://github.com/vuldin/raw-post-mod","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vuldin%2Fraw-post-mod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vuldin%2Fraw-post-mod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vuldin%2Fraw-post-mod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vuldin%2Fraw-post-mod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vuldin","download_url":"https://codeload.github.com/vuldin/raw-post-mod/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240549434,"owners_count":19819131,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["plugin","wordpress","wp-api"],"created_at":"2024-11-10T10:12:50.295Z","updated_at":"2025-02-24T19:58:48.285Z","avatar_url":"https://github.com/vuldin.png","language":"PHP","readme":"# Raw post mod\nAdds new fields `content_rawmod` and `excerpt_rawmod` to the post response from Wordpress API that contains a modified JSON version of the post's raw content.\n\n## Install\nThis plugin will be available from the [Wordpress plugin directory](https://wordpress.org/plugins/) once it has gone through the approval process.\nInstead you can follow the steps below:\n```bash\ngit clone https://github.com/vuldin/raw-post-mod.git\nzip -x *.git* -r raw-post-mod raw-post-mod/\n```\nThen upload this `raw-post-mod.zip` file from the plugins page of your wordpress admin portal.\nOnce uploaded, select `enable`.\n\n## Purpose\nWhile 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.\n\nHere is an example of what an unauthenticated post GET request returns by default:\n```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\":\"\u003cp\u003eFirst sentence of first paragraph. Second sentence of first paragraph.\u003c\\/p\u003e\\n\u003cp\u003eFirst sentence of second paragraph. Second sentence of second paragraph.\u003c\\/p\u003e\\n\u003cp\u003e\u003cimg 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\\\" \\/\u003e\u003c\\/p\u003e\\n\u003cp\u003eFirst sentence of third paragraph. Second sentence of third paragraph.\u003c\\/p\u003e\\n\",\n    \"protected\":false\n  },\"excerpt\":{\n    \"rendered\":\"\u003cp\u003eFirst 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.\u003c\\/p\u003e\\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}\n```\nThe `guid`, `title`, `content`, and `excerpt` 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 `content` and `excerpt` objects.\n\n## Feature\nThis mod reads the raw content and generates a JSON array.\nEach entry in the array is the contents of the post's paragraph.\n\nHere is an example of the same request above after this plugin is installed (see the `content_rawmod` and `excerpt_rawmod` properties):\n```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\":\"\u003cp\u003eFirst sentence of first paragraph. Second sentence of first paragraph.\u003c\\/p\u003e\\n\u003cp\u003eFirst sentence of second paragraph. Second sentence of second paragraph.\u003c\\/p\u003e\\n\u003cp\u003e\u003cimg 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\\\" \\/\u003e\u003c\\/p\u003e\\n\u003cp\u003eFirst sentence of third paragraph. Second sentence of third paragraph.\u003c\\/p\u003e\\n\",\n    \"protected\":false\n  },\"excerpt\":{\n    \"rendered\":\"\u003cp\u003eFirst 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.\u003c\\/p\u003e\\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\\\"]\u003cimg 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\\\" \\/\u003e caption[\\/caption]\",\n    \"First sentence of third paragraph. Second sentence of third paragraph.\"\n  ],\n  \"excerpt_rawmod\":\"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.\",\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}\n```\n\n## Future plans\nFor the `excerpt_rawmod`, this mod must use the rendered property instead of raw since there seems to be no raw property even when authenticated for excerpt.\nSo for this transformation I strip the `\u003cp\u003e` tags from the string and return the response. This may need to be changed in the future.\n\nThe 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.\n\nFor example:\n```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}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvuldin%2Fraw-post-mod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvuldin%2Fraw-post-mod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvuldin%2Fraw-post-mod/lists"}