';
}
// Section callback function for file upload settings
function ppc3d_file_upload_settings_section_callback()
{
// Add the info icon with tooltip after the section title
echo '';
echo '
Configure options for the file upload section.
';
}
// Field callback function for printing technology options
function ppc3d_show_printing_technology_options_field_callback()
{
$enabled = get_option('ppc3d_enable_technology_options', 0);
if ($enabled) {
$saved_options = get_option('ppc3d_printing_technology_options', array());
?>
$option,
'value' => $value,
'description' => $description
);
update_option('ppc3d_printing_technology_options', $saved_options);
wp_send_json_success('Printing technology option added successfully.');
} else {
wp_send_json_error('Invalid request.');
}
wp_die(); // This is required to terminate immediately and return a proper response
}
add_action('wp_ajax_add_printing_technology_option', 'ppc3d_add_printing_technology_option_callback');
//Callback Function for Printing Technnology Option
function ppc3d_edit_printing_technology_option_callback()
{
// Verify nonce
if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ppc3d_upload_stl_nonce')) {
wp_send_json_error('Nonce verification failed.');
wp_die();
}
// Validate required fields
$required_fields = ['option_id', 'original_name', 'printing_technology', 'printing_technology_value', 'printing_technology_description'];
foreach ($required_fields as $field) {
if (!isset($_POST[$field])) {
wp_send_json_error("Missing required field: $field");
wp_die();
}
}
$old_option_id = sanitize_text_field(wp_unslash($_POST['option_id']));
$original_name = sanitize_text_field(wp_unslash($_POST['original_name']));
$new_option = sanitize_text_field(wp_unslash($_POST['printing_technology']));
$new_value = floatval($_POST['printing_technology_value']);
$new_description = sanitize_text_field(wp_unslash($_POST['printing_technology_description']));
// Get existing options
$saved_options = get_option('ppc3d_printing_technology_options', array());
// Check if original option exists
if (!isset($saved_options[$original_name])) {
wp_send_json_error('Original option not found.');
wp_die();
}
// Handle name change
if ($original_name !== $new_option) {
// Check if new name already exists (except for the current option)
if (isset($saved_options[$new_option])) {
wp_send_json_error('An option with this name already exists.');
wp_die();
}
// Create new entry with new name
$saved_options[$new_option] = [
'name' => $new_option,
'value' => $new_value,
'description' => $new_description
];
// Remove old entry
unset($saved_options[$original_name]);
} else {
// Just update the existing entry
$saved_options[$original_name] = [
'name' => $new_option,
'value' => $new_value,
'description' => $new_description
];
}
// Save updated options
if (update_option('ppc3d_printing_technology_options', $saved_options)) {
wp_send_json_success([
'message' => 'Option updated successfully',
'new_name' => $new_option,
'new_value' => $new_value,
'new_description' => $new_description
]);
} else {
wp_send_json_error('Failed to update option.');
}
wp_die();
}
add_action('wp_ajax_edit_printing_technology_option', 'ppc3d_edit_printing_technology_option_callback');
// Callback function to delete printing technology option
function ppc3d_delete_printing_technology_option_callback()
{
// Verify nonce
if (! isset($_POST['nonce']) || ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ppc3d_upload_stl_nonce')) {
// Nonce verification failed
wp_die('Nonce verification failed. Please refresh the page and try again.');
}
if (isset($_POST['optionName'])) {
$optionName = sanitize_text_field(wp_unslash($_POST['optionName']));
// Get current printing technology options
$printingTechnologyOptions = get_option('ppc3d_printing_technology_options', array());
// Check if the option exists
if (isset($printingTechnologyOptions[$optionName])) {
// Remove the option
unset($printingTechnologyOptions[$optionName]);
update_option('ppc3d_printing_technology_options', $printingTechnologyOptions);
// Return success response
wp_send_json_success();
} else {
// Return error response if the option does not exist
wp_send_json_error('Printing technology option does not exist.');
}
} else {
// Return error response if option name is not provided
wp_send_json_error('Option name not provided.');
}
}
add_action('wp_ajax_delete_printing_technology_option', 'ppc3d_delete_printing_technology_option_callback');
// Field callback function for material options
function ppc3d_show_material_options_field_callback()
{
$enabled = get_option('ppc3d_enable_material_options', 0);
if ($enabled) {
$saved_options = get_option('ppc3d_material_options', array());
?>
$option,
'value' => $value,
'description' => $description
);
update_option('ppc3d_material_options', $saved_options);
wp_send_json_success('Material option added successfully.');
} else {
wp_send_json_error('Invalid request.');
}
wp_die(); // This is required to terminate immediately and return a proper response
}
add_action('wp_ajax_add_material_option', 'ppc3d_add_material_option_callback');
function ppc3d_edit_material_option_callback()
{
// Verify nonce
if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ppc3d_upload_stl_nonce')) {
wp_send_json_error('Nonce verification failed.');
wp_die();
}
// Validate required fields
$required_fields = ['option_id', 'original_name', 'material', 'material_value', 'material_description'];
foreach ($required_fields as $field) {
if (!isset($_POST[$field])) {
wp_send_json_error("Missing required field: $field");
wp_die();
}
}
// Sanitize and prepare input data
$old_option_id = sanitize_text_field(wp_unslash($_POST['option_id']));
$original_name = sanitize_text_field(wp_unslash($_POST['original_name']));
$new_option = sanitize_text_field(wp_unslash($_POST['material']));
$new_value = floatval($_POST['material_value']);
$new_description = sanitize_text_field(wp_unslash($_POST['material_description']));
// Get existing options
$saved_options = get_option('ppc3d_material_options', array());
// Check if original option exists
if (!isset($saved_options[$original_name])) {
wp_send_json_error('Original option not found.');
wp_die();
}
// Handle name change
if ($original_name !== $new_option) {
// Check if new name already exists (except for the current option)
if (isset($saved_options[$new_option])) {
wp_send_json_error('An option with this name already exists.');
wp_die();
}
// Create new entry with new name
$saved_options[$new_option] = [
'name' => $new_option,
'value' => $new_value,
'description' => $new_description
];
// Remove old entry
unset($saved_options[$original_name]);
} else {
// Just update the existing entry
$saved_options[$original_name] = [
'name' => $new_option,
'value' => $new_value,
'description' => $new_description
];
}
// Save updated options
if (update_option('ppc3d_material_options', $saved_options)) {
wp_send_json_success([
'message' => 'Material option updated successfully',
'new_name' => $new_option,
'new_value' => $new_value,
'new_description' => $new_description
]);
} else {
wp_send_json_error('Failed to update material option.');
}
wp_die();
}
add_action('wp_ajax_edit_material_option', 'ppc3d_edit_material_option_callback');
// Callback function to delete material option
function ppc3d_delete_material_option_callback()
{
// Verify nonce
if (! isset($_POST['nonce']) || ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ppc3d_upload_stl_nonce')) {
// Nonce verification failed
wp_die('Nonce verification failed. Please refresh the page and try again.');
}
if (isset($_POST['optionName'])) {
$optionName = sanitize_text_field(wp_unslash($_POST['optionName']));
// Get current material options
$materialOptions = get_option('ppc3d_material_options', array());
// Check if the option exists
if (isset($materialOptions[$optionName])) {
// Remove the option
unset($materialOptions[$optionName]);
update_option('ppc3d_material_options', $materialOptions);
// Return success response
wp_send_json_success();
} else {
// Return error response if the option does not exist
wp_send_json_error('Material option does not exist.');
}
} else {
// Return error response if option name is not provided
wp_send_json_error('Option name not provided.');
}
}
add_action('wp_ajax_delete_material_option', 'ppc3d_delete_material_option_callback');
// Field callback function for quality options
function ppc3d_show_quality_options_field_callback()
{
$enabled = get_option('ppc3d_enable_quality_options', 0);
if ($enabled) {
$saved_options = get_option('ppc3d_quality_options', array());
?>
$value) : ?>
$option,
'value' => $value,
'description' => $description
);
update_option('ppc3d_quality_options', $saved_options);
wp_send_json_success('Quality option added successfully.');
wp_die();
}
add_action('wp_ajax_add_quality_option', 'ppc3d_add_quality_option_callback');
function ppc3d_edit_quality_option_callback()
{
// Verify nonce
if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ppc3d_upload_stl_nonce')) {
wp_send_json_error('Nonce verification failed.');
wp_die();
}
// Validate required fields
$required_fields = ['option_id', 'original_name', 'quality', 'quality_value', 'quality_description'];
foreach ($required_fields as $field) {
if (!isset($_POST[$field])) {
wp_send_json_error("Missing required field: $field");
wp_die();
}
}
$old_option_id = sanitize_text_field(wp_unslash($_POST['option_id']));
$original_name = sanitize_text_field(wp_unslash($_POST['original_name']));
$new_option = sanitize_text_field(wp_unslash($_POST['quality']));
$new_value = floatval($_POST['quality_value']);
$new_description = sanitize_text_field(wp_unslash($_POST['quality_description']));
// Get existing options
$saved_options = get_option('ppc3d_quality_options', array());
// Check if original option exists
if (!isset($saved_options[$original_name])) {
wp_send_json_error('Original option not found.');
wp_die();
}
// Handle name change
if ($original_name !== $new_option) {
// Check if new name already exists (except for the current option)
if (isset($saved_options[$new_option])) {
wp_send_json_error('An option with this name already exists.');
wp_die();
}
// Create new entry with new name
$saved_options[$new_option] = [
'name' => $new_option,
'value' => $new_value,
'description' => $new_description
];
// Remove old entry
unset($saved_options[$original_name]);
} else {
// Just update the existing entry
$saved_options[$original_name] = [
'name' => $new_option,
'value' => $new_value,
'description' => $new_description
];
}
// Save updated options
if (update_option('ppc3d_quality_options', $saved_options)) {
wp_send_json_success([
'message' => 'Option updated successfully',
'new_name' => $new_option,
'new_value' => $new_value,
'new_description' => $new_description
]);
} else {
wp_send_json_error('Failed to update option.');
}
wp_die();
}
add_action('wp_ajax_edit_quality_option', 'ppc3d_edit_quality_option_callback');
// Callback function to delete quality option
function ppc3d_delete_quality_option_callback()
{
// Verify nonce
if (! isset($_POST['nonce']) || ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ppc3d_upload_stl_nonce')) {
// Nonce verification failed
wp_die('Nonce verification failed. Please refresh the page and try again.');
}
if (isset($_POST['optionName'])) {
$optionName = sanitize_text_field(wp_unslash($_POST['optionName']));
// Get current quality options
$qualityOptions = get_option('ppc3d_quality_options', array());
// Check if the option exists
if (isset($qualityOptions[$optionName])) {
// Remove the option
unset($qualityOptions[$optionName]);
update_option('ppc3d_quality_options', $qualityOptions);
// Return success response
wp_send_json_success();
} else {
// Return error response if the option does not exist
wp_send_json_error('Quality option does not exist.');
}
} else {
// Return error response if option name is not provided
wp_send_json_error('Option name not provided.');
}
}
add_action('wp_ajax_delete_quality_option', 'ppc3d_delete_quality_option_callback');
// Field callback function for infill options
function ppc3d_show_infill_options_field_callback()
{
$enabled = get_option('ppc3d_enable_infill_options', 0);
if ($enabled) {
$saved_options = get_option('ppc3d_infill_options', array());
?>
$option,
'value' => $value,
'description' => $description
);
update_option('ppc3d_infill_options', $saved_options);
// Return success response
wp_send_json_success('Infill option added successfully.');
wp_die();
}
add_action('wp_ajax_add_infill_option', 'ppc3d_add_infill_option_callback');
//edit infill
function ppc3d_edit_infill_option_callback()
{
// Verify nonce
if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ppc3d_upload_stl_nonce')) {
wp_send_json_error('Nonce verification failed.');
wp_die();
}
// Validate required fields
$required_fields = ['infill_id', 'original_name', 'infill', 'infill_value', 'infill_description'];
foreach ($required_fields as $field) {
if (!isset($_POST[$field])) {
wp_send_json_error("Missing required field: $field");
wp_die();
}
}
$old_infill_id = sanitize_text_field(wp_unslash($_POST['infill_id']));
$original_name = sanitize_text_field(wp_unslash($_POST['original_name']));
$new_infill = sanitize_text_field(wp_unslash($_POST['infill']));
$new_value = floatval($_POST['infill_value']);
$new_description = sanitize_text_field(wp_unslash($_POST['infill_description']));
// Retrieve and update options
$saved_options = get_option('ppc3d_infill_options', array());
if (!isset($saved_options[$original_name])) {
wp_send_json_error('Original option not found.');
wp_die();
}
if ($original_name !== $new_infill) {
if (isset($saved_options[$new_infill])) {
wp_send_json_error('An option with this name already exists.');
wp_die();
}
$saved_options[$new_infill] = [
'value' => $new_value,
'description' => $new_description
];
unset($saved_options[$original_name]);
} else {
$saved_options[$original_name] = [
'value' => $new_value,
'description' => $new_description
];
}
if (update_option('ppc3d_infill_options', $saved_options)) {
wp_send_json_success('Option updated successfully.');
} else {
wp_send_json_error('Failed to update option.');
}
wp_die();
}
add_action('wp_ajax_edit_infill_option', 'ppc3d_edit_infill_option_callback');
// Callback function to delete infill option
function ppc3d_delete_infill_option_callback()
{
// Verify nonce
if (! isset($_POST['nonce']) || ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ppc3d_upload_stl_nonce')) {
// Nonce verification failed
wp_die('Nonce verification failed. Please refresh the page and try again.');
}
if (isset($_POST['optionName'])) {
$optionName = sanitize_text_field(wp_unslash($_POST['optionName']));
// Get current infill options
$infillOptions = get_option('ppc3d_infill_options', array());
// Check if the option exists
if (isset($infillOptions[$optionName])) {
// Remove the option
unset($infillOptions[$optionName]);
update_option('ppc3d_infill_options', $infillOptions);
// Return success response
wp_send_json_success();
} else {
// Return error response if the option does not exist
wp_send_json_error('Infill option does not exist.');
}
} else {
// Return error response if option name is not provided
wp_send_json_error('Option name not provided.');
}
}
add_action('wp_ajax_delete_infill_option', 'ppc3d_delete_infill_option_callback');
// Field callback function for color options
function ppc3d_show_color_options_field_callback()
{
$enabled = get_option('ppc3d_enable_color_options', 0);
if ($enabled) {
$saved_options = get_option('ppc3d_color_options', array());
?>
$value) :
$checked = $first ? 'checked' : ''; // Check the first option
$first = false; // Set flag to false after first option
?>
$option,
'value' => $value, // Color hex code
'price' => $price, // Price value
'description' => $description
);
update_option('ppc3d_color_options', $saved_options);
// Return success response
wp_send_json_success('Color option added successfully.');
wp_die();
}
add_action('wp_ajax_add_color_option', 'ppc3d_add_color_option_callback');
//Color ni siya
function ppc3d_edit_color_option_callback()
{
// Verify nonce
if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ppc3d_upload_stl_nonce')) {
wp_send_json_error('Nonce verification failed.');
wp_die();
}
// Validate required fields
$required_fields = ['color_id', 'original_name', 'color', 'color_value', 'color_price', 'color_description'];
foreach ($required_fields as $field) {
if (!isset($_POST[$field])) {
wp_send_json_error("Missing required field: $field");
wp_die();
}
}
$colorId = sanitize_text_field(wp_unslash($_POST['color_id']));
$originalName = sanitize_text_field(wp_unslash($_POST['original_name']));
$newColor = sanitize_text_field(wp_unslash($_POST['color']));
$newValue = sanitize_text_field(wp_unslash($_POST['color_value'])); // Color hex code
$newPrice = floatval($_POST['color_price']); // Price as float
$newDescription = sanitize_text_field(wp_unslash($_POST['color_description']));
// Get existing options
$saved_options = get_option('ppc3d_color_options', []);
// Handle name change
if ($originalName !== $newColor) {
if (isset($saved_options[$newColor])) {
wp_send_json_error('A color with this name already exists.');
wp_die();
}
// Create new entry with new name
$saved_options[$newColor] = [
'value' => $newValue,
'price' => $newPrice,
'description' => $newDescription,
];
// Remove old entry
unset($saved_options[$originalName]);
} else {
// Update existing entry
$saved_options[$originalName] = [
'value' => $newValue,
'price' => $newPrice,
'description' => $newDescription,
];
}
// Save updated options
if (update_option('ppc3d_color_options', $saved_options)) {
wp_send_json_success([
'message' => 'Color option updated successfully.',
'new_name' => $newColor,
'new_value' => $newValue,
'new_description' => $newDescription,
]);
} else {
wp_send_json_error('Failed to update color option.');
}
wp_die();
}
add_action('wp_ajax_edit_color_option', 'ppc3d_edit_color_option_callback');
// Callback function to delete color option
function ppc3d_delete_color_option_callback()
{
// Verify nonce
if (! isset($_POST['nonce']) || ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ppc3d_upload_stl_nonce')) {
// Nonce verification failed
wp_die('Nonce verification failed. Please refresh the page and try again.');
}
if (isset($_POST['optionName'])) {
$optionName = sanitize_text_field(wp_unslash($_POST['optionName']));
// Get current color options
$colorOptions = get_option('ppc3d_color_options', array());
// Check if the option exists
if (isset($colorOptions[$optionName])) {
// Remove the option
unset($colorOptions[$optionName]);
update_option('ppc3d_color_options', $colorOptions);
// Return success response
wp_send_json_success();
} else {
// Return error response if the option does not exist
wp_send_json_error('Color option does not exist.');
}
} else {
// Return error response if option name is not provided
wp_send_json_error('Option name not provided.');
}
}
add_action('wp_ajax_delete_color_option', 'ppc3d_delete_color_option_callback');
/**
* AJAX handler for saving individual settings
*/
function ppc3d_save_setting_callback()
{
// Check nonce for security
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'ppc3d_upload_stl_nonce')) {
wp_send_json_error('Security check failed');
}
// Get option name and value
$option_name = isset($_POST['option_name']) ? sanitize_text_field($_POST['option_name']) : '';
$option_value = isset($_POST['option_value']) ? sanitize_text_field($_POST['option_value']) : '';
// Validate option name
$valid_options = [
'ppc3d_stl_parser_cost_per_cc'
];
if (!in_array($option_name, $valid_options)) {
wp_send_json_error('Invalid option name');
}
// Update option in database
$result = update_option($option_name, $option_value);
if ($result) {
wp_send_json_success(['message' => 'Setting saved successfully']);
} else {
wp_send_json_error('Failed to update setting');
}
}
add_action('wp_ajax_ppc3d_save_setting', 'ppc3d_save_setting_callback');
// Add confirmation modal HTML at the end of the settings page
function ppc3d_add_confirmation_modal()
{
?>
×
Confirm Deletion
Are you sure you want to delete this item? This action cannot be undone.
Printing Technology Options
/>
|
Option Name
Description
Price Per CC
Actions
No options added yet. Click 'Add Option' to create
your first option.
Configure email addresses for notifications and invoices. These emails will be used when customers submit orders through the 3D Print Calculator.';
}
/**
* Notification email field callback
*/
function ppc3d_notification_email_field_callback()
{
$notification_email = get_option('ppc3d_notification_email', '');
echo '';
echo '
Email address that will receive notifications when new 3D print orders are submitted.
';
}
/**
* Invoice email field callback
*/
function ppc3d_invoice_email_field_callback()
{
$invoice_email = get_option('ppc3d_invoice_email', '');
echo '';
echo '
Email address that will be used as the sender for invoice emails to customers.