From 050be1bb7fa0ae14d3d9dade9774db55f9e47255 Mon Sep 17 00:00:00 2001 From: Shady Sharaf Date: Tue, 25 Feb 2014 09:39:25 +0200 Subject: [PATCH] Correct handling of pre_update_option_ filter Fixes #116 --- includes/export.php | 27 +++++++++++++-------------- includes/settings.php | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/includes/export.php b/includes/export.php index 00ae3bc41..93882e673 100644 --- a/includes/export.php +++ b/includes/export.php @@ -39,22 +39,21 @@ public static function export() { public static function import() { $filename = 'notifications_import_rules'; - if ( empty( $_FILES[ WP_Stream_Settings::KEY ][ 'tmp_name' ][ $filename ] ) ) { - return; - } - - $tmpfile = $_FILES[ WP_Stream_Settings::KEY ][ 'tmp_name' ][ $filename ]; - $result = self::_import( file_get_contents( $tmpfile ) ); + if ( ! empty( $_FILES[ WP_Stream_Settings::KEY ][ 'tmp_name' ][ $filename ] ) ) { + $tmpfile = $_FILES[ WP_Stream_Settings::KEY ][ 'tmp_name' ][ $filename ]; + $result = self::_import( file_get_contents( $tmpfile ) ); - if ( $result ) { - list( $class, $message ) = $result; - add_settings_error( - WP_Stream_Settings::KEY, - 'imported', - $message, - $class - ); + if ( $result ) { + list( $class, $message ) = $result; + add_settings_error( + WP_Stream_Settings::KEY, + 'imported', + $message, + $class + ); + } } + return func_get_arg( 0 ); // This is filtering 'pre_update_option_' so must return the passed value } private static function _import( $contents ) { diff --git a/includes/settings.php b/includes/settings.php index bce19ca85..c994dd2b2 100644 --- a/includes/settings.php +++ b/includes/settings.php @@ -22,7 +22,7 @@ public static function load() { // Export function add_action( 'wp_ajax_wp_stream_notifications_export', array( 'WP_Stream_Notifications_Import_Export', 'export' ) ); - add_action( 'pre_update_option_' . WP_Stream_Settings::KEY, array( 'WP_Stream_Notifications_Import_Export', 'import' ) ); + add_filter( 'pre_update_option_' . WP_Stream_Settings::KEY, array( 'WP_Stream_Notifications_Import_Export', 'import' ) ); } public static function get_fields() {