'title' => $title, 'data' => $data ); $this->update($profile_data); return $key; } public function get($key = '') { $profiles = get_option($this->option_key, array()); if (isset($profiles[$key])) { return $profiles[$key]; } return $profiles; } public function update($profile_data) { update_option($this->option_key, $profile_data); } public function delete($key) { if (in_array($key, $this->non_deletable_profiles)) { return false; } //*** $profile_data = $this->get(); unset($profile_data[$key]); $this->update($profile_data); return true; } public function get_current($data) { $profiles = $this->get(); if (!empty($profiles)) { foreach ($profiles as $key => $p) { if ($p['data'] === $data AND count($data) === count($p['data'])) { return array('key' => $key, 'title' => $p['title']); } } } return array(); } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //ajax public function load_profile() { if (!current_user_can('manage_woocommerce')) { die('0'); } if (!isset($_REQUEST['tools_panel_nonce']) || !wp_verify_nonce($_REQUEST['tools_panel_nonce'], 'woobe_tools_panel_nonce')) { die('0'); } $profile = $this->get(sanitize_text_field($_REQUEST['profile_key'])); if (!empty($profile)) { if (isset($profile['data']) AND ! empty($profile['data'])) { $options = $this->settings->get_options(); if (isset($options['fields']) AND ! empty($options['fields'])) { //set zero to all foreach ($options['fields'] as $key => $o) { $options['fields'][$key]['show'] = 0; } //collect columns from profile to set them on the top and ordered as they saved $new_columns_fields_structure = array(); foreach ($profile['data'] as $cid) { if (isset($options['fields'][$cid])) { $new_columns_fields_structure[$cid] = $options['fields'][$cid]; $new_columns_fields_structure[$cid]['show'] = 1; } } //remove columns from options which are in profile foreach ($options['fields'] as $key => $o) { if (isset($new_columns_fields_structure[$key])) { unset($options['fields'][$key]); } } $options['fields'] = array_merge($new_columns_fields_structure, $options['fields']); $this->settings->update_options($options); } } else { echo -1; } } else { echo -1; } exit; } //ajax public function create_profile() { if (!current_user_can('manage_woocommerce')) { die('0'); } if (!isset($_REQUEST['tools_panel_nonce']) || !wp_verify_nonce($_REQUEST['tools_panel_nonce'], 'woobe_tools_panel_nonce')) { die('0'); } $profile_title = sanitize_text_field(trim(htmlentities($_REQUEST['profile_title'], ENT_NOQUOTES))); if (!empty($profile_title)) { $columns = array(); foreach ($this->settings->get_fields(false) as $key => $f) { if (intval($f['show']) === 1) { $columns[] = $key; } } echo $this->create($columns, $profile_title); } exit; } //ajax public function delete_profile() { if (!current_user_can('manage_woocommerce')) { die('0'); } if (!isset($_REQUEST['tools_panel_nonce']) || !wp_verify_nonce($_REQUEST['tools_panel_nonce'], 'woobe_tools_panel_nonce')) { die('0'); } $this->delete(sanitize_text_field($_REQUEST['profile_key'])); exit; } //hook public function woobe_print_plugin_options($args) { $args['current_profile'] = $this->get_current(array_keys($this->settings->active_fields)); return $args; } }