get_class( 'settings' )->get_account_ids_by_access_token( $existing_access_token ); // Bail if no accounts are found. if ( count( $account_ids ) === 0 ) { return; } // Update the access and refresh tokens for each account. foreach ( $account_ids as $account_id ) { $wp_to_buffer->get_class( 'settings' )->update_account_credentials( $result['access_token'], $result['refresh_token'], $result['token_expires'], $account_id ); } } // Update Access Token when refreshed by the API class. add_action( 'wp_to_buffer_api_refresh_token', 'wp_to_buffer_update_credentials', 10, 3 ); /** * Schedules the WordPress Cron event to refresh the access token before it expires. * * Runs whenever an access token is refreshed, so that each token schedules the * refresh of its successor. * * @since 6.2.0 */ function wp_to_buffer_schedule_refresh_token_event() { WP_To_Buffer::get_instance()->get_class( 'cron' )->reschedule_refresh_token_event(); } // Schedule the next token refresh whenever a token is refreshed. add_action( 'wp_to_buffer_api_refresh_token', 'wp_to_buffer_schedule_refresh_token_event', 20 );