示例#1
0
 /**
  * Saves settings, applies filters, and loads settings into global variable
  *
  * Run from WP_CRM_C::WP_CRM_C()
  *
  * @since 0.01
  *
  */
 static function settings_action($force_db = false, $args = false)
 {
     global $wp_crm;
     // Process saving settings
     if (isset($_REQUEST['wp_crm']) && !empty($_REQUEST['_wpnonce']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'wp_crm_setting_save')) {
         // Handle backup
         if ($backup_file = $_FILES['wp_crm']['tmp_name']['settings_from_backup']) {
             $backup_contents = file_get_contents($backup_file);
             if (!empty($backup_contents)) {
                 $decoded_settings = json_decode($backup_contents, true);
             }
             if (!empty($decoded_settings)) {
                 $_REQUEST['wp_crm'] = $decoded_settings;
             }
         }
         $wp_crm_settings = apply_filters('wp_crm_settings_save', $_REQUEST['wp_crm'], $wp_crm);
         // Prevent removal of featured settings configurations if they are not present
         if (!empty($wp_crm['configuration']['feature_settings'])) {
             foreach ($wp_crm['configuration']['feature_settings'] as $feature_type => $preserved_settings) {
                 if (empty($_REQUEST['wp_crm']['configuration']['feature_settings'][$feature_type])) {
                     $wp_crm_settings['configuration']['feature_settings'][$feature_type] = $preserved_settings;
                 }
             }
         }
         //* Regenerate possible meta keys */
         $wp_crm_settings['data_structure'] = WP_CRM_F::build_meta_keys($wp_crm_settings);
         update_option('wp_crm_settings', $wp_crm_settings);
         // Load settings out of database to overwrite defaults from action_hooks.
         $wp_crm_db = get_option('wp_crm_settings');
         // Overwrite $wp_crm with database setting
         $wp_crm = array_merge($wp_crm, $wp_crm_db);
         // Reload page to make sure higher-end functions take affect of new settings
         // The filters below will be ran on reload, but the saving functions won't
         if ($_REQUEST['page'] == 'wp_crm_settings') {
         }
         unset($_REQUEST);
         wp_redirect(admin_url("admin.php?page=wp_crm_settings&message=updated"));
         exit;
     } else {
         //** Check if this is a new install */
         $check_crm_settings = get_option('wp_crm_settings');
         if (empty($check_crm_settings['configuration']) || $args['force_defaults'] == true) {
             $assumed_email = 'crm@' . $_SERVER['HTTP_HOST'];
             //* Load some basic data structure (need better place to put this) */
             $wp_crm['data_structure']['attributes']['display_name']['title'] = 'Display Name';
             $wp_crm['data_structure']['attributes']['display_name']['primary'] = 'true';
             $wp_crm['data_structure']['attributes']['display_name']['display'] = 'true';
             $wp_crm['data_structure']['attributes']['display_name']['input_type'] = 'text';
             $wp_crm['data_structure']['attributes']['display_name']['required'] = 'true';
             $wp_crm['data_structure']['attributes']['user_email']['title'] = 'User Email';
             $wp_crm['data_structure']['attributes']['user_email']['primary'] = 'true';
             $wp_crm['data_structure']['attributes']['user_email']['display'] = 'false';
             $wp_crm['data_structure']['attributes']['user_email']['input_type'] = 'text';
             $wp_crm['data_structure']['attributes']['user_email']['required'] = 'true';
             $wp_crm['data_structure']['attributes']['user_email']['overview_column'] = 'true';
             $wp_crm['data_structure']['attributes']['company']['title'] = 'Company';
             $wp_crm['data_structure']['attributes']['company']['input_type'] = 'text';
             $wp_crm['data_structure']['attributes']['company']['primary'] = 'true';
             $wp_crm['data_structure']['attributes']['company']['display'] = 'true';
             $wp_crm['data_structure']['attributes']['phone_number']['title'] = 'Phone Number';
             $wp_crm['data_structure']['attributes']['phone_number']['input_type'] = 'text';
             $wp_crm['data_structure']['attributes']['phone_number']['display'] = 'true';
             $wp_crm['data_structure']['attributes']['user_type']['title'] = 'Important Date';
             $wp_crm['data_structure']['attributes']['user_type']['options'] = 'Birthday, Anniversary';
             $wp_crm['data_structure']['attributes']['user_type']['input_type'] = 'date';
             $wp_crm['data_structure']['attributes']['user_type']['title'] = 'User Type';
             $wp_crm['data_structure']['attributes']['user_type']['options'] = 'Customer,Vendor,Employee';
             $wp_crm['data_structure']['attributes']['user_type']['input_type'] = 'checkbox';
             $wp_crm['data_structure']['attributes']['instant_messenger']['title'] = 'IM';
             $wp_crm['data_structure']['attributes']['instant_messenger']['options'] = 'Skype,Google Talk,AIM';
             $wp_crm['data_structure']['attributes']['instant_messenger']['input_type'] = 'text';
             $wp_crm['data_structure']['attributes']['instant_messenger']['allow_multiple'] = 'true';
             $wp_crm['data_structure']['attributes']['description']['title'] = 'Description';
             $wp_crm['data_structure']['attributes']['description']['input_type'] = 'textarea';
             $wp_crm['configuration']['overview_table_options']['main_view'] = array('display_name', 'user_email');
             $wp_crm['configuration']['default_sender_email'] = "CRM <{$assumed_email}>";
             $wp_crm['configuration']['primary_user_attribute'] = 'display_name';
             $wp_crm['wp_crm_contact_system_data']['example_form']['title'] = __('Example Shortcode Form', 'wp_crm');
             $wp_crm['wp_crm_contact_system_data']['example_form']['full_shortcode'] = '[wp_crm_form form=example_contact_form]';
             $wp_crm['wp_crm_contact_system_data']['example_form']['current_form_slug'] = 'example_contact_form';
             $wp_crm['wp_crm_contact_system_data']['example_form']['message_field'] = 'on';
             $wp_crm['wp_crm_contact_system_data']['example_form']['fields'] = array('display_name', 'user_email', 'company', 'phone_number');
             $wp_crm['notifications']['example']['subject'] = __('Thank your for your message!', 'wp_crm');
             $wp_crm['notifications']['example']['to'] = '[user_email]';
             $wp_crm['notifications']['example']['send_from'] = $assumed_email;
             $wp_crm['notifications']['example']['message'] = __("Hello [display_name],\nThank you, your message has been received.", 'wp_crm');
             $wp_crm['notifications']['example']['fire_on_action'] = array('example_form');
             $wp_crm['notifications']['message_notification']['subject'] = __('Message from Website', 'wp_crm');
             $wp_crm['notifications']['message_notification']['to'] = get_bloginfo('admin_email');
             $wp_crm['notifications']['message_notification']['send_from'] = $assumed_email;
             $wp_crm['notifications']['message_notification']['message'] = __("Shortcode Form: [trigger_action]\nSender Name: [display_name]\nSender Email: [user_email]\nMessage: [message_content]", 'wp_crm');
             $wp_crm['notifications']['message_notification']['fire_on_action'] = array('example_form');
             $wp_crm['data_structure'] = WP_CRM_F::build_meta_keys($wp_crm);
             //** Commit defaults to DB */
             update_option('wp_crm_settings', $wp_crm);
         }
     }
     if ($force_db) {
         //** Load settings out of database to overwrite defaults from action_hooks. */
         $wp_crm_db = get_option('wp_crm_settings');
         //* Overwrite $wp_crm with database setting */
         $wp_crm = array_merge($wp_crm, $wp_crm_db);
     }
     $wp_crm = stripslashes_deep($wp_crm);
     $wp_crm = apply_filters('wp_crm_settings', $wp_crm);
     return $wp_crm;
 }