Skip to content

Commit

Permalink
improve update action
Browse files Browse the repository at this point in the history
  • Loading branch information
unfulvio committed Jun 24, 2015
1 parent 739bb91 commit e75e237
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,29 @@ public function options_page( ) {
* @param string $new_value
*/
public function updated_options( $option, $old_value, $new_value ) {
// Are we on the right option?

// Are we on the right option? Is there an update?
if ( $option == 'wp_currencies_settings' ) {
// Set new schedule.
if ( isset( $new_value['update_interval'] ) || isset( $old_value['update_interval'] ) ) {
$wp_currencies = get_option( 'wp_currencies_settings' );
$api_key = isset( $wp_currencies['api_key'] ) ? $wp_currencies['api_key'] : '';
if ( $old_value != $new_value ) {

// Makes sure we have an API key (won't tell if valid, but at least is not empty).
$api_key = isset( $new_value['api_key'] ) ? $new_value['api_key'] : ( isset( $old_value['api_key'] ) ? $old_value['api_key'] : '' );
if ( ! empty( $api_key ) ) {

wp_clear_scheduled_hook( 'wp_currencies_update' );

// Has this ever been scheduled before?
if ( ! wp_next_scheduled( 'wp_currencies_update' ) ) {
wp_schedule_event( time(), $new_value['update_interval'], 'wp_currencies_update' );
} else {
wp_reschedule_event( time(), $new_value['update_interval'], 'wp_currencies_update' );
}

}

}
}

}

}
Expand Down

0 comments on commit e75e237

Please sign in to comment.