/**
  * Upgrades all the existing forms in the database to include the new fields and settings offered by the latest plugin version.
  *
  * @param array $default_fields An array containing the default form fields and their settings.
  * @param array $default_settings An array containing the default form settings.
  * @param array $default_emails An array containing the default emails.
  * @param array $default_custom_field An array containing the default custom field settings.
  * @param array $post_type The post type for which we want to upgrade the forms.
  **/
 public function upgrade_forms($default_fields, $default_settings, $default_emails, $default_custom_field, $post_type)
 {
     $forms = $this->get_forms(1, 1000, $post_type);
     if (is_array($forms) && count($forms)) {
         foreach ($forms as $key => $form) {
             $form_fields = $this->unserialize($form['fields']);
             $form_settings = $this->unserialize($form['settings']);
             $form_emails = $this->unserialize($form['emails']);
             $upgraded_fields = wpfepp_update_form_fields($form_fields, $default_fields, $default_custom_field);
             $upgraded_settings = wpfepp_update_array($form_settings, $default_settings);
             $upgraded_emails = wpfepp_update_array($form_emails, $default_emails);
             $this->db->update($this->table_name, array('fields' => $this->serialize($upgraded_fields), 'settings' => $this->serialize($upgraded_settings), 'emails' => $this->serialize($upgraded_emails)), array('id' => $form['id']));
         }
     }
 }
 /**
  * Adds settings that are not currently in the database. Used when the plugin is updated.
  *
  **/
 public function update_settings()
 {
     $current_media_settings = get_option('wpfepp_media_settings', array());
     $default_media_settings = array('max_upload_size' => 500, 'own_media_only' => '1', 'allowed_media_types' => array('image' => '1', 'video' => '0', 'text' => '0', 'audio' => '0', 'office' => '0', 'open_office' => '0', 'wordperfect' => '0', 'iwork' => '0', 'misc' => '0'), 'exempt_roles' => wpfepp_prepare_default_role_settings(), 'force_allow_uploads' => '0');
     $final_media_settings = wpfepp_update_array($current_media_settings, $default_media_settings);
     update_option('wpfepp_media_settings', $final_media_settings);
     $current_post_list_settings = get_option('wpfepp_post_list_settings', array());
     $default_post_list_settings = array('post_list_page_len' => '10', 'post_list_cols' => array('link' => '1', 'edit' => '1', 'delete' => '1'), 'post_list_tabs' => array('live' => '1', 'pending' => '1', 'draft' => '1'));
     $final_post_list_settings = wpfepp_update_array($current_post_list_settings, $default_post_list_settings);
     update_option('wpfepp_post_list_settings', $final_post_list_settings);
     $current_data_settings = get_option('wpfepp_data_settings', array());
     $default_data_settings = array('delete_on_uninstall' => '0');
     $final_data_settings = wpfepp_update_array($current_data_settings, $default_data_settings);
     update_option('wpfepp_data_settings', $final_data_settings);
     $current_errors = get_option('wpfepp_errors', array());
     $default_errors = array('form' => __("There are errors in your submission. Please try again.", 'wpfepp-plugin'), 'required' => __("This field is required.", 'wpfepp-plugin'), 'min_words' => __("Please enter atleast {0} words.", 'wpfepp-plugin'), 'max_words' => __("You can't enter more than {0} words.", 'wpfepp-plugin'), 'max_links' => __("You can't enter more than {0} links.", 'wpfepp-plugin'), 'min_segments' => __("Please enter atleast {0}.", 'wpfepp-plugin'), 'max_segments' => __("You can't enter more than {0}.", 'wpfepp-plugin'), 'invalid_email' => __("Please enter a valid email address.", 'wpfepp-plugin'), 'invalid_url' => __("Please enter a valid URL.", 'wpfepp-plugin'), 'copyscape' => __("The content you have entered is not original.", 'wpfepp-plugin'));
     $final_errors = wpfepp_update_array($current_errors, $default_errors);
     update_option('wpfepp_errors', $final_errors);
     $current_email_settings = get_option('wpfepp_email_settings', array());
     $default_email_settings = array('sender_address' => "", 'sender_name' => "", 'email_format' => 'plain');
     $final_email_settings = wpfepp_update_array($current_email_settings, $default_email_settings);
     update_option('wpfepp_email_settings', $final_email_settings);
     $current_copyscape_settings = get_option('wpfepp_copyscape_settings', array());
     $default_copyscape_settings = array('username' => "", 'api_key' => "", 'block' => false, 'column_types' => wpfepp_get_post_type_settings());
     $final_copyscape_settings = wpfepp_update_array($current_copyscape_settings, $default_copyscape_settings);
     update_option('wpfepp_copyscape_settings', $final_copyscape_settings);
     $current_recaptcha_settings = get_option('wpfepp_recaptcha_settings', array());
     $default_recaptcha_settings = array('site_key' => "", 'secret' => "", 'theme' => 'light');
     $final_recaptcha_settings = wpfepp_update_array($current_recaptcha_settings, $default_recaptcha_settings);
     update_option('wpfepp_recaptcha_settings', $final_recaptcha_settings);
 }