From 69e41a27cf070ce49a11bc13686a8a77b6321c9e Mon Sep 17 00:00:00 2001 From: David Shanske Date: Sun, 29 Oct 2023 14:22:38 +0000 Subject: [PATCH 1/5] Bump testing to minimum 5.6 --- phpcs.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpcs.xml b/phpcs.xml index a144072..26d27ec 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -7,7 +7,7 @@ ./feed-json-comments.php ./feed-json-functions.php - + From 188f28063d43fd9e4fce66ce0f1c97228efbda74 Mon Sep 17 00:00:00 2001 From: David Shanske Date: Sun, 29 Oct 2023 14:25:58 +0000 Subject: [PATCH 2/5] Ensure Max Pages is either what the query calculates or 1 --- feed-json-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feed-json-functions.php b/feed-json-functions.php index 1073ac1..46aac99 100644 --- a/feed-json-functions.php +++ b/feed-json-functions.php @@ -51,7 +51,7 @@ function get_link_from_json_feed( $link ) { function get_json_feed_next_url() { global $paged, $wp_query; - $max_page = $wp_query->max_num_pages; + $max_page = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; $nextpage = ( ! $paged ) ? 2 : (int) $paged + 1; From c4cd6a58e4c771dc171f6297aa3c0a6ffba9029d Mon Sep 17 00:00:00 2001 From: David Shanske Date: Sun, 29 Oct 2023 14:32:55 +0000 Subject: [PATCH 3/5] Add filter to disable comments feed json --- jsonfeed-wp.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jsonfeed-wp.php b/jsonfeed-wp.php index b1c2004..e409a3b 100644 --- a/jsonfeed-wp.php +++ b/jsonfeed-wp.php @@ -81,7 +81,8 @@ function json_feed_links_extra( $args = array() ) { if ( is_singular() ) { $id = 0; $post = get_post( $id ); - if ( comments_open() || pings_open() || $post->comment_count > 0 ) { + $comments = apply_filters( 'jsonfeed_comments_feed_enable', true ); + if ( $comments && ( comments_open() || pings_open() || $post->comment_count > 0 ) ) { $title = sprintf( $args['singletitle'], get_bloginfo( 'name' ), $args['separator'], the_title_attribute( array( 'echo' => false ) ) ); $href = get_post_comments_feed_link( $post->ID, 'json' ); } From 16e79faa4c5486d593c6cf1f83a0736cf05af190 Mon Sep 17 00:00:00 2001 From: David Shanske Date: Sun, 29 Oct 2023 14:37:03 +0000 Subject: [PATCH 4/5] Add filter for W3C to cache this feed type --- jsonfeed-wp.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/jsonfeed-wp.php b/jsonfeed-wp.php index e409a3b..c03a16b 100644 --- a/jsonfeed-wp.php +++ b/jsonfeed-wp.php @@ -43,6 +43,14 @@ function json_feed_content_type( $content_type, $type ) { return $content_type; } + +function json_feed_w3tc_is_cacheable_content_type( $types ) { + $types[] = 'application/feed+json'; + return array_unique( $types ); +} + +add_filter( 'w3tc_is_cacheable_content_type', 'json_feed_w3tc_is_cacheable_content_type' ); + add_action( 'wp_head', 'json_feed_link' ); function json_feed_link() { printf( From fe392b7304da71568bf64274765f10176cc8d290 Mon Sep 17 00:00:00 2001 From: David Shanske Date: Sun, 29 Oct 2023 14:40:18 +0000 Subject: [PATCH 5/5] Bump version --- README.md | 6 ++++++ feed-json-functions.php | 2 +- jsonfeed-wp.php | 12 ++++++------ readme.txt | 11 ++++++++--- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 78abf6d..94d957b 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,12 @@ This is a syndication format, which means it only represents your posts and comm ## Changelog +### 1.4.5 + +* Sanity check on $max_page +* Add filter `jsonfeed_comments_feed_enable`, which if set to false will disable the comments feed header. +* Add mime type for jsonfeed to filter for W3C Cache Plugin per GitHub issue 67. + ### 1.4.4 * Fix declaration error diff --git a/feed-json-functions.php b/feed-json-functions.php index 46aac99..c102f1e 100644 --- a/feed-json-functions.php +++ b/feed-json-functions.php @@ -51,7 +51,7 @@ function get_link_from_json_feed( $link ) { function get_json_feed_next_url() { global $paged, $wp_query; - $max_page = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; + $max_page = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; $nextpage = ( ! $paged ) ? 2 : (int) $paged + 1; diff --git a/jsonfeed-wp.php b/jsonfeed-wp.php index c03a16b..1c6eff7 100644 --- a/jsonfeed-wp.php +++ b/jsonfeed-wp.php @@ -3,7 +3,7 @@ Plugin Name: JSON Feed Plugin URI: https://github.com/manton/jsonfeed-wp/ Description: Adds a feed of recent posts in JSON Feed format. -Version: 1.4.4 +Version: 1.4.5 Author: Manton Reece and Daniel Jalkut Text Domain: jsonfeed License: GPL2.0+ @@ -28,10 +28,10 @@ function do_feed_json( $for_comments ) { header( 'Access-Control-Allow-Origin: *' ); if ( $for_comments ) { - load_template( dirname( __FILE__ ) . '/feed-json-comments.php' ); + load_template( __DIR__ . '/feed-json-comments.php' ); } else { - load_template( dirname( __FILE__ ) . '/feed-json.php' ); + load_template( __DIR__ . '/feed-json.php' ); } } @@ -87,8 +87,8 @@ function json_feed_links_extra( $args = array() ) { ); $args = wp_parse_args( $args, $defaults ); if ( is_singular() ) { - $id = 0; - $post = get_post( $id ); + $id = 0; + $post = get_post( $id ); $comments = apply_filters( 'jsonfeed_comments_feed_enable', true ); if ( $comments && ( comments_open() || pings_open() || $post->comment_count > 0 ) ) { $title = sprintf( $args['singletitle'], get_bloginfo( 'name' ), $args['separator'], the_title_attribute( array( 'echo' => false ) ) ); @@ -154,4 +154,4 @@ function json_feed_websub( $feed_types ) { } add_filter( 'pubsubhubbub_supported_feed_types', 'json_feed_websub' ); -require_once dirname( __FILE__ ) . '/feed-json-functions.php'; +require_once __DIR__ . '/feed-json-functions.php'; diff --git a/readme.txt b/readme.txt index d12f447..649cdb3 100644 --- a/readme.txt +++ b/readme.txt @@ -2,9 +2,9 @@ Contributors: mantonr, redsweater, dshanske Tags: jsonfeed, json, feed, feeds Requires at least: 4.9 -Tested up to: 6.2 -Requires PHP: 5.4 -Stable tag: 1.4.4 +Tested up to: 6.3 +Requires PHP: 5.6 +Stable tag: 1.4.5 License: GPL-2.0+ License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -47,6 +47,11 @@ This is a syndication format, which means it only represents your posts and comm == Changelog == += 1.4.5 = +* Sanity check on $max_page +* Add filter `jsonfeed_comments_feed_enable`, which if set to false will disable the comments feed header. +* Add mime type for jsonfeed to filter for W3C Cache Plugin per GitHub issue 67. + = 1.4.4 = * Fix declaration error