Skip to content

Commit

Permalink
Merge pull request #1155 from alleyinteractive/fix/channel-read-fatal
Browse files Browse the repository at this point in the history
Don't fatal on channel read failure
  • Loading branch information
kevinfodness authored Sep 3, 2024
2 parents 0899545 + f66ae79 commit 29fd125
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 8 deletions.
16 changes: 14 additions & 2 deletions admin/apple-actions/index/class-channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
}
4 changes: 3 additions & 1 deletion admin/partials/page-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

?>
<div class="wrap apple-news-settings">
<h1><?php esc_html_e( 'Manage Settings', 'apple-news' ); ?></h1>
<?php if ( Apple_News::is_initialized() ) : ?>
<?php if ( $apple_news_successful_update ) : ?>
<div class="notice notice-success">
<p><?php esc_html_e( 'The Apple News channel config has been successfully added.', 'apple-news' ); ?></p>
</div>
Expand Down
1 change: 1 addition & 0 deletions admin/settings/class-admin-apple-settings-section.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ public function save_settings() {
}

// Clear certain caches.
delete_transient( 'apple_news_channel' );
delete_transient( 'apple_news_sections' );

// Save to options.
Expand Down
2 changes: 1 addition & 1 deletion apple-news.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion includes/class-apple-news.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "publish-to-apple-news",
"version": "2.5.0",
"version": "2.5.1",
"license": "GPLv3",
"main": "index.php",
"engines": {
Expand Down
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 29fd125

Please sign in to comment.