├── .github └── workflows │ ├── deploy.yml │ ├── phpcs.yml │ └── update-assets.yml ├── .gitignore ├── .svnignore ├── .wordpress-org ├── icon-128x128.png └── icon-256x256.png ├── LICENSE ├── README.md ├── composer.json ├── feed-json-comments.php ├── feed-json-functions.php ├── feed-json.php ├── jsonfeed-wp.php ├── jsonfeed.png ├── jsonfeed.svg ├── phpcs.xml └── readme.txt /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Deploy to WordPress.org 2 | on: 3 | push: 4 | tags: 5 | - "*" 6 | jobs: 7 | tag: 8 | name: New tag 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | - name: WordPress Plugin Deploy 13 | uses: 10up/action-wordpress-plugin-deploy@stable 14 | env: 15 | SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} 16 | SVN_USERNAME: ${{ secrets.SVN_USERNAME }} 17 | SLUG: jsonfeed 18 | -------------------------------------------------------------------------------- /.github/workflows/phpcs.yml: -------------------------------------------------------------------------------- 1 | name: PHP_CodeSniffer 2 | on: push 3 | jobs: 4 | phpcs: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - name: Checkout 8 | uses: actions/checkout@v3 9 | - name: Setup PHP 10 | uses: shivammathur/setup-php@v2 11 | with: 12 | php-version: '7.4' 13 | coverage: none 14 | tools: composer, cs2pr 15 | - name: Install Composer dependencies for PHP 16 | uses: "ramsey/composer-install@v2" 17 | - name: Detect coding standard violations 18 | run: composer lint 19 | 20 | -------------------------------------------------------------------------------- /.github/workflows/update-assets.yml: -------------------------------------------------------------------------------- 1 | name: Plugin asset/readme update 2 | on: 3 | push: 4 | branches: 5 | - master 6 | jobs: 7 | master: 8 | name: Push to master 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | - name: WordPress Plugin asset/readme update 13 | uses: 10up/action-wordpress-plugin-asset-update@stable 14 | env: 15 | SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} 16 | SVN_USERNAME: ${{ secrets.SVN_USERNAME }} 17 | SLUG: jsonfeed 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/* 2 | composer.lock 3 | -------------------------------------------------------------------------------- /.svnignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .editorconfig 3 | .git 4 | .gitignore 5 | .travis.yml 6 | Gruntfile.js 7 | LINGUAS 8 | Makefile 9 | README.md 10 | _site 11 | bin 12 | composer.json 13 | composer.lock 14 | docker-compose.yml 15 | gulpfile.js 16 | package.json 17 | npm-debug.log 18 | phpcs.xml 19 | package.json 20 | phpunit.xml 21 | phpunit.xml.dist 22 | tests 23 | node_modules 24 | sass 25 | vendor 26 | -------------------------------------------------------------------------------- /.wordpress-org/icon-128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manton/jsonfeed-wp/ad7da9f53e29ec303b87db20cb6cbebd90d46bfb/.wordpress-org/icon-128x128.png -------------------------------------------------------------------------------- /.wordpress-org/icon-256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manton/jsonfeed-wp/ad7da9f53e29ec303b87db20cb6cbebd90d46bfb/.wordpress-org/icon-256x256.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **License URI:** http://www.gnu.org/licenses/gpl-2.0.html 2 | 3 | Adds feeds in JSON Feed format. 4 | 5 | ## Description 6 | 7 | Adds a JSON Feed to your WordPress site by adding `/feed/json` to any URL. 8 | 9 | The JSON Feed format is a pragmatic syndication format, like RSS and Atom, but with one big difference: it's JSON instead of XML. Learn more at [jsonfeed.org](http://jsonfeed.org/). 10 | 11 | ## Installation 12 | 13 | 1. Upload the plugin files to the `/wp-content/plugins/jsonfeed` directory, or install the plugin through the WordPress plugins screen directly. 14 | 1. Activate the plugin through the 'Plugins' screen in WordPress 15 | 16 | ## Frequently Asked Questions 17 | 18 | ### What is JSONFeed? 19 | 20 | JSON Feed, a format similar to RSS and Atom but in JSON. JSON has become the developers’ choice for APIs, and that developers will often go out of their way to avoid XML. 21 | JSON is simpler to read and write, and it’s less prone to bugs. 22 | 23 | ### Can I add other fields to the feed? 24 | 25 | Yes you can! There is a filter, `json_feed_item`, that allows you to modify the items in the feed just before they're inserted into the feed itself. For example, if you want to add a link to a post author's archive page to the respective item in the feed, you can use the following code: 26 | 27 | ``` 28 | function wp_custom_json_feed_fields( $feed_item, $post ){ 29 | $feed_item['author']['archive_link'] = get_author_posts_url( $post->post_author ); 30 | 31 | return $feed_item; 32 | } 33 | add_filter( 'json_feed_item', 'wp_custom_json_feed_fields', 10, 2); 34 | ``` 35 | 36 | ### Can I write information to my posts? 37 | 38 | This is a syndication format, which means it only represents your posts and comments as feed elements. This is read only, similar to RSS or Atom. It is not an API. 39 | 40 | ## Changelog 41 | 42 | ### 1.4.5 43 | 44 | * Sanity check on $max_page 45 | * Add filter `jsonfeed_comments_feed_enable`, which if set to false will disable the comments feed header. 46 | * Add mime type for jsonfeed to filter for W3C Cache Plugin per GitHub issue 67. 47 | 48 | ### 1.4.4 49 | 50 | * Fix declaration error 51 | 52 | ### 1.4.3 53 | 54 | * Add next_url 55 | * Add CORS header 56 | 57 | ### 1.4.2 58 | 59 | * Update WebSub support 60 | 61 | ### 1.4.1 62 | 63 | * Added author field back for compatibility with JSON Feed 1.0. 64 | 65 | ### 1.4.0 66 | 67 | * Switch to using GUID for the ID 68 | * Update to the JSONFeed 1.1 standard 69 | * Use the RSS versions of title functions to allow these filters to be used 70 | 71 | ### 1.3.1 72 | 73 | * Fix attachment array 74 | * Replace custom function with backcompat of function introduced into Core 75 | 76 | ### 1.3.0 77 | 78 | * Add comments template 79 | * JSONFeed icon now part of repo 80 | * Allow for multiple attachments 81 | * Respect summary setting 82 | * Add support for extra feeds in header 83 | 84 | ### 1.2.0 85 | 86 | * dshanske added as a contributor/maintainer 87 | * Add featured image if set 88 | * Add site icon if set 89 | * home_page_url now actually returns the correct URL instead of always returning the homepage of the site 90 | * Add avatar and URL to author 91 | * Include site name in feed name in the discovery title 92 | * Fix issue with timezone not reflecting on date 93 | 94 | ### 1.1.2 95 | 96 | ### 1.1.1 97 | 98 | ### 1.0 99 | 100 | * Initial release 101 | 102 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "manton/jsonfeed-wp", 3 | "description": "JSON Feed for WordPress", 4 | "type": "wordpress-plugin", 5 | "license": "GPLv2 or later", 6 | "support": { 7 | "issues": "https://github.com/manton/jsonfeed-wp/issues", 8 | "source": "https://github.com/manton/jsonfeed-wp" 9 | }, 10 | "extra": { 11 | "installer-name": "jsonfeed" 12 | }, 13 | "config": { 14 | "allow-plugins": { 15 | "composer/installers": true, 16 | "dealerdirect/phpcodesniffer-composer-installer": true 17 | } 18 | }, 19 | "require": { 20 | "php": ">=5.6.0", 21 | "composer/installers": "~1.12" 22 | }, 23 | "require-dev": { 24 | "dealerdirect/phpcodesniffer-composer-installer": "*", 25 | "squizlabs/php_codesniffer": "*", 26 | "phpcompatibility/php-compatibility": "*", 27 | "wp-coding-standards/wpcs": "*", 28 | "wpreadme2markdown/wp2md": "*", 29 | "phpcompatibility/phpcompatibility-wp": "*", 30 | "php-parallel-lint/php-parallel-lint": "^1.2", 31 | "sebastian/phpcpd": "^3.0 || ^5.0 || ^6.0" 32 | }, 33 | "prefer-stable" : true, 34 | "scripts": { 35 | "lint:phpcpd": "./vendor/bin/phpcpd --fuzzy --exclude .git --exclude vendor .", 36 | "lint:wpcs": "./vendor/bin/phpcs -s --runtime-set ignore_warnings_on_exit 1", 37 | "lint:wpcs-fix": "./vendor/bin/phpcbf", 38 | "lint": "./vendor/bin/phpcs -n -q", 39 | "lint:php": "@php ./vendor/bin/parallel-lint --exclude .git --exclude vendor .", 40 | "install-codestandards": [ 41 | "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run" 42 | ], 43 | "update-readme": [ 44 | "wp2md -i readme.txt | tail -n +10 > README.md" 45 | ], 46 | "post-update-cmd": [ 47 | "@update-readme" 48 | ] 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /feed-json-comments.php: -------------------------------------------------------------------------------- 1 | $val ) { 17 | if ( 'enclosure' === $key ) { 18 | foreach ( (array) $val as $enc ) { 19 | $enclosure = explode( "\n", $enc ); 20 | 21 | // only get the first element, e.g. audio/mpeg from 'audio/mpeg mpga mp2 mp3' 22 | $t = preg_split( '/[ \t]/', trim( $enclosure[2] ) ); 23 | $type = $t[0]; 24 | 25 | $return[] = array( 26 | 'url' => trim( $enclosure[0] ), 27 | 'mime_type' => $type, 28 | 'size_in_bytes' => (int) $enclosure[1], 29 | ); 30 | } 31 | } 32 | } 33 | return $return; 34 | } 35 | 36 | function get_link_from_json_feed( $link ) { 37 | global $wp_rewrite; 38 | $arg = $wp_rewrite->get_feed_permastruct(); 39 | // If empty this site does not have pretty permalinks enabled 40 | if ( empty( $arg ) ) { 41 | wp_parse_str( wp_parse_url( $link, PHP_URL_QUERY ), $query_args ); 42 | unset( $query_args['feed'] ); 43 | return add_query_arg( $query_args, home_url( '/' ) ); 44 | } else { 45 | $arg = str_replace( '%feed%', 'json', $arg ); 46 | $arg = preg_replace( '#/+#', '/', "/$arg" ); 47 | $link = str_replace( $arg, '', $link ); 48 | } 49 | return $link; 50 | } 51 | 52 | function get_json_feed_next_url() { 53 | global $paged, $wp_query; 54 | $max_page = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; 55 | 56 | $nextpage = ( ! $paged ) ? 2 : (int) $paged + 1; 57 | 58 | if ( ! is_single() && ( $nextpage <= $max_page ) ) { 59 | return add_query_arg( 'paged', $nextpage, get_self_link() ); 60 | } 61 | return ''; 62 | } 63 | 64 | 65 | function get_json_feed_data() { 66 | $return = array( 67 | 'version' => 'https://jsonfeed.org/version/1.1', 68 | // translators: 1. get_self_link URL 69 | 'user_comment' => sprintf( __( 'This feed allows you to read the posts from this site in any feed reader that supports the JSON Feed format. To add this feed to your reader, copy the following URL -- %1$s -- and add it your reader.', 'jsonfeed' ), get_self_link() ), 70 | 'next_url' => get_json_feed_next_url(), 71 | 'home_page_url' => get_link_from_json_feed( get_self_link() ), 72 | 'feed_url' => get_self_link(), 73 | 'language' => get_bloginfo( 'language' ), 74 | 'title' => get_wp_title_rss(), 75 | 'description' => get_bloginfo( 'description' ), 76 | 'icon' => get_site_icon_url(), 77 | ); 78 | return array_filter( $return ); 79 | } 80 | 81 | 82 | function get_json_comment_feed_item() { 83 | $comment = get_comment(); 84 | $comment_post = get_post( $comment->comment_post_ID ); 85 | if ( 1 === (int) get_option( 'rss_use_excerpt' ) ) { 86 | $content = get_comment_excerpt(); 87 | } else { 88 | $content = get_comment_text(); 89 | } 90 | 91 | if ( ! is_singular() ) { 92 | $title = get_the_title( $comment_post->ID ); 93 | /** This filter is documented in wp-includes/feed.php */ 94 | $title = apply_filters( 'the_title_rss', $title ); 95 | /* translators: Individual comment title. 1: Post title, 2: Comment author name */ 96 | $title = sprintf( ent2ncr( __( 'Comment on %1$s by %2$s', 'jsonfeed' ) ), $title, get_comment_author_rss() ); 97 | } else { 98 | $title = ''; 99 | } 100 | 101 | $feed_item = array( 102 | 'id' => get_comment_link(), 103 | 'url' => get_comment_link(), 104 | 'title' => html_entity_decode( $title ), 105 | 'content_html' => $content, 106 | 'content_text' => wp_strip_all_tags( $content ), 107 | 'date_published' => get_comment_date( 'Y-m-d\TH:i:sP' ), 108 | 'authors' => array( get_json_comment_author() ), 109 | 'author' => get_json_comment_author(), 110 | ); 111 | 112 | if ( ! is_singular() ) { 113 | $feed_item['_parent_url'] = get_permalink( $comment_post ); 114 | } 115 | 116 | // If anything is an empty string or null then remove it 117 | $feed_item = array_filter( $feed_item ); 118 | 119 | return apply_filters( 'json_feed_comment_item', $feed_item, get_comment() ); 120 | } 121 | 122 | function get_json_feed_item() { 123 | if ( 1 === (int) get_option( 'rss_use_excerpt' ) ) { 124 | $content = get_the_json_excerpt_feed(); 125 | } else { 126 | $content = get_the_content_feed( 'json' ); 127 | } 128 | 129 | $feed_item = array( 130 | 'id' => get_the_guid(), 131 | 'url' => get_permalink(), 132 | 'title' => html_entity_decode( get_the_title_rss() ), 133 | 'content_html' => $content, 134 | 'content_text' => wp_strip_all_tags( $content ), 135 | 'date_published' => get_the_date( 'Y-m-d\TH:i:sP' ), 136 | 'date_modified' => get_the_modified_date( 'Y-m-d\TH:i:sP' ), 137 | 'authors' => array( get_json_item_author() ), 138 | 'author' => get_json_item_author(), 139 | 'image' => get_the_post_thumbnail_url( null, 'full' ), // If there is a set featured image 140 | 'tags' => json_get_merged_tags(), // Tags is a merge of the category and the tags names 141 | ); 142 | 143 | // Only add custom excerpts not generated ones 144 | if ( has_excerpt() ) { 145 | $feed_item['summary'] = get_the_excerpt(); 146 | } 147 | // If anything is an empty string or null then remove it 148 | $feed_item = array_filter( $feed_item ); 149 | 150 | $attachment = get_attachment_json_info(); 151 | if ( ! empty( $attachment ) ) { 152 | $feed_item['attachments'] = $attachment; 153 | } 154 | 155 | return apply_filters( 'json_feed_item', $feed_item, get_post() ); 156 | } 157 | 158 | function get_json_item_author() { 159 | return array( 160 | 'name' => get_the_author(), 161 | 'url' => get_author_posts_url( get_the_author_meta( 'ID' ) ), 162 | 'avatar' => get_avatar_url( get_the_author_meta( 'ID' ), array( 'size' => 512 ) ), 163 | ); 164 | } 165 | 166 | function get_json_comment_author() { 167 | return array( 168 | 'name' => get_comment_author(), 169 | 'url' => get_comment_author_url(), 170 | 'avatar' => get_avatar_url( get_comment(), array( 'size' => 512 ) ), 171 | ); 172 | } 173 | 174 | 175 | 176 | function json_get_merged_tags( $post_id = null ) { 177 | $post = get_post( $post_id ); 178 | if ( ! $post ) { 179 | return array(); 180 | } 181 | $tags = get_the_terms( $post, 'post_tag' ); 182 | $categories = get_the_terms( $post, 'category' ); 183 | $tags = is_array( $tags ) ? $tags : array(); 184 | $categories = is_array( $categories ) ? $categories : array(); 185 | $tags = array_merge( $tags, $categories ); 186 | $tags = wp_list_pluck( $tags, 'name', 'slug' ); 187 | $return = array(); 188 | foreach ( $tags as $key => $value ) { 189 | if ( 'uncategorized' !== $key ) { 190 | $return[] = $value; 191 | } 192 | } 193 | return $return; 194 | } 195 | 196 | function get_the_json_excerpt_feed() { 197 | $output = get_the_excerpt(); 198 | /** 199 | * Filters the post excerpt for a feed. 200 | * 201 | * @since 1.2.0 202 | * 203 | * @param string $output The current post excerpt. 204 | */ 205 | return apply_filters( 'the_excerpt_rss', $output ); 206 | } 207 | -------------------------------------------------------------------------------- /feed-json.php: -------------------------------------------------------------------------------- 1 | ' . PHP_EOL, 58 | esc_attr( get_bloginfo( 'name' ) ), 59 | esc_url( get_feed_link( 'json' ) ) 60 | ); 61 | } 62 | 63 | /** 64 | * Display the links to the extra feeds such as category feeds. 65 | * 66 | * 67 | * @param array $args Optional arguments. 68 | */ 69 | function json_feed_links_extra( $args = array() ) { 70 | $defaults = array( 71 | /* translators: Separator between blog name and feed type in feed links */ 72 | 'separator' => _x( '»', 'feed link', 'jsonfeed' ), 73 | /* translators: 1: blog name, 2: separator(raquo), 3: post title */ 74 | 'singletitle' => __( '%1$s %2$s %3$s Comments Feed', 'jsonfeed' ), 75 | /* translators: 1: blog name, 2: separator(raquo), 3: category name */ 76 | 'cattitle' => __( '%1$s %2$s %3$s Category Feed', 'jsonfeed' ), 77 | /* translators: 1: blog name, 2: separator(raquo), 3: tag name */ 78 | 'tagtitle' => __( '%1$s %2$s %3$s Tag Feed', 'jsonfeed' ), 79 | /* translators: 1: blog name, 2: separator(raquo), 3: term name, 4: taxonomy singular name */ 80 | 'taxtitle' => __( '%1$s %2$s %3$s %4$s Feed', 'jsonfeed' ), 81 | /* translators: 1: blog name, 2: separator(raquo), 3: author name */ 82 | 'authortitle' => __( '%1$s %2$s Posts by %3$s Feed', 'jsonfeed' ), 83 | /* translators: 1: blog name, 2: separator(raquo), 3: search phrase */ 84 | 'searchtitle' => __( '%1$s %2$s Search Results for “%3$s” Feed', 'jsonfeed' ), 85 | /* translators: 1: blog name, 2: separator(raquo), 3: post type name */ 86 | 'posttypetitle' => __( '%1$s %2$s %3$s Feed', 'jsonfeed' ), 87 | ); 88 | $args = wp_parse_args( $args, $defaults ); 89 | if ( is_singular() ) { 90 | $id = 0; 91 | $post = get_post( $id ); 92 | $comments = apply_filters( 'jsonfeed_comments_feed_enable', true ); 93 | if ( $comments && ( comments_open() || pings_open() || $post->comment_count > 0 ) ) { 94 | $title = sprintf( $args['singletitle'], get_bloginfo( 'name' ), $args['separator'], the_title_attribute( array( 'echo' => false ) ) ); 95 | $href = get_post_comments_feed_link( $post->ID, 'json' ); 96 | } 97 | } elseif ( is_post_type_archive() ) { 98 | $post_type = get_query_var( 'post_type' ); 99 | if ( is_array( $post_type ) ) { 100 | $post_type = reset( $post_type ); 101 | } 102 | $post_type_obj = get_post_type_object( $post_type ); 103 | $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name ); 104 | $href = get_post_type_archive_feed_link( $post_type_obj->name, 'json' ); 105 | } elseif ( is_category() ) { 106 | $term = get_queried_object(); 107 | if ( $term ) { 108 | $title = sprintf( $args['cattitle'], get_bloginfo( 'name' ), $args['separator'], $term->name ); 109 | $href = get_category_feed_link( $term->term_id, 'json' ); 110 | } 111 | } elseif ( is_tag() ) { 112 | $term = get_queried_object(); 113 | if ( $term ) { 114 | $title = sprintf( $args['tagtitle'], get_bloginfo( 'name' ), $args['separator'], $term->name ); 115 | $href = get_tag_feed_link( $term->term_id, 'json' ); 116 | } 117 | } elseif ( is_tax() ) { 118 | $term = get_queried_object(); 119 | $tax = get_taxonomy( $term->taxonomy ); 120 | $title = sprintf( $args['taxtitle'], get_bloginfo( 'name' ), $args['separator'], $term->name, $tax->labels->singular_name ); 121 | $href = get_term_feed_link( $term->term_id, $term->taxonomy, 'json' ); 122 | } elseif ( is_author() ) { 123 | $author_id = intval( get_query_var( 'author' ) ); 124 | $title = sprintf( $args['authortitle'], get_bloginfo( 'name' ), $args['separator'], get_the_author_meta( 'display_name', $author_id ) ); 125 | $href = get_author_feed_link( $author_id, 'json' ); 126 | } elseif ( is_search() ) { 127 | $title = sprintf( $args['searchtitle'], get_bloginfo( 'name' ), $args['separator'], get_search_query( false ) ); 128 | $href = get_search_feed_link( '', 'json' ); 129 | } elseif ( is_post_type_archive() ) { 130 | $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], post_type_archive_title( '', false ) ); 131 | $post_type_obj = get_queried_object(); 132 | if ( $post_type_obj ) { 133 | $href = get_post_type_archive_feed_link( $post_type_obj->name, 'json' ); 134 | } 135 | } 136 | if ( isset( $title ) && isset( $href ) ) { 137 | printf( '', esc_attr( feed_content_type( 'json' ) ), esc_attr( $title ), esc_url( $href ) ); 138 | echo PHP_EOL; 139 | } 140 | } 141 | add_filter( 'wp_head', 'json_feed_links_extra' ); 142 | 143 | /** 144 | * Add `json` as "supported feed type" for the WebSub implementation. 145 | * 146 | * 147 | * @param array $feed_types The list of supported feed types. 148 | * 149 | * @return array $feed_types The filtered list of supported feed types. 150 | */ 151 | function json_feed_websub( $feed_types ) { 152 | $feed_types[] = 'json'; 153 | return $feed_types; 154 | } 155 | add_filter( 'pubsubhubbub_supported_feed_types', 'json_feed_websub' ); 156 | 157 | require_once __DIR__ . '/feed-json-functions.php'; 158 | -------------------------------------------------------------------------------- /jsonfeed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manton/jsonfeed-wp/ad7da9f53e29ec303b87db20cb6cbebd90d46bfb/jsonfeed.png -------------------------------------------------------------------------------- /jsonfeed.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | icon 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /phpcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | JSONFeed for WordPress Standards 4 | 5 | ./jsonfeed-wp.php 6 | ./feed-json.php 7 | ./feed-json-comments.php 8 | ./feed-json-functions.php 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === JSON Feed (jsonfeed.org) === 2 | Contributors: mantonr, redsweater, dshanske 3 | Tags: jsonfeed, json, feed, feeds 4 | Requires at least: 4.9 5 | Tested up to: 6.5 6 | Requires PHP: 5.6 7 | Stable tag: 1.4.5 8 | License: GPL-2.0+ 9 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 | 11 | Adds feeds in JSON Feed format. 12 | 13 | == Description == 14 | 15 | Adds a JSON Feed to your WordPress site by adding `/feed/json` to any URL. 16 | 17 | The JSON Feed format is a pragmatic syndication format, like RSS and Atom, but with one big difference: it's JSON instead of XML. Learn more at [jsonfeed.org](http://jsonfeed.org/). 18 | 19 | == Installation == 20 | 21 | 1. Upload the plugin files to the `/wp-content/plugins/jsonfeed` directory, or install the plugin through the WordPress plugins screen directly. 22 | 1. Activate the plugin through the 'Plugins' screen in WordPress 23 | 24 | == Frequently Asked Questions == 25 | 26 | = What is JSONFeed? = 27 | 28 | JSON Feed, a format similar to RSS and Atom but in JSON. JSON has become the developers’ choice for APIs, and that developers will often go out of their way to avoid XML. 29 | JSON is simpler to read and write, and it’s less prone to bugs. 30 | 31 | = Can I add other fields to the feed? = 32 | 33 | Yes you can! There is a filter, `json_feed_item`, that allows you to modify the items in the feed just before they're inserted into the feed itself. For example, if you want to add a link to a post author's archive page to the respective item in the feed, you can use the following code: 34 | 35 | ``` 36 | function wp_custom_json_feed_fields( $feed_item, $post ){ 37 | $feed_item['author']['archive_link'] = get_author_posts_url( $post->post_author ); 38 | 39 | return $feed_item; 40 | } 41 | add_filter( 'json_feed_item', 'wp_custom_json_feed_fields', 10, 2); 42 | ``` 43 | 44 | = Can I write information to my posts? = 45 | 46 | This is a syndication format, which means it only represents your posts and comments as feed elements. This is read only, similar to RSS or Atom. It is not an API. 47 | 48 | == Changelog == 49 | 50 | = 1.4.5 = 51 | * Sanity check on $max_page 52 | * Add filter `jsonfeed_comments_feed_enable`, which if set to false will disable the comments feed header. 53 | * Add mime type for jsonfeed to filter for W3C Cache Plugin per GitHub issue 67. 54 | 55 | = 1.4.4 = 56 | * Fix declaration error 57 | 58 | = 1.4.3 = 59 | * Add next_url 60 | * Add CORS header 61 | 62 | = 1.4.2 = 63 | * Update WebSub support 64 | 65 | = 1.4.1 = 66 | * Added author field back for compatibility with JSON Feed 1.0. 67 | 68 | = 1.4.0 = 69 | * Switch to using GUID for the ID 70 | * Update to the JSONFeed 1.1 standard 71 | * Use the RSS versions of title functions to allow these filters to be used 72 | 73 | = 1.3.1 = 74 | * Fix attachment array 75 | * Replace custom function with backcompat of function introduced into Core 76 | 77 | = 1.3.0 = 78 | * Add comments template 79 | * JSONFeed icon now part of repo 80 | * Allow for multiple attachments 81 | * Respect summary setting 82 | * Add support for extra feeds in header 83 | 84 | = 1.2.0 = 85 | * dshanske added as a contributor/maintainer 86 | * Add featured image if set 87 | * Add site icon if set 88 | * home_page_url now actually returns the correct URL instead of always returning the homepage of the site 89 | * Add avatar and URL to author 90 | * Include site name in feed name in the discovery title 91 | * Fix issue with timezone not reflecting on date 92 | 93 | = 1.1.2 = 94 | 95 | = 1.1.1 = 96 | 97 | = 1.0 = 98 | * Initial release 99 | --------------------------------------------------------------------------------