Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 61: Fire cron event if auto-purge value is updated #208

Merged
merged 3 commits into from
Feb 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static function load() {

// Auto purge setup
add_action( 'init', array( __CLASS__, 'purge_schedule_setup' ) );
add_action( 'stream_auto_purge', array( __CLASS__, 'purge_scheduled_action' ) );
add_action( 'wp_stream_auto_purge', array( __CLASS__, 'purge_scheduled_action' ) );

// Admin notices
add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) );
Expand Down
23 changes: 22 additions & 1 deletion includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public static function load() {
add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );

// Check if we need to flush rewrites rules
add_action( 'update_option_' . self::KEY , array( __CLASS__, 'updated_option_trigger_flush_rules' ), 10, 2 );
add_action( 'update_option_' . self::KEY, array( __CLASS__, 'updated_option_trigger_flush_rules' ), 10, 2 );

// Remove records when records TTL is shortened
add_action( 'update_option_' . self::KEY, array( __CLASS__, 'updated_option_ttl_remove_records' ), 10, 2 );

add_filter( 'wp_stream_serialized_labels', array( __CLASS__, 'get_settings_translations' ) );
}
Expand Down Expand Up @@ -401,4 +404,22 @@ public static function get_settings_translations( $labels ) {

return $labels;
}

/**
* Remove records when records TTL is shortened
*
* @param array $old_value
* @param array $new_value
*
* @action update_option_wp_stream
* @return void
*/
public function updated_option_ttl_remove_records( $old_value, $new_value ) {
$ttl_before = isset( $old_value['general_records_ttl'] ) ? (int) $old_value['general_records_ttl'] : -1;
$ttl_after = isset( $new_value['general_records_ttl'] ) ? (int) $new_value['general_records_ttl'] : -1;

if ( $ttl_after < $ttl_before ) {
do_action( 'wp_stream_auto_purge' );
}
}
}
2 changes: 1 addition & 1 deletion tests/tests/test-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function test_constructor() {
array( 'admin_enqueue_scripts', self::CLASSNAME, 'admin_menu_css' ),
array( 'wp_ajax_wp_stream_reset', self::CLASSNAME, 'wp_ajax_reset' ),
array( 'init', self::CLASSNAME, 'purge_schedule_setup' ),
array( 'stream_auto_purge', self::CLASSNAME, 'purge_scheduled_action' ),
array( 'wp_stream_auto_purge', self::CLASSNAME, 'purge_scheduled_action' ),
);

$this->do_action_validation( $test_actions );
Expand Down