Exemplo n.º 1
0
 /**
  * Performs removal of optin or account. Can remove parent optin, child optin or account
  * @return void
  */
 function perform_optin_removal($optin_id, $is_account = false, $service = '', $parent_id = '', $remove_child = true)
 {
     $options_array = ET_Bloom::get_bloom_options();
     if ('' !== $optin_id) {
         if ('true' == $is_account) {
             if ('' !== $service) {
                 if (isset($options_array['accounts'][$service][$optin_id])) {
                     unset($options_array['accounts'][$service][$optin_id]);
                     foreach ($options_array as $id => $details) {
                         if ('accounts' !== $id) {
                             if ($optin_id == $details['account_name']) {
                                 $options_array[$id]['email_provider'] = 'empty';
                                 $options_array[$id]['account_name'] = 'empty';
                                 $options_array[$id]['email_list'] = 'empty';
                                 $options_array[$id]['optin_status'] = 'inactive';
                             }
                         }
                     }
                     ET_Bloom::update_option($options_array);
                 }
             }
         } else {
             if ('' != $parent_id) {
                 $updated_array[$parent_id] = $options_array[$parent_id];
                 $new_child_optins = array();
                 foreach ($updated_array[$parent_id]['child_optins'] as $child) {
                     if ($child != $optin_id) {
                         $new_child_optins[] = $child;
                     }
                 }
                 $updated_array[$parent_id]['child_optins'] = $new_child_optins;
                 // change test status to 'inactive' if there is no child options after removal.
                 if (empty($new_child_optins)) {
                     $updated_array[$parent_id]['test_status'] = 'inactive';
                 }
                 ET_Bloom::update_option($updated_array);
             } else {
                 if (!empty($options_array[$optin_id]['child_optins']) && true == $remove_child) {
                     foreach ($options_array[$optin_id]['child_optins'] as $single_optin) {
                         ET_Bloom::remove_option($single_optin);
                         $this->remove_optin_from_db($single_optin);
                     }
                 }
             }
             ET_Bloom::remove_option($optin_id);
             $this->remove_optin_from_db($optin_id);
         }
     }
 }