Skip to content

Commit

Permalink
Correct handling of pre_update_option_ filter
Browse files Browse the repository at this point in the history
Fixes #116
  • Loading branch information
shadyvb committed Feb 25, 2014
1 parent d7b2036 commit 050be1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
27 changes: 13 additions & 14 deletions includes/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 050be1b

Please sign in to comment.