Skip to content

Commit

Permalink
Don't fatal on channel read failure
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinfodness committed Aug 30, 2024
1 parent 0899545 commit a30a699
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 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

0 comments on commit a30a699

Please sign in to comment.