Exemple #1
0
 /**
  * Processes and saves options array into Database
  * $option_sub_title variable toggles between 2 option formats:
  *	1) '' -  [option_1, option_2, ... , option_n]
  * 	2) '<subtitle>' -  <subtitle>[option_1, option_2, ... , option_n]
  *
  * Supports 'et_<plugin_name>_after_save_options' hook
  *
  * @return string
  */
 function process_and_update_options($options, $option_sub_title = '')
 {
     $this->dashboard_options = $this->get_options_array();
     $dashboard_options = $this->dashboard_options;
     $dashboard_sections = $this->dashboard_sections;
     $dashboard_options_assigned = $this->assigned_options;
     $error_message = '';
     $dashboard_options_temp = array();
     if (!is_array($options)) {
         $processed_array = str_replace(array('%5B', '%5D'), array('[', ']'), $options);
         parse_str($processed_array, $output);
         $array_prefix = true;
     } else {
         $output = $options;
         $array_prefix = false;
     }
     if (isset($dashboard_sections)) {
         foreach ($dashboard_sections as $key => $value) {
             $current_section = $key;
             if (isset($value['contents'])) {
                 foreach ($value['contents'] as $key => $value) {
                     $options_prefix = $current_section . '_' . $key;
                     $options_array = $dashboard_options_assigned[$current_section . '_' . $key . '_options'];
                     if (isset($options_array)) {
                         foreach ($options_array as $option) {
                             $current_option_name = '';
                             if (isset($option['name'])) {
                                 if ('' !== $option_sub_title) {
                                     $current_option_name = $option['name'];
                                 } else {
                                     $current_option_name = $options_prefix . '_' . $option['name'];
                                 }
                             }
                             //determine where the value is stored and set appropriate value as current
                             if (true === $array_prefix) {
                                 $current_option_value = isset($output['et_dashboard'][$current_option_name]) ? $output['et_dashboard'][$current_option_name] : false;
                             } else {
                                 $current_option_value = isset($output[$current_option_name]) ? $output[$current_option_name] : false;
                             }
                             if (isset($option['validation_type'])) {
                                 switch ($option['validation_type']) {
                                     case 'simple_array':
                                         $dashboard_options_temp[$current_option_name] = !empty($current_option_value) ? array_map('sanitize_text_field', $current_option_value) : array();
                                         break;
                                     case 'simple_text':
                                         $dashboard_options_temp[$current_option_name] = !empty($current_option_value) ? sanitize_text_field(stripslashes($current_option_value)) : '';
                                         if (function_exists('icl_register_string') && isset($option['is_wpml_string'])) {
                                             $wpml_option_name = '' !== $option_sub_title ? $current_option_name . '_' . $option_sub_title : $option_sub_title;
                                             icl_register_string($this->plugin_name, $wpml_option_name, sanitize_text_field($current_option_value));
                                         }
                                         break;
                                     case 'boolean':
                                         $dashboard_options_temp[$current_option_name] = !empty($current_option_value) ? in_array($current_option_value, array('1', false)) ? sanitize_text_field($current_option_value) : false : false;
                                         break;
                                     case 'number':
                                         $dashboard_options_temp[$current_option_name] = intval(stripslashes(!empty($current_option_value) ? absint($current_option_value) : ''));
                                         break;
                                     case 'complex_array':
                                         if (isset($current_option_name) && '' != $current_option_name) {
                                             if (!empty($current_option_value) && is_array($current_option_value)) {
                                                 foreach ($current_option_value as $key => $value) {
                                                     foreach ($value as $_key => $_value) {
                                                         $value[$_key] = sanitize_text_field($_value);
                                                     }
                                                     $current_option_value[$key] = $value;
                                                 }
                                                 $dashboard_options_temp[$current_option_name] = $current_option_value;
                                             }
                                         }
                                         break;
                                     case 'url':
                                         if (isset($current_option_name) && '' != $current_option_name) {
                                             $dashboard_options_temp[$current_option_name] = !empty($current_option_value) ? esc_url_raw(stripslashes($current_option_value)) : '';
                                         }
                                         break;
                                     case 'html':
                                         if (isset($current_option_name) && '' != $current_option_name) {
                                             $dashboard_options_temp[$current_option_name] = !empty($current_option_value) ? stripslashes(esc_html($current_option_value)) : '';
                                             if (function_exists('icl_register_string') && isset($option['is_wpml_string'])) {
                                                 $wpml_option_name = '' !== $option_sub_title ? $current_option_name . '_' . $option_sub_title : $option_sub_title;
                                                 icl_register_string($this->plugin_name, $wpml_option_name, esc_html($current_option_value));
                                             }
                                         }
                                         break;
                                 }
                                 // end switch
                             }
                             do_action('et_' . $this->plugin_name . '_after_save_options', $dashboard_options_temp, $current_option_name, $option, $output);
                         }
                         // end foreach( $options_array as $option )
                     }
                     //if ( isset( $options_array ) )
                 }
                 // end foreach( $value[ 'contents' ] as $key => $value )
             }
             // end if ( isset( $value[ 'contents' ] ) )
         }
         // end foreach ( $dashboard_sections as $key => $value )
     }
     //end if ( isset( $dashboard_sections ) )
     if ('' !== $option_sub_title) {
         $final_array[$option_sub_title] = $dashboard_options_temp;
     } else {
         $final_array = $dashboard_options_temp;
     }
     ET_Dashboard::update_option($final_array);
     if (!empty($final_array['sharing_locations_manage_locations']) && empty($final_array['sharing_networks_networks_sorting'])) {
         $error_message = $this->generate_modal_warning(__('Please select social networks in "Social Sharing / Networks" settings', 'et_dashboard'), '#tab_et_social_tab_content_sharing_networks');
     }
     return $error_message;
 }