/** * Delete a single custom option contained in the page or tab. * * @since 0.4.0 * @param string $handle The element handle. */ protected function _delete_single_field($handle) { ev_delete_option($handle); }
/** * When the page is refreshed, save the custom data contained in the admin page. * * @since 0.1.0 * @param string $group The group of the page that is being saved. */ public function save($group = '') { /* This should run on admin only. */ if (!is_admin()) { return; } /* Verify that we're submitting any data. */ if (empty($_POST)) { return; } /* Verify the validity of the supplied nonce. */ $nonce = isset($_POST['nonce']) ? $_POST['nonce'] : ''; $action = 'ev_admin_page'; $is_valid_nonce = wp_verify_nonce($nonce, $action); /* Check the user has the capability to save the page. */ $is_valid_cap = current_user_can($this->capability()); /* Exit if the nonce is invalid or the user doesn't have the required capability to save the page. */ if (!$is_valid_nonce || !$is_valid_cap) { return; } $elements = $this->elements(); if (!empty($elements)) { foreach ($elements as $index => $element) { if ($element['type'] === 'group' && $element['handle'] === $group) { foreach ($element['fields'] as $field) { if (!ev_is_skipped_on_saving($field['type'])) { if (!isset($_POST[$field['handle']])) { ev_delete_option($field['handle']); } else { $this->_save_single_field($field, $_POST[$field['handle']]); } } } break; } else { if (!ev_is_skipped_on_saving($element['type'])) { if (!isset($_POST[$element['handle']])) { ev_delete_option($element['handle']); } else { $this->_save_single_field($element, $_POST[$element['handle']]); } } } } $type = 'success'; $message = apply_filters('ev_save_options_tab_response_message', __('All saved!', 'ev_framework'), $type); $heading = apply_filters('ev_save_options_tab_response_heading', '', $type); $args = apply_filters("ev_save_options_tab_response_args[tab:{$group}]", array()); ev_ajax_message($message, $type, $heading, $args); } }