From a30a699e232303fdd7eef3d8f48b894ddcb092b2 Mon Sep 17 00:00:00 2001 From: Kevin Fodness <2650828+kevinfodness@users.noreply.github.com> Date: Thu, 29 Aug 2024 20:52:35 -0400 Subject: [PATCH 1/2] Don't fatal on channel read failure --- admin/apple-actions/index/class-channel.php | 16 ++++++++++++++-- admin/partials/page-options.php | 4 +++- .../class-admin-apple-settings-section.php | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/admin/apple-actions/index/class-channel.php b/admin/apple-actions/index/class-channel.php index 13f5819a..48934e1c 100644 --- a/admin/apple-actions/index/class-channel.php +++ b/admin/apple-actions/index/class-channel.php @@ -9,7 +9,9 @@ require_once dirname( __DIR__ ) . '/class-api-action.php'; +use Admin_Apple_Notice; use Apple_Actions\API_Action; +use Apple_Push_API\Request\Request_Exception; /** * A class to handle a channel request from the admin. @@ -26,11 +28,21 @@ public function perform() { $channel = get_transient( 'apple_news_channel' ); if ( false === $channel ) { if ( $this->is_api_configuration_valid() ) { - $channel = $this->get_api()->get_channel( $this->get_setting( 'api_channel' ) ); - set_transient( 'apple_news_channel', $channel, 300 ); + try { + $channel = $this->get_api()->get_channel( $this->get_setting( 'api_channel' ) ); + } catch ( Request_Exception $e ) { + $channel = ''; + } } } + set_transient( 'apple_news_channel', $channel, 300 ); + + if ( '' === $channel ) { + // Unable to get channel information. This likely means the user entered their API credentials incorrectly. + Admin_Apple_Notice::error( __( 'Publish to Apple News error: Unable to get channel information. Please check your API credentials.', 'apple-news' ) ); + } + return ! empty( $channel ) ? $channel : null; } } diff --git a/admin/partials/page-options.php b/admin/partials/page-options.php index 17776de9..cc155b36 100644 --- a/admin/partials/page-options.php +++ b/admin/partials/page-options.php @@ -9,10 +9,12 @@ * @package Apple_News */ +$apple_news_successful_update = isset( $_POST['action'] ) && 'apple_news_options' === $_POST['action'] && Apple_News::is_initialized(); // phpcs:ignore WordPress.Security.NonceVerification.Missing + ?>

- +

diff --git a/admin/settings/class-admin-apple-settings-section.php b/admin/settings/class-admin-apple-settings-section.php index 4598d508..5ad1c7d6 100644 --- a/admin/settings/class-admin-apple-settings-section.php +++ b/admin/settings/class-admin-apple-settings-section.php @@ -638,6 +638,7 @@ public function save_settings() { } // Clear certain caches. + delete_transient( 'apple_news_channel' ); delete_transient( 'apple_news_sections' ); // Save to options. From f66ae79c081ed74b47c56562e1748c4aed92a8d4 Mon Sep 17 00:00:00 2001 From: Kevin Fodness <2650828+kevinfodness@users.noreply.github.com> Date: Thu, 29 Aug 2024 20:59:56 -0400 Subject: [PATCH 2/2] Bump plugin version to 2.5.1, update changelog --- apple-news.php | 2 +- includes/class-apple-news.php | 2 +- package.json | 2 +- readme.txt | 7 +++++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apple-news.php b/apple-news.php index e3353713..090ed089 100644 --- a/apple-news.php +++ b/apple-news.php @@ -14,7 +14,7 @@ * Plugin Name: Publish to Apple News * Plugin URI: http://github.com/alleyinteractive/apple-news * Description: Export and sync posts to Apple format. - * Version: 2.5.0 + * Version: 2.5.1 * Author: Alley * Author URI: https://alley.com * Text Domain: apple-news diff --git a/includes/class-apple-news.php b/includes/class-apple-news.php index efdeca47..c19955f5 100644 --- a/includes/class-apple-news.php +++ b/includes/class-apple-news.php @@ -50,7 +50,7 @@ class Apple_News { * @var string * @access public */ - public static string $version = '2.5.0'; + public static string $version = '2.5.1'; /** * Link to support for the plugin on WordPress.org. diff --git a/package.json b/package.json index f390f23f..2601af05 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "publish-to-apple-news", - "version": "2.5.0", + "version": "2.5.1", "license": "GPLv3", "main": "index.php", "engines": { diff --git a/readme.txt b/readme.txt index d2b02dae..0f8a478a 100644 --- a/readme.txt +++ b/readme.txt @@ -3,9 +3,9 @@ Contributors: potatomaster, kevinfodness, jomurgel, tylermachado, benpbolton, al Donate link: https://wordpress.org Tags: publish, apple, news, iOS Requires at least: 6.3 -Tested up to: 6.5.3 +Tested up to: 6.6.1 Requires PHP: 8.0 -Stable tag: 2.5.0 +Stable tag: 2.5.1 License: GPLv3 or later License URI: https://www.gnu.org/licenses/gpl.html @@ -45,6 +45,9 @@ Please visit our [wiki](https://github.com/alleyinteractive/apple-news/wiki) for == Changelog == += 2.5.1 = +* Bugfix: Fixed an issue where the plugin would crash if the Apple News API returned an error when fetching information about the configured channel. Now surfaces an admin notice with the error message instead. + = 2.5.0 = * Breaking Change: Removed support for per-article advertising settings, which have been deprecated by Apple. Advertising settings can now only be set at the channel level.