/**
  * Sanitizes TML settings
  *
  * This is the callback for register_setting()
  *
  * @since 6.0
  * @access public
  *
  * @param string|array $settings Settings passed in from filter
  * @return string|array Sanitized settings
  */
 function save_settings($settings)
 {
     global $theme_my_login;
     // Sanitize new settings
     $settings['page_id'] = absint($settings['page_id']);
     $settings['show_page'] = isset($settings['show_page']);
     $settings['enable_css'] = isset($settings['enable_css']);
     $settings['email_login'] = isset($settings['email_login']);
     $modules = isset($_POST['theme_my_login_modules']) ? $_POST['theme_my_login_modules'] : array();
     // If we have modules to activate
     if ($activate = array_diff((array) $modules, (array) $theme_my_login->options->get_option('active_modules'))) {
         // Attempt to activate them
         $result = $this->activate_modules($activate);
         // Check for WP_Error
         if (is_wp_error($result)) {
             // Loop through each module in the WP_Error object
             foreach ($result->get_error_data('modules_invalid') as $module => $wp_error) {
                 // Store the module and error message to a temporary array which will be passed to 'admin_notices'
                 if (is_wp_error($wp_error)) {
                     $theme_my_login->options->options['module_errors'][$module] = $wp_error->get_error_message();
                 }
             }
         }
     }
     // If we have modules to deactivate
     if ($deactivate = array_diff((array) $theme_my_login->options->get_option('active_modules'), $modules)) {
         // Deactive them
         $this->deactivate_modules($deactivate);
     }
     // Flush permalinks if they have changed
     if (isset($settings['permalinks'])) {
         foreach ($settings['permalinks'] as $action => $slug) {
             if ($slug !== $theme_my_login->options->get_option(array('permalinks', $action))) {
                 $settings['flush_rules'] = true;
                 break;
             }
         }
     }
     // Merge current settings
     $settings = Theme_My_Login::array_merge_recursive($theme_my_login->options->options, $settings);
     // Allow plugins/modules to add/modify settings
     $settings = apply_filters('tml_save_settings', $settings);
     return $settings;
 }
 /**
  * Merges arrays recursively, replacing duplicate string keys
  *
  * @since 6.0
  * @access public
  */
 function array_merge_recursive()
 {
     $args = func_get_args();
     $result = array_shift($args);
     foreach ($args as $arg) {
         foreach ($arg as $key => $value) {
             // Renumber numeric keys as array_merge() does.
             if (is_numeric($key)) {
                 if (!in_array($value, $result)) {
                     $result[] = $value;
                 }
             } elseif (array_key_exists($key, $result) && is_array($result[$key]) && is_array($value)) {
                 $result[$key] = Theme_My_Login::array_merge_recursive($result[$key], $value);
             } else {
                 $result[$key] = $value;
             }
         }
     }
     return $result;
 }