diff --git a/admin/class-gdpr-admin.php b/admin/class-gdpr-admin.php index 87011773..139c0714 100755 --- a/admin/class-gdpr-admin.php +++ b/admin/class-gdpr-admin.php @@ -104,6 +104,7 @@ public function add_menu() { $icon_url = 'dashicons-id'; $requests = get_option( 'gdpr_requests', array() ); + $confirmed_requests = array_filter( $requests, function( $item ) { return true === $item['confirmed']; @@ -135,9 +136,16 @@ public function add_menu() { $settings_hook = add_submenu_page( $parent_slug, $menu_title, $menu_title, $capability, $menu_slug, $function ); + $menu_title = esc_html__( 'Export/Import', 'gdpr' ); + $menu_slug = 'gdpr-export'; + $function = array( $this, 'export_page_template' ); + + $export_hook = add_submenu_page( $parent_slug, $menu_title, $menu_title, $capability, $menu_slug, $function ); + add_action( "load-{$requests_hook}", array( 'GDPR_Help', 'add_requests_help' ) ); add_action( "load-{$tools_hook}", array( 'GDPR_Help', 'add_tools_help' ) ); add_action( "load-{$settings_hook}", array( 'GDPR_Help', 'add_settings_help' ) ); + add_action( "load-{$export_hook}", array( 'GDPR_Help', 'add_export_help' ) ); } /** @@ -514,6 +522,35 @@ public function audit_log() { wp_send_json_success( $log ); } + /** + * Export/Import Pluging Settings Page Template + * + * @since 1.0.0 + * @author Moutushi Mandal + */ + public function export_page_template() { + global $wpdb; + $setting_data = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}options WHERE option_name like 'gdpr_%'", ARRAY_A ); + $plugin_settings_json = array(); + $option_data = array(); + + if ( ! empty ( $setting_data ) ) { + foreach ( $setting_data as $value ) { + $temp_arr = array(); + $temp_arr['option_name'] = $value['option_name']; + $temp_arr['option_value'] = $value['option_value']; + $temp_arr['autoload'] = $value['autoload']; + + $option_data[] = $temp_arr; + } + } + $encrypt_key = 'TrewK123456789'; + $iv = openssl_random_pseudo_bytes( openssl_cipher_iv_length( 'aes-256-cbc' ) ); + $encrypted_plugin_settings_data = openssl_encrypt( json_encode( $option_data ), 'aes-256-cbc', $encrypt_key, 0, $iv ); + $gdpr_settings_data = base64_encode( $encrypted_plugin_settings_data . '::' . $iv ); + include plugin_dir_path( __FILE__ ) . 'partials/import_export_settings.php'; + } + public function review_settings_after_v2_notice() { // Check the transient to see if we've just updated the plugin if ( get_transient( 'gdpr_updated' ) && '2.0.0' === $this->version ) { @@ -1010,4 +1047,49 @@ public function sort_logic_for_consents_from_user_table( $query ) { } } + /** + * Import plugin settings + * @since 1.0.0 + * @author Moutushi Mandal + */ + public function gdpr_import_plugin_settings() { + if ( ! isset( $_POST['gdpr_settings_import_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['gdpr_settings_import_nonce'] ), 'gdpr-import-settings' ) ) { // phpcs:ignore + wp_send_json_error( esc_html__( 'We could not verify the security token. Please try again.', 'gdpr' ) ); + } + $settings_data = sanitize_text_field( wp_unslash( $_POST['import_settings'] ) ); + if ( ! empty ( $settings_data ) ) { + list( $encrypted_data, $iv ) = explode( '::', base64_decode( $settings_data ), 2 ); + $decrypted_plugin_settings = openssl_decrypt( $encrypted_data, 'aes-256-cbc', 'TrewK123456789', 0, $iv ); + $plugin_settings_data = json_decode( $decrypted_plugin_settings ); + + if ( ! empty ( $plugin_settings_data ) ) { + foreach( $plugin_settings_data as $option_data ) { + $option_name = sanitize_text_field( wp_unslash( $option_data->option_name ) ); + + if ( is_serialized( $option_data->option_value ) ) { + $option_value = maybe_unserialize( $option_data->option_value ); + } else { + $option_value = wp_filter_post_kses( $option_data->option_value ); + } + + $autoload = sanitize_text_field( wp_unslash( $option_data->autoload ) ); + update_option( $option_name, $option_value, $autoload ); + } + } + + } + GDPR_Audit_Log::log( $user->ID, sprintf( esc_html__( 'Plugin settings imported on %1$s.', 'gdpr' ), date( 'm/d/Y' ) ) ); + wp_safe_redirect( + esc_url_raw( + add_query_arg( + array( + 'settings-imported' => true, + ), + wp_get_referer() . '#import' + ) + ) + ); + exit; + } + } diff --git a/admin/partials/import_export_settings.php b/admin/partials/import_export_settings.php new file mode 100644 index 00000000..23205fc0 --- /dev/null +++ b/admin/partials/import_export_settings.php @@ -0,0 +1,39 @@ + +
+

+ + + + + + + +
+ diff --git a/includes/class-gdpr-help.php b/includes/class-gdpr-help.php index 77651d5a..403df6a3 100644 --- a/includes/class-gdpr-help.php +++ b/includes/class-gdpr-help.php @@ -186,4 +186,22 @@ public static function add_settings_help() { ) ); } + + /** + * Add the export data page help tabs. + * @since 1.0.0 + * @author Moutushi Mandal + * @static + */ + public static function add_export_help() { + $general_settings_help = '

' . esc_html__( 'Export Data', 'gdpr' ) . '

' . + '

' . esc_html__( 'Export plugin data.', 'gdpr' ) . '

'; + get_current_screen()->add_help_tab( + array( + 'id' => 'export_data', + 'title' => esc_html__( 'Export Data', 'gdpr' ), + 'content' => $general_export_data_help, + ) + ); + } } diff --git a/includes/class-gdpr.php b/includes/class-gdpr.php index a19d2ca5..050a8353 100755 --- a/includes/class-gdpr.php +++ b/includes/class-gdpr.php @@ -216,7 +216,8 @@ private function define_admin_hooks() { add_action( 'admin_post_gdpr_mark_resolved', array( $requests_admin, 'mark_resolved' ) ); add_action( 'wp_ajax_gdpr_anonymize_comments', array( $requests_admin, 'anonymize_comments' ) ); add_action( 'wp_ajax_gdpr_reassign_content', array( $requests_admin, 'reassign_content' ) ); - + add_action( 'admin_post_gdpr_import_settings', array( $plugin_admin, 'gdpr_import_plugin_settings' ) ); + // CRON JOBS add_action( 'clean_gdpr_requests', array( $requests, 'clean_requests' ) ); add_action( 'clean_gdpr_user_request_key', array( $requests, 'clean_user_request_key' ), 10, 2 ); diff --git a/src/js/admin.js b/src/js/admin.js index 8735d209..d68da0e7 100644 --- a/src/js/admin.js +++ b/src/js/admin.js @@ -315,4 +315,14 @@ $( function() { ); } ); + $( document ).on( 'click', '.copy-settings', function( e ) { + e.preventDefault(); + $( '#gdpr_settings_data' ).select(); + + //$( '#gdpr_settings_data' ).setSelectionRange( 0, 99999 ); /*For mobile devices*/ + + /* Copy the text inside the text field */ + document.execCommand( 'copy' ); + }); + } ); diff --git a/src/scss/admin.scss b/src/scss/admin.scss index 53339b97..79cb3ebc 100644 --- a/src/scss/admin.scss +++ b/src/scss/admin.scss @@ -220,3 +220,7 @@ } } } +.gdpr-import-msg{ + padding: 13px 0; + font-size: 17px; +}