Skip to content

Commit

Permalink
Merge pull request #1221 from alleyinteractive/fix/APPLE10-33/transient
Browse files Browse the repository at this point in the history
Update handling of transients and upgrades
  • Loading branch information
dlh01 authored Feb 12, 2025
2 parents c6bdf2c + 889c19b commit a28ad23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 7 additions & 3 deletions admin/apple-actions/index/class-channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ class Channel extends API_Action {
*/
public function perform() {
$channel = get_transient( 'apple_news_channel' );

if ( false === $channel ) {
$channel = '';

if ( $this->is_api_configuration_valid() ) {
try {
$channel = $this->get_api()->get_channel( $this->get_setting( 'api_channel' ) );
} catch ( Request_Exception $e ) {
$channel = '';
// Do nothing.
unset( $e );
}
}
}

set_transient( 'apple_news_channel', $channel, 300 );
set_transient( 'apple_news_channel', $channel, 300 );
}

if ( '' === $channel ) {
// Unable to get channel information. This likely means the user entered their API credentials incorrectly.
Expand Down
10 changes: 6 additions & 4 deletions includes/class-apple-news.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ public function __construct() {
);

add_action(
'init',
[ $this, 'action_init' ]
'admin_init',
[ $this, 'action_admin_init' ]
);

add_filter(
Expand Down Expand Up @@ -476,9 +476,11 @@ public function action_enqueue_block_editor_assets(): void {
/**
* Action hook callback for init.
*
* @since 1.3.0
* @since 2.7.0
* @since 2.6.2 as action_init()
* @since 1.3.0 as action_plugins_loaded()
*/
public function action_init(): void {
public function action_admin_init(): void {

// Determine if the database version and code version are the same.
$current_version = get_option( 'apple_news_version', '' );
Expand Down

0 comments on commit a28ad23

Please sign in to comment.