/** * Update an option * * Updates an give setting value in both the db and the global variable. * Warning: Passing in an empty, false or null string value will remove * the key from the give_options array. * * @since 1.0 * * @param string $key The Key to update * @param string|bool|int $value The value to set the key to * * @return boolean True if updated, false if not. */ function give_update_option($key = '', $value = false) { // If no key, exit if (empty($key)) { return false; } if (empty($value)) { $remove_option = give_delete_option($key); return $remove_option; } // First let's grab the current settings $options = get_option('give_settings'); // Let's let devs alter that value coming in $value = apply_filters('give_update_option', $value, $key); // Next let's try to update the value $options[$key] = $value; $did_update = update_option('give_settings', $options); // If it updated, let's update the global variable if ($did_update) { global $give_options; $give_options[$key] = $value; } return $did_update; }
function give_license_key_callback($field_object, $escaped_value, $object_id, $object_type, $field_type_object) { $id = $field_type_object->field->args['id']; $field_description = $field_type_object->field->args['desc']; $license_status = get_option($field_type_object->field->args['options']['is_valid_license_option']); $field_classes = 'regular-text give-license-field'; $type = empty($escaped_value) ? 'text' : 'password'; if ($license_status === 'valid') { $field_classes .= ' give-license-active'; } $html = $field_type_object->input(array('class' => $field_classes, 'type' => $type)); //License is active so show deactivate button if ($license_status === 'valid') { $html .= '<input type="submit" class="button-secondary give-license-deactivate" name="' . $id . '_deactivate" value="' . __('Deactivate License', 'give') . '"/>'; } else { //This license is not valid so delete it give_delete_option($id); } $html .= '<label for="give_settings[' . $id . ']"> ' . $field_description . '</label>'; wp_nonce_field($id . '-nonce', $id . '-nonce'); echo $html; }